From f24d6a6e83d9c85602dd66aa4951e995fad50e4f Mon Sep 17 00:00:00 2001 From: albert Date: Fri, 5 Apr 2013 16:59:51 -0400 Subject: [PATCH] fixes #697 --- app/assets/javascripts/blacklists.js | 66 ++++++++----------- .../stylesheets/specific/posts.css.scss | 4 ++ 2 files changed, 33 insertions(+), 37 deletions(-) diff --git a/app/assets/javascripts/blacklists.js b/app/assets/javascripts/blacklists.js index c3da6b8b5..55cc226c7 100644 --- a/app/assets/javascripts/blacklists.js +++ b/app/assets/javascripts/blacklists.js @@ -31,33 +31,23 @@ }); } - Danbooru.Blacklist.show_entry = function(e) { - $(".blacklisted").addClass("blacklisted-active"); - - Danbooru.Blacklist.posts().each(function(i, post) { - var $post = $(post); - var tag = $(e.target).html(); - var entry = Danbooru.Blacklist.parse_entry(tag); - - if (Danbooru.Blacklist.post_match($post, entry)) { - $post.removeClass("blacklisted-active"); + Danbooru.Blacklist.toggle_entry = function(e) { + var tags = $(e.target).html(); + var match = $.grep(Danbooru.Blacklist.entries, function(entry, i) { + return entry.tags === tags; + })[0]; + if (match) { + match.disabled = !match.disabled; + if (match.disabled) { + $(e.target).addClass("blacklisted-active"); + } else { + $(e.target).removeClass("blacklisted-active"); } - }); - } - - Danbooru.Blacklist.toggle_all = function(e) { - if ($(".blacklisted-active").length) { - $(".blacklisted").removeClass("blacklisted-active"); - } else { - $(".blacklisted").addClass("blacklisted-active"); } + Danbooru.Blacklist.apply(); } Danbooru.Blacklist.update_sidebar = function() { - if (this.entries.length > 0) { - this.entries.unshift({"tags": "~all~", "hits": -1}); - } - $.each(this.entries, function(i, entry) { if (entry.hits === 0) { return; @@ -67,19 +57,12 @@ var link = $(""); var count = $(""); - if (entry.tags === "~all~") { - link.html("All"); - link.click(Danbooru.Blacklist.toggle_all); - item.append(link); - item.append(" "); - } else { - link.html(entry.tags); - link.click(Danbooru.Blacklist.show_entry); - count.html(entry.hits); - item.append(link); - item.append(" "); - item.append(count); - } + link.html(entry.tags); + link.click(Danbooru.Blacklist.toggle_entry); + count.html(entry.hits); + item.append(link); + item.append(" "); + item.append(count); $("#blacklist-list").append(item); }); @@ -95,13 +78,19 @@ var count = 0 $.each(this.posts(), function(i, post) { + var post_count = 0; $.each(Danbooru.Blacklist.entries, function(i, entry) { if (Danbooru.Blacklist.post_match(post, entry)) { - Danbooru.Blacklist.post_hide(post); entry.hits += 1; count += 1; + post_count += 1; } }); + if (post_count > 0) { + Danbooru.Blacklist.post_hide(post); + } else { + $(post).removeClass("blacklisted-active"); + } }); return count; @@ -112,6 +101,10 @@ } Danbooru.Blacklist.post_match = function(post, entry) { + if (entry.disabled) { + return false; + } + var $post = $(post); var tags = String($post.data("tags")).match(/\S+/g) || []; tags.push("rating:" + $post.data("rating")); @@ -119,7 +112,6 @@ $.each(String($post.data("flags")).match(/\S+/g) || [], function(i, v) { tags.push("status:" + v); }); - return (entry.require.length > 0 || entry.exclude.length > 0) && Danbooru.is_subset(tags, entry.require) && !Danbooru.intersect(tags, entry.exclude).length; } diff --git a/app/assets/stylesheets/specific/posts.css.scss b/app/assets/stylesheets/specific/posts.css.scss index 8327bb04b..b8a907d1e 100644 --- a/app/assets/stylesheets/specific/posts.css.scss +++ b/app/assets/stylesheets/specific/posts.css.scss @@ -14,6 +14,10 @@ article.post-preview { } } +a.blacklisted-active { + font-weight: bold; +} + .post-preview.blacklisted-active { display: none; }