1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-30 10:42:41 +01:00
phorge-phorge/webroot/rsrc/js/application/ponder/behavior-votebox.js
Cihad OGE b92acf0e5a Fixed voting comments bug on Ponder
Summary: When user changed his mind for voting, counting does not work properly. If user vote up first and vote down, vote count must be decreased 2. fixed in javascript file

Test Plan:
http://cihad.phabricator.pompa.la/Q11
user : demo
pass : demodemo

Reviewers: aran, Korvin, epriestley

Reviewed By: epriestley

CC: simsekburak

Differential Revision: https://secure.phabricator.com/D6446
2013-07-13 15:58:37 -07:00

57 lines
1.3 KiB
JavaScript

/**
* @provides javelin-behavior-ponder-votebox
* @requires javelin-behavior
* javelin-dom
* javelin-util
* javelin-stratcom
* javelin-request
*/
JX.behavior('ponder-votebox', function(config) {
function handle_vote(e, vote) {
e.kill();
var root = e.getNode('ponder-votable');
var data = e.getNodeData('ponder-votable');
if (data.vote != vote) {
// Remove the user's current vote, if they have one.
data.count -= data.vote;
data.vote = vote;
data.count += vote;
} else {
// User is undoing their vote.
data.vote = 0;
data.count -= vote;
}
var upv = JX.DOM.find(root, 'a', 'upvote');
JX.DOM.alterClass(upv, 'ponder-vote-active', (data.vote > 0));
var downv = JX.DOM.find(root, 'a', 'downvote');
JX.DOM.alterClass(downv, 'ponder-vote-active', (data.vote < 0));
JX.DOM.setContent(
JX.DOM.find(root, 'div', 'ponder-vote-count'),
data.count);
new JX.Request(e.getTarget().href, JX.bag)
.setData({vote: data.vote})
.send();
}
JX.Stratcom.listen(
'click',
'downvote',
function(e) {
handle_vote(e, -1);
});
JX.Stratcom.listen(
'click',
'upvote',
function(e) {
handle_vote(e, 1);
});
});