Fix voting.
This commit is contained in:
parent
db185a9ef2
commit
0082434458
2 changed files with 86 additions and 86 deletions
|
@ -2,92 +2,6 @@ document.getElementById('awardModal').addEventListener('show.bs.modal', function
|
||||||
document.getElementById("awardTarget").action = event.relatedTarget.dataset.url;
|
document.getElementById("awardTarget").action = event.relatedTarget.dataset.url;
|
||||||
});
|
});
|
||||||
|
|
||||||
function vote(type, id, dir, vid) {
|
|
||||||
const upvotes = document.getElementsByClassName(type + '-' + id + '-up');
|
|
||||||
const downvotes = document.getElementsByClassName(type + '-' + id + '-down');
|
|
||||||
const scoretexts = document.getElementsByClassName(type + '-score-' + id);
|
|
||||||
|
|
||||||
for (let i=0; i<upvotes.length; i++) {
|
|
||||||
|
|
||||||
const upvote = upvotes[i]
|
|
||||||
const downvote = downvotes[i]
|
|
||||||
const scoretext = scoretexts[i]
|
|
||||||
const score = Number(scoretext.textContent);
|
|
||||||
|
|
||||||
if (dir == "1") {
|
|
||||||
if (upvote.classList.contains('active')) {
|
|
||||||
upvote.classList.remove('active')
|
|
||||||
scoretext.textContent = score - 1
|
|
||||||
votedirection = "0"
|
|
||||||
if (vid && ['1','9'].includes(vid)) document.getElementById(id+'-title').classList.remove('visited')
|
|
||||||
} else if (downvote.classList.contains('active')) {
|
|
||||||
upvote.classList.add('active')
|
|
||||||
downvote.classList.remove('active')
|
|
||||||
scoretext.textContent = score + 2
|
|
||||||
votedirection = "1"
|
|
||||||
} else {
|
|
||||||
upvote.classList.add('active')
|
|
||||||
scoretext.textContent = score + 1
|
|
||||||
votedirection = "1"
|
|
||||||
if (vid && ['1','9'].includes(vid)) document.getElementById(id+'-title').classList.add('visited')
|
|
||||||
}
|
|
||||||
|
|
||||||
if (upvote.classList.contains('active')) {
|
|
||||||
scoretext.classList.add('score-up')
|
|
||||||
scoretext.classList.remove('score-down')
|
|
||||||
scoretext.classList.remove('score')
|
|
||||||
} else if (downvote.classList.contains('active')) {
|
|
||||||
scoretext.classList.add('score-down')
|
|
||||||
scoretext.classList.remove('score-up')
|
|
||||||
scoretext.classList.remove('score')
|
|
||||||
} else {
|
|
||||||
scoretext.classList.add('score')
|
|
||||||
scoretext.classList.remove('score-up')
|
|
||||||
scoretext.classList.remove('score-down')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (downvote.classList.contains('active')) {
|
|
||||||
downvote.classList.remove('active')
|
|
||||||
scoretext.textContent = score + 1
|
|
||||||
votedirection = "0"
|
|
||||||
if (vid && ['1','9'].includes(vid)) document.getElementById(id+'-title').classList.remove('visited')
|
|
||||||
} else if (upvote.classList.contains('active')) {
|
|
||||||
downvote.classList.add('active')
|
|
||||||
upvote.classList.remove('active')
|
|
||||||
scoretext.textContent = score - 2
|
|
||||||
votedirection = "-1"
|
|
||||||
} else {
|
|
||||||
downvote.classList.add('active')
|
|
||||||
scoretext.textContent = score - 1
|
|
||||||
votedirection = "-1"
|
|
||||||
if (vid && ['1','9'].includes(vid)) document.getElementById(id+'-title').classList.add('visited')
|
|
||||||
}
|
|
||||||
|
|
||||||
if (upvote.classList.contains('active')) {
|
|
||||||
scoretext.classList.add('score-up')
|
|
||||||
scoretext.classList.remove('score-down')
|
|
||||||
scoretext.classList.remove('score')
|
|
||||||
} else if (downvote.classList.contains('active')) {
|
|
||||||
scoretext.classList.add('score-down')
|
|
||||||
scoretext.classList.remove('score-up')
|
|
||||||
scoretext.classList.remove('score')
|
|
||||||
} else {
|
|
||||||
scoretext.classList.add('score')
|
|
||||||
scoretext.classList.remove('score-up')
|
|
||||||
scoretext.classList.remove('score-down')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const xhr = new XMLHttpRequest();
|
|
||||||
xhr.open("POST", "/vote/" + type.replace('-mobile','') + "/" + id + "/" + votedirection);
|
|
||||||
xhr.setRequestHeader('xhr', 'xhr');
|
|
||||||
var form = new FormData()
|
|
||||||
form.append("formkey", formkey());
|
|
||||||
xhr.send(form);
|
|
||||||
}
|
|
||||||
|
|
||||||
function pick(kind, canbuy1, canbuy2) {
|
function pick(kind, canbuy1, canbuy2) {
|
||||||
let buy1 = document.getElementById('buy1')
|
let buy1 = document.getElementById('buy1')
|
||||||
if (canbuy1 && kind != "grass") buy1.disabled=false;
|
if (canbuy1 && kind != "grass") buy1.disabled=false;
|
||||||
|
|
|
@ -194,3 +194,89 @@ function bet_vote(cid) {
|
||||||
post('/bet/' + cid);
|
post('/bet/' + cid);
|
||||||
document.getElementById("user-coins-amount").innerText = parseInt(document.getElementById("user-coins-amount").innerText) - 200;
|
document.getElementById("user-coins-amount").innerText = parseInt(document.getElementById("user-coins-amount").innerText) - 200;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function vote(type, id, dir, vid) {
|
||||||
|
const upvotes = document.getElementsByClassName(type + '-' + id + '-up');
|
||||||
|
const downvotes = document.getElementsByClassName(type + '-' + id + '-down');
|
||||||
|
const scoretexts = document.getElementsByClassName(type + '-score-' + id);
|
||||||
|
|
||||||
|
for (let i=0; i<upvotes.length; i++) {
|
||||||
|
|
||||||
|
const upvote = upvotes[i]
|
||||||
|
const downvote = downvotes[i]
|
||||||
|
const scoretext = scoretexts[i]
|
||||||
|
const score = Number(scoretext.textContent);
|
||||||
|
|
||||||
|
if (dir == "1") {
|
||||||
|
if (upvote.classList.contains('active')) {
|
||||||
|
upvote.classList.remove('active')
|
||||||
|
scoretext.textContent = score - 1
|
||||||
|
votedirection = "0"
|
||||||
|
if (vid && ['1','9'].includes(vid)) document.getElementById(id+'-title').classList.remove('visited')
|
||||||
|
} else if (downvote.classList.contains('active')) {
|
||||||
|
upvote.classList.add('active')
|
||||||
|
downvote.classList.remove('active')
|
||||||
|
scoretext.textContent = score + 2
|
||||||
|
votedirection = "1"
|
||||||
|
} else {
|
||||||
|
upvote.classList.add('active')
|
||||||
|
scoretext.textContent = score + 1
|
||||||
|
votedirection = "1"
|
||||||
|
if (vid && ['1','9'].includes(vid)) document.getElementById(id+'-title').classList.add('visited')
|
||||||
|
}
|
||||||
|
|
||||||
|
if (upvote.classList.contains('active')) {
|
||||||
|
scoretext.classList.add('score-up')
|
||||||
|
scoretext.classList.remove('score-down')
|
||||||
|
scoretext.classList.remove('score')
|
||||||
|
} else if (downvote.classList.contains('active')) {
|
||||||
|
scoretext.classList.add('score-down')
|
||||||
|
scoretext.classList.remove('score-up')
|
||||||
|
scoretext.classList.remove('score')
|
||||||
|
} else {
|
||||||
|
scoretext.classList.add('score')
|
||||||
|
scoretext.classList.remove('score-up')
|
||||||
|
scoretext.classList.remove('score-down')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (downvote.classList.contains('active')) {
|
||||||
|
downvote.classList.remove('active')
|
||||||
|
scoretext.textContent = score + 1
|
||||||
|
votedirection = "0"
|
||||||
|
if (vid && ['1','9'].includes(vid)) document.getElementById(id+'-title').classList.remove('visited')
|
||||||
|
} else if (upvote.classList.contains('active')) {
|
||||||
|
downvote.classList.add('active')
|
||||||
|
upvote.classList.remove('active')
|
||||||
|
scoretext.textContent = score - 2
|
||||||
|
votedirection = "-1"
|
||||||
|
} else {
|
||||||
|
downvote.classList.add('active')
|
||||||
|
scoretext.textContent = score - 1
|
||||||
|
votedirection = "-1"
|
||||||
|
if (vid && ['1','9'].includes(vid)) document.getElementById(id+'-title').classList.add('visited')
|
||||||
|
}
|
||||||
|
|
||||||
|
if (upvote.classList.contains('active')) {
|
||||||
|
scoretext.classList.add('score-up')
|
||||||
|
scoretext.classList.remove('score-down')
|
||||||
|
scoretext.classList.remove('score')
|
||||||
|
} else if (downvote.classList.contains('active')) {
|
||||||
|
scoretext.classList.add('score-down')
|
||||||
|
scoretext.classList.remove('score-up')
|
||||||
|
scoretext.classList.remove('score')
|
||||||
|
} else {
|
||||||
|
scoretext.classList.add('score')
|
||||||
|
scoretext.classList.remove('score-up')
|
||||||
|
scoretext.classList.remove('score-down')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const xhr = new XMLHttpRequest();
|
||||||
|
xhr.open("POST", "/vote/" + type.replace('-mobile','') + "/" + id + "/" + votedirection);
|
||||||
|
xhr.setRequestHeader('xhr', 'xhr');
|
||||||
|
var form = new FormData()
|
||||||
|
form.append("formkey", formkey());
|
||||||
|
xhr.send(form);
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue