PluginProbe
Forumax – AI Powered Advanced Community Forum Plugin / 1.3.0
Forumax – AI Powered Advanced Community Forum Plugin v1.3.0
2.4.4 2.4.3 2.4.2 2.4.1 2.4.0 trunk 1.0.8 1.1.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 2.0.0 2.1.0 All 29 releases
bbp-core / assets / js / bbpc-voting.js

bbpc-voting.js in Forumax – AI Powered Advanced Community Forum Plugin 1.3.0, at assets/js/bbpc-voting.js

179 lines 8.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 function bbpress_post_vote_link_clicked(post_id, direction) {
2 var post_clicked = jQuery('.bbp-voting.bbp-voting-post-'+post_id);
3 // Validate you're allowed to vote
4 if(post_clicked.hasClass('view-only')) {
5 console.log('Post ID ' + post_id + ' is view only.');
6 return false;
7 }
8 // Loading CSS
9 post_clicked.css('opacity', 0.5).css('pointer-events', 'none');
10 // Ajax data
11 var data = {
12 'action': 'bbpress_post_vote_link_clicked',
13 'post_id': post_id,
14 'direction': direction
15 };
16 jQuery.post(bbpc_localize_script.ajaxurl, data, function(response) {
17 if(response.hasOwnProperty('error')) {
18 // Error response
19 console.log('Voting error:', response.error);
20 } else if(!response.hasOwnProperty('score')) {
21 // Catch invalid AJAX response
22 console.log('SOMETHING WENT WRONG', response);
23 } else {
24 // Proper response that has score, direction, ups, and downs
25 var score = parseInt(response.score);
26 direction = parseInt(response.direction);
27 var up = parseInt(response.ups);
28 var down = parseInt(response.downs);
29 console.log('Voted ' + direction, 'post #' + post_id, 'score: ' + score, 'ups: ' + up, 'downs: ' + down);
30 jQuery('.bbp-voting.bbp-voting-post-'+post_id).each(function() {
31 // Get elements
32 var wrapper = jQuery(this);
33 var score_el = jQuery(this).find('.score');
34 var up_el = jQuery(this).find('.up');
35 var down_el = jQuery(this).find('.down');
36 // Set elements' html
37 score_el.html(score);
38 up_el.attr('data-votes', '+' + up);
39 down_el.attr('data-votes', down);
40 // Change arrow colors
41 if(direction > 0) {
42 // Up vote
43 up_el.css('border-bottom-color', '#1e851e');
44 wrapper.removeClass('voted-down').addClass('voted-up');
45 } else if (direction < 0) {
46 // Down vote
47 down_el.css('border-top-color', '#992121');
48 wrapper.removeClass('voted-up').addClass('voted-down');
49 } else if (direction == 0) {
50 // Remove vote
51 up_el.css('border-bottom-color', 'inherit');
52 down_el.css('border-top-color', 'inherit');
53 wrapper.removeClass('voted-down').removeClass('voted-up');
54 }
55 // Restore the CSS
56 wrapper.css('opacity', 1).css('pointer-events', 'auto');
57 });
58 }
59 });
60 }
61
62 function bbp_voting_select_accepted_answer(post_id) {
63 // Ajax data
64 var data = {
65 'action': 'bbp_voting_select_accepted_answer',
66 'post_id': post_id
67 };
68 jQuery.post(bbpc_localize_script.ajaxurl, data, function(response) {
69 console.log('Accepted answer', response);
70 if(response) window.location.reload();
71 });
72 }
73
74 ;(function($) {
75 // Fix for BuddyBoss theme grabbing reply excerpt text including vote buttons and score
76 $( document ).on(
77 'click',
78 'a[data-modal-id-inline]',
79 function (e) {
80 e.preventDefault();
81 // Use setTimeout to move the end of the call stack
82 setTimeout(function() {
83 var bbpress_forums_element = $( e.target ).closest( '.bb-grid' );
84 var reply_excerpt_el = bbpress_forums_element.find( '.bbp-reply-form' ).find( '#bbp-reply-exerpt' );
85 reply_excerpt_el.html( reply_excerpt_el.html().replace(/^.*\:\:/, '') );
86 }, 0);
87 }
88 );
89
90 $(document).ready(function(){
91
92 // Agree/Disagree button AJAX
93 if ($('.bbpc-agree-button, .bbpc-disagree-button').length) {
94 $('.bbpc-agree-button, .bbpc-disagree-button').on('click', function() {
95
96 var dataLogin = $(this).attr('data-login');
97 if (dataLogin) {
98 window.location.href = dataLogin;
99 return;
100 }
101
102 var topicID = $(this).data('topic');
103 var isAgreeButton = $(this).hasClass('bbpc-agree-button');
104 var action = isAgreeButton ? 'bbpc_agree' : 'bbpc_disagree';
105
106 var dataType = $(this).attr('data-type');
107
108 // Determine if the button is already active (meaning a toggle click)
109 var isActive = $(this).hasClass('active');
110
111 $.ajax({
112 url: bbpc_localize_script.ajaxurl,
113 type: 'POST',
114 data: {
115 action: action,
116 topic_id: topicID,
117 nonce: bbpc_localize_script.nonce
118 },
119 beforeSend: function() {
120 if ( dataType === 'like' ) {
121 $('.bbpc-agree-button').append('<span class="bbpc-preloader"></span>');
122 } else {
123 $('.bbpc-disagree-button').append('<span class="bbpc-preloader"></span>');
124 }
125 },
126 success: function(response) {
127 if (response.success) {
128
129 var agreeCount = response.data.agree_count;
130 if (agreeCount === null || agreeCount === undefined || agreeCount === '') {
131 $('#bbpc-agree-count-' + topicID).text(0);
132 } else {
133 $('#bbpc-agree-count-' + topicID).text(agreeCount);
134 }
135
136 if ( dataType === 'like' ) {
137 $('.bbpc-agree-button span.bbpc-preloader').remove();
138 } else {
139 $('.bbpc-disagree-button span.bbpc-preloader').remove();
140 }
141
142 var disagreeCount = response.data.disagree_count;
143 if (disagreeCount === null || disagreeCount === undefined || disagreeCount === '') {
144 $('#bbpc-disagree-count-' + topicID).text(0);
145 } else {
146 $('#bbpc-disagree-count-' + topicID).text(disagreeCount);
147 }
148
149 // Toggle active classes
150 if (isAgreeButton) {
151 if (isActive) {
152 // Unvoting: Remove the active class if it was previously active
153 $('.bbpc-agree-button').removeClass('active');
154 } else {
155 // Voting: Add active class to agree and remove from disagree
156 $('.bbpc-agree-button').addClass('active');
157 $('.bbpc-disagree-button').removeClass('active');
158 }
159 } else {
160 if (isActive) {
161 // Unvoting: Remove the active class if it was previously active
162 $('.bbpc-disagree-button').removeClass('active');
163 } else {
164 // Voting: Add active class to disagree and remove from agree
165 $('.bbpc-disagree-button').addClass('active');
166 $('.bbpc-agree-button').removeClass('active');
167 }
168 }
169 }
170 }
171 });
172 });
173 }
174
175 $('.bbpc-footer-actions:empty').remove();
176
177 });
178
179 })(jQuery);