YaWK  24.1
Yet another WebKit
voting.js
Go to the documentation of this file.
1 $(document).ready(function(){
2 
3  // set vars for voting
4  var votingAmount = 1;
5  var itemid = $('#itemid').val();
6 
7  // the fields to update the view
8  var totalVotesText = $('#totalVotesText');
9  var voteUpText = $('#voteUpText');
10  var voteDownText = $('#voteDownText');
11 
12  var voteUpIcon = $('#voteUpIcon');
13  var voteDownIcon = $('#voteDownIcon');
14 
15  // the vars (data)
16  var totalVotes = $(totalVotesText).text();
17  var voteUp = $(voteUpText).text();
18  var voteDown = $(voteDownText).text();
19 
20 
21  // VOTE UP BUTTON CLICKED
22  $('#voteUp').click(function(){
23 
24  $.ajax({
25  url:'system/plugins/blog/js/vote-up.php',
26  type:'post',
27  data:'voteUp='+votingAmount+'&itemid='+itemid,
28  success:function(data){
29  if(! data ){
30  alert('Something went wrong!');
31  return false;
32  }
33  else {
34  // UPDATE THE VOTING VIEW (user voted UP)
35 
36  // check if user has already voted
37  // var voted = localStorage.getItem('voted');
38  // if (voted > 1)
39  // {
40  // add color to thumb
41  $(voteUpIcon).addClass('fa fa-thumbs-up');
42  $(voteUpIcon).addClass('animated bounceIn');
43  // add total votes
44  totalVotes++;
45  voteUp++;
46  // update upvotes
47  voteUpText.html(voteUp);
48  // update the view
49  totalVotesText.html(totalVotes);
50 
51  // set local storage
52  // localStorage.setItem('voted', '1');
53  // }
54  }
55  }
56  });
57  });
58 
59  // VOTE DOWN BUTTON CLICKED
60  $('#voteDown').click(function(){
61 
62  $.ajax({
63  url:'system/plugins/blog/js/vote-down.php',
64  type:'post',
65  data:'voteDown='+votingAmount+'&itemid='+itemid,
66  success:function(data){
67  if(! data ){
68  alert('Something went wrong!');
69  return false;
70  }
71  else {
72  // UPDATE THE VOTING VIEW (user voted DOWN)
73 
74  // add color to thumb
75  $(voteDownIcon).addClass('fa fa-thumbs-down');
76  $(voteDownIcon).addClass('animated bounceIn');
77  // add total votes
78  totalVotes++;
79  voteDown++;
80  // update upvotes
81  voteDownText.html(voteDown);
82  // update the view
83  totalVotesText.html(totalVotes);
84  localStorage.setItem('voted', '1');
85  }
86  }
87  });
88  });
89 });
print $blog itemid
Definition: blog-edit.php:376
type
Definition: menu-new.php:35
document ready(function(){ var votingAmount=1;var itemid=$('#itemid').val();var totalVotesText=$('#totalVotesText');var voteUpText=$('#voteUpText');var voteDownText=$('#voteDownText');var voteUpIcon=$('#voteUpIcon');var voteDownIcon=$('#voteDownIcon');var totalVotes=$(totalVotesText).text();var voteUp=$(voteUpText).text();var voteDown=$(voteDownText).text();$('#voteUp').click(function(){ $.ajax({ url:'system/plugins/blog/js/vote-up.php', type:'post', data:'voteUp='+votingAmount+'&itemid='+itemid, success:function(data){ if(! data){ alert('Something went wrong!');return false;} else { $(voteUpIcon).addClass('fa fa-thumbs-up');$(voteUpIcon).addClass('animated bounceIn');totalVotes++;voteUp++;voteUpText.html(voteUp);totalVotesText.html(totalVotes);} } });});$('#voteDown').click(function(){ $.ajax({ url:'system/plugins/blog/js/vote-down.php', type:'post', data:'voteDown='+votingAmount+'&itemid='+itemid, success:function(data){ if(! data){ alert('Something went wrong!');return false;} else { $(voteDownIcon).addClass('fa fa-thumbs-down');$(voteDownIcon).addClass('animated bounceIn');totalVotes++;voteDown++;voteDownText.html(voteDown);totalVotesText.html(totalVotes);localStorage.setItem('voted', '1');} } });});})