rebuilt comment tree DOM structure as valid HTML

This commit is contained in:
Serge Paquet 2014-01-15 22:25:20 -05:00
parent 41c9dfad5d
commit 42ce1e3b4c
8 changed files with 36 additions and 34 deletions

View file

@ -32,7 +32,7 @@ var _Lobsters = Class.extend({
if (!Lobsters.curUser)
return Lobsters.bounceToLogin();
var li = $(voterEl).parents("li").first();
var li = $(voterEl).closest(".story, .comment");
if (li.hasClass("downvoted")) {
/* already upvoted, neutralize */
Lobsters.vote(thingType, voterEl, -1, null);
@ -91,7 +91,7 @@ var _Lobsters = Class.extend({
if (!Lobsters.curUser)
return Lobsters.bounceToLogin();
var li = $(voterEl).parents("li").first();
var li = $(voterEl).closest(".story, .comment");
var scoreDiv = li.find("div.score").get(0);
var score = parseInt(scoreDiv.innerHTML);
var action = "";
@ -136,7 +136,7 @@ var _Lobsters = Class.extend({
Lobsters.commentDownvoteReasons[reason].toLowerCase() + ")");
$.post("/" + (thingType == "story" ? "stories" : thingType + "s") + "/" +
$(voterEl).parents("li").first().attr("data-shortid") + "/" +
li.attr("data-shortid") + "/" +
action, { reason: reason });
},
@ -225,11 +225,11 @@ var _Lobsters = Class.extend({
var Lobsters = new _Lobsters();
$(document).ready(function() {
$("li.comment a.downvoter").click(function() {
$(".comment a.downvoter").click(function() {
Lobsters.downvoteComment(this);
return false;
});
$("li.comment a.upvoter").click(function() {
$(".comment a.upvoter").click(function() {
Lobsters.upvoteComment(this);
return false;
});
@ -279,7 +279,7 @@ $(document).ready(function() {
$(document).on("click", "a.comment_deletor", function() {
if (confirm("Are you sure you want to delete this comment?")) {
var li = $(this).parents("li.comment").first();
var li = $(this).closest(".comment");
$.post("/comments/" + $(li).attr("data-shortid") + "/delete",
function(d) {
$(li).replaceWith(d);
@ -289,7 +289,7 @@ $(document).ready(function() {
$(document).on("click", "a.comment_undeletor", function() {
if (confirm("Are you sure you want to undelete this comment?")) {
var li = $(this).parents("li.comment").first();
var li = $(this).closest(".comment");
$.post("/comments/" + $(li).attr("data-shortid") + "/undelete",
function(d) {
$(li).replaceWith(d);

View file

@ -402,7 +402,7 @@ div.voters .downvoter {
}
div.voters .upvoter:hover,
li.upvoted div.voters .upvoter {
.upvoted div.voters .upvoter {
border-bottom-color: #ac130d;
}
@ -419,7 +419,7 @@ div.voters .downvoter {
border-top-width: 9px;
}
div.voters .downvoter:hover,
li.downvoted div.voters .downvoter {
.downvoted div.voters .downvoter {
border-top-color: gray;
}
@ -428,17 +428,17 @@ div.voters .downvoter.downvoter_stub {
}
li.story,
li.comment {
.comment {
clear: both;
padding-top: 0.4em;
padding-bottom: 0.4em;
}
li.comment {
.comment {
padding-top: 0.5em;
padding-bottom: 0.5em;
}
li.comment a {
.comment a {
color: #666;
}
@ -449,21 +449,21 @@ li div.details {
padding-top: 0.1em;
}
li.negative {
.negative {
opacity: 0.7;
color: gray !important;
}
li.negative_3 {
.negative_3 {
opacity: 0.4;
}
li.negative_5 {
.negative_5 {
opacity: 0.3;
}
li.negative_7 {
.negative_7 {
opacity: 0.2;
}
li.comment.highlighted {
.comment.highlighted {
background-color: #ffffbf;
}
@ -677,6 +677,9 @@ div.markdown_help_label {
cursor: pointer;
}
.comment .preview {
padding-left: 25px;
}
div#story_preview {
margin-top: 2em;

View file

@ -1,4 +1,4 @@
<li id="comment_<%= comment.short_id %>" data-shortid="<%= comment.short_id %>"
<div id="comment_<%= comment.short_id %>" data-shortid="<%= comment.short_id %>"
class="comment <%= comment.current_vote ? (comment.current_vote[:vote] == 1 ?
"upvoted" : "downvoted") : "" %>
<%= comment.highlighted ? "highlighted" : "" %>
@ -92,7 +92,7 @@ class="comment <%= comment.current_vote ? (comment.current_vote[:vote] == 1 ?
<% end %>
</div>
</div>
</li>
</div>
<% if comment.highlighted %>
<script>

View file

@ -1,5 +1,4 @@
<li class="comment">
<div class="comment_form_container">
<div class="comment comment_form_container">
<%= form_tag comment.new_record? ?
"/comments/post_to/#{comment.story.short_id}" :
"/comments/#{comment.short_id}/update" do |f| %>
@ -44,9 +43,8 @@
<p></p>
<% end %>
<% if defined?(show_comment) && show_comment.valid? %>
<ol class="comments comments1 preview">
<div class="preview">
<%= render "comments/comment", :comment => show_comment %>
</ol>
</div>
<% end %>
</div>
</li>

View file

@ -1,7 +1,7 @@
<ol class="comments comments1">
<% @comments.each do |comment| %>
<%= render "comments/comment", :comment => comment,
:show_story => true %>
<li><%= render "comments/comment", :comment => comment,
:show_story => true %></li>
<% end %>
</ol>

View file

@ -7,6 +7,7 @@
<% while subtree %>
<% if (comment = subtree.shift) %>
<li>
<%= render "comments/comment", :comment => comment,
:show_story => ancestors.empty? %>
@ -15,10 +16,10 @@
<% subtree = children %>
<ol class="comments">
<% else %>
<ol class="comments"></ol>
<ol class="comments"></ol></li>
<% end %>
<% elsif (subtree = ancestors.pop) %>
</ol>
</ol></li>
<% end %>
<% end %>
</ol>

View file

@ -62,9 +62,8 @@
<%= render :partial => "stories/listdetail",
:locals => { :story => res } %>
<% elsif res.class == Comment %>
<%= render :partial => "comments/comment",
:locals => { :comment => res,
:show_story => true, :hide_voters => true } %>
<li><%= render "comments/comment", :comment => res,
:show_story => true, :hide_voters => true %></li>
<% end %>
<% end %>
</ol>

View file

@ -13,7 +13,7 @@
<ol class="comments comments1">
<% if @user && !@story.is_gone? && !@story.previewing %>
<%= render "comments/commentbox", :comment => @comment %>
<li><%= render "comments/commentbox", :comment => @comment %></li>
<% end %>
<% comments_by_parent = @comments.group_by(&:parent_comment_id) %>
@ -22,6 +22,7 @@
<% while subtree %>
<% if (comment = subtree.shift) %>
<li>
<%= render "comments/comment", :comment => comment %>
<% if (children = comments_by_parent[comment.id]) %>
@ -29,10 +30,10 @@
<% subtree = children %>
<ol class="comments">
<% else %>
<ol class="comments"></ol>
<ol class="comments"></ol></li>
<% end %>
<% elsif (subtree = ancestors.pop) %>
</ol>
</ol></li>
<% end %>
<% end %>
</ol>