From 8a66470975990532b6b8cb25042136d27f228ea4 Mon Sep 17 00:00:00 2001 From: albert Date: Mon, 18 Feb 2013 19:11:30 -0500 Subject: [PATCH] enable blacklists in comments, wiki pages --- app/assets/javascripts/blacklists.js | 57 +++++++++++-------- .../stylesheets/common/main_layout.css.scss | 17 ++++++ .../stylesheets/specific/comments.css.scss | 4 ++ .../stylesheets/specific/posts.css.scss | 17 ------ app/controllers/comments_controller.rb | 2 +- app/views/comments/index_by_post.html.erb | 2 +- app/views/favorites/index.html.erb | 3 +- app/views/wiki_pages/_sidebar.html.erb | 6 ++ 8 files changed, 63 insertions(+), 45 deletions(-) diff --git a/app/assets/javascripts/blacklists.js b/app/assets/javascripts/blacklists.js index 0e5ce4835..66e6b09c0 100644 --- a/app/assets/javascripts/blacklists.js +++ b/app/assets/javascripts/blacklists.js @@ -3,24 +3,30 @@ Danbooru.Blacklist.blacklists = []; + Danbooru.Blacklist.parse_entry = function(string) { + var blacklist = { + "tags": string, + "require": [], + "exclude": [], + "disabled": false, + "hits": 0 + }; + var matches = string.match(/\S+/g) || []; + $.each(matches, function(i, tag) { + if (tag.charAt(0) === '-') { + blacklist.exclude.push(tag.slice(1)); + } else { + blacklist.require.push(tag); + } + }); + return blacklist; + } + Danbooru.Blacklist.parse_entries = function() { var entries = (Danbooru.meta("blacklisted-tags") || "[]").replace(/(rating:[qes])\w+/, "$1").split(/,/); + $.each(entries, function(i, tags) { - var blacklist = { - "tags": tags, - "require": [], - "exclude": [], - "disabled": false, - "hits": 0 - }; - var matches = tags.match(/\S+/g) || []; - $.each(matches, function(i, tag) { - if (tag.charAt(0) === '-') { - blacklist.exclude.push(tag.slice(1)); - } else { - blacklist.require.push(tag); - } - }) + var blacklist = Danbooru.Blacklist.parse_entry(tags); Danbooru.Blacklist.blacklists.push(blacklist); }); } @@ -29,7 +35,12 @@ $(".blacklisted").each(function(i, element) { var $element = $(element); if ($element.hasClass("blacklisted-active")) { - $element.removeClass("blacklisted-active"); + var tag = $(e.target).html(); + var blacklist = Danbooru.Blacklist.parse_entry(tag); + + if (Danbooru.Blacklist.post_match($element, blacklist)) { + $element.removeClass("blacklisted-active"); + } } else { $element.addClass("blacklisted-active"); } @@ -104,14 +115,12 @@ } Danbooru.Blacklist.initialize_all = function() { - if ($("#c-posts").length || $("#c-favorites").length || $("#c-pools").length) { - Danbooru.Blacklist.parse_entries(); - - if (Danbooru.Blacklist.apply() > 0) { - Danbooru.Blacklist.update_sidebar(); - } else { - $("#blacklist-box").hide(); - } + Danbooru.Blacklist.parse_entries(); + + if (Danbooru.Blacklist.apply() > 0) { + Danbooru.Blacklist.update_sidebar(); + } else { + $("#blacklist-box").hide(); } } })(); diff --git a/app/assets/stylesheets/common/main_layout.css.scss b/app/assets/stylesheets/common/main_layout.css.scss index 8df49fe4a..3756e36e2 100644 --- a/app/assets/stylesheets/common/main_layout.css.scss +++ b/app/assets/stylesheets/common/main_layout.css.scss @@ -45,6 +45,23 @@ div#page { margin-bottom: 1em; } + aside#sidebar > section#blacklist-box ul { + margin-left: 1em; + + li { + list-style-type: disc; + } + + a { + color: $link_color; + cursor: pointer; + } + + span { + color: #AAA; + } + } + section#content { width: 70%; float: left; diff --git a/app/assets/stylesheets/specific/comments.css.scss b/app/assets/stylesheets/specific/comments.css.scss index 51609865a..b53e3b264 100644 --- a/app/assets/stylesheets/specific/comments.css.scss +++ b/app/assets/stylesheets/specific/comments.css.scss @@ -88,5 +88,9 @@ div#c-comments { width: 55em; } } + + div.post.blacklisted { + display: none; + } } } diff --git a/app/assets/stylesheets/specific/posts.css.scss b/app/assets/stylesheets/specific/posts.css.scss index 13a079aeb..516f74f44 100644 --- a/app/assets/stylesheets/specific/posts.css.scss +++ b/app/assets/stylesheets/specific/posts.css.scss @@ -140,23 +140,6 @@ div#c-posts { margin-left: 1em; } - aside#sidebar > section#blacklist-box ul { - margin-left: 1em; - - li { - list-style-type: disc; - } - - a { - color: $link_color; - cursor: pointer; - } - - span { - color: #AAA; - } - } - h1 { font-size: $h3_size; } diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 626fea31b..cc6a63b64 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -63,7 +63,7 @@ private end def index_by_post - @posts = Post.commented_before(Time.now).tag_match(params[:tags]).paginate(params[:page]) + @posts = Post.commented_before(Time.now).tag_match(params[:tags]).paginate(params[:page], :limit => 5) respond_with(@posts) do |format| format.html {render :action => "index_by_post"} end diff --git a/app/views/comments/index_by_post.html.erb b/app/views/comments/index_by_post.html.erb index e520ff501..bb28df264 100644 --- a/app/views/comments/index_by_post.html.erb +++ b/app/views/comments/index_by_post.html.erb @@ -7,7 +7,7 @@ <% end %> <% @posts.each do |post| %> -
+
<%= link_to(image_tag(post.preview_file_url), post_path(post)) %>
diff --git a/app/views/favorites/index.html.erb b/app/views/favorites/index.html.erb index 807fca9c9..64cf5981a 100644 --- a/app/views/favorites/index.html.erb +++ b/app/views/favorites/index.html.erb @@ -11,8 +11,7 @@

Blacklisted

- <%= link_to "Hidden", "#" %> -
    +
diff --git a/app/views/wiki_pages/_sidebar.html.erb b/app/views/wiki_pages/_sidebar.html.erb index 77445d8ea..f6f3884d1 100644 --- a/app/views/wiki_pages/_sidebar.html.erb +++ b/app/views/wiki_pages/_sidebar.html.erb @@ -7,4 +7,10 @@ <%= render "wiki_pages/recent_changes" %> + +
+

Blacklisted

+
    +
+