fixed comment hiding

This commit is contained in:
albert
2011-09-11 16:40:58 -04:00
parent 7483ad2e28
commit 3395c97c65
8 changed files with 60 additions and 7 deletions

View File

@@ -5,6 +5,7 @@
$("div.dtext-preview").hide(); $("div.dtext-preview").hide();
this.initialize_response_link(); this.initialize_response_link();
this.initialize_preview_button(); this.initialize_preview_button();
this.hide_threshold_comments();
} }
Danbooru.Comment.initialize_response_link = function() { Danbooru.Comment.initialize_response_link = function() {
@@ -31,6 +32,37 @@
}); });
}); });
} }
Danbooru.Comment.highlight_threshold_comments = function(post_id) {
var threshold = parseInt(Danbooru.meta("user-comment-threshold"));
var articles = $("article.comment[data-post-id=" + post_id + "]");
console.log("articles=%o", articles);
articles.each(function(i, v) {
var $comment = $(v);
console.log("testing %o", $comment);
if (parseInt($comment.data("score")) < threshold) {
$comment.addClass("below-threshold");
}
})
}
Danbooru.Comment.hide_threshold_comments = function(post_id) {
var threshold = parseInt(Danbooru.meta("user-comment-threshold"));
var articles = null;
if (post_id) {
articles = $("article.comment[data-post-id=" + post_id + "]");
} else {
articles = $("article.comment");
}
articles.each(function(i, v) {
var $comment = $(v);
if (parseInt($comment.data("score")) < threshold) {
$comment.hide();
}
});
}
})(); })();
$(document).ready(function() { $(document).ready(function() {

View File

@@ -539,7 +539,7 @@ div#c-pool-orders {
div.comments-for-post { div.comments-for-post {
div.list-of-comments { div.list-of-comments {
article { article.comment {
margin-bottom: 2em; margin-bottom: 2em;
div.author { div.author {
@@ -558,6 +558,14 @@ div.comments-for-post {
float: left; float: left;
} }
} }
article.comment.below-threshold {
opacity: 0.2;
}
article.comment.below-threshold:hover {
opacity: 1.0;
}
} }
div.comment-preview { div.comment-preview {

View File

@@ -40,7 +40,7 @@ private
def index_for_post def index_for_post
@post = Post.find(params[:post_id]) @post = Post.find(params[:post_id])
@comments = @post.comments @comments = @post.comments
@comments = @comments.visible unless params[:include_hidden] @comments = @comments.visible(CurrentUser.user) unless params[:include_below_threshold]
render :action => "index_for_post" render :action => "index_for_post"
end end

View File

@@ -1 +1,11 @@
$("div.comments-for-post[data-post-id=<%= @post.id %>] div.notices").hide(); $("#hidden-comments-notice-for-<%= @post.id %>").hide();
$("div.comments-for-post[data-post-id=<%= @post.id %>] div.list-of-comments").html("<%= j(render(:partial => 'comments/partials/show/comment', :collection => @comments))%>");
<% if params[:include_below_threshold] %>
$("#threshold-comments-notice-for-<%= @post.id %>").hide();
Danbooru.Comment.highlight_threshold_comments(<%= @post.id %>);
<% else %>
Danbooru.Comment.hide_threshold_comments(<%= @post.id %>);
<% end %>

View File

@@ -33,12 +33,12 @@
<div class="row notices"> <div class="row notices">
<% if post.comments.count > 6 %> <% if post.comments.count > 6 %>
<span class="info" id="hidden-comments-notice-for-<%= post.id %>"%> <span class="info" id="hidden-comments-notice-for-<%= post.id %>"%>
<%= link_to "#{pluralize(post.comments.size, 'comment')} hidden", comments_path(:post_id => post.id), :remote => true %>. <%= link_to "#{pluralize(post.comments.size, 'comment')} hidden", comments_path(:post_id => post.id), :remote => true %>
</span> </span>
<% end %> <% end %>
<% if post.comments.hidden(CurrentUser.user).count > 0 %> <% if post.comments.hidden(CurrentUser.user).count > 0 %>
<span class="info" id="threshold-comments-notice-for-<%= post.id %>"%> <span class="info" id="threshold-comments-notice-for-<%= post.id %>"%>
<%= link_to "#{pluralize(post.comments.hidden(CurrentUser.user).count, 'comment')} below threshold", comments_path(:post_id => post.id, :include_hidden => true), :remote => true %>. <%= link_to "#{pluralize(post.comments.hidden(CurrentUser.user).count, 'comment')} below threshold", comments_path(:post_id => post.id, :include_below_threshold => true), :remote => true %>
</span> </span>
<% end %> <% end %>
</div> </div>

View File

@@ -1,4 +1,4 @@
<article data-comment-id="<%= comment.id %>"> <article class="comment" data-post-id="<%= comment.post_id %>" data-comment-id="<%= comment.id %>" data-score="<%= comment.score %>">
<div class="author"> <div class="author">
<h1><%= link_to comment.creator_name, user_path(comment.creator_id) %></h1> <h1><%= link_to comment.creator_name, user_path(comment.creator_id) %></h1>
<p> <p>

View File

@@ -7,6 +7,7 @@
<%= csrf_meta_tag %> <%= csrf_meta_tag %>
<meta name="current-user-name" content="<%= CurrentUser.name %>"> <meta name="current-user-name" content="<%= CurrentUser.name %>">
<meta name="current-user-id" content="<%= CurrentUser.id %>"> <meta name="current-user-id" content="<%= CurrentUser.id %>">
<meta name="user-comment-threshold" content="<%= CurrentUser.comment_threshold %>">
<% unless CurrentUser.user.blacklisted_tags.blank? %> <% unless CurrentUser.user.blacklisted_tags.blank? %>
<meta name="blacklisted-tags" content="<%= CurrentUser.user.blacklisted_tags %>"> <meta name="blacklisted-tags" content="<%= CurrentUser.user.blacklisted_tags %>">
<% end %> <% end %>

View File

@@ -45,7 +45,9 @@ end
if Comment.count == 0 if Comment.count == 0
puts "Creating comments" puts "Creating comments"
Post.all.each do |post| Post.all.each do |post|
Comment.create(:post_id => post.id, :body => rand(1_000_000).to_s) 20.times do
Comment.create(:post_id => post.id, :body => rand(1_000_000).to_s)
end
end end
else else
puts "Skipping comments" puts "Skipping comments"