1/** 2* @package Reputation System 3* @copyright (c) 2014 Pico 4* @license http://opensource.org/licenses/gpl-license.php GNU Public License 5*/ 6var reputation = {}; 7reputation.requestSent = false; 8 9(function ($) { // Avoid conflicts with other libraries 10 11/*$(document).ready(function() { 12 //TO-DO Highlighting and hiding post 13 $('.positive').each(function() { 14 $(this).parents('.post').addClass("hidden"); 15 }); 16});*/ 17 18// Close reputation popup 19$('body').click(function() { 20 if (!reputation.requestSent) { 21 $("#reputation-popup").fadeOut('fast'); 22 } 23}); 24 25// Stop propagation 26$('#reputation-popup').click(function(e) { 27 e.stopPropagation(); 28}); 29 30// Rating user 31$('#rate-user').click(function(event) { 32 reputation.show_popup(this.href, event, 'user', $(this).attr('data-referer')); 33}); 34 35// Rating post - positive 36$('a.rate-good-icon').click(function(event) { 37 reputation.show_popup(this.href, event, 'post', $(this).attr('data-referer')); 38}); 39 40// Rating post - negative 41$('a.rate-bad-icon').click(function(event) { 42 reputation.show_popup(this.href, event, 'post', $(this).attr('data-referer')); 43}); 44 45// Display post reputation details 46$('a.post-reputation').click(function(event) { 47 reputation.show_popup(this.href, event, 'details', $(this).attr('data-referer')); 48}); 49 50// Display user reputation details 51$('.user-reputation a').click(function(event) { 52 reputation.show_popup(this.href, event, 'details', $(this).attr('data-referer')); 53}); 54 55// Save vote 56$('#reputation-popup').on("click", '.button1', function(event) { 57 event.stopPropagation(); 58 event.preventDefault(); 59 60 reputation.submit_action($('#reputation-popup > form').attr('action'), $('#reputation-popup > form').attr('data-rate')); 61}); 62 63// Cancel rating 64$('#reputation-popup').on("click", '.button2', function(event) { 65 event.stopPropagation(); 66 event.preventDefault(); 67 68 $('#reputation-popup').fadeOut('fast').queue(function() { 69 $(this).empty(); 70 $(this).dequeue(); 71 }); 72}); 73 74// Sort reputation by 75$('#reputation-popup').on("click", 'a.sort_order', function(event) { 76 event.stopPropagation(); 77 event.preventDefault(); 78 79 reputation.sort_order_by(this.href, $('.footer-popup').attr('data-referer')); 80}); 81 82// Delete reputation 83$('#reputation-popup').on("click", '.reputation-delete', function(event) { 84 event.stopPropagation(); 85 event.preventDefault(); 86 87 var confirmation = $('a.reputation-delete').attr('data-lang-confirm'); 88 89 if (confirm(confirmation)) { 90 reputation.submit_action(this.href, 'delete'); 91 } 92}); 93 94// Clear reputation 95$('#reputation-popup').on("click", '.clear-reputation', function(event) { 96 event.stopPropagation(); 97 event.preventDefault(); 98 99 var confirmation = $('a.clear-reputation').attr('data-lang-confirm'); 100 101 if (confirm(confirmation)) { 102 reputation.submit_action(this.href, 'clear'); 103 } 104}); 105 106/** 107* Show the reputation popup with proper data 108*/ 109reputation.show_popup = function(href, event, mode, ref) { 110 event.stopPropagation(); 111 event.preventDefault(); 112 113 if (!reputation.requestSent) { 114 reputation.requestSent = true; 115 116 $.ajax({ 117 url: href, 118 data: ref, 119 dataType: 'html', 120 beforeSend: function() { 121 $('#reputation-popup').hide().empty().removeClass('small-popup normal-popup'); 122 }, 123 success: function(data) { 124 // Fix - do not display the empty popup when comment and reputation power are disabled 125 if (data.substr(0,1) != '{') { 126 $('#reputation-popup').append(data).fadeIn('fast'); 127 } 128 129 switch(mode) { 130 case 'details': 131 $('#reputation-popup').addClass('normal-popup'); 132 targetleft = ($(window).width() - $('#reputation-popup').outerWidth()) / 2; 133 targettop = ($(window).height() - $('#reputation-popup').outerHeight()) / 2; 134 break; 135 136 default: 137 $('#reputation-popup').addClass('small-popup'); 138 // Center popup relative to clicked coordinate 139 targetleft = event.pageX - $('#reputation-popup').outerWidth() / 2; 140 // Popup can not be too close or behind the right border of the screen 141 targetleft = Math.min (targetleft, $(document).width() - 20 - $('#reputation-popup').outerWidth()); 142 targetleft = Math.max (targetleft, 20); 143 targettop = event.pageY + 10; 144 break; 145 } 146 147 $('#reputation-popup').css({'top': targettop + 'px', 'left': targetleft + 'px'}); 148 149 // It's JSON! Probably an error. Lets clean the reputation popup and show the error there 150 if (data.substr(0,1) == '{') { 151 reputation.response(jQuery.parseJSON(data), mode); 152 } 153 },
154 complete: function() { 155 reputation.requestSent = false; 156 } 157 }); 158 } 159} 160 161/** 162* Submit reputation action 163*/ 164reputation.submit_action = function(href, mode) { 165 switch(mode) { 166 case 'post': 167 case 'user': 168 data = $('#reputation-popup form').serialize(); 169 break; 170 171 default: 172 data = ''; 173 break; 174 } 175 176 $.ajax({ 177 url: href, 178 data: data, 179 dataType: 'json', 180 type: 'POST', 181 success: function(r) { 182 reputation.response(r, mode); 183 } 184 }); 185} 186 187/** 188* Reputation response 189*/ 190reputation.response = function(data, mode) { 191 // If there is an error, show it 192 if (data.error_msg) { 193 $('#reputation-popup').empty().append('<div class="error">' + data.error_msg + '</div>').fadeIn(); 194 } 195 // If there is a comment error, show it 196 else if (data.comment_error) { 197 $('.error').detach(); 198 $('.comment').append('<dl class="error"><span>' + data.comment_error + '</span></dl>'); 199 } 200 // Otherwise modify the board outlook 201 else { 202 switch (mode) { 203 case 'post': 204 var post_id = data.post_id; 205 var poster_id = data.poster_id; 206 207 $('#reputation-popup').empty().append('<div class="error">' + data.success_msg + '</div>').delay(500).fadeOut('fast').queue(function() { 208 $('#profile-' + poster_id + ' span').text(data.user_reputation); 209 $('#p' + post_id + ' .post-reputation span').text(data.post_reputation); 210 $('#p' + post_id + ' .post-reputation').removeClass('neutral negative positive').addClass(data.reputation_class); 211 $('#p' + post_id + ' .rate-good-icon').removeClass('rated_good rated_bad').addClass(data.reputation_vote); 212 $('#p' + post_id + ' .rate-bad-icon').removeClass('rated_good rated_bad').addClass(data.reputation_vote); 213 $(this).empty().dequeue(); 214 }); 215 break; 216 217 case 'user': 218 $('#reputation-popup').empty().append('<div class="error">' + data.success_msg + '</div>').delay(500).fadeOut('fast').queue(function() { 219 $('#user-reputation').html(data.user_reputation); 220 $(this).empty().dequeue(); 221 }); 222 break; 223 224 case 'delete': 225 var post_id = data.post_id; 226 var poster_id = data.poster_id; 227 var rid = data.rid; 228 229 $('#r' + rid).hide('fast', function() { 230 $('#r' + rid).detach(); 231 if ($('.reputation-list').length == 0) { 232 $('#reputation-popup').fadeOut('fast').empty(); 233 } 234 }); 235 $('#profile-' + poster_id + ' span').text(data.user_reputation); 236 $('#p' + post_id + ' .post-reputation span').text(data.post_reputation); 237 $('#p' + post_id + ' .post-reputation').removeClass('neutral negative positive').addClass(data.reputation_class); 238 239 if (data.own_vote) { 240 $('#p' + post_id + ' .rate-good-icon').removeClass('rated_good rated_bad'); 241 $('#p' + post_id + ' .rate-bad-icon').removeClass('rated_good rated_bad'); 242 } 243 break; 244 245 case 'clear': 246 if (data.clear_post) { 247 var post_id = data.post_id; 248 var poster_id = data.poster_id; 249 250 $('.reputation-list').slideUp(function() { 251 $('#reputation-popup').fadeOut('fast').empty().delay(300).queue(function() { 252 $('#profile-' + poster_id + ' span').text(data.user_reputation); 253 $('#p' + post_id + ' .post-reputation span').text(data.post_reputation); 254 $('#p' + post_id + ' .post-reputation').removeClass('neutral negative positive').addClass(data.reputation_class); 255 $('#p' + post_id + ' .rate-good-icon').removeClass('rated_good rated_bad'); 256 $('#p' + post_id + ' .rate-bad-icon').removeClass('rated_good rated_bad'); 257 }).dequeue(); 258 }); 259 260 } 261 else if (data.clear_user) { 262 var post_ids = data.post_ids; 263 var poster_id = data.poster_id; 264 265 $('.reputation-list').slideUp(function() { 266 $('#reputation-popup').fadeOut('fast').empty().delay(300).queue(function() { 267 $('#profile-' + poster_id + ' span').text(data.user_reputation); 268 269 $.each(post_ids, function(i, post_id) { 270 $('#p' + post_id + ' .post-reputation span').text(data.post_reputation); 271 $('#p' + post_id + ' .post-reputation').removeClass('neutral negative positive').addClass(data.reputation_class); 272 $('#p' + post_id + ' .rate-good-icon').removeClass('rated_good rated_bad'); 273 $('#p' + post_id + ' .rate-bad-icon').removeClass('rated_good rated_bad'); 274 }); 275 }).dequeue(); 276 }); 277 } 278 break; 279 } 280 } 281} 282 283/** 284* Sort reputations 285*/ 286reputation.sort_order_by = function(href, ref) { 287 $.ajax({ 288 url: href, 289 data: ref, 290 dataType: 'html', 291 success: function(s) { 292 $('#reputation-popup').empty().append(s); 293 } 294 }); 295} 296 297})(jQuery); // Avoid conflicts with other libraries
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.