Guest User

Untitled

a guest
Aug 19th, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. /*** js ***/
  2. mw.loader.using(['jquery.cookie'], function () {
  3. $('.ajax-poll').each(function () {
  4. var $poll = $(this),
  5. pollId = $poll.attr('id').split('-')[2],
  6. cookieName = 'mainpage-poll',
  7. cookie = $.cookie(cookieName);
  8.  
  9. console.log(pollId);
  10.  
  11. if (cookie === pollId) {
  12. $poll.addClass('voted')
  13. } else {
  14. // setting value to null removes it
  15. $.cookie(cookieName, null);
  16. }
  17.  
  18. $poll.find('input[type="submit"]').on('click', function () {
  19. $poll.addClass('voted');
  20. $.cookie(cookieName, pollId, { path: '/', expires: 365 });
  21. });
  22. });
  23. });
  24.  
  25. /*** css ***/
  26. .ajax-poll .pollAnswerVotes {
  27. display: none;
  28. }
  29.  
  30. .ajax-poll.voted .pollAnswerVotes {
  31. display: block;
  32. }
Add Comment
Please, Sign In to add comment