1// comments box on story pages 2jQuery(document).ready(function($) { 3 4 //comment form submission 5 $('body').on('click', '.sno-comments-wrap form#commentform input#submit[type="submit"]', function(e) { 6 $(this).val('Submitting comment...') 7 }) 8 9 // story liking mechanism 10 // on load, check the cookie to see if this post has been liked. If so, flag it with a data attibute so that other actions can be based on this 11 12 setTimeout(function(){ 13 $('.like-side-icon').data('d', 1); 14 $('.like-row-icon').data('d', 1); 15 }, 2000); 16 17 var z = $('.sno-color-inverter').data(); 18 $.each( z, function( x, y ) { 19 $('.sno-color-inverter').removeAttr('data-' + x); 20 }); 21 22 function generateUniqueKey() { 23 if (window.crypto && window.crypto.randomUUID) { 24 return crypto.randomUUID(); 25 } else { 26 return Math.random().toString(36).substr(2, 9); 27 } 28 } 29 30 31 $('body').on('click', '.like-side-icon, .like-row-icon', function(event) { 32 33 // if (event.originalEvent && event.originalEvent.isTrusted == true) {} else { 34 // return; 35 // } 36 37 if (!cookiesEnabled()) return; 38 if( $(this).data('d') != 1 ) return; 39 40 var l = ''; 41 $.each( z, function( a, b ) { 42 a += ' '; b += ' '; 43 $.each( a.split(''), function( c, d ) { 44 l += d + b.split('')[c]; 45 }) 46 }) 47 48 var r = $(this).data('remember'); 49 50 let change; 51 let postID = $(this).data('post'); 52 const button = $(this); 53 54 let cookieName = '498727595015785'; 55 let testCookie = readCookie(cookieName); 56 let parsedCookie = JSON.parse(testCookie); 57 58 let uniqueKey = generateUniqueKey(); 59 60 if( testCookie && parsedCookie ) { 61 if ( parsedCookie.hasOwnProperty(postID) ) { 62 change = 'decrement'; 63 uniqueKey = parsedCookie[postID]; 64 } else { 65 change = 'increment'; 66 } 67 } else { 68 change = 'increment'; 69 } 70 71 if( change ) { 72 r += '\u200B'; 73 $.ajax({ 74 url: comment_ajax_object.ajaxurl, 75 type: 'POST', 76 data: { 77 'action': 'recommendpost', 78 'postid': postID, 79 'change': change, 80 'like': l, 81 'remember': r, 82 'key': uniqueKey, 83 'nonce': comment_ajax_object.nonce 84 }, 85 success:function(results) { 86 if( results != '' ) { 87 if( change == 'increment' ) $(button).find('.like-count-bubble').removeClass('like-count-hide').addClass('like-count-display'); 88 if( change == 'decrement' && results === "0" ) $(button).find('.like-count-bubble').removeClass('like-count-display').addClass('like-count-hide'); 89 $(button).find('.like-count-bubble').text(results); 90 91 if( testCookie && parsedCookie ) { 92 if ( parsedCookie.hasOwnProperty(postID) ) { 93 delete parsedCookie[postID]; 94 } else { 95 parsedCookie[postID] = uniqueKey; 96 } 97 eraseCookie(cookieName); 98 createCookie( cookieName, JSON.stringify(parsedCookie), 30); 99 } else { 100 const cookieData = {}; 101 cookieData[postID] = uniqueKey; 102 createCookie(cookieName, JSON.stringify(cookieData), 30); 103 } 104 105 } 106 } 107 108 }) 109 } 110 }); 111 112 function cookiesEnabled() { 113 document.cookie = "cookietest=1; SameSite=Strict"; 114 const enabled = document.cookie.indexOf("cookietest=") !== -1; 115 document.cookie = "cookietest=1; expires=Thu, 01 Jan 1970 00:00:00 GMT; SameSite=Strict"; 116 return enabled; 117 } 118 119 120 // load comments after page load 121 /* 122 const postid = $('.comments_template_space').data('postid'); 123 if( postid ) { 124 $.ajax({ 125 url: comment_ajax_object.ajaxurl, 126 type: 'POST', 127 data: { 128 'action': 'loadcomments', 129 'postid': postid 130 }, 131 success:function(results) { 132 $('.comments_template_space').replaceWith(results); 133 } 134 }); 135 } 136 */ 137 138 // comment verification mechanisms 139 140 $('body').on('keydown', '.sno-captcha-button, .comment-close-icon, .comments-toggle span, .comment-row-icon-wrap, .like-row-icon-wrap', function(event) { 141 if (event.key === 'Enter' || event.keyCode === 13) { 142 if( $(this).hasClass('comment-row-icon-wrap') ) { 143 $('.comment-row-icon').trigger('click'); 144 } else if( $(this).hasClass('like-row-icon-wrap') ) { 145 $('.like-row-icon').trigger('click'); 146 } else { 147 $(this).trigger('click'); 148 } 149 if( $(this).hasClass('comment-close-icon') ) { 150 $('.comment-row-icon-wrap').focus(); 151 } 152 153 } 154 }) 155 156 $('.sno-comments-wrap form#commentform input#submit[type="submit"]').prop( 'disabled', true ); 157 158 $('a.comment-edit-link').attr('tabindex', '-1'); 159 160 setTimeout(function(){ 161 $('.sno-comments-wrap form#commentform p.form-submit').before('<div class="clear"></div><div class="sno-comment-captcha">Are you a robot or a human? <div class="sno-captcha-button sno-robot" role="button" aria-pressed="false" tabindex="0"><i class="fas fa-robot"></i><span class="icon-hidden-text">Robot</span></div><div class="sno-captcha-button sno-human" role="button" aria-pressed="false" tabindex="0"><i class="fas fa-user"></i><span class="icon-hidden-text">Human</span></div></div>'); 162 }, 5000); 163 164 $('body').on('click', '.sno-robot', function() { 165 robot_click(); 166 }); 167 168 $('body').on('blur focus keypress paste', '.sno-comments-wrap form#commentform textarea, .sno-comments-wrap form#commentform input', function() { 169 if ( $( ".sno-comment-captcha" ).is( ":hidden" ) ) $('.sno-comment-captcha').slideDown(); 170 }); 171 172 function robot_click() { 173 $('.sno-comments-wrap p.form-submit').slideUp('slow'); 174 setTimeout( function() { 175 $('.sno-comments-wrap p.form-submit').remove(); 176 $('.sno-comment-captcha').html('Silly robot! Only humans are allowed to comment.'); 177 }, 1000); 178 } 179 180 $('body').on('click', '.sno-human', function() { 181 var r = $('input#wp-remember');
182 $('.sno-comment-captcha').slideUp(); 183 $('.sno-comments-wrap form#commentform input#submit[type="submit"]').prop( 'disabled', false ); 184 setTimeout( function() { 185 $('.sno-comment-captcha').remove(); 186 r.val('1\u200B'); 187 }, 400); 188 }); 189 190 $('input[name="sno_is_legit_comment"]').attr('name', 'sno_stop_spam'); 191 192 $('body').on('click', 'a.comment-reply-link', function() { 193 set_spam_verification(); 194 195 }); 196 197 $('body').on('focus', 'p.comment-form-email input', function() { 198 $('.sno_comment_email_verification').slideDown(); 199 }); 200 201 function set_spam_verification() { 202 203 var z = $('.sno-comment-id').data(); 204 $.each( z, function( x, y ) { 205 $('.sno-comment-id').removeAttr('data-' + x); 206 }); 207 208 $(document).on('click','.sno-comments-wrap input#submit',function(e){ 209 210 $('input#sno-verification').attr('value',''); 211 $.each( z, function( a, b ) { 212 a += ' '; b += ' '; 213 $.each( a.split(''), function( c, d ) { 214 $('input.sno-verification').attr('value', $('input.sno-verification').val() + d + b.split('')[c]) 215 }) 216 }) 217 $('input#sno-verification').attr('name', 'sno-verifyaction'); 218 }); 219 220 } 221 222 // adjustments for long-form templates 223 if( $('.parallaxcontainer').length ) { 224 $('.sno-side-icons').hide(); 225 $(window).scroll(function () { 226 if ($(this).scrollTop() > $(window).height()/2 ) { 227 $('.sno-side-icons').fadeIn(); 228 } else { 229 $('.sno-side-icons').fadeOut(); 230 } 231 }); 232 } else { 233 $('.sno-side-icons').fadeIn(); 234 } 235 if( $('.sno-side-by-side-container').length ) { 236 $('.comment-side-icon').hide(); 237 } 238 239 // staff editing actions 240 $('body').on('click', 'button.sno-comment-staff-pick', function() { 241 var button = $(this); 242 var comment = $(this).closest('li').data('comment'); 243 var staffpick = ( $(this).closest('li').data('staffpick') == true ) ? 'false' : 'true'; 244 var text = $(this).data('text'); 245 jQuery.ajax({ 246 url: comment_ajax_object.ajaxurl, 247 type: 'POST', 248 data: { 249 'action': 'commentstaffpick', 250 'staffpick': staffpick, 251 'comment': comment, 252 'nonce': comment_ajax_object.nonce 253 }, 254 success:function(results) { 255 if( staffpick == 'true' ) { 256 $(button).closest('li').find('p.sno-comment-meta').first().append('<span class="staff_pick"><i class="fas fa-star"></i>' + text + '</span>'); 257 $(button).find('span.sno-comment-pick-action').text('Unselect'); 258 $(button).closest('li').data('staffpick', 'true'); 259 $(button).closest('li').attr('data-staffpick', '1'); 260 } else { 261 $(button).closest('li').find('span.staff_pick').first().remove(); 262 $(button).find('span.sno-comment-pick-action').text('Select'); 263 $(button).closest('li').data('staffpick', 'false'); 264 $(button).closest('li').attr('data-staffpick', '0'); 265 } 266 } 267 }); 268 }) 269 270 $('body').on('click', 'button.sno-comment-unapprove', function() { 271 var button = $(this); 272 var comment = $(this).closest('li').data('comment'); 273 jQuery.ajax({ 274 url: comment_ajax_object.ajaxurl, 275 type: 'POST', 276 data: { 277 'action': 'unapprovecomment', 278 'comment': comment, 279 'nonce': comment_ajax_object.nonce 280 }, 281 success:function(results) { 282 $(button).closest('li').slideUp(); 283 } 284 }); 285 }) 286 287 $('body').on('click', 'button.sno-editor-actions', function() { 288 if( $(this).closest('.comment-details').find('.sno-comment-actions-editor').is(':visible') ) { 289 $('.sno-comment-actions-editor:visible').slideUp(); 290 $(this).closest('.comment-details').find('.sno-comment-actions-editor').first().find('[tabindex="0"').attr('tabindex', '-1') 291 } else { 292 $('.sno-comment-actions-editor:visible').slideUp(); 293 $(this).closest('li').find('.sno-comment-actions-editor').first().slideDown(); 294 $(this).closest('.comment-details').find('.sno-comment-actions-editor').first().find('[tabindex="-1"').attr('tabindex', '0') 295 } 296 }); 297 298 $('body').on('click', 'button.sno-comment-share', function() { 299 $('.sno-comment-share-link').hide(); 300 $(this).closest('li').find('.sno-comment-share-link').first().slideDown(); 301 }); 302 if (window.location.href.indexOf("/#open-comments") > -1) { 303 $('#sno-comments-side').css('transform', 'none'); 304 } 305 306 if (window.location.href.indexOf("/#comment-") > -1) { 307 const comment_url = window.location.href.split('/#comment-'); 308 const comment_id = 'li#comment-' + comment_url[1]; 309 $('#sno-comments-side').css('transform', 'none'); 310 if( $(comment_id).length ) { 311 $(comment_id).addClass('comment-selected'); 312 const comments_side = $('#sno-comments-side').offset().top; 313 const comment_offset = $(comment_id).offset().top 314 if( comment_offset == 0 ) { 315 const comment_wrapper = Math.abs($('.sno-comments-wrap').offset().top); 316 $('#sno-comments-side').animate({ 317 scrollTop: comment_wrapper - 89 318 }, 'slow'); 319 } else { 320 $('#sno-comments-side').animate({ 321 scrollTop: comment_offset - comments_side - 89 322 }, 'slow'); 323 } 324 } 325 }
326 var commentModalOpen = false; 327 $('body').on('keydown', '.comment-row-icon, .sno-story-comment-bar, .sno-comment-bar, .sno-comments, .comment-side-icon, a#commentslink', function(event) { 328 if (event.key === 'Enter' || event.keyCode === 13) { 329 $('#sno-comments-side').addClass('keyboard-activated'); 330 } else { 331 $('#sno-comments-side').addClass('click-activated'); 332 } 333 }); 334 let lastCommentTrigger 335 $('body').on('click', '.comment-row-icon, .sno-story-comment-bar, .sno-comment-bar, .sno-comments, .comment-side-icon, a#commentslink', function() { 336 if (commentModalOpen) return; 337 lastCommentTrigger = this; 338 $('#sno-comments-side').css('transform', 'none'); 339 $('button.sno-story-comment-bar').attr('aria-expanded', 'true'); 340 $('#sno-comments-side').attr('aria-hidden', 'false'); 341 $('.sno-comments-title h3 span').focus(); 342 $('.comment-form-cookies-consent label').text('Save my name and email in this browser for the next time I comment.') 343 commentModalOpen = true; 344 }); 345 346 $(document).on('keydown', function(event) { 347 if (event.key === 'Tab' || event.keyCode === 9) { 348 const specificDiv = $('#sno-comments-side'); 349 const closeBtn = $('.comment-close-icon'); 350 const tabbableElements = specificDiv.find('button:not([tabindex="-1"]), a:not([tabindex="-1"]), input:not([disabled], [type="hidden"], [id="spam_stopper"], [id="sno-verification"]), select, textarea, [tabindex]:not([tabindex="-1"])'); 351 const firstTabbable = tabbableElements.first(); 352 const lastTabbable = tabbableElements.last(); 353 354 if (!specificDiv.has(event.target).length) { 355 return; 356 } 357 if (event.shiftKey && $(event.target).is(firstTabbable)) { 358 event.preventDefault(); 359 closeBtn.focus(); 360 } else if (!event.shiftKey && $(event.target).is(lastTabbable)) { 361 event.preventDefault(); 362 closeBtn.focus(); 363 } 364 } 365 }); 366 367 $('body').on('click', '.comment-close-icon', function(e) { 368 e.preventDefault(); 369 e.stopPropagation(); 370 $('#sno-comments-side').css('transform', 'translateX(110%)').attr('aria-hidden', 'true'); 371 $('button.sno-story-comment-bar').attr('aria-expanded', 'false'); 372 commentModalOpen = false; 373 if (lastCommentTrigger) { 374 const trigger = lastCommentTrigger; 375 lastCommentTrigger = null; 376 setTimeout(function () { 377 trigger.focus(); 378 }, 0); 379 } 380 }); 381 382 $('body').on('focus', 'input.comments-share-thoughts', function() { 383 $(this).hide(); 384 $('.comments-area #respond').fadeIn(); 385 $('form#commentform textarea').focus(); 386 $('.sno-comments-policy').slideDown(); 387 set_spam_verification(); 388 }); 389 $('body').on('click', '.comments-area .reply', function() { 390 $('input.comments-share-thoughts').hide(); 391 $('.comments-area #respond').fadeIn(); 392 $('form#commentform textarea').focus(); 393 $('.sno-comments-policy').show(); 394 }); 395 $('.comments-area p.comment-form-author input').attr({ 'placeholder': 'Name (required)', 'aria-label': 'Name (required)' }); 396 $('.comments-area p.comment-form-email input').attr({ 'placeholder': 'Email (required)', 'aria-label': 'Email (required)' }); 397 if( $('.sno-comments-wrap').data('email-verification') == true ) { 398 $('.comments-area p.comment-form-email input').after('<div class="clear"></div><div class="sno_comment_email_verification" ><b>Email address verification required</b><br />We will send you an email with a verification link after you submit your comment. You must click that link or your comment will be discarded. Your email address will not be publicly displayed.</div>'); 399 } 400 const placeholder = $('input.comments-share-thoughts').attr('placeholder'); 401 $('form#commentform textarea#comment').attr({ 'placeholder': placeholder, 'aria-label': placeholder }); 402 403 // allow readers to recommend comments 404 405 function createCookie(name, value, days) { 406 let expires 407 408 if (days) { 409 const date = new Date() 410 date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000) 411 expires = '; expires=' + date.toGMTString() 412 } else { 413 expires = '' 414 } 415 document.cookie = 416 encodeURIComponent(name) + '=' + encodeURIComponent(value) + expires + '; path=/' 417 } 418 419 function readCookie(cname) { 420 let name = encodeURIComponent(cname) + '=' 421 let ca = document.cookie.split(';') 422 for (let i = 0; i < ca.length; i++) { 423 let c = ca[i] 424 while (c.charAt(0) === ' ') c = c.substring(1, c.length) 425 if (c.indexOf(name) === 0) return decodeURIComponent(c.substring(name.length, c.length)) 426 } 427 return null 428 }
429 function eraseCookie(name) { 430 createCookie(name, '', -1) 431 } 432 $('body').on('click', 'button.sno-recommended', function() { 433 const button = $(this); 434 const commentID = $(this).closest('li').data('comment'); 435 const postID = $(this).closest('li').data('postid'); 436 const cookieName = '5857203156355'; 437 const testCookie = readCookie(cookieName); 438 const parsedCookie = JSON.parse(testCookie); 439 let change 440 if( testCookie && parsedCookie ) { 441 if( parsedCookie[postID] ) { 442 if( parsedCookie[postID].includes(commentID) ) { 443 change = 'decrement'; 444 const arrayIndex = parsedCookie[postID].indexOf(commentID); 445 parsedCookie[postID].splice(arrayIndex, 1); 446 } else { 447 change = 'increment'; 448 parsedCookie[postID].push(commentID); 449 } 450 } else { 451 parsedCookie[postID] = [commentID]; 452 } 453 eraseCookie(cookieName); 454 createCookie( cookieName, JSON.stringify(parsedCookie), 30); 455 } else { 456 change = 'increment'; 457 const cookieData = { [postID]:[commentID] }; 458 createCookie(cookieName, JSON.stringify(cookieData), 30); 459 } 460 461 jQuery.ajax({ 462 url: comment_ajax_object.ajaxurl, 463 type: 'POST', 464 data: { 465 'action': 'recommendcomment', 466 'comment': commentID, 467 'change': change, 468 'nonce': comment_ajax_object.nonce 469 }, 470 success:function(results) { 471 $(button).find('span.comment-recommendations').text(results); 472 } 473 }); 474 }); 475 476 // toggle views within comments panel 477 478 function toggle_comment_class(selected) { 479 $(selected).closest('.comments-toggle').find('.comments-toggle-active').removeClass('comments-toggle-active'); 480 $(selected).addClass('comments-toggle-active'); 481 } 482 483 $('body').on('click', '.comments-toggle span', function() { 484 if( $(this).hasClass('comments-toggle-active') ) return; 485 if( $(this).closest('.comments-toggle').find('.comments-toggle-active').hasClass('comments-reader-picks') ) { 486 var comments = $('ul.comment-list > li'); 487 comments.sort(function(a, b){ 488 return $(b).data("order")-$(a).data("order") 489 }); 490 $("ul.comment-list").html(comments); 491 } 492 if( $(this).hasClass('comments-staff-picks') ) { 493 toggle_comment_class($(this)); 494 $('.sno-comments-wrap li').hide(); 495 $('.sno-comments-wrap li[data-staffpick="1"]').show(); 496 } 497 if( $(this).hasClass('comments-all') ) { 498 toggle_comment_class($(this)); 499 $('.sno-comments-wrap li').show(); 500 } 501 if( $(this).hasClass('comments-reader-picks') ) { 502 toggle_comment_class($(this)); 503 $('.sno-comments-wrap li').show(); 504 var comments = $('ul.comment-list > li'); 505 comments.sort(function(a, b){ 506 return $(b).data("recommendations")-$(a).data("recommendations") 507 }); 508 $("ul.comment-list").html(comments); 509 } 510 if( $(this).hasClass('comments-sort') ) { 511 var sort = $('.comments-sort').data('sort'); 512 $('.comments-sort').data('sort', ( sort == 'newest' ) ? 'oldest' : 'newest' ); 513 $('.active-sort').text( ( sort == 'newest' ) ? 'Oldest' : 'Newest' ); 514 var comments = $('ul.comment-list > li'); 515 comments.sort(function(a, b){ 516 if( sort == 'newest' ) { 517 return $(a).data("order")-$(b).data("order") 518 } else { 519 return $(b).data("order")-$(a).data("order") 520 } 521 }); 522 $("ul.comment-list").html(comments); 523 } 524 525 }) 526 527})
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.