Advertisement
cyberdev

Untitled

Jul 19th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (function($) {
  2.     $(document).ready(function() {
  3.         snax.updateVoteState = function(itemId, type, $box) {
  4.             var typeCookie  = 'snax_vote_type_' + itemId;
  5.             var scoreCookie = 'snax_vote_score_' + itemId;
  6.             var currentValue = snax.readCookie(typeCookie);
  7.             // Cookie can't be read immediately so we need to update CSS classes manually.
  8.             $box.find('.snax-user-voted').removeClass('snax-user-voted');
  9.             // User voted and now he wants to remove the vote.
  10.             if (currentValue === type) {
  11.                 snax.deleteCookie(typeCookie);
  12.             } else {
  13.                 snax.createCookie(typeCookie, type, 30);
  14.                 // Cookie can't be read immediately so we need to update CSS classes manually.
  15.                 $box.find('.snax-voting-' + type).addClass('snax-user-voted');
  16.             }
  17.             // Update score.
  18.             var score = parseInt($box.find('.snax-voting-score strong').text(), 10);
  19.             snax.createCookie(scoreCookie, score, 30);
  20.             window.location.reload(true);
  21.         };
  22.     });
  23. })(jQuery);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement