refactored out thread rendering; vote

This commit is contained in:
Rocky Duan
2012-07-23 19:03:36 -04:00
parent 28113d8b43
commit 5e5dda2dfb
5 changed files with 146 additions and 125 deletions

View File

@@ -9,6 +9,7 @@ $ ->
$('#open_close_accordion a').click @toggle
$('#accordion').show()
$("section.discussion").each (index, discussion) ->
Discussion.bindDiscussionEvents(discussion)
@@ -32,7 +33,7 @@ Discussion =
}[name]
handleAnchorAndReload: (response) ->
window.location = window.location.pathname + "#" + response['id']
#window.location = window.location.pathname + "#" + response['id']
window.location.reload()
bindContentEvents: (content) ->
@@ -100,12 +101,26 @@ Discussion =
Discussion.handleAnchorAndReload(response)
, 'json'
handleVote = (elem, value) ->
contentType = if $content.hasClass("thread") then "thread" else "comment"
url = Discussion.urlFor("#{value}vote_#{contentType}", $content.attr("_id"))
$.post url, {}, (response, textStatus) ->
if textStatus == "success"
Discussion.handleAnchorAndReload(response)
, 'json'
$local(".discussion-reply").click ->
handleReply(this)
$local(".discussion-cancel-reply").click ->
handleCancelReply(this)
$local(".discussion-vote-up").click ->
handleVote(this, "up")
$local(".discussion-vote-down").click ->
handleVote(this, "down")
bindDiscussionEvents: (discussion) ->
$discussion = $(discussion)
$discussionNonContent = $discussion.children(".discussion-non-content")

View File

@@ -1,4 +1,4 @@
$comment_margin_left: 20px;
$comment_margin_left: 30px;
$discussion_title_size: 1.6em;
$comment_title_size: 1.2em;
$comment_body_size: 1.0em;
@@ -45,6 +45,33 @@ $discussion_input_width: 60%;
margin-bottom: 20px;
display: block;
}
.discussion-votes {
margin-right: 8px;
margin-top: 5px;
text-align: center;
height: 40px;
float: left;
.discussion-vote-count {
font-size: $comment_body_size;
@include discussion-font;
}
a.discussion-vote {
display: block;
color: black;
font-weight: bold;
font-size: 15px;
&.discussion-vote-up {
margin-bottom: 3px;
}
&.discussion-vote-down {
margin-top: 3px;
}
}
}
.discussion-right-wrapper {
min-height: 40px;
float: left;
}
.new-post-form {
.new-post-title, .new-post-body {
@include discussion-font;
@@ -105,6 +132,8 @@ $discussion_input_width: 60%;
}
}
.discussion-content {
margin-top: 10px;
overflow: hidden;
.discussion-content-edit {
.comment-edit {
@include discussion-font;
@@ -118,16 +147,20 @@ $discussion_input_width: 60%;
.comments {
//display: none;
margin-left: $comment_margin_left;
overflow: hidden;
.comment {
.comment-body {
@include discussion-font;
font-size: $comment_body_size;
margin-top: 10px;
margin-top: 3px;
display: block;
color: black;
}
}
.discussion-votes {
margin-right: 6px;
margin-top: 6px;
}
}
}