1var _edit = false; 2var _editId = false; 3var _key = false; 4 5$(function() { 6 var form = '<div id="comment_form">' + $('#comment_form').html() + '</div>'; 7 var url = location.protocol + '//' + location.host + '/cms/plugins/comments/comments.php'; 8 var max_file_size = maxFileSize; 9 10 $('a#rulescomments').live('click', function() { 11 $.getJSON(url, 'getrules=1', function(json) { 12 console.log(json); 13 if (json.success) modal.open(json.text, {width: '450px'}); 14 }); 15 return false; 16 }); 17 18 var progressHandler = function(e) { 19 var percent = parseInt(e.loaded * 100 / e.total) 20 21 $('#attachProgress').html(percent + '%'); 22 23 } 24 25 function clearFileInputField(Id) { 26 document.getElementById(Id).innerHTML = document.getElementById(Id).innerHTML; 27 } 28 29 $('#attachComment').live('change', function(e) { 30 var maxMb = 2; 31 var maxImageSize = maxMb * 1024 * 1024; 32 var maxPx = 3000; 33 var error = 'ÐзобÑажение {name} ÑлиÑком болÑÑое. ÐопÑобÑйÑе ÑменÑÑиÑÑ ÐµÐ³Ð¾.'; 34 35 var self = this; 36 for (var i = 0, length = this.files.length; i < length; i++) { 37 var file = this.files[i]; 38 39 if (file) { 40 if (file.type == 'image/jpeg') { 41 if (file.size > maxImageSize) { 42 alert(error.replace("{name}", file.name)); 43 clearFileInputField('inputsFiles'); 44 return false; 45 } else { 46 var reader = new FileReader(); 47 var image = new Image(); 48 $('#send').attr('disabled', 1); 49 reader.readAsDataURL(file); 50 reader.onload = function (_file) { 51 image.src = _file.target.result; 52 image.onload = function () { 53 $('#send').removeAttr('disabled'); 54 if (this.width > maxPx || this.height > maxPx) { 55 alert(error.replace("{name}", file.name)); 56 clearFileInputField('inputsFiles'); 57 58 return false; 59 } 60 } 61 } 62 } 63 } 64 } 65 } 66 }); 67 68 //ÐобавиÑÑ ÐºÐ¾Ð¼Ð¼ÐµÐ½ÑаÑий 69 $('div#comments form#comments').live('submit', function() { 70 $('div#comments div.errors').html(''); 71 72 if (!$('#commentsrules').prop('checked') && _key == '') { 73 $('div#comments div.errors').html('<ul><li>ÐÑ ÑоглаÑÐ½Ñ Ñ Ð¿Ñавилами пÑбликаÑии комменÑаÑиев?</li></ul>'); 74 return false; 75 } 76 //var data = $('form#comments').serialize(); 77 78 79 //_data += '&' + data + '&ref=' + encodeURIComponent(location.pathname + location.search); 80 81 var formdata = new FormData(this); 82 formdata.append('ref', encodeURIComponent(location.pathname + location.search)); 83 formdata.append(_edit ? 'edit' : 'comment', 1) 84 if (_edit) { 85 formdata.append('id', _editId); 86 } 87 if (_key) { 88 formdata.append(_key, 'true'); 89 } 90 91 var fileInput = $('#attachComment'); 92 93 94 95 if (fileInput.length > 0) { 96 for (var i = 0, length = fileInput[0].files.length; i < length; i++) { 97 var file = fileInput[0].files[i]; 98 if (file) { 99 100 if (file.size > max_file_size) { 101 alert('СлиÑком болÑÑой Ñайл. ÐакÑималÑнÑй ÑÐ°Ð·Ð¼ÐµÑ Ñайла: ' + (max_file_size / 1024 / 1024) + ' Mb.'); 102 return false; 103 } 104 } 105 } 106 } 107 108 $.ajax({ 109 url: url, 110 data: formdata, 111 type: 'post', 112 cache: false, 113 contentType: false, 114 processData: false, 115 dataType: 'json', 116 xhr: function() { 117 var myXhr = $.ajaxSettings.xhr(); 118 if (myXhr.upload) { 119 myXhr.upload.addEventListener('progress', progressHandler, false); 120 } 121 return myXhr; 122 }, 123 success: function(json) {; 124 if (!json.success) { 125 if (_edit) { 126 alert(json.error); 127 } else { 128 var errors = '<ul>'; 129 $(json.errors).each(function(key, val) { 130 errors += '<li>' + val + '</li>'; 131 }); 132 $('div#comments div.errors').html(errors + '</ul>'); 133 } 134 135 } else { 136 137 if (_edit) { 138 $('#commentslist').find('div.comment' + json.id + ' div.text').html(json.text); 139 appendForm($('#comments'), form); 140 $('input#root').val('0'); 141 alert(json.message); 142 } else { 143 144 $('textarea#msg').val(''); 145 $('input#answer').val(''); 146 if (json.guestmessage) { 147 popup.show(json.guestmessage, 'success', 'topRight', 5500); 148 } 149 var root = parseInt($('input#root').val()); 150 var newText = json.newcomment; 151 if (root == 0) { 152 if ($('#commentslist div.comment:last').length != 0) 153 $('#commentslist div.comment:last').after(newText); 154 else 155 $('#commentslist').html(newText); 156 } else { 157 $('#commentslist').find('div#' + root).after(newText); 158 appendForm($('#comments'), form); 159 } 160 161 if (json.donate) { 162 $('#donate').click(); 163 } 164 } 165 resetAllButtons(); 166 $('b.haventcom').remove(); 167 } 168 _edit = false;
169 $('#attachProgress').html(''); 170 } 171 }); 172 173 return false; 174 }); 175 176 177 //ÐÑвеÑиÑÑ Ð½Ð° комменÑаÑий 178 $(this).on('click', '#commentslist div.answer, #commentslist div.cancel', function() { 179 180 var toggled = $(this).data('toggled'); 181 $(this).data('toggled', !toggled); 182 183 if (!toggled) { 184 appendForm($(this).parent(), form); 185 $('input#root').val($(this).parent().parent().attr('id')); 186 resetAllButtons(); 187 $(this).attr('class', 'cancel'); 188 $(this).text('ÐÑмениÑÑ'); 189 $(this).attr('title', 'ÐÑмениÑÑ Ð¾ÑÐ²ÐµÑ Ð½Ð° данное ÑообÑение'); 190 } else { 191 appendForm($('#comments'), form); 192 $('input#root').val('0'); 193 $(this).text('ÐÑвеÑиÑÑ'); 194 $(this).attr('class', 'answer'); 195 $(this).attr('title', 'ÐÑвеÑиÑÑ Ð½Ð° данное ÑообÑение'); 196 } 197 }); 198 199 200 $(this).on('click', '#commentslist div.editcomment span.edt', function() { 201 var thisObj = $(this); 202 var toggled = thisObj.data('toggled'); 203 thisObj.data('toggled', !toggled); 204 if (!toggled) { 205 var objBut = $(this); 206 var objAppend = $(this).parent().parent().parent(); 207 var id = objAppend.attr('id'); 208 209 $.getJSON(url, 'get=true&id=' + id, function(json) { 210 if (!json.success) { 211 alert(json.error); 212 } else { 213 appendForm(objAppend, form); 214 $('input#root').val(id); 215 $('#comment_form textarea#msg').val(json.text); 216 if ($('#norder').length > 0) $('#norder').val(json.norder); 217 _editId = json.id; 218 _edit = true; 219 objBut.text('[оÑмениÑÑ]'); 220 thisObj.data('toggled', true); 221 $('#comment_form').find('input#rules').parent().hide(); 222 } 223 }); 224 } else { 225 appendForm($('#comments'), form); 226 resetAllButtons(); 227 $('input#root').val('0'); 228 $('#comment_form').find('input#rules').parent().show(); 229 } 230 }); 231 232 $(this).on('click', '#commentslist div.editcomment span.dlt', function() { 233 if (confirm('ÐÑ Ð´ÐµÐ¹ÑÑвиÑелÑно Ñ Ð¾ÑиÑе ÑдалиÑÑ ÑÑÐ¾Ñ ÐºÐ¾Ð¼Ð¼ÐµÐ½ÑаÑий?')) { 234 var objBut = $(this); 235 var objAppend = $(this).parent().parent().parent(); 236 var id = objAppend.attr('id'); 237 238 $.getJSON(url, 'delete=true&id=' + id, function(json) { 239 if (!json.success) { 240 alert(json.error); 241 } else { 242 objAppend.remove(); 243 if ($('#commentslist div.comment').length == 0) $('#commentslist').prepend('<b class="haventcom">СÑаÑÑÑ ÐµÑе никÑо не комменÑиÑовал. ÐÑ Ð¼Ð¾Ð¶ÐµÑе ÑÑаÑÑ Ð¿ÐµÑвÑм</b>'); 244 alert(json.message); 245 } 246 247 }); 248 } 249 }); 250 251 252 $(this).on('click', '#commentslist div.paginator span.page', function() { 253 var page = $(this).attr('id'); 254 var data = 'paginator=true&page=' + page + '&url=' + encodeURIComponent(location.pathname); 255 $.getJSON(url, data, function(json) { 256 $('#commentslist').html(json.comments + json.paginator); 257 }); 258 }); 259 260 261 $(this).on('click', '#commentslist div.elements img', function() { 262 var vote = ($(this).attr('class') == 'up') ? true : false; 263 var id = $(this).parent().parent().attr('id'); 264 var ratObj = $(this).parent().find('span.rating'); 265 266 $.getJSON(url, 'rating=true&id=' + id + '&vote=' + vote, function(json) { 267 if (!json.success) { 268 alert(json.error); 269 } else { 270 ratObj.html(json.rating); 271 } 272 }); 273 }); 274 275 $('div.toTop').click(function() { 276 $('html, body').scrollTop(0); 277 }); 278 279 if (typeof(countComments) != 'undefined') $('span#count_comments').html(countComments); 280 281}); 282 283 284 285 286 287function appendForm(obj, form) { 288 $('#comment_form').remove(); 289 obj.append(form) 290} 291 292function appendComment(data, root) { 293 var margin = 0; 294 295 if (root != 0) { 296 var currentMargin = $('#commentslist').find('div#' + root).css('margin-left').replace('px', ''); 297 margin = parseInt(currentMargin) + 20; 298 } 299 300 var result = '<div style="margin-left: ' + margin + 'px" class="comment" id="' + data.id + '">'; 301 302 result += '<div class="title">'; 303 result += '<img src="' + data.avatar + '" width="48">'; 304 result += (data.user_id != 'null') ? '<a href="http://' + location.host + '/cms/profile/' + data.user_id + '/">' + data.name + '</a>' : data.name; 305 result += ' <span class="date">' + data.date + '</span>'; 306 result += '</div>'; 307 result += '<div class="text">' + data.text + '</div>'; 308 result += '<div class="answer" title="ÐÑвеÑиÑÑ Ð½Ð° данное ÑообÑение">ÐÑвеÑиÑÑ</div>'; 309 310 if (data.premoder) result += '<br><sub>ÐÑо ÑообÑение поÑвиÑÑÑ Ð¿Ð¾Ñле пÑовеÑки модеÑаÑоÑом</sub>'; 311 312 result += '</div>'; 313 314 return result; 315} 316 317function resetAllButtons() { 318 $('#commentslist div.cancel').text('ÐÑвеÑиÑÑ'); 319 $('#commentslist div.cancel').attr('class', 'answer'); 320 $('#commentslist div.cancel').attr('title', 'ÐÑвеÑиÑÑ Ð½Ð° данное ÑообÑение'); 321 322 $('#commentslist div.editcomment span.edt').text('[ÑедакÑиÑоваÑÑ]'); 323 _edit = false;
324} 325 326function selText(tag1, tag2) { 327 var memo = $('div#comments textarea#msg'); 328 var range = memo.caret(); 329 var value = memo.val(); 330 331 var lenTag2 = (range.text.length > 0) ? 0 : tag2.length; 332 333 var before = value.substring(0, range.start); 334 var after = value.substring(range.end, value.length); 335 336 memo.val(before + tag1 + range.text + tag2 + after); 337 memo.focus(); 338 339 memo.caret(memo.val().length - after.length - lenTag2, memo.val().length - after.length - lenTag2); 340}
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.