1// Post voting system with Ajax 2 3FORUM.PartnerVote = function(post_id,vote) { 4 return true; 5}; 6 7$(function() { 8 $('.topic div.post-vote, .topic li.pa-respect').find('a[href*="relation.php?"]').on('click', function(e) { 9 e.preventDefault(); 10 var a = $(this).prop('href'); 11 var pid = a.match(/\?id=(\d+)/)[1]; 12 var uid = $(this).parents('.post').find('.pl-email a[href*="profile.php?"]').prop('href'); 13 if (uid) uid = uid.match(/\?id=(\d+)$/)[1]; 14 var v = a.match(/&v=(\d+)/)[1] == 0 ? -1 : 1; 15 $('#post-' + pid + '-vote').hide(); 16 if(FORUM.PartnerVote(pid, v)) $.get(a + '&format=json', function(data) { 17 if (data.error && data.error.message) $.jGrowl(data.error.message); 18 if (data.delta) { 19 var pr = data.response; 20 if (pr > 0) pr = '+' + pr.toString(); 21 $('#p' + pid + ' .post-rating a').text(pr); 22 var $res = $('.pl-email a[href$="profile.php?id=' + uid + '"]').parents('.post').find('.pa-respect'); 23 var $pos = $('.pl-email a[href$="profile.php?id=' + UserID + '"]').parents('.post').find('.pa-positive'); 24 25 function replaceRating(sel, v, revert) { 26 var html = $(sel).html(), delta = v; 27 if (!html) return; 28 if (revert) delta = delta > 0 ? -1 : 1; 29 if (v > 0) { 30 html = html.replace(/\[\+(\d+)\//g, function(str, p1, b, p2) { 31 return '[+' + (parseInt(p1) + delta) + '/'; 32 }); 33 } else { 34 html = html.replace(/\/-(\d+)\]/g, function(str, p1, b, p2) { 35 return '/-' + (parseInt(p1) - delta) + ']'; 36 }); 37 } 38 $(sel).html(html); 39 }; 40 if ($res.length && $res.html().indexOf('[') != -1 || $pos.length && $pos.html().indexOf('[') != -1) { 41 $res.each(function() { 42 replaceRating(this, v); 43 }); 44 $pos.each(function() { 45 replaceRating(this, v); 46 }); 47 if (Math.abs(data.delta) == 2) { 48 v = v > 0 ? -1 : 1; 49 $res.each(function() { 50 replaceRating(this, v, 1); 51 }); 52 $pos.each(function() { 53 replaceRating(this, v, 1); 54 }); 55 } 56 } else { 57 var d0 = $res.find('span:not(.fld-name)').html(), 58 p0 = $pos.find('span:not(.fld-name)').html(); 59 var d1 = parseInt(d0) + v; 60 if (p0) { 61 var p1 = parseInt(p0) + v; 62 } 63 if (d1 && d1 > 0) { 64 d1 = '+' + d1; 65 } 66 if (p1 && p1 > 0) { 67 p1 = '+' + p1; 68 } 69 $res.find('span:not(.fld-name)').html(d1); 70 if(p0) $pos.find('span:not(.fld-name)').html(p1); 71 } 72 } 73 }); 74 }); 75}); 76 77// Post share link 78 79function sharelink_init(element) { 80 element.tooltipsy({ 81 alignTo: 'element', 82 offset: [-1, 0], 83 showEvent: 'click', 84 hideEvent: 'click', 85 show: function (e, $el) { 86 var $a = $(e.currentTarget); 87 $el.css({'position': 'absolute','top':($a.offset().top + 25) + 'px','left': ($a.offset().left + $a.width()- 162) +'px'}).fadeIn(200); 88 $a.addClass('open'); 89 }, 90 hide: function (e, $el) { 91 var $a = $(e.currentTarget); $(e.currentTarget).removeClass('open'); $el.fadeOut(200); 92 }, 93 content: function($el) { 94 var providers = ['facebook','vkontakte','odnoklassniki','mailru','twitter','linkedin','reddit','tumblr'] 95 var output = ''; 96 var a = $el.prop('href'); 97 var pid = a.match(/#p(\d+)$/)[1]; 98 $.each(providers, function(key, val) { 99 output += '<a class="social social-'+val+'" href="/share.php?p='+val+'&pid='+pid+'" target="_blank" title="'+val+'"></a>' 100 }); 101 return '<div class="post-share-tip"><div class="post-share-legend"><span>'+FORUM.get('topic.language.share_legend')+'</span></div><div class="post-share-icons">'+output+'</div></div>'; 102 }, 103 css: {'background': 'rgba(0,0,0,0.8)','border-radius': '3px'} 104 }); 105} 106 107$(function() { 108 sharelink_init($('.topic .sharelink')); 109 var busy = false; 110 $('body').on('click', '.post-share-tip', function(e) { 111 busy = true; 112 setTimeout(function() { busy = false }, 20); 113 }).on('click', function() { 114 if (!busy && $('.post-share-tip:visible').length) { 115 $('.topic .sharelink.open').trigger('click'); 116 } 117 }); 118 119 var requestTimeout = 1000; 120 121 function requestTranslation(pid) { 122 $.get('/api.php', { 123 method: 'post.getTranslation', 124 post_id: pid, 125 language: window.UserLanguage || $('html').attr('lang'), 126 async: true 127 }, function(data) { 128 if (!data.response) 129 return $(e.target).removeClass('translation-busy'); 130 if (data.response.message) { 131 var post = $('#p' + pid), content = $('#p' + pid + '-content'); 132 var sig = post.find('.post-sig').detach(); 133 var lastedit = post.find('.lastedit').detach(); 134 post.data('post-sig', sig).data('post-lastedit', lastedit); 135 content.empty().append(data.response.message).append(lastedit.clone()).append(sig.clone()); 136 //$(document).trigger($.Event('pun_translate', {'sender': content, 'pid': pid})); 137 $(document).trigger($.Event('pun_edit', {'sender': content, 'pid': pid, 'mode': 'translate'})); 138 post.find('.translatelink').removeClass('translation-busy') 139 .addClass('show-original').text(FORUM.get('topic.language.show_original')); 140 } else if (data.response.status) { 141 setTimeout(function() { 142 requestTranslation(pid) 143 }, requestTimeout); 144 } 145 }).fail(function() { 146 $('#p' + pid).find('.translatelink').removeClass('translation-busy'); 147 }); 148 } 149 150 function translatelinkInit() { 151 $('.topic .translatelink').off('click').on('click', function(e) { 152 e.preventDefault(); 153 if ($(this).hasClass('translation-busy')) return false;
154 155 var post = $(this).closest('.post'), 156 content = post.find('.post-content'), 157 pid = +post.attr('id').substr(1); 158 159 if ($(this).hasClass('show-original')) { 160 content.empty().append(post.data('original-content')) 161 .append(post.data('post-lastedit').clone()) 162 .append(post.data('post-sig').clone()); 163 $(document).trigger($.Event('pun_translate', {'sender': content, 'pid': pid, 'mode': 'translate'})); 164 $(this).removeClass('show-original').text(FORUM.get('topic.language.translate')); 165 return; 166 } 167 168 $(this).addClass('translation-busy'); 169 170 requestTranslation(pid); 171 }); 172 } 173 174 translatelinkInit(); 175 $(document).on('pun_post', translatelinkInit); 176 177 $(document).on('pun_preedit', function() { 178 $('.topic .translatelink.show-original').trigger('click'); 179 }); 180}); 181 182$(document).pun_mainReady(function() { 183 function preserveContent(post) { 184 $(post).each(function() { 185 var content = $(this).find('.post-content').clone(); 186 content.find('.post-sig,.lastedit').remove(); 187 $(this).data('original-content', content.html()); 188 }); 189 } 190 191 if ($('#pun-viewtopic').length) { 192 preserveContent('.topic .post[id]'); 193 $(document).on('pun_post', function() { 194 preserveContent('.topic .post.new-ajax'); 195 }); 196 } 197}); 198 199// toggleSpoiler for opening or closing spoilers 200 201function toggleSpoiler(element) { 202 var noscript = $(element).siblings('script'), blockquote = $(element).next('blockquote'); 203 if (noscript.length) { 204 blockquote.html(noscript.text()); 205 noscript.remove(); 206 $(element).parent('.spoiler-box').trigger($.Event('spoiler.firstOpen', {'sender': element})); 207 } 208 $(element).toggleClass('visible'); 209 blockquote.toggleClass('visible'); 210 $(element).parent('.spoiler-box').trigger($.Event('spoiler.toggle', {'sender': element})); 211}
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.