Added extension: vanilla-voting-0.2beta-0.2beta.zip
[vanilla-miry.git] / extensions / VanillaVoting / js / AddVote.js.php
blobca52381e9fd3d30941ece91cb10c50fccac34c8f
1 <?php
2 header("Content-Type: text/javascript");
3 include("../../../appg/settings.php");
4 include("../../../appg/init_vanilla.php");
5 global $Context;
6 ?>
8 function AddDiscussionVote (AjaxURL, DiscussionID, Vote, CurrentTotalVotes, PostBackKey) {
10 $.post(AjaxURL, {'DiscussionID': DiscussionID, 'Vote': Vote, 'CurrentTotalVotes': CurrentTotalVotes, 'PostBackKey': PostBackKey },
11 function(data) {
12 if (data == 'Complete') {
13 $("li#Discussion_"+DiscussionID+" li.DiscussionVoteCount span:first-child").fadeTo('slow','0.1');
14 $("li#Discussion_"+DiscussionID+" li.DiscussionVoteCount span:first-child").text(CurrentTotalVotes + Vote);
15 if(Vote > 0) {
16 $("li#Discussion_"+DiscussionID+" li.DiscussionAddVote").html('<span class="VotedPositive"><input class="VotePositive" type="button" disabled="disabled"/><input class="VoteNegative" type="button" disabled="disabled"/></span>');
17 $("li#Discussion_"+DiscussionID).addClass("VotedPositive");
18 } else if (Vote < 0) {
19 $("li#Discussion_"+DiscussionID+" li.DiscussionAddVote").html('<span class="VotedNegative"><input class="VotePositive" type="button" disabled="disabled"/><input class="VoteNegative" type="button" disabled="disabled"/></span>');
20 $("li#Discussion_"+DiscussionID).addClass("VotedNegative");
23 else {
24 alert('Adding vote to discussion did not work');
26 $("li#Discussion_"+DiscussionID+" li.DiscussionVoteCount span:first-child").fadeTo('slow','1');
30 return false;
32 function AddCommentVote (AjaxURL, CommentID, Vote, CurrentTotalVotes, PostBackKey) {
34 $.post(AjaxURL, {'CommentID': CommentID, 'Vote': Vote, 'CurrentTotalVotes': CurrentTotalVotes, 'PostBackKey': PostBackKey },
35 function(data) {
36 if (data == 'Complete') {
37 $("li#Comment_"+CommentID+" span.CommentVoteCount").fadeTo('slow','0.1');
38 $("li#Comment_"+CommentID+" span.CommentVoteCount").text(CurrentTotalVotes + Vote);
39 if(Vote > 0) {
40 $("li#Comment_"+CommentID+" span.AddCommentVote").html('<span class="VotedPositive"><input class="VotePositive" type="button" disabled="disabled"/><input class="VoteNegative" type="button" disabled="disabled"/></span>');
42 } else if (Vote < 0) {
43 $("li#Comment_"+CommentID+" .CommentBody").slideUp('slow');
44 $("li#Comment_"+CommentID+" span.AddCommentVote").html('<span class="VotedNegative"><input class="VotePositive" type="button" disabled="disabled"/><input class="VoteNegative" type="button" disabled="disabled"/></span>');
45 $("li#Comment_"+CommentID+" span.CommentVoteCount").addClass('VotedNegative');
46 $("li#Comment_"+CommentID).addClass('VotedNegative');
49 else {
50 alert('Adding vote to comment did not work');
52 $("li#Comment_"+CommentID+" span.CommentVoteCount").fadeTo('slow','1');
55 return false;
57 function ShowComment (CommentID) {
58 $("li#Comment_"+CommentID+" .CommentBody").slideToggle('slow');
61 $(document).ready(function() {
62 $("li ul.VotedNegative").each(function() {
63 $(this).parent().addClass('VotedNegative');
64 });
65 $("li span.VotedNegative").each(function() {
66 $(this).parent().parent().parent().addClass('VotedNegative');
67 $("li.VotedNegative .CommentBody").hide();
68 });
70 });