sneed
parent
05a3475730
commit
163a69c6be
|
@ -1,6 +1,181 @@
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
|
<script>
|
||||||
|
// Voting
|
||||||
|
|
||||||
|
var upvote = function(event) {
|
||||||
|
|
||||||
|
var type = event.target.dataset.contentType;
|
||||||
|
var id = event.target.dataset.idUp;
|
||||||
|
|
||||||
|
var downvoteButton = document.getElementsByClassName(type + '-' + id + '-down');
|
||||||
|
var upvoteButton = document.getElementsByClassName(type + '-' + id + '-up');
|
||||||
|
var scoreText = document.getElementsByClassName(type + '-score-' + id);
|
||||||
|
|
||||||
|
for (var j = 0; j < upvoteButton.length && j < downvoteButton.length && j < scoreText.length; j++) {
|
||||||
|
|
||||||
|
var thisUpvoteButton = upvoteButton[j];
|
||||||
|
var thisDownvoteButton = downvoteButton[j];
|
||||||
|
var thisScoreText = scoreText[j];
|
||||||
|
var thisScore = Number(thisScoreText.textContent);
|
||||||
|
|
||||||
|
if (thisUpvoteButton.classList.contains('active')) {
|
||||||
|
thisUpvoteButton.classList.remove('active')
|
||||||
|
thisScoreText.textContent = thisScore - 1
|
||||||
|
voteDirection = "0"
|
||||||
|
} else if (thisDownvoteButton.classList.contains('active')) {
|
||||||
|
thisUpvoteButton.classList.add('active')
|
||||||
|
thisDownvoteButton.classList.remove('active')
|
||||||
|
thisScoreText.textContent = thisScore + 2
|
||||||
|
voteDirection = "1"
|
||||||
|
} else {
|
||||||
|
thisUpvoteButton.classList.add('active')
|
||||||
|
thisScoreText.textContent = thisScore + 1
|
||||||
|
voteDirection = "1"
|
||||||
|
}
|
||||||
|
|
||||||
|
if (thisUpvoteButton.classList.contains('active')) {
|
||||||
|
thisScoreText.classList.add('score-up')
|
||||||
|
thisScoreText.classList.remove('score-down')
|
||||||
|
thisScoreText.classList.remove('score')
|
||||||
|
} else if (thisDownvoteButton.classList.contains('active')) {
|
||||||
|
thisScoreText.classList.add('score-down')
|
||||||
|
thisScoreText.classList.remove('score-up')
|
||||||
|
thisScoreText.classList.remove('score')
|
||||||
|
} else {
|
||||||
|
thisScoreText.classList.add('score')
|
||||||
|
thisScoreText.classList.remove('score-up')
|
||||||
|
thisScoreText.classList.remove('score-down')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
post_toast("/api/vote/" + type + "/" + id + "/" + voteDirection);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
var downvote = function(event) {
|
||||||
|
|
||||||
|
var type = event.target.dataset.contentType;
|
||||||
|
var id = event.target.dataset.idDown;
|
||||||
|
|
||||||
|
var downvoteButton = document.getElementsByClassName(type + '-' + id + '-down');
|
||||||
|
var upvoteButton = document.getElementsByClassName(type + '-' + id + '-up');
|
||||||
|
var scoreText = document.getElementsByClassName(type + '-score-' + id);
|
||||||
|
|
||||||
|
for (var j = 0; j < upvoteButton.length && j < downvoteButton.length && j < scoreText.length; j++) {
|
||||||
|
|
||||||
|
var thisUpvoteButton = upvoteButton[j];
|
||||||
|
var thisDownvoteButton = downvoteButton[j];
|
||||||
|
var thisScoreText = scoreText[j];
|
||||||
|
var thisScore = Number(thisScoreText.textContent);
|
||||||
|
|
||||||
|
if (thisDownvoteButton.classList.contains('active')) {
|
||||||
|
thisDownvoteButton.classList.remove('active')
|
||||||
|
thisScoreText.textContent = thisScore + 1
|
||||||
|
voteDirection = "0"
|
||||||
|
} else if (thisUpvoteButton.classList.contains('active')) {
|
||||||
|
thisDownvoteButton.classList.add('active')
|
||||||
|
thisUpvoteButton.classList.remove('active')
|
||||||
|
thisScoreText.textContent = thisScore - 2
|
||||||
|
voteDirection = "-1"
|
||||||
|
} else {
|
||||||
|
thisDownvoteButton.classList.add('active')
|
||||||
|
thisScoreText.textContent = thisScore - 1
|
||||||
|
voteDirection = "-1"
|
||||||
|
}
|
||||||
|
|
||||||
|
if (thisUpvoteButton.classList.contains('active')) {
|
||||||
|
thisScoreText.classList.add('score-up')
|
||||||
|
thisScoreText.classList.remove('score-down')
|
||||||
|
thisScoreText.classList.remove('score')
|
||||||
|
} else if (thisDownvoteButton.classList.contains('active')) {
|
||||||
|
thisScoreText.classList.add('score-down')
|
||||||
|
thisScoreText.classList.remove('score-up')
|
||||||
|
thisScoreText.classList.remove('score')
|
||||||
|
} else {
|
||||||
|
thisScoreText.classList.add('score')
|
||||||
|
thisScoreText.classList.remove('score-up')
|
||||||
|
thisScoreText.classList.remove('score-down')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
post_toast("/api/vote/" + type + "/" + id + "/" + voteDirection);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
var register_votes = function() {
|
||||||
|
var upvoteButtons = document.getElementsByClassName('upvote-button')
|
||||||
|
|
||||||
|
var downvoteButtons = document.getElementsByClassName('downvote-button')
|
||||||
|
|
||||||
|
var voteDirection = 0
|
||||||
|
|
||||||
|
for (var i = 0; i < upvoteButtons.length; i++) {
|
||||||
|
upvoteButtons[i].addEventListener('click', upvote, false);
|
||||||
|
upvoteButtons[i].addEventListener('keydown', function(event) {
|
||||||
|
if (event.keyCode === 13) {
|
||||||
|
upvote(event)
|
||||||
|
}
|
||||||
|
}, false)
|
||||||
|
};
|
||||||
|
|
||||||
|
for (var i = 0; i < downvoteButtons.length; i++) {
|
||||||
|
downvoteButtons[i].addEventListener('click', downvote, false);
|
||||||
|
downvoteButtons[i].addEventListener('keydown', function(event) {
|
||||||
|
if (event.keyCode === 13) {
|
||||||
|
downvote(event)
|
||||||
|
}
|
||||||
|
}, false)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
register_votes()
|
||||||
|
|
||||||
|
function vote_comment(comment_id, direction) {
|
||||||
|
url="/api/vote/comment/"+ comment_id +"/"+direction;
|
||||||
|
|
||||||
|
callback=function(){
|
||||||
|
thing = document.getElementById("comment-"+ comment_id+"-actions");
|
||||||
|
uparrow1=document.getElementById("comment-"+ comment_id +"-up");
|
||||||
|
downarrow1=document.getElementById("comment-"+ comment_id +"-down");
|
||||||
|
scoreup1=document.getElementById("comment-"+ comment_id +"-score-up");
|
||||||
|
scorenone1=document.getElementById("comment-"+ comment_id +"-score-none");
|
||||||
|
scoredown1=document.getElementById("comment-"+ comment_id +"-score-down");
|
||||||
|
|
||||||
|
if (direction=="1") {
|
||||||
|
thing.classList.add("upvoted");
|
||||||
|
thing.classList.remove("downvoted");
|
||||||
|
uparrow1.onclick=function(){vote_comment(comment_id, 0)};
|
||||||
|
downarrow1.onclick=function(){vote_comment(comment_id, -1)};
|
||||||
|
scoreup1.classList.remove("d-none");
|
||||||
|
scorenone1.classList.add("d-none");
|
||||||
|
scoredown1.classList.add("d-none");
|
||||||
|
}
|
||||||
|
else if (direction=="-1"){
|
||||||
|
thing.classList.remove("upvoted");
|
||||||
|
thing.classList.add("downvoted");
|
||||||
|
uparrow1.onclick=function(){vote_comment(comment_id, 1)};
|
||||||
|
downarrow1.onclick=function(){vote_comment(comment_id, 0)};
|
||||||
|
scoreup1.classList.add("d-none");
|
||||||
|
scorenone1.classList.add("d-none");
|
||||||
|
scoredown1.classList.remove("d-none");
|
||||||
|
}
|
||||||
|
else if (direction=="0"){
|
||||||
|
thing.classList.remove("upvoted");
|
||||||
|
thing.classList.remove("downvoted");
|
||||||
|
uparrow1.onclick=function(){vote_comment(comment_id, 1)};
|
||||||
|
downarrow1.onclick=function(){vote_comment(comment_id, -1)};
|
||||||
|
scoreup1.classList.add("d-none");
|
||||||
|
scorenone1.classList.remove("d-none");
|
||||||
|
scoredown1.classList.add("d-none");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
post(url, callback, "Unable to vote at this time. Please try again later.");
|
||||||
|
}
|
||||||
|
</script>
|
||||||
{% if v %}
|
{% if v %}
|
||||||
<script src="https://js.pusher.com/beams/1.0/push-notifications-cdn.js"></script>
|
<script src="https://js.pusher.com/beams/1.0/push-notifications-cdn.js"></script>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue