enable blacklists in comments, wiki pages

This commit is contained in:
albert
2013-02-18 19:11:30 -05:00
parent 85f3a79e9d
commit 8a66470975
8 changed files with 63 additions and 45 deletions

View File

@@ -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();
}
}
})();

View File

@@ -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;

View File

@@ -88,5 +88,9 @@ div#c-comments {
width: 55em;
}
}
div.post.blacklisted {
display: none;
}
}
}

View File

@@ -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;
}

View File

@@ -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

View File

@@ -7,7 +7,7 @@
<% end %>
<% @posts.each do |post| %>
<div class="post">
<div class="post post-preview" data-tags="<%= post.tag_string %>" data-uploader="<%= post.uploader_name %>" data-rating="<%= post.rating %>" data-flags="<%= post.status %>" data-score="<%= post.score %>">
<div class="preview">
<%= link_to(image_tag(post.preview_file_url), post_path(post)) %>
</div>

View File

@@ -11,8 +11,7 @@
<section id="blacklist-box">
<h1>Blacklisted</h1>
<%= link_to "Hidden", "#" %>
<ul>
<ul id="blacklist-list">
</ul>
</section>
</aside>

View File

@@ -7,4 +7,10 @@
</section>
<%= render "wiki_pages/recent_changes" %>
<section id="blacklist-box">
<h1>Blacklisted</h1>
<ul id="blacklist-list">
</ul>
</section>
</aside>