-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update votes ferom comments dynamically
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
- Loading branch information
1 parent
32c7310
commit 00056c8
Showing
2 changed files
with
26 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
class NotesVotes | ||
updateVotes: -> | ||
votes = $("#votes .votes") | ||
notes = $("#notes-list .note .vote") | ||
|
||
# only update if there is a vote display | ||
if votes.size() | ||
upvotes = notes.filter(".upvote").size() | ||
downvotes = notes.filter(".downvote").size() | ||
votesCount = upvotes + downvotes | ||
upvotesPercent = (if votesCount then (100.0 / votesCount * upvotes) else 0) | ||
downvotesPercent = (if votesCount then (100.0 - upvotesPercent) else 0) | ||
|
||
# change vote bar lengths | ||
votes.find(".bar-success").css "width", upvotesPercent + "%" | ||
votes.find(".bar-danger").css "width", downvotesPercent + "%" | ||
|
||
# replace vote numbers | ||
votes.find(".upvotes").text votes.find(".upvotes").text().replace(/\d+/, upvotes) | ||
votes.find(".downvotes").text votes.find(".downvotes").text().replace(/\d+/, downvotes) | ||
|
||
@NotesVotes = NotesVotes |