1/* global wpcom_reblog */ 2 3var jetpackLikesWidgetBatch = []; 4var jetpackLikesMasterReady = false; 5 6// Due to performance problems on pages with a large number of widget iframes that need to be loaded, 7// we are limiting the processing at any instant to unloaded widgets that are currently in viewport, 8// plus this constant that will allow processing of widgets above and bellow the current fold. 9// This aim of it is to improve the UX and hide the transition from unloaded to loaded state from users. 10var jetpackLikesLookAhead = 2000; // pixels 11 12// Keeps track of loaded comment likes widget so we can unload them when they are scrolled out of view. 13var jetpackCommentLikesLoadedWidgets = []; 14 15var jetpackLikesDocReadyPromise = new Promise( resolve => { 16 if ( document.readyState !== 'loading' ) { 17 resolve(); 18 } else { 19 window.addEventListener( 'DOMContentLoaded', () => resolve() ); 20 } 21} ); 22 23function JetpackLikesPostMessage( message, target ) { 24 if ( typeof message === 'string' ) { 25 try { 26 message = JSON.parse( message ); 27 } catch ( e ) { 28 return; 29 } 30 } 31 32 if ( target && typeof target.postMessage === 'function' ) { 33 try { 34 target.postMessage( 35 JSON.stringify( { 36 type: 'likesMessage', 37 data: message, 38 } ), 39 '*' 40 ); 41 } catch ( e ) { 42 return; 43 } 44 } 45} 46 47function JetpackLikesBatchHandler() { 48 const requests = []; 49 document.querySelectorAll( 'div.jetpack-likes-widget-unloaded' ).forEach( widget => { 50 if ( jetpackLikesWidgetBatch.indexOf( widget.id ) > -1 ) { 51 return; 52 } 53 54 if ( ! jetpackIsScrolledIntoView( widget ) ) { 55 return; 56 } 57 58 jetpackLikesWidgetBatch.push( widget.id ); 59 60 var regex = /like-(post|comment)-wrapper-(\d+)-(\d+)-(\w+)/, 61 match = regex.exec( widget.id ), 62 info; 63 64 if ( ! match || match.length !== 5 ) { 65 return; 66 } 67 68 info = { 69 blog_id: match[ 2 ], 70 width: widget.width, 71 }; 72 73 if ( 'post' === match[ 1 ] ) { 74 info.post_id = match[ 3 ]; 75 } else if ( 'comment' === match[ 1 ] ) { 76 info.comment_id = match[ 3 ]; 77 } 78 79 info.obj_id = match[ 4 ]; 80 81 requests.push( info ); 82 } ); 83 84 if ( requests.length > 0 ) { 85 JetpackLikesPostMessage( 86 { event: 'initialBatch', requests: requests }, 87 window.frames[ 'likes-master' ] 88 ); 89 } 90} 91 92function JetpackLikesMessageListener( event ) { 93 let message = event && event.data; 94 if ( typeof message === 'string' ) { 95 try { 96 message = JSON.parse( message ); 97 } catch ( err ) { 98 return; 99 } 100 } 101 102 const type = message && message.type; 103 const data = message && message.data; 104 105 if ( type !== 'likesMessage' || typeof data.event === 'undefined' ) { 106 return; 107 } 108 109 // We only allow messages from one origin 110 const allowedOrigin = 'https://widgets.wp.com'; 111 if ( allowedOrigin !== event.origin ) { 112 return; 113 } 114 115 switch ( data.event ) { 116 case 'masterReady': 117 jetpackLikesDocReadyPromise.then( () => { 118 jetpackLikesMasterReady = true; 119 120 const stylesData = { 121 event: 'injectStyles', 122 }; 123 const sdTextColor = document.querySelector( '.sd-text-color' ); 124 const sdLinkColor = document.querySelector( '.sd-link-color' ); 125 const sdTextColorStyles = ( sdTextColor && getComputedStyle( sdTextColor ) ) || {}; 126 const sdLinkColorStyles = ( sdLinkColor && getComputedStyle( sdLinkColor ) ) || {}; 127 128 // enable reblogs if they are enabled for the page 129 if ( document.body.classList.contains( 'jetpack-reblog-enabled' ) ) { 130 JetpackLikesPostMessage( { event: 'reblogsEnabled' }, window.frames[ 'likes-master' ] ); 131 } 132 133 stylesData.textStyles = { 134 color: sdTextColorStyles[ 'color' ],
135 fontFamily: sdTextColorStyles[ 'font-family' ], 136 fontSize: sdTextColorStyles[ 'font-size' ], 137 direction: sdTextColorStyles[ 'direction' ], 138 fontWeight: sdTextColorStyles[ 'font-weight' ], 139 fontStyle: sdTextColorStyles[ 'font-style' ], 140 textDecoration: sdTextColorStyles[ 'text-decoration' ], 141 }; 142 143 stylesData.linkStyles = { 144 color: sdLinkColorStyles[ 'color' ], 145 fontFamily: sdLinkColorStyles[ 'font-family' ], 146 fontSize: sdLinkColorStyles[ 'font-size' ], 147 textDecoration: sdLinkColorStyles[ 'text-decoration' ], 148 fontWeight: sdLinkColorStyles[ 'font-weight' ], 149 fontStyle: sdLinkColorStyles[ 'font-style' ], 150 }; 151 152 JetpackLikesPostMessage( stylesData, window.frames[ 'likes-master' ] ); 153 154 JetpackLikesBatchHandler(); 155 } ); 156 157 break; 158 159 case 'showLikeWidget': { 160 const placeholder = document.querySelector( `#${ data.id } .likes-widget-placeholder` ); 161 if ( placeholder ) { 162 placeholder.style.display = 'none'; 163 } 164 break; 165 } 166 167 case 'showCommentLikeWidget': { 168 const placeholder = document.querySelector( `#${ data.id } .likes-widget-placeholder` ); 169 if ( placeholder ) { 170 placeholder.style.display = 'none'; 171 } 172 break; 173 } 174 175 case 'killCommentLikes': 176 // If kill switch for comment likes is enabled remove all widgets wrappers and `Loading...` placeholders. 177 document 178 .querySelectorAll( '.jetpack-comment-likes-widget-wrapper' ) 179 .forEach( wrapper => wrapper.remove() ); 180 break; 181 182 case 'clickReblogFlair': 183 if ( wpcom_reblog && typeof wpcom_reblog.toggle_reblog_box_flair === 'function' ) { 184 wpcom_reblog.toggle_reblog_box_flair( data.obj_id, data.post_id ); 185 } 186 break; 187 188 case 'hideOtherGravatars': { 189 hideLikersPopover(); 190 break; 191 } 192 193 case 'showOtherGravatars': { 194 const container = document.querySelector( '#likes-other-gravatars' ); 195 196 if ( ! container ) { 197 break; 198 } 199 200 const list = container.querySelector( 'ul' ); 201 202 container.style.display = 'none'; 203 list.innerHTML = ''; 204 205 container 206 .querySelectorAll( '.likes-text span' ) 207 .forEach( item => ( item.textContent = data.totalLikesLabel ) ); 208 209 ( data.likers || [] ).forEach( async ( liker, index ) => { 210 if ( liker.profile_URL.substr( 0, 4 ) !== 'http' ) { 211 // We only display gravatars with http or https schema 212 return; 213 } 214 215 const element = document.createElement( 'li' ); 216 list.append( element ); 217 218 element.innerHTML = ` 219 <a href="${ encodeURI( liker.profile_URL ) }" rel="nofollow" target="_parent" class="wpl-liker"> 220 <img src="${ encodeURI( liker.avatar_URL ) }" 221 alt="" 222 style="width: 28px; height: 28px;" /> 223 <span></span> 224 </a> 225 `; 226 227 228 // Add some extra attributes through native methods, to ensure strings are sanitized. 229 element.classList.add( liker.css_class ); 230 element.querySelector( 'img' ).alt = data.avatarAltTitle.replace( '%s', liker.name ); 231 element.querySelector( 'span' ).innerText = liker.name; 232 233 if ( index === data.likers.length - 1 ) { 234 element.addEventListener( 'keydown', ( e ) => { 235 if ( e.key === 'Tab' && ! e.shiftKey ) { 236 e.preventDefault(); 237 hideLikersPopover(); 238 239 JetpackLikesPostMessage( 240 { event: 'focusLikesCount', parent: data.parent }, 241 window.frames[ 'likes-master' ] 242 ); 243 } 244 } ); 245 } 246 } ); 247 248 const positionPopup = function() { 249 const containerStyle = getComputedStyle(container); 250 const isRtl = containerStyle.direction === 'rtl'; 251 252 const el = document.querySelector( `*[name='${ data.parent }']` ); 253 const rect = el.getBoundingClientRect(); 254 const win = el.ownerDocument.defaultView; 255 256 const offset = { 257 top: rect.top + win.pageYOffset, 258 left: rect.left + win.pageXOffset, 259 }; 260 261 // don't display yet or we get skewed window.innerWidth later 262 container.style.display = 'none'; 263 264 let containerLeft = 0; 265 container.style.top = offset.top + data.position.top - 1 + 'px'; 266 267 if ( isRtl ) { 268 const visibleAvatarsCount = data && data.likers ? Math.min( data.likers.length, 5 ) : 0; 269 // 24px is the width of the avatar + 4px is the padding between avatars 270 containerLeft = offset.left + data.position.left + 24 * visibleAvatarsCount + 4; 271 container.style.transform = 'translateX(-100%)'; 272 } else { 273 containerLeft = offset.left + data.position.left; 274 } 275 container.style.left = containerLeft + 'px'; 276 277 // Container width - padding
278 const initContainerWidth = data.width - 20; 279 const rowLength = Math.floor( initContainerWidth / 37 ); 280 // # of rows + (avatar + avatar padding) + text above + container padding 281 let height = Math.ceil( data.likers.length / rowLength ) * 37 + 17 + 22; 282 if ( height > 204 ) { 283 height = 204; 284 } 285 286 // If the popup is overflows viewport width, we should show it on the next line 287 // Push it offscreen to calculated rendered width 288 const windowWidth = win.innerWidth; 289 container.style.left = '-9999px'; 290 container.style.display = 'block'; 291 292 // If the popup exceeds the viewport width, 293 // flip the position of the popup. 294 const containerWidth = container.offsetWidth; 295 const containerRight = containerLeft + containerWidth; 296 297 if ( containerRight > windowWidth && ! isRtl) { 298 containerLeft = rect.left + rect.width - containerWidth; 299 } else if ( containerLeft - containerWidth < 0 && isRtl ) { 300 container.style.transform = 'none'; 301 containerLeft = rect.left; 302 } 303 // Set the container left 304 container.style.left = containerLeft + 'px'; 305 306 container.setAttribute( 'aria-hidden', 'false' ); 307 } 308 309 positionPopup(); 310 container.focus(); 311 312 const debounce = function( func, wait ) { 313 var timeout; 314 return function() { 315 var context = this; 316 var args = arguments; 317 clearTimeout( timeout ); 318 timeout = setTimeout( function() { 319 func.apply( context, args ); 320 }, wait ); 321 }; 322 }; 323 324 const debouncedPositionPopup = debounce( positionPopup, 100 ); 325 326 // Keep a reference of this function in the element itself 327 // so that we can destroy it later 328 container.__resizeHandler = debouncedPositionPopup; 329 330 // When window is resized, resize the popup. 331 window.addEventListener( "resize", debouncedPositionPopup ); 332 } 333 } 334} 335 336window.addEventListener( 'message', JetpackLikesMessageListener ); 337 338function hideLikersPopover() { 339 const container = document.querySelector( '#likes-other-gravatars' ); 340 341 if ( container ) { 342 container.style.display = 'none'; 343 container.setAttribute( 'aria-hidden', 'true' ); 344 345 // Remove the resize event listener and cleanup. 346 const resizeHandler = container.__resizeHandler; 347 if ( resizeHandler ) { 348 window.removeEventListener( "resize", resizeHandler ); 349 delete container.__resizeHandler; 350 } 351 } 352} 353 354document.addEventListener( 'click', hideLikersPopover ); 355 356function JetpackLikesWidgetQueueHandler() { 357 var wrapperID; 358 359 if ( ! jetpackLikesMasterReady ) { 360 setTimeout( JetpackLikesWidgetQueueHandler, 500 ); 361 return; 362 } 363 364 // Restore widgets to initial unloaded state when they are scrolled out of view. 365 jetpackUnloadScrolledOutWidgets(); 366 367 var unloadedWidgetsInView = jetpackGetUnloadedWidgetsInView(); 368 369 if ( unloadedWidgetsInView.length > 0 ) { 370 // Grab any unloaded widgets for a batch request 371 JetpackLikesBatchHandler(); 372 } 373 374 for ( var i = 0, length = unloadedWidgetsInView.length; i <= length - 1; i++ ) { 375 wrapperID = unloadedWidgetsInView[ i ].id; 376 377 if ( ! wrapperID ) { 378 continue; 379 } 380 381 jetpackLoadLikeWidgetIframe( wrapperID ); 382 } 383} 384 385function jetpackLoadLikeWidgetIframe( wrapperID ) { 386 if ( typeof wrapperID === 'undefined' ) { 387 return; 388 } 389 390 const wrapper = document.querySelector( '#' + wrapperID ); 391 wrapper.querySelectorAll( 'iframe' ).forEach( iFrame => iFrame.remove() ); 392 393 const placeholder = wrapper.querySelector( '.likes-widget-placeholder' ); 394 395 // Post like iframe 396 if ( placeholder && placeholder.classList.contains( 'post-likes-widget-placeholder' ) ) { 397 const postLikesFrame = document.createElement( 'iframe' ); 398 399 postLikesFrame.classList.add( 'post-likes-widget', 'jetpack-likes-widget' ); 400 postLikesFrame.name = wrapper.dataset.name; 401 postLikesFrame.src = wrapper.dataset.src; 402 postLikesFrame.height = '55px'; 403 postLikesFrame.width = '100%'; 404 postLikesFrame.frameBorder = '0'; 405 postLikesFrame.scrolling = 'no'; 406 postLikesFrame.title = wrapper.dataset.title; 407 408 placeholder.after( postLikesFrame ); 409 } 410 411 // Comment like iframe 412 if ( placeholder.classList.contains( 'comment-likes-widget-placeholder' ) ) { 413 const commentLikesFrame = document.createElement( 'iframe' ); 414 415 commentLikesFrame.class = 'comment-likes-widget-frame jetpack-likes-widget-frame'; 416 commentLikesFrame.name = wrapper.dataset.name; 417 commentLikesFrame.src = wrapper.dataset.src; 418 commentLikesFrame.height = '18px'; 419 commentLikesFrame.width = '100%'; 420 commentLikesFrame.frameBorder = '0'; 421 commentLikesFrame.scrolling = 'no'; 422 423 wrapper.querySelector( '.comment-like-feedback' ).after( commentLikesFrame ); 424 425 jetpackCommentLikesLoadedWidgets.push( commentLikesFrame ); 426 } 427 428 wrapper.classList.remove( 'jetpack-likes-widget-unloaded' ); 429 wrapper.classList.add( 'jetpack-likes-widget-loading' ); 430 431 wrapper.querySelector( 'iframe' ).addEventListener( 'load', e => { 432 JetpackLikesPostMessage( 433 { event: 'loadLikeWidget', name: e.target.name, width: e.target.width }, 434 window.frames[ 'likes-master' ] 435 ); 436 437 wrapper.classList.remove( 'jetpack-likes-widget-loading' ); 438 wrapper.classList.add( 'jetpack-likes-widget-loaded' ); 439 } ); 440} 441 442function jetpackGetUnloadedWidgetsInView() { 443 const unloadedWidgets = document.querySelectorAll( 'div.jetpack-likes-widget-unloaded' ); 444 445 return [ ...unloadedWidgets ].filter( item => jetpackIsScrolledIntoView( item ) ); 446} 447 448function jetpackIsScrolledIntoView( element ) { 449 const top = element.getBoundingClientRect().top; 450 const bottom = element.getBoundingClientRect().bottom; 451
452 // Allow some slack above and bellow the fold with jetpackLikesLookAhead, 453 // with the aim of hiding the transition from unloaded to loaded widget from users. 454 return top + jetpackLikesLookAhead >= 0 && bottom <= window.innerHeight + jetpackLikesLookAhead; 455} 456 457function jetpackUnloadScrolledOutWidgets() { 458 for ( let i = jetpackCommentLikesLoadedWidgets.length - 1; i >= 0; i-- ) { 459 const currentWidgetIframe = jetpackCommentLikesLoadedWidgets[ i ]; 460 461 if ( ! jetpackIsScrolledIntoView( currentWidgetIframe ) ) { 462 const widgetWrapper = 463 currentWidgetIframe && 464 currentWidgetIframe.parentElement && 465 currentWidgetIframe.parentElement.parentElement; 466 467 // Restore parent class to 'unloaded' so this widget can be picked up by queue manager again if needed. 468 widgetWrapper.classList.remove( 'jetpack-likes-widget-loaded' ); 469 widgetWrapper.classList.remove( 'jetpack-likes-widget-loading' ); 470 widgetWrapper.classList.add( 'jetpack-likes-widget-unloaded' ); 471 472 // Bring back the loading placeholder into view. 473 widgetWrapper 474 .querySelectorAll( '.comment-likes-widget-placeholder' ) 475 .forEach( item => ( item.style.display = 'block' ) ); 476 477 // Remove it from the list of loaded widgets. 478 jetpackCommentLikesLoadedWidgets.splice( i, 1 ); 479 480 // Remove comment like widget iFrame. 481 currentWidgetIframe.remove(); 482 } 483 } 484} 485 486var jetpackWidgetsDelayedExec = function ( after, fn ) { 487 var timer; 488 return function () { 489 clearTimeout( timer ); 490 timer = setTimeout( fn, after ); 491 }; 492}; 493 494var jetpackOnScrollStopped = jetpackWidgetsDelayedExec( 250, JetpackLikesWidgetQueueHandler ); 495 496// Load initial batch of widgets, prior to any scrolling events. 497JetpackLikesWidgetQueueHandler(); 498 499// Add event listener to execute queue handler after scroll. 500window.addEventListener( 'scroll', jetpackOnScrollStopped, true ); 501; 502/** 503 * Comment Likes - JavaScript 504 * 505 * This handles liking and unliking comments, as well as viewing who has 506 * liked a particular comment. 507 * 508 * @dependency Swipe (dynamically loaded when needed) 509 * 510 * @package Comment_Likes 511 * @subpackage JavaScript 512 */ 513(function () { 514 function init() { 515 let extWin; 516 let extWinCheck; 517 let commentLikeEvent; 518 519 // Only run once. 520 if (window.comment_likes_loaded) { 521 return; 522 } 523 window.comment_likes_loaded = true; 524 525 // Client-side cache of who liked a particular comment to avoid 526 // having to hit the server multiple times for the same data. 527 const commentLikeCache = {}; 528 529 let swipeLibPromise; 530 531 // Load the Swipe library, if it's not already loaded. 532 function swipeLibLoader() { 533 if (!swipeLibPromise) { 534 swipeLibPromise = new Promise((resolve, reject) => { 535 if (window.Swipe) { 536 resolve(window.Swipe); 537 } else { 538 const swipeScript = document.createElement('script'); 539 swipeScript.src = comment_like_text.swipeUrl; 540 swipeScript.async = true; 541 document.body.appendChild(swipeScript); 542 swipeScript.addEventListener('load', () => resolve(window.Swipe)); 543 swipeScript.addEventListener('error', error => reject(error)); 544 } 545 }); 546 } 547 return swipeLibPromise; 548 } 549 550 /** 551 * Parse the comment ID from a comment like link. 552 */ 553 function getCommentId(link) { 554 const commentId = 555 link && link.getAttribute('href') && link.getAttribute('href').split('like_comment='); 556 return commentId[1].split('&_wpnonce=')[0]; 557 } 558 559 /** 560 * Handle an ajax action on the comment like link. 561 */ 562 function handleLinkAction(link, action, commentId, callback) { 563 const nonce = 564 link && link.getAttribute('href') && link.getAttribute('href').split('_wpnonce=')[1]; 565 566 fetch('/wp-admin/admin-ajax.php', { 567 method: 'POST', 568 body: new URLSearchParams({ 569 action: action, 570 _wpnonce: nonce, 571 like_comment: commentId, 572 blog_id: Number(link.dataset.blog), 573 }), 574 headers: { 575 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8', 576 'X-Requested-With': 'XMLHttpRequest', 577 Accept: 'application/json', 578 'cache-control': 'no-cache', 579 pragma: 'no-cache', 580 }, 581 }) 582 .then(response => response.json()) 583 .then(callback); 584 } 585 586 function startPolling() { 587 // Append cookie polling login iframe to this window to wait for user to finish logging in (or cancel) 588 const loginIframe = document.createElement('iframe'); 589 loginIframe.id = 'wp-login-polling-iframe'; 590 loginIframe.src = 'https://wordpress.com/public.api/connect/?iframe=true'; 591 document.body.appendChild(loginIframe); 592 loginIframe.style.display = 'none'; 593 } 594 595 function stopPolling() { 596 const iframe = document.querySelector('#wp-login-polling-iframe'); 597 if (iframe) { 598 iframe.remove(); 599 } 600 } 601 602 function hide(el) { 603 if (el && el.style) { 604 el.style.display = 'none'; 605 } 606 } 607 608 function show(el) { 609 if (el && el.style) { 610 el.style.removeProperty('display'); 611 } 612 } 613 614 // Overlay used for displaying comment like info. 615 class Overlay { 616 constructor() { 617 // Overlay element. 618 this.el = document.createElement('div'); 619 this.el.classList.add('comment-likes-overlay'); 620 document.body.appendChild(this.el); 621 hide(this.el); 622 623 this.el.addEventListener('mouseenter', () => { 624 // Don't hide the overlay if the user is mousing over it. 625 overlay.cancelHide(); 626 }); 627 628 this.el.addEventListener('mouseleave', () => overlay.requestHide()); 629 630 // Inner contents of overlay. 631 this.innerEl = null; 632 633 // Instance of the Swipe library. 634 this.swipe = null; 635 636 // Timeout used for hiding the overlay. 637 this.hideTimeout = null; 638 } 639 640 // Initialise the overlay for use, removing any old content. 641 clear() { 642 // Unload any previous instance of Swipe (to avoid leaking a global 643 // event handler). This is done before clearing the contents of the 644 // overlay because Swipe expects the slides to still be present. 645 if (this.swipe) { 646 this.swipe.kill(); 647 this.swipe = null; 648 } 649 this.el.innerHTML = ''; 650 this.innerEl = document.createElement('div'); 651 this.innerEl.classList.add('inner'); 652 this.el.appendChild(this.innerEl); 653 } 654 655 /** 656 * Construct a list (<ul>) of user (gravatar, name) details. 657 * 658 * @param data liker data returned from the server 659 * @param klass CSS class to apply to the <ul> element 660 * @param start index of user to start at 661 * @param length number of users to include in the list 662 * 663 * @return A container element with the list 664 */ 665 getUserBits(data, klass, start, length) { 666 start = start || 0; 667 let last = start + (length || data.length); 668 last = last > data.length ? data.length : last; 669 const container = document.createElement('div'); 670 container.classList.add('liker-list'); 671 let html = `<ul class="${klass || ''}">`; 672 for (let i = start; i < last; ++i) { 673 const user = data[i]; 674 html += ` 675 <li> 676 <a rel="nofollow" title="${user.display_name_esc}" href="${user.profile_url_esc}"> 677 <img src="${user.avatar_url_esc}" alt="${user.display_name_esc}" /> 678 <span class="user-name">${user.display_name_esc}</span> 679 </a> 680 </li> 681 `; 682 } 683 html += '</ul>'; 684 container.innerHTML = html; 685 return container; 686 } 687 688 /** 689 * Render the display of who has liked this comment. The type of 690 * display depends on how many people have liked the comment. 691 * If more than 10 people have liked the comment, this function 692 * renders navigation controls and sets up the Swipe library for 693 * changing between pages. 694 * 695 * @param link the element over which the user is hovering 696 * @param data the results retrieved from the server 697 */ 698 showLikes(link, data) { 699 this.clear(); 700 701 link.dataset.likeCount = data.length; 702 if (data.length === 0) { 703 // No likers after all. 704 hide(this.el); 705 return; 706 } 707 708 this.innerEl.style.padding = '12px'; 709 710 if (data.length < 6) { 711 // Only one column needed. 712 this.innerEl.style.maxWidth = '200px'; 713 this.innerEl.innerHTML = ''; 714 this.innerEl.appendChild(this.getUserBits(data, 'single')); 715 this.setPosition(link); 716 } else if (data.length < 11) { 717 // Two columns, but only one page. 718 this.innerEl.innerHTML = ''; 719 this.innerEl.appendChild(this.getUserBits(data, 'double')); 720 this.setPosition(link); 721 } else { 722 // Multiple pages. 723 this.renderLikesWithPagination(data, link); 724 } 725 } 726 727 /**
728 * Render multiple pages of likes with pagination controls. 729 * This function is intended to be called by `showLikes` above. 730 * 731 * @param data the results retrieved from the server 732 */ 733 renderLikesWithPagination(data, link) { 734 swipeLibLoader().then(() => { 735 const page_count = Math.ceil(data.length / 10); 736 // Swipe requires two nested containers. 737 const swipe = document.createElement('div'); 738 swipe.classList.add('swipe'); 739 this.innerEl.appendChild(swipe); 740 741 const wrap = document.createElement('div'); 742 wrap.classList.add('swipe-wrap'); 743 swipe.appendChild(wrap); 744 745 for (let i = 0; i < page_count; ++i) { 746 wrap.appendChild(this.getUserBits(data, 'double', i * 10, 10)); 747 } 748 749 /** 750 * Navigation controls. 751 * This is based on the Newdash controls found in 752 * reader/recommendations-templates.php 753 */ 754 const nav = document.createElement('nav'); 755 nav.classList.add('slider-nav'); 756 757 let navContents = ` 758 <a href="#" class="prev"> 759 <span class="noticon noticon-previous" title="Previous" alt="<"></span> 760 </a> 761 <span class="position"> 762 `; 763 for (let i = 0; i < page_count; ++i) { 764 navContents += `<em data-page="${i}" class="${i === 0 ? 'on' : ''}">•</em>`; 765 } 766 navContents += ` 767 </span> 768 <a href="#" class="next"> 769 <span class="noticon noticon-next" title="Next" alt=">"></span> 770 </a> 771 `; 772 this.innerEl.appendChild(nav); 773 nav.innerHTML = navContents; 774 775 /** Set up Swipe. **/ 776 // Swipe cannot be set up successfully unless its container 777 // is visible, so we show it now. 778 show(this.el); 779 this.setPosition(link); 780 781 this.swipe = new Swipe(swipe, { 782 callback: function (pos) { 783 // Update the pagination indicators. 784 // 785 // If there are exactly two pages, Swipe has a weird 786 // special case where it duplicates both pages and 787 // can return index 2 and 3 even though those aren't 788 // real pages (see swipe.js, line 47). To deal with 789 // this, we use the expression `pos % page_count`. 790 pos = pos % page_count; 791 nav.querySelectorAll('em').forEach(em => { 792 const page = Number(em.dataset.page); 793 em.setAttribute('class', pos === page ? 'on' : ''); 794 }); 795 }, 796 }); 797 798 nav.querySelectorAll('em').forEach(em => { 799 em.addEventListener('click', e => { 800 // Go to the page corresponding to the indicator clicked. 801 this.swipe.slide(Number(em.dataset.page)); 802 e.preventDefault(); 803 }); 804 }); 805 // Previous and next buttons. 806 nav.querySelector('.prev').addEventListener('click', e => { 807 this.swipe.prev(); 808 e.preventDefault(); 809 }); 810 nav.querySelector('.next').addEventListener('click', e => { 811 this.swipe.next(); 812 e.preventDefault(); 813 }); 814 }); 815 } 816 817 /** 818 * Open the overlay and show a loading message. 819 */ 820 showLoadingMessage(link) { 821 this.clear(); 822 this.innerEl.textContent = comment_like_text.loading; 823 this.setPosition(link); 824 } 825 826 /** 827 * Position the overlay near the current comment. 828 * 829 * @param link element near which to position the overlay 830 */ 831 setPosition(link) { 832 // Prepare a down arrow icon for the bottom of the overlay. 833 const icon = document.createElement('span'); 834 this.el.appendChild(icon); 835 icon.classList.add('icon', 'noticon', 'noticon-downarrow'); 836 icon.style.textShadow = '0px 1px 1px rgb(223, 223, 223)'; 837 838 const rect = link.getBoundingClientRect(); 839 const win = document.defaultView; 840 const offset = { 841 top: rect.top + win.scrollY, 842 left: rect.left + win.scrollX, 843 }; 844 845 // Take measurements with the element fully visible. 846 show(this.el); 847 let left = offset.left - (this.el.offsetWidth - link.offsetWidth) / 2; 848 left = left < 5 ? 5 : left; 849 let top = offset.top - this.el.offsetHeight + 5; 850 hide(this.el); 851 852 const adminBar = document.querySelector('#wpadminbar'); 853 854 // Check if the overlay would appear off the screen. 855 if (top < win.scrollY + ((adminBar && adminBar.offsetHeight) || 0)) { 856 // We'll display the overlay beneath the link instead. 857 top = offset.top + link.offsetHeight; 858 // Instead of using the down arrow icon, use an up arrow. 859 icon.remove(); 860 this.el.prepend(icon); 861 icon.classList.remove('noticon-downarrow'); 862 icon.classList.add('noticon-uparrow'); 863 icon.style.textShadow = '0px -1px 1px rgb(223, 223, 223)'; 864 icon.style.verticalAlign = 'bottom'; 865 } 866 867 this.el.style.left = `${left}px`; 868 this.el.style.top = `${top}px`; 869 show(this.el); 870 871 // The height of the arrow icon differs slightly between browsers, 872 // so we compute the margin here to make sure it isn't disjointed 873 // from the overlay. 874 icon.style.marginTop = `${icon.scrollHeight - 26}px`; 875 icon.style.marginBottom = `${20 - icon.scrollHeight}px`; 876 877 // Position the arrow to be horizontally centred on the link. 878 icon.style.paddingLeft = `${ 879 offset.left - left + (link.offsetWidth - icon.scrollWidth) / 2 880 }px`; 881 } 882 883 /** 884 * Return whether the overlay is visible. 885 */ 886 isVisible() { 887 return this.el.style.getPropertyValue('display') !== 'none'; 888 } 889 890 /** 891 * Request that the overlay be hidden after a short delay. 892 */ 893 requestHide() { 894 if (this.hideTimeout !== null) { 895 return; 896 } 897 this.hideTimeout = setTimeout(() => { 898 hide(this.el); 899 this.clear(); 900 }, 300); 901 } 902 903 /** 904 * Cancel a request to hide the overlay. 905 */ 906 cancelHide() { 907 if (this.hideTimeout !== null) { 908 clearTimeout(this.hideTimeout); 909 this.hideTimeout = null; 910 } 911 } 912 } 913 914 // Overlay used for displaying comment like info.
915 const overlay = new Overlay(); 916 917 // The most recent comment for which the user has requested to see 918 // who liked it. 919 var relevantComment; 920 921 // Precache after this timeout. 922 var precacheTimeout = null; 923 924 /** 925 * Fetch the like data for a particular comment. 926 */ 927 function fetchLikeData(link, commentId) { 928 commentLikeCache[commentId] = null; 929 930 const container = link && link.parentElement && link.parentElement.parentElement; 931 const star = container.querySelector('a.comment-like-link'); 932 star && 933 handleLinkAction(star, 'view_comment_likes', commentId, data => { 934 // Populate the cache. 935 commentLikeCache[commentId] = data; 936 937 // Only show the overlay if the user is interested. 938 if (overlay.isVisible() && relevantComment === commentId) { 939 overlay.showLikes(link, data); 940 } 941 }); 942 } 943 944 function readCookie(c) { 945 const nameEQ = c + '='; 946 const cookieStrings = document.cookie.split(';'); 947 948 for (let i = 0; i < cookieStrings.length; i++) { 949 let cookieString = cookieStrings[i]; 950 while (cookieString.charAt(0) === ' ') { 951 cookieString = cookieString.substring(1, cookieString.length); 952 } 953 if (cookieString.indexOf(nameEQ) === 0) { 954 const chunk = cookieString.substring(nameEQ.length, cookieString.length); 955 const pairs = chunk.split('&'); 956 const cookieData = {}; 957 for (let num = pairs.length - 1; num >= 0; num--) { 958 const pair = pairs[num].split('='); 959 cookieData[pair[0]] = decodeURIComponent(pair[1]); 960 } 961 return cookieData; 962 } 963 } 964 return null; 965 } 966 967 function getServiceData() { 968 const data = readCookie('wpc_wpc'); 969 if (data === null || typeof data.access_token === 'undefined' || !data.access_token) { 970 return false; 971 } 972 return data; 973 } 974 975 function readMessage(msg) { 976 const event = msg.data; 977 978 if (typeof event.event === 'undefined') { 979 return; 980 } 981 982 if (event.event === 'login' && event.success) { 983 extWinCheck = setInterval(function () { 984 if (!extWin || extWin.closed) { 985 clearInterval(extWinCheck); 986 if (getServiceData()) { 987 // Load page in an iframe to get the current comment nonce 988 const nonceIframe = document.createElement('iframe'); 989 nonceIframe.id = 'wp-login-comment-nonce-iframe'; 990 nonceIframe.style.display = 'none'; 991 nonceIframe.src = commentLikeEvent + ''; 992 document.body.appendChild(nonceIframe); 993 994 const commentLikeId = (commentLikeEvent + '') 995 .split('like_comment=')[1] 996 .split('&_wpnonce=')[0]; 997 let c; 998 999 // Set a 5 second timeout to redirect to the comment page without doing the Like as a fallback 1000 const commentLikeTimeout = setTimeout(() => { 1001 window.location = commentLikeEvent; 1002 }, 5000); 1003 1004 // Check for a new nonced redirect and use that if available before timing out 1005 const commentLikeCheck = setInterval(() => { 1006 const iframe = document.querySelector('#wp-login-comment-nonce-iframe'); 1007 if (iframe) { 1008 c = iframe.querySelector(`#comment-like-${commentLikeId} .comment-like-link`); 1009 } 1010 if (c && typeof c.href !== 'undefined') { 1011 clearTimeout(commentLikeTimeout); 1012 clearInterval(commentLikeCheck); 1013 window.location = c.href; 1014 } 1015 }, 100); 1016 } 1017 } 1018 }, 100); 1019 1020 if (extWin) { 1021 if (!extWin.closed) { 1022 extWin.close(); 1023 } 1024 extWin = false; 1025 } 1026 1027 stopPolling(); 1028 } 1029 } 1030 1031 if (typeof window.postMessage !== 'undefined') { 1032 window.addEventListener('message', e => { 1033 let message = e && e.data; 1034 if (typeof message === 'string') { 1035 try { 1036 message = JSON.parse(message); 1037 } catch (err) { 1038 return; 1039 } 1040 } 1041 1042 const type = message && message.type; 1043 if (type === 'loginMessage') { 1044 readMessage(message); 1045 } 1046 }); 1047 } 1048 1049 document.body.addEventListener('click', e => { 1050 let target = e.target; 1051 1052 // Don't do anything when clicking on the "X people" link. 1053 if (target.matches('p.comment-likes a.view-likers')) { 1054 e.preventDefault(); 1055 return; 1056 } 1057 1058 // Retrieve the surrounding paragraph to the star, if it hasn't been liked. 1059 const notLikedPar = target.closest('p.comment-not-liked'); 1060 1061 // Return if not clicking on star or surrounding paragraph. 1062 if (!target.matches('a.comment-like-link') && !notLikedPar) { 1063 return; 1064 } 1065 1066 // When a comment hasn't been liked, make the text clickable, too. 1067 if (notLikedPar) { 1068 target = notLikedPar.querySelector('a.comment-like-link'); 1069 if (!target) { 1070 return; 1071 } 1072 } 1073 1074 if (target.classList.contains('needs-login')) { 1075 e.preventDefault(); 1076 commentLikeEvent = target; 1077 if (extWin) { 1078 if (!extWin.closed) { 1079 extWin.close(); 1080 } 1081 extWin = false;
1082 } 1083 1084 stopPolling(); 1085 1086 const url = 'https://wordpress.com/public.api/connect/?action=request&service=wordpress'; 1087 extWin = window.open( 1088 url, 1089 'likeconn', 1090 'status=0,toolbar=0,location=1,menubar=0,directories=0,resizable=1,scrollbars=1,height=560,width=500' 1091 ); 1092 1093 startPolling(); 1094 1095 return false; 1096 } 1097 1098 // Record that the user likes or does not like this comment. 1099 const commentId = getCommentId(target); 1100 target.classList.add('loading'); 1101 1102 let commentEl = document.querySelector(`p#comment-like-${commentId}`); 1103 // Determine whether to like or unlike based on whether the comment is 1104 // currently liked. 1105 const action = 1106 commentEl && commentEl.dataset.liked === 'comment-liked' 1107 ? 'unlike_comment' 1108 : 'like_comment'; 1109 handleLinkAction(target, action, commentId, data => { 1110 // Invalidate the like cache for this comment. 1111 delete commentLikeCache[commentId]; 1112 1113 const countEl = document.querySelector(`#comment-like-count-${data.context}`); 1114 if (countEl) { 1115 countEl.innerHTML = data.display; 1116 } 1117 1118 commentEl = document.querySelector(`p#comment-like-${data.context}`); 1119 if (action === 'like_comment') { 1120 commentEl.classList.remove('comment-not-liked'); 1121 commentEl.classList.add('comment-liked'); 1122 commentEl.dataset.liked = 'comment-liked'; 1123 } else { 1124 commentEl.classList.remove('comment-liked'); 1125 commentEl.classList.add('comment-not-liked'); 1126 commentEl.dataset.liked = 'comment-not-liked'; 1127 } 1128 1129 // Prefetch new data for this comment (if there are likers left). 1130 const parent = target.closest('.comment-likes'); 1131 const link = parent && parent.querySelector('a.view-likers'); 1132 if (link) { 1133 fetchLikeData(link, commentId); 1134 } 1135 1136 target.classList.remove('loading'); 1137 }); 1138 e.preventDefault(); 1139 e.stopPropagation(); 1140 }); 1141 1142 document.body.addEventListener( 1143 'mouseenter', 1144 function (e) { 1145 if (!e.target.matches('p.comment-likes a.view-likers')) { 1146 return; 1147 } 1148 // Show the user a list of who has liked this comment. 1149 1150 const link = e.target; 1151 if (Number(link.dataset.likeCount || 0) === 0) { 1152 // No one has liked this comment. 1153 return; 1154 } 1155 1156 // Don't hide the overlay. 1157 overlay.cancelHide(); 1158 1159 // Get the comment ID. 1160 const container = link.parentElement && link.parentElement.parentElement; 1161 const star = container && container.querySelector('a.comment-like-link'); 1162 const commentId = star && getCommentId(star); 1163 relevantComment = commentId; 1164 1165 // Check if the list of likes for this comment is already in 1166 // the cache. 1167 if (commentId in commentLikeCache) { 1168 const entry = commentLikeCache[commentId];
1169 // Only display the likes if the ajax request is 1170 // actually done. 1171 if (entry !== null) { 1172 overlay.showLikes(link, entry); 1173 } else { 1174 // Make sure the overlay is visible (in case 1175 // the user moved the mouse away while loading 1176 // but then came back before it finished 1177 // loading). 1178 overlay.showLoadingMessage(link); 1179 } 1180 return; 1181 } 1182 1183 // Position the "Loading..." overlay. 1184 overlay.showLoadingMessage(link); 1185 1186 // Fetch the data. 1187 fetchLikeData(link, commentId); 1188 }, 1189 true 1190 ); 1191 1192 document.body.addEventListener( 1193 'mouseleave', 1194 e => { 1195 if (!e.target.matches('p.comment-likes a.view-likers')) { 1196 return; 1197 } 1198 // User has moved cursor away - hide the overlay. 1199 overlay.requestHide(); 1200 }, 1201 true 1202 ); 1203 1204 document.body.addEventListener( 1205 'mouseenter', 1206 e => { 1207 if (!e.target.matches('.comment') || !e.target.querySelector('a.comment-like-link')) { 1208 return; 1209 } 1210 // User is moving over a comment - precache the comment like data.
1211 if (precacheTimeout !== null) { 1212 clearTimeout(precacheTimeout); 1213 precacheTimeout = null; 1214 } 1215 1216 const star = e.target.querySelector('a.comment-like-link'); 1217 const parent = star.closest('.comment-likes'); 1218 const link = parent && parent.querySelector('a.view-likers'); 1219 if (!link || Number(link.dataset.likeCount || 0) === 0) { 1220 // No likes. 1221 return; 1222 } 1223 const commentId = getCommentId(star); 1224 if (commentId in commentLikeCache) { 1225 // Already in cache. 1226 return; 1227 } 1228 1229 precacheTimeout = setTimeout(() => { 1230 precacheTimeout = null; 1231 if (commentId in commentLikeCache) { 1232 // Was cached in the interim. 1233 return; 1234 } 1235 fetchLikeData(link, commentId); 1236 }, 1000); 1237 }, 1238 true 1239 ); 1240 } 1241 1242 if (document.readyState !== 'loading') { 1243 init(); 1244 } else { 1245 document.addEventListener('DOMContentLoaded', init); 1246 } 1247})(); 1248; 1249!function(e){var o={};function n(t){if(o[t])return o[t].exports;var r=o[t]={i:t,l:!1,exports:{}};return e[t].call(r.exports,r,r.exports,n),r.l=!0,r.exports}n.m=e,n.c=o,n.d=function(e,o,t){n.o(e,o)||Object.defineProperty(e,o,{enumerable:!0,get:t})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,o){if(1&o&&(e=n(e)),8&o)return e;if(4&o&&"object"==typeof e&&e&&e.__esModule)return e;var t=Object.create(null);if(n.r(t),Object.defineProperty(t,"default",{enumerable:!0,value:e}),2&o&&"string"!=typeof e)for(var r in e)n.d(t,r,function(o){return e[o]}.bind(null,r));return t},n.n=function(e){var o=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(o,"a",o),o},n.o=function(e,o){return Object.prototype.hasOwnProperty.call(e,o)},n.p="",n(n.s=273)}({273:function(e,o){!function(){"use strict";let e,o;function n(e){return new Promise((o,n)=>{const t=document.createElement("script");t.onload=()=>o(),t.onerror=e=>n(e),t.src=e,document.body.appendChild(t)})}function t(){if(e)return e;const o=window.wpcom_coblocks_js;return e=n(o.coblocks_lightbox_js),e}function r(){if(o)return o;window.wpcomJQueryUsageLoggerDisabled=!0;const e=window.wpcom_coblocks_js,t=window.jQuery?Promise.resolve():n(e.jquery_core_js).then(()=>n(e.jquery_migrate_js)),r=t.then(()=>window.imagesLoaded?Promise.resolve():n(e.imagesloaded_js)),c=t.then(()=>window.Masonry?Promise.resolve():n(e.masonry_js)),u=Promise.all([t,r,c]).then(()=>n(e.coblocks_masonry_js));return o=u,o}function c(){document.querySelector(".wp-block-coblocks-gallery-masonry")&&r(),document.querySelector(".has-lightbox")&&t(),document.body.classList.contains("block-editor-page")&&(r(),t())}"loading"!==document.readyState?c():document.addEventListener("DOMContentLoaded",c)}()}});; 1250(function() { 1251 1252 /** 1253 * Debounce 1254 * 1255 * @param {Function} func 1256 * @param {number} wait 1257 * @param {boolean} immediate 1258 */ 1259 function debounce(func, wait, immediate) { 1260 'use strict'; 1261 1262 var timeout; 1263 wait = (typeof wait !== 'undefined') ? wait : 20; 1264 immediate = (typeof immediate !== 'undefined') ? immediate : true; 1265 1266 return function() { 1267 1268 var context = this, args = arguments; 1269 var later = function() { 1270 timeout = null; 1271 1272 if (!immediate) { 1273 func.apply(context, args); 1274 } 1275 }; 1276 1277 var callNow = immediate && !timeout; 1278 1279 clearTimeout(timeout); 1280 timeout = setTimeout(later, wait); 1281 1282 if (callNow) { 1283 func.apply(context, args); 1284 } 1285 }; 1286 } 1287 1288 /** 1289 * Get page header height and use it for top-margin on 1290 * site-content when above mobile breakpoint 1291 */ 1292 function pageHeaderHeight() { 1293 var body = document.body; 1294 1295 if ( document.documentElement.clientWidth <= 640 ) { 1296 document.getElementById( "primary" ).style.marginTop = 0; 1297 body.classList.remove( 'wp-sticky-header' ); 1298 } else { 1299 var header = document.getElementById( 'masthead' ); 1300 var content = document.getElementById( 'primary' ); 1301 var headerOffsetHeight = 0; 1302 1303 if ( header ) { 1304 headerOffsetHeight = header.offsetHeight; 1305 content.style.marginTop = headerOffsetHeight + "px"; 1306 } 1307 1308 if ( document.documentElement.clientHeight / 5 - headerOffsetHeight >= 0 ) { 1309 body.classList.add( 'wp-sticky-header' ); 1310 } else { 1311 body.classList.remove( 'wp-sticky-header' ); 1312 } 1313 } 1314 }; 1315 1316 /** 1317 * Run our function every time the window resizes 1318 */ 1319 var isResizing = false;
1320 window.addEventListener( 'resize', 1321 debounce( function() { 1322 if ( isResizing ) { 1323 return; 1324 } 1325 1326 isResizing = true; 1327 setTimeout( function() { 1328 pageHeaderHeight(); 1329 isResizing = false; 1330 }, 150 ); 1331 } ) 1332 ); 1333 1334 /** 1335 * Run our page header height function 1336 */ 1337 window.addEventListener( 'load', pageHeaderHeight ); 1338 pageHeaderHeight(); 1339})(); 1340; 1341!function(){"use strict";var e,t={noop:function(){},texturize:function(e){return(e=(e=(e=(e+="").replace(/'/g,"’").replace(/'/g,"’")).replace(/"/g,"”").replace(/"/g,"”").replace(/"/g,"”").replace(/[\u201D]/g,"”")).replace(/([\w]+)=&#[\d]+;(.+?)&#[\d]+;/g,'$1="$2"')).trim()},applyReplacements:function(e,t){if(e)return t?e.replace(/{(\d+)}/g,(function(e,r){return void 0!==t[r]?t[r]:e})):e},getBackgroundImage:function(e){var t=document.createElement("canvas"),r=t.getContext&&t.getContext("2d");if(e){r.filter="blur(20px) ",r.drawImage(e,0,0);var o=t.toDataURL("image/png");return t=null,o}}},r=function(){function e(e,t){return Element.prototype.matches?e.matches(t):Element.prototype.msMatchesSelector?e.msMatchesSelector(t):void 0}function r(e,t,r,o){if(!e)return o();e.style.removeProperty("display"),e.style.opacity=t,e.style.pointerEvents="none";var a=function(i,n){var l=(performance.now()-i)/n;l<1?(e.style.opacity=t+(r-t)*l,requestAnimationFrame((()=>a(i,n)))):(e.style.opacity=r,e.style.removeProperty("pointer-events"),o())};requestAnimationFrame((function(){requestAnimationFrame((function(){a(performance.now(),200)}))}))}return{closest:function(t,r){if(t.closest)return t.closest(r);var o=t;do{if(e(o,r))return o;o=o.parentElement||o.parentNode}while(null!==o&&1===o.nodeType);return null},matches:e,hide:function(e){e&&(e.style.display="none")},show:function(e){e&&(e.style.display="block")},fadeIn:function(e,o){r(e,0,1,o=o||t.noop)},fadeOut:function(e,o){o=o||t.noop,r(e,1,0,(function(){e&&(e.style.display="none"),o()}))},scrollToElement:function(e,t,r){if(!e||!t)return r?r():void 0;var o=t.querySelector(".jp-carousel-info-extra");o&&(o.style.minHeight=window.innerHeight-64+"px");var a=!0,i=Date.now(),n=t.scrollTop,l=Math.max(0,e.offsetTop-Math.max(0,window.innerHeight-function(e){var t=e.querySelector(".jp-carousel-info-footer"),r=e.querySelector(".jp-carousel-info-extra"),o=e.querySelector(".jp-carousel-info-content-wrapper");if(t&&r&&o){var a=window.getComputedStyle(r),i=parseInt(a.paddingTop,10)+parseInt(a.paddingBottom,10);return i=isNaN(i)?0:i,o.offsetHeight+t.offsetHeight+i}return 0}(t)))-t.scrollTop;function s(){a=!1}l=Math.min(l,t.scrollHeight-window.innerHeight),t.addEventListener("wheel",s),function e(){var c,u=Date.now(),d=(c=(u-i)/300)<.5?2*c*c:1-Math.pow(-2*c+2,2)/2,p=(d=d>1?1:d)*l;if(t.scrollTop=n+p,u<=i+300&&a)return requestAnimationFrame(e);r&&r(),o&&(o.style.minHeight=""),a=!1,t.removeEventListener("wheel",s)}()},getJSONAttribute:function(e,t){if(e&&e.hasAttribute(t))try{return JSON.parse(e.getAttribute(t))}catch(e){return}},convertToPlainText:function(e){var t=document.createElement("div");return t.textContent=e,t.innerHTML},stripHTML:function(e){return e.replace(/<[^>]*>?/gm,"")},emitEvent:function(e,t,r){var o;try{o=new CustomEvent(t,{bubbles:!0,cancelable:!0,detail:r||null})}catch(e){(o=document.createEvent("CustomEvent")).initCustomEvent(t,!0,!0,r||null)}e.dispatchEvent(o)},isTouch:function(){return"ontouchstart"in window||window.DocumentTouch&&document instanceof DocumentTouch}}}();function o(){var o,a,i,n,l="",s=!1,c="div.gallery, div.tiled-gallery, ul.wp-block-gallery, ul.blocks-gallery-grid, figure.wp-block-gallery.has-nested-images, div.wp-block-jetpack-tiled-gallery, a.single-image-gallery",u=".gallery-item, .tiled-gallery-item, .blocks-gallery-item, .tiled-gallery__item",d=u+", .wp-block-image",p={},m="undefined"!=typeof wpcom&&wpcom.carousel&&wpcom.carousel.stat?wpcom.carousel.stat:t.noop,g="undefined"!=typeof wpcom&&wpcom.carousel&&wpcom.carousel.pageview?wpcom.carousel.pageview:t.noop;function h(t){if(!s)switch(t.which){case 38:t.preventDefault(),p.overlay.scrollTop-=100;break;case 40:t.preventDefault(),p.overlay.scrollTop+=100;break;case 39:t.preventDefault(),e.slideNext();break;case 37:case 8:t.preventDefault(),e.slidePrev();break;case 27:t.preventDefault(),b()}}function f(){s=!0}function v(){s=!1}function y(){p.overlay||(p.overlay=document.querySelector(".jp-carousel-overlay"),p.container=p.overlay.querySelector(".jp-carousel-wrap"),p.gallery=p.container.querySelector(".jp-carousel"),p.info=p.overlay.querySelector(".jp-carousel-info"),p.caption=p.info.querySelector(".jp-carousel-caption"),p.commentField=p.overlay.querySelector("#jp-carousel-comment-form-comment-field"),p.emailField=p.overlay.querySelector("#jp-carousel-comment-form-email-field"),p.authorField=p.overlay.querySelector("#jp-carousel-comment-form-author-field"),p.urlField=p.overlay.querySelector("#jp-carousel-comment-form-url-field"),window.innerWidth<=760&&Math.round(window.innerWidth/760*110)<40&&r.isTouch(),[p.commentField,p.emailField,p.authorField,p.urlField].forEac
1341h((function(e){e&&(e.addEventListener("focus",f),e.addEventListener("blur",v))})),p.overlay.addEventListener("click",(function(e){var t,o,a=e.target,i=!!r.closest(a,".jp-carousel-close-hint"),n=!!window.matchMedia("(max-device-width: 760px)").matches;if(a===p.overlay){if(n)return;b()}else if(i)b();else if(a.classList.contains("jp-carousel-image-download"))m("download_original_click");else if(a.classList.contains("jp-carousel-comment-login"))t=p.currentSlide,o=t?t.attrs.attachmentId:"0",window.location.href=jetpackCarouselStrings.login_url+"%23jp-carousel-"+o;else if(r.closest(a,"#jp-carousel-comment-form-container"))!function(e){var t=e.target,o=r.getJSONAttribute(p.container,"data-carousel-extra")||{},a=p.currentSlide.attrs.attachmentId,i=document.querySelector("#jp-carousel-comment-form-submit-and-info-wrapper"),n=document.querySelector("#jp-carousel-comment-form-spinner"),l=document.querySelector("#jp-carousel-comment-form-button-submit"),s=document.querySelector("#jp-carousel-comment-form");if(p.commentField&&p.commentField.getAttribute("id")===t.getAttribute("id"))f(),r.show(i);else if(r.matches(t,'input[type="submit"]')){e.preventDefault(),e.stopPropagation(),r.show(n),s.classList.add("jp-carousel-is-disabled");var c={action:"post_attachment_comment",nonce:jetpackCarouselStrings.nonce,blog_id:o.blog_id,id:a,comment:p.commentField.value};if(!c.comment.length)return void w(jetpackCarouselStrings.no_comment_text,!1);if(1!==Number(jetpackCarouselStrings.is_logged_in)&&(c.email=p.emailField.value,c.author=p.authorField.value,c.url=p.urlField.value,1===Number(jetpackCarouselStrings.require_name_email))){if(!c.email.length||!c.email.match("@"))return void w(jetpackCarouselStrings.no_comment_email,!1);if(!c.author.length)return void w(jetpackCarouselStrings.no_comment_author,!1)}var u=new XMLHttpRequest;u.open("POST",jetpackCarouselStrings.ajaxurl,!0),u.setRequestHeader("X-Requested-With","XMLHttpRequest"),u.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8"),u.onreadystatechange=function(){if(this.readyState===XMLHttpRequest.DONE&&this.status>=200&&this.status<300){var e;try{e=JSON.parse(this.response)}catch(e){return void w(jetpackCarouselStrings.comment_post_error,!1)}"approved"===e.comment_status?w(jetpackCarouselStrings.comment_approved,!0):"unapproved"===e.comment_status?w(jetpackCarouselStrings.comment_unapproved,!0):w(jetpackCarouselStrings.comment_post_error,!1),E(),q(a),l.value=jetpackCarouselStrings.post_comment,r.hide(n),s.classList.remove("jp-carousel-is-disabled")}else w(jetpackCarouselStrings.comment_post_error,!1)};var d=[];for(var m in c)if(m){var g=encodeURIComponent(m)+"="+encodeURIComponent(c[m]);d.push(g.replace(/%20/g,"+"))}var h=d.join("&");u.send(h)}}(e);else if(r.closest(a,".jp-carousel-photo-icons-container")||a.classList.contains("jp-carousel-photo-title"))!function(e){e.preventDefault();var t=e.target,o=p.info.querySelector(".jp-carousel-info-extra"),a=p.info.querySelector(".jp-carousel-image-meta"),i=p.info.querySelector(".jp-carousel-comments-wrapper"),n=p.info.querySelector(".jp-carousel-icon-info"),l=p.info.querySelector(".jp-carousel-icon-comments");function s(){l&&l.classList.remove("jp-carousel-selected"),n.classList.toggle("jp-carousel-selected"),i&&i.classList.remove("jp-carousel-show"),a&&(a.classList.toggle("jp-carousel-show"),a.classList.contains("jp-carousel-show")?o.classList.add("jp-carousel-show"):o.classList.remove("jp-carousel-show"))}function c(){n&&n.classList.remove("jp-carousel-selected"),l.classList.toggle("jp-carousel-selected"),a&&a.classList.remove("jp-carousel-show"),i&&(i.classList.toggle("jp-carousel-show"),i.classList.contains("jp-carousel-show")?o.classList.add("jp-carousel-show"):o.classList.remove("jp-carousel-show"))}(r.closest(t,".jp-carousel-icon-info")||t.classList.contains("jp-carousel-photo-title"))&&(a&&a.classList.contains("jp-carousel-show")?r.scrollToElement(p.overlay,p.overlay,s):(s(),r.scrollToElement(p.info,p.overlay))),r.closest(t,".jp-carousel-icon-comments")&&(i&&i.classList.contains("jp-carousel-show")?r.scrollToElement(p.overlay,p.overlay,c):(c(),r.scrollToElement(p.info,p.overlay)))}(e);else if(!r.closest(a,".jp-carousel-info"))return})),window.addEventListener("keydown",h),p.overlay.addEventListener("jp_carousel.afterOpen",(function(){v(),p.slides.length<=1||(p.slides.length<=5?r.show(p.info.querySelector(".jp-swiper-pagination")):r.show(p.info.querySelector(".jp-carousel-pagination")))})),p.overlay.addEventListener("jp_carousel.beforeClose",(function(){f(),document.documentElement.style.removeProperty("height"),e&&e.enable(),r.hide(p.info.querySelector(".jp-swiper-pagination")),r.hide(p.info.querySelector(".jp-carousel-pagination"))})),p.overlay.addEventListener("jp_carousel.afterClose",(function(){window.history.pushState?history.pushState("",document.title,window.location.pathname+window.location.search):window.location.href="",l="",p.isOpen=!1})),p.overlay.addEventListener("touchstart",(function(e){e.touches.length>1&&e.preventDefault()})))}function w(e,t){var o=p.overlay.querySelector("#jp-carousel-comment-post-results"),a="jp-carousel-comment-post-"+(t?"success":"error");o.innerHTML='<span class="'+a+'">'+e+"</span>",r.hide(p.overlay.querySelector("#jp-carousel-comment-form-spinner")),p.overlay.querySelector("#jp-carousel-comment-form").classList.remove("jp-carousel-is-disabled"),r.show(o)}function j(){var e=document.querySelectorAll("a img[data-attachment-id]");Array.prototype.forEach.call(e,(function(e){var t=e.parentElement,o=t.parentElement;if(!o.classList.contains("gallery-icon")&&!r.closest(o,u)&&t.hasAttribute("href")){var a=!1;t.getAttribute("href").split("?")[0]===e.getAttribute("data-orig-file").split("?")[0]&&1===Number(jetpackCarouselStrings.single_image_gallery_media_file)&&(a=!0),t.getAttribute("href")===e.getAttribute("data-permalink")&&(a=!0),a&&(t.classList.add("single-image-gallery"),t.setAttribute("data-carousel-extra",JSON.stringify({blog_id:Number(jetpackCarouselStrings.blog_id)})))}}))}function S(o){(!o||o<0||o>p.slides.length)&&(o=0),p.currentSlide=p.slides[o];var a,i,n=p.currentSlide,s=n.attrs.attachmentId;!function(e){var t=e.el,r=e.attrs,o=t.querySelector("img");if(!o.hasAttribute("data-loaded")){var a=!!r.previewImage,i=r.thumbSize;!a||i&&t.offsetWidth>i.width?o.src=r.src:o.src=r.previewImage,o.setAttribute("itemprop","image"),o.setAttribute("data-loaded",1)}}(p.slides[o]),1!==Number(jetpackCarouselStrings.display_background_image)||p.slides[o].backgroundImage||function(t){var r=t.el;e&&e.slides&&(r=e.slides[e.activeIndex]);var o=t.attrs.originalElement;o.complete&&0!==o.naturalHeight?A(t,r,o):o.onload=function(){A(t,r,o)}}(p.slides[o]),r.hide(p.caption),function(e){var t,o,a,i,n="",l="",s="";if(t=p.overlay.querySelector(".jp-carousel-photo-caption"),o=p.overlay.querySelector(".jp-carousel-caption"),a=p.overlay.querySelector(".jp-carousel-photo-title"),i=p.overlay.querySelector(".jp-carousel-photo-description"),r.hide(t),r.hide(o),r.hide(a),r.hide(i),n=k(e.caption)||"",l=k(e.title)||"",s=k(e.desc)||"",(n||l||s)&&(n&&(t.innerHTML=n,o.innerHTML=n,r.show(t),r.show(o)),r.stripHTML(n)===r.stripHTML(l)&&(l=""),r.stripHTML(n)===r.stripHTML(s)&&(s=""),r.stripHTML(l)===r.
1341stripHTML(s)&&(s=""),s&&(i.innerHTML=s,r.show(i),l||n||(t.innerHTML=r.stripHTML(s),r.show(t))),l)){var c=r.stripHTML(l);a.innerHTML=c,n||(t.innerHTML=c,o.innerHTML=c,r.show(t)),r.show(a)}}({caption:n.attrs.caption,title:n.attrs.title,desc:n.attrs.desc}),function(e){if(!e||1!==Number(jetpackCarouselStrings.display_exif))return!1;var t=p.info.querySelector(".jp-carousel-image-meta ul.jp-carousel-image-exif"),r="";for(var o in e){var a=e[o],i=jetpackCarouselStrings.meta_data||[];if(0!==parseFloat(a)&&a.length&&-1!==i.indexOf(o)){switch(o){case"focal_length":a+="mm";break;case"shutter_speed":a=x(a);break;case"aperture":a="f/"+a}r+="<li><h5>"+jetpackCarouselStrings[o]+"</h5>"+a+"</li>"}}t.innerHTML=r,t.style.removeProperty("display")}(p.slides[o].attrs.imageMeta),function(e){if(!e)return!1;var r,o=[e.attrs.origWidth,e.attrs.origHeight],a=document.createElement("a");a.href=e.attrs.src.replace(/\?.+$/,""),r=null!==a.hostname.match(/^i[\d]{1}\.wp\.com$/i)?a.href:e.attrs.origFile.replace(/\?.+$/,"");var i=p.info.querySelector(".jp-carousel-download-text"),n=p.info.querySelector(".jp-carousel-image-download");i.innerHTML=t.applyReplacements(jetpackCarouselStrings.download_original,o),n.setAttribute("href",r),n.style.removeProperty("display")}(n),1===Number(jetpackCarouselStrings.display_comments)&&(a=p.slides[o].attrs.commentsOpened,i=p.container.querySelector(".jp-carousel-comment-form-container"),1===parseInt(a,10)?r.fadeIn(i):r.fadeOut(i),q(s),r.hide(p.info.querySelector("#jp-carousel-comment-post-results")));var c=p.info.querySelector(".jp-carousel-pagination");if(c&&p.slides.length>5){var u=o+1;c.innerHTML="<span>"+u+" / "+p.slides.length+"</span>"}jetpackCarouselStrings.stats&&((new Image).src=document.location.protocol+"../g.gif"+jetpackCarouselStrings.stats+"&post="+encodeURIComponent(s)+"&rand="+Math.random()),g(s),window.location.hash=l="#jp-carousel-"+s}function b(){document.body.style.overflow=a,document.documentElement.style.overflow=i,E(),f(),r.emitEvent(p.overlay,"jp_carousel.beforeClose"),window.scrollTo(window.scrollX||window.pageXOffset||0,n||0),e.destroy(),p.isOpen=!1,p.slides=[],p.currentSlide=void 0,p.gallery.innerHTML="",r.fadeOut(p.overlay,(function(){r.emitEvent(p.overlay,"jp_carousel.afterClose")}))}function L(e,t,r){var o=r?e.replace(/.*=([\d]+%2C[\d]+).*$/,"$1"):e.replace(/.*-([\d]+x[\d]+)\..+$/,"$1"),a=o!==e?r?o.split("%2C"):o.split("x"):[t,0];return"9999"===a[0]&&(a[0]="0"),"9999"===a[1]&&(a[1]="0"),a}function x(e){return e>=1?Math.round(10*e)/10+"s":"1/"+Math.round(1/e)+"s"}function k(e){return!e.match(" ")&&e.match("_")?"":e}function q(e,t){var a=void 0===t,i=p.info.querySelector(".jp-carousel-icon-comments .jp-carousel-has-comments-indicator");if(i.classList.remove("jp-carousel-show"),clearInterval(o),e){(!t||t<1)&&(t=0);var n=p.info.querySelector(".jp-carousel-comments"),l=p.info.querySelector("#jp-carousel-comments-loading");r.show(l),a&&(r.hide(n),n.innerHTML="");var s=new XMLHttpRequest,c=jetpackCarouselStrings.ajaxurl+"?action=get_attachment_comments&nonce="+jetpackCarouselStrings.nonce+"&id="+e+"&offset="+t;s.open("GET",c),s.setRequestHeader("X-Requested-With","XMLHttpRequest");var u=function(){r.fadeIn(n),r.fadeOut(l)};s.onload=function(){if(p.currentSlide&&p.currentSlide.attrs.attachmentId===e){var c,d=s.status>=200&&s.status<300;try{c=JSON.parse(s.responseText)}catch(e){}if(!d||!c||!Array.isArray(c))return u();a&&(n.innerHTML="");for(var m=0;m<c.length;m++){var g=c[m],h=document.createElement("div");h.classList.add("jp-carousel-comment"),h.setAttribute("id","jp-carousel-comment-"+g.id),h.innerHTML='<div class="comment-gravatar">'+g.gravatar_markup+'</div><div class="comment-content"><div class="comment-author">'+g.author_markup+'</div><div class="comment-date">'+g.date_gmt+"</div>"+g.content+"</div>",n.appendChild(h),clearInterval(o),o=setInterval((function(){p.container.scrollTop+150>window.innerHeight&&(q(e,t+10),clearInterval(o))}),300)}c.length>0&&(r.show(n),i.innerText=c.length,i.classList.add("jp-carousel-show")),r.hide(l)}},s.onerror=u,s.send()}}
1341function A(e,r,o){var a=t.getBackgroundImage(o);e.backgroundImage=a,r.style.backgroundImage="url("+a+")",r.style.backgroundSize="cover"}function E(){p.commentField&&(p.commentField.value="")}function H(e,o){p.slides=[];var a={width:window.innerWidth,height:window.innerHeight-64};0!==o&&((new Image).src=e[o].getAttribute("data-gallery-src"));var i=!!r.closest(e[0],".tiled-gallery.type-rectangular");Array.prototype.forEach.call(e,(function(e,o){var n=r.closest(e,"a"),l=e.getAttribute("data-orig-file")||e.getAttribute("src-orig"),s=e.getAttribute("data-attachment-id")||e.getAttribute("data-id")||"0",c=document.querySelector('img[data-attachment-id="'+s+'"] + figcaption');c=c?c.innerHTML:e.getAttribute("data-image-caption");var u={originalElement:e,attachmentId:s,commentsOpened:e.getAttribute("data-comments-opened")||"0",imageMeta:r.getJSONAttribute(e,"data-image-meta")||{},title:e.getAttribute("data-image-title")||"",desc:e.getAttribute("data-image-description")||"",mediumFile:e.getAttribute("data-medium-file")||"",largeFile:e.getAttribute("data-large-file")||"",origFile:l||"",thumbSize:{width:e.naturalWidth,height:e.naturalHeight},caption:c||"",permalink:n&&n.getAttribute("href"),src:l||e.getAttribute("src")||""},d=r.closest(e,".tiled-gallery-item"),m=d&&d.querySelector(".tiled-gallery-caption"),g=m&&m.innerHTML;g&&(u.caption=g);var h=function(e){var t=e.getAttribute("data-orig-size")||"";if(t){var r=t.split(",");return{width:parseInt(r[0],10),height:parseInt(r[1],10)}}return{width:e.getAttribute("data-original-width")||e.getAttribute("width")||void 0,height:e.getAttribute("data-original-height")||e.getAttribute("height")||void 0}}(e);if(u.origWidth=h.width||u.thumbSize.width,u.origHeight=h.height||u.thumbSize.height,"undefined"!=typeof wpcom&&wpcom.carousel&&wpcom.carousel.generateImgSrc?u.src=wpcom.carousel.generateImgSrc(e,a):u.src=function(e){if("object"!=typeof e&&(e={}),void 0===e.origFile)return"";if(void 0===e.origWidth||void 0===e.maxWidth)return e.origFile;if(void 0===e.mediumFile||void 0===e.largeFile)return e.origFile;var t=document.createElement("a");t.href=e.largeFile;var r=/^i[0-2]\.wp\.com$/i.test(t.hostname),o=L(e.mediumFile,e.origWidth,r),a=L(e.largeFile,e.origWidth,r),i=parseInt(a[0],10),n=parseInt(a[1],10),l=parseInt(o[0],10),s=parseInt(o[1],10);if(e.origMaxWidth=e.maxWidth,e.origMaxHeight=e.maxHeight,void 0!==window.devicePixelRatio&&window.devicePixelRatio>1&&(e.maxWidth=e.maxWidth*window.devicePixelRatio,e.maxHeight=e.maxHeight*window.devicePixelRatio),i>=e.maxWidth||n>=e.maxHeight)return e.largeFile;if(l>=e.maxWidth||s>=e.maxHeight)return e.mediumFile;if(r){var c=e.largeFile.lastIndexOf("?"),u=e.largeFile;return-1!==c&&(u=e.largeFile.substring(0,c),(e.origWidth>e.maxWidth||e.origHeight>e.maxHeight)&&(e.origMaxWidth=2*e.maxWidth,e.origMaxHeight=2*e.maxHeight,u+="?fit="+e.origMaxWidth+"%2C"+e.origMaxHeight)),u}return e.origFile}({origFile:u.src,origWidth:u.origWidth,origHeight:u.origHeight,maxWidth:a.width,maxHeight:a.height,mediumFile:u.mediumFile,largeFile:u.largeFile}),e.setAttribute("data-gallery-src",u.src),"0"!==u.attachmentId){u.title=t.texturize(u.title),u.desc=t.texturize(u.desc),u.caption=t.texturize(u.caption);var f=new Image;f.src=u.src;var v=document.createElement("div");v.classList.add("swiper-slide"),v.setAttribute("itemprop","associatedMedia"),v.setAttribute("itemscope",""),v.setAttribute("itemtype","https://schema.org/ImageObject");var y=document.createElement("div");y.classList.add("swiper-zoom-container"),p.gallery.appendChild(v),v.appendChild(y),y.appendChild(f),v.setAttribute("data-attachment-id",u.attachmentId),v.setAttribute("data-permalink",u.permalink),v.setAttribute("data-orig-file",u.origFile),i&&(u.previewImage=u.src);var w={el:v,attrs:u,index:o};p.slides.push(w)}}))}function T(e,t){if(!window.Swiper670){var o=document.querySelector("#jp-carousel-loading-overlay");r.show(o);var a=document.createElement("script");return a.id="jetpack-carousel-swiper-js",a.src=window.jetpackSwiperLibraryPath.url,a.async=!0,a.onload=function(){r.hide(o),_(e,t)},a.onerror=function(){r.hide(o)},void document.head.appendChild(a)}_(e,t)}function _(t,o){var l,s={imgSelector:".gallery-item [data-attachment-id], .tiled-gallery-item [data-attachment-id], img[data-attachment-id], img[data-id]",startIndex:0},c=r.getJSONAttribute(t,"data-carousel-extra");if(!c)return;const u=t.querySelectorAll(s.imgSelector);if(u.length&&(y(),!p.isOpen)){for(var d in p.isOpen=!0,a=getComputedStyle(document.body).overflow,document.body.style.overflow="hidden",i=getComputedStyle(document.documentElement).overflow,document.documentElement.style.overflow="hidden",n=window.scrollY||window.pageYOffset||0,p.container.setAttribute("data-carousel-extra",JSON.stringify(c)),m(["open","view_image"]),o||{})s[d]=o[d];-1===s.startIndex&&(s.startIndex=0),r.emitEvent(p.overlay,"jp_carousel.beforeOpen"),p.gallery.innerHTML="",p.overlay.style.opacity=1,p.overlay.style.display="block",H(u,s.startIndex),(e=new window.Swiper670(".jp-carousel-swiper-container",{centeredSlides:!0,zoom:!0,loop:p.slides.length>1,enabled:p.slides.length>1,pagination:{el:".jp-swiper-pagination",clickable:!0},navigation:{nextEl:".jp-swiper-button-next",prevEl:".jp-swiper-button-prev"},initialSlide:s.startIndex,on:{init:function(){S(s.startIndex)}},preventClicks:!1,preventClicksPropagation:!1,preventInteractionOnTransition:!r.isTouch(),threshold:5}
1341)).on("slideChange",(function(e){S(0===e.activeIndex?p.slides.length-1:e.activeIndex===p.slides.length+1?0:e.activeIndex-1),p.overlay.classList.remove("jp-carousel-hide-controls")})),e.on("zoomChange",(function(e,t){t>1&&p.overlay.classList.add("jp-carousel-hide-controls"),1===t&&p.overlay.classList.remove("jp-carousel-hide-controls")})),e.on("doubleTap",(function(e){if(clearTimeout(l),1===e.zoom.scale)var t=setTimeout((function(){p.overlay.classList.remove("jp-carousel-hide-controls"),clearTimeout(t)}),150)})),e.on("tap",(function(){e.zoom.scale>1&&(l=setTimeout((function(){p.overlay.classList.toggle("jp-carousel-hide-controls")}),150))})),r.fadeIn(p.overlay,(function(){r.emitEvent(p.overlay,"jp_carousel.afterOpen")}))}}function C(e){if("click"!==e.type){if("keydown"===e.type){const t=document.activeElement.parentElement,r=t&&t.classList.contains("tiled-gallery__item");if((" "===e.key||"Enter"===e.key)&&r)return void I(e)}}else I(e)}function I(e){if(window.CSS&&window.CSS.supports&&window.CSS.supports("display","grid")){var t,o=e.target,a=r.closest(o,c);if(a){if(!(t=a)||!t.getAttribute("data-carousel-extra"))return;var i=o.parentElement,n=i.parentElement,l=null;if(n&&n.classList.contains("wp-block-image")?l=i.getAttribute("href"):i&&i.classList.contains("wp-block-image")&&i.querySelector(":scope > a")&&(l=i.querySelector(":scope > a").getAttribute("href")),l&&l.split("?")[0]!==o.getAttribute("data-orig-file").split("?")[0]&&l!==o.getAttribute("data-permalink"))return;if(i.classList.contains("gallery-caption"))return;if(r.matches(i,"figcaption"))return;document.documentElement.style.height="auto",e.preventDefault(),e.stopPropagation();var s=r.closest(o,d),u=Array.prototype.indexOf.call(a.querySelectorAll(d),s);T(a,{startIndex:u})}}}document.body.addEventListener("click",C),document.body.addEventListener("keydown",C),1===Number(jetpackCarouselStrings.single_image_gallery)&&(j(),document.body.addEventListener("is.post-load",(function(){j()}))),window.addEventListener("hashchange",(function(){var t=/jp-carousel-(\d+)/;if(window.location.hash&&t.test(window.location.hash)){if(window.location.hash!==l||!p.isOpen)if(window.location.hash&&p.gallery&&!p.isOpen&&history.back)history.back();else{l=window.location.hash;for(var r,o,a=window.location.hash.match(t),i=parseInt(a[1],10),n=document.querySelectorAll(c),s=0;s<n.length;s++){for(var u,d=n[s],m=d.querySelectorAll("img"),g=0;g<m.length;g++)if(parseInt(m[g].getAttribute("data-attachment-id"),10)===i||parseInt(m[g].getAttribute("data-id"),10)===i){u=g;break}if(void 0!==u){r=d,o=u,p.isOpen?(S(o),e.slideTo(o+1)):T(r,{startIndex:o});break}}}}else p.isOpen&&b()})),window.location.hash&&r.emitEvent(window,"hashchange")}"loading"!==document.readyState?o():document.addEventListener("DOMContentLoaded",o)}();; 1342( function () { 1343 'use strict'; 1344 1345 if ( typeof window.wpcom === 'undefined' ) { 1346 window.wpcom = {}; 1347 } 1348 1349 if ( window.wpcom.carousel ) { 1350 return; 1351 } 1352 1353 var prebuilt_widths = jetpackCarouselStrings.widths; 1354 var pageviews_stats_args = jetpackCarouselStrings.stats_query_args; 1355 1356 var findFirstLargeEnoughWidth = function ( original_w, original_h, dest_w, dest_h ) { 1357 var inverse_ratio = original_h / original_w; 1358 1359 for ( var i = 0; i < prebuilt_widths.length; ++i ) { 1360 if ( prebuilt_widths[ i ] >= dest_w || prebuilt_widths[ i ] * inverse_ratio >= dest_h ) { 1361 return prebuilt_widths[ i ]; 1362 } 1363 } 1364 1365 return original_w; 1366 }; 1367 1368 var removeResizeFromImageURL = function ( url ) { 1369 return removeArgFromURL( url, 'resize' ); 1370 }; 1371 1372 var removeArgFromURL = function ( url, arg ) { 1373 var re = new RegExp( '[\\?&]' + arg + '(=[^?&]+)?' ); 1374 if ( url.match( re ) ) { 1375 return url.replace( re, '' ); 1376 } 1377 return url; 1378 }; 1379 1380 var addWidthToImageURL = function ( url, width ) { 1381 width = parseInt( width, 10 ); 1382 // Give devices with a higher devicePixelRatio higher-res images (Retina display = 2, Android phones = 1.5, etc) 1383 if ( 'undefined' !== typeof window.devicePixelRatio && window.devicePixelRatio > 1 ) { 1384 width = Math.round( width * window.devicePixelRatio ); 1385 } 1386 url = addArgToURL( url, 'w', width ); 1387 url = addArgToURL( url, 'h', '' ); 1388 return url; 1389 }; 1390 1391 var addArgToURL = function ( url, arg, value ) {
1392 var re = new RegExp( arg + '=[^?&]+' ); 1393 if ( url.match( re ) ) { 1394 return url.replace( re, arg + '=' + value ); 1395 } else { 1396 var divider = url.indexOf( '?' ) !== -1 ? '&' : '?'; 1397 return url + divider + arg + '=' + value; 1398 } 1399 }; 1400 1401 var stat = function ( names ) { 1402 if ( typeof names !== 'string' ) { 1403 names = names.join( ',' ); 1404 } 1405 1406 new Image().src = window.location.protocol + 1407 '../g.gifv=wpcom-no-pv' + 1408 '&x_carousel=' + names + 1409 '&baba=' + Math.random(); 1410 }; 1411 1412 var pageview = function ( post_id ) { 1413 new Image().src = window.location.protocol + 1414 '../g.gifhost=' + encodeURIComponent( window.location.host ) + 1415 '&ref=' + encodeURIComponent( document.referrer ) + 1416 '&rand=' + Math.random() + 1417 '&' + pageviews_stats_args + 1418 '&post=' + encodeURIComponent( post_id ); 1419 }; 1420 1421 var generateImgSrc = function ( srcItem, max ) { 1422 var origSize = srcItem.getAttribute( 'data-orig-size' ) || ''; 1423 1424 var src = srcItem.getAttribute( 'src' ) || srcItem.getAttribute( 'original' ) || srcItem.getAttribute( 'data-original' ) || srcItem.getAttribute( 'data-lazy-src' ); 1425 if ( src.indexOf( 'imgpress' ) !== -1 ) { 1426 src = srcItem.getAttribute( 'data-orig-file' ); 1427 } 1428 // Square/Circle galleries use a resize param that needs to be removed. 1429 src = removeResizeFromImageURL( src ); 1430 src = addWidthToImageURL( 1431 src, 1432 findFirstLargeEnoughWidth( origSize.width, origSize.height, max.width, max.height ) 1433 ); 1434 1435 return src; 1436 }; 1437 1438 window.wpcom.carousel = { 1439 findFirstLargeEnoughWidth: findFirstLargeEnoughWidth, 1440 removeResizeFromImageURL: removeResizeFromImageURL, 1441 addWidthToImageURL: addWidthToImageURL, 1442 stat: stat, 1443 pageview: pageview, 1444 generateImgSrc: generateImgSrc 1445 }; 1446 1447} )(); 1448; 1449!function(){var e=document.currentScript;function t(t){var n=document.createElement("script"),o=e||document.getElementsByTagName("script")[0];n.setAttribute("async",!0),n.setAttribute("src",t),o.parentNode.insertBefore(n,o)}function n(e,t){return Element.prototype.matches?e.matches(t):Element.prototype.msMatchesSelector?e.msMatchesSelector(t):void 0}function o(e,t){if(e.closest)return e.closest(t);var o=e;do{if(n(o,t))return o;o=o.parentElement||o.parentNode}while(null!==o&&1===o.nodeType);return null}function i(e,t){for(var n=0;n<e.length;n++)t(e[n],n,e)}var r=".sharing-hidden .inner",s="data-sharing-more-button-id";function a(e){this.button=e,this.pane=o(e,"div").querySelector(r),this.openedBy=null,this.recentlyOpenedByHover=!1,a.instances.push(this),this.pane.setAttribute(s,a.instances.length-1),this.attachHandlers()}if(a.instances=[],a.hoverOpenDelay=200,a.recentOpenDelay=400,a.hoverCloseDelay=300,a.instantiateOrReuse=function(e){var t=o(e,"div").querySelector(r),n=t&&t.getAttribute(s),i=a.instances[n];return i||new a(e)},a.getButtonInstanceFromPane=function(e){var t=e&&e.getAttribute(s);return a.instances[t]},a.closeAll=function(){for(var e=0;e<a.instances.length;e++)a.instances[e].close()},a.prototype.open=function(){var e,t,n=[0,0];function o(e){var t=e.getBoundingClientRect();return[t.left+(window.scrollX||window.pageXOffset||0),t.top+(window.scrollY||window.pageYOffset||0)]}function i(e,t){return parseInt(getComputedStyle(e).getPropertyValue(t)||0)}for(e=o(this.button),t=this.button.offsetParent||document.documentElement;t&&(t===document.body||t===document.documentElement)&&"static"===getComputedStyle(t).getPropertyValue("position");)t=t.parentNode;t&&t!==this.button&&1===t.nodeType&&(n=[(n=o(t))[0]+i(t,"border-left-width"),n[1]+i(t,"border-top-width")]);var r,s=e[0]-n[0]-i(this.button,"margin-left"),a=e[1]-n[1]-i(this.button,"margin-top");this.pane.style.left=s+"px",this.pane.style.top=a+this.button.offsetHeight+3+"px",(r=this.pane)&&r.style.removeProperty("display")},a.prototype.close=function(){var e;(e=this.pane)&&(e.style.display="none"),this.openedBy=null},a.prototype.toggle=function(){var e;(e=this.pane)&&"none"!==e.style.display?this.close():this.open()},a.prototype.nonHoverOpen=function(){clearTimeout(this.openTimer),clearTimeout(this.closeTimer),this.recentlyOpenedByHover?(this.recentlyOpenedByHover=!1,clearTimeout(this.hoverOpenTimer),this.open()):this.toggle()},a.prototype.resetCloseTimer=function(){clearTimeout(this.closeTimer),this.closeTimer=setTimeout(this.close.bind(this),a.hoverCloseDelay)},a.prototype.attachHandlers=function(){this.buttonClick=function(e){e.preventDefault(),e.stopPropagation(),this.openedBy="click",this.nonHoverOpen()}.bind(this),this.buttonKeydown=function(e){13!==e.keyCode&&32!==e.keyCode||(e.preventDefault(),e.stopPropagation(),this.openedBy="keydown",this.nonHoverOpen())}.bind(this),this.buttonEnter=function(){this.openedBy||(this.openTimer=setTimeout(function(){this.open(),this.openedBy="hover",this.recentlyOpenedByHover=!0,this.hoverOpenTimer=setTimeout(function(){this.recentlyOpenedByHover=!1}.bind(this),a.recentOpenDelay)}.bind(this),a.hoverOpenDelay)),clearTimeout(this.closeTimer)}.bind(this),this.buttonLeave=function(){"hover"===this.openedBy&&this.resetCloseTimer(),clearTimeout(this.openTimer)}.bind(this),this.paneEnter=function(){clearTimeout(this.closeTimer)}.bind(this),this.paneLeave=function(){"hover"===this.openedBy&&this.resetCloseTimer()}.bind(this),this.documentClick=function(){this.close()}.bind(this),this.button.addEventListener("click",this.buttonClick),this.button.addEventListener("keydown",this.buttonKeydown),document.addEventListener("click",this.documentClick),void 0===document.ontouchstart&&(this.button.addEventListener("mouseenter",this.buttonEnter),this.button.addEventListener("mouseleave",this.buttonLeave),this.pane.addEventListener("mouseenter",this.paneEnter),this.pane.addEventListener("mouseleave",this.paneLeave))},window.sharing_js_options&&window.sharing_js_options.counts){var c={done_urls:[],get_counts:function(){var e,n,o,i,r;if("undefined"!=typeof WPCOM_sharing_counts)for(e in WPCOM_sharing_counts)if(o=WPCOM_sharing_counts[e],void 0===c.done_urls[o]){for(i in n={pinterest:[window.location.protocol+"https://api.pinterest.com/v1/urls/count.json?callback=WPCOMSharing.update_pinterest_count&url="+encodeURIComponent(e)]})if(document.querySelector("a[data-shared=sharing-"+i+"-"+o+"]")){for(;r=n[i].pop();)t(r);window.sharing_js_options.is_stats_active&&c.bump_sharing_count_stat(i)}c.done_urls[o]=!0}},update_pinterest_count:function(e){void 0!==e.count&&1*e.count>0&&c.inject_share_count("sharing-pinterest-"+WPCOM_sharing_counts[e.url],e.count)},inject_share_count:function(e,t){i(document.querySelectorAll("a[data-shared="+e+"] > span"),(function(e){var n,o=e.querySelector(".share-count");(n=o)&&n.parentNode&&n.parentNode.removeChild(n);var i=document.createElement("span");
1449i.className="share-count",i.textContent=c.format_count(t),e.appendChild(i)}))},format_count:function(e){return e<1e3?e:e>=1e3&&e<1e4?String(e).substring(0,1)+"K+":"10K+"},bump_sharing_count_stat:function(e){(new Image).src=document.location.protocol+"../g.gifv=wpcom-no-pv&x_sharing-count-request="+e+"&r="+Math.random()}};window.WPCOMSharing=c}function u(e,t){e.setAttribute("jetpack-share-click-count",t)}function d(e){var t=e.getAttribute("jetpack-share-click-count");return null===t?0:parseInt(t,10)}function l(e,t){var n,o=new XMLHttpRequest;o.open("POST",e,!0),o.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8"),o.setRequestHeader("x-requested-with","XMLHttpRequest"),o.send((n=t,(encodeURIComponent("email-share-nonce")+"="+encodeURIComponent(n)).replace(/%20/g,"+")))}function h(){p()}function p(){window.WPCOMSharing&&window.WPCOMSharing.get_counts(),i(document.querySelectorAll(".sharedaddy a"),(function(e){var t=e.getAttribute("href");t&&-1!==t.indexOf("share=")&&-1===t.indexOf("&nb=1")&&e.setAttribute("href",t+"&nb=1")})),i(document.querySelectorAll(".sharedaddy a.sharing-anchor"),(function(e){a.instantiateOrReuse(e)})),void 0!==document.ontouchstart&&document.body.classList.add("jp-sharing-input-touch"),i(document.querySelectorAll(".sharedaddy ul"),(function(e){"true"!==e.getAttribute("data-sharing-events-added")&&(e.setAttribute("data-sharing-events-added","true"),i(e.querySelectorAll("a.share-print"),(function(e){e.addEventListener("click",(function(t){t.preventDefault(),t.stopPropagation();var n=e.getAttribute("href")||"",i=function(){if(-1===n.indexOf("#print")){var e=(new Date).getTime();t=e,o=n,(i=document.createElement("iframe")).setAttribute("style","position:fixed; top:100; left:100; height:1px; width:1px; border:none;"),i.setAttribute("id","printFrame-"+t),i.setAttribute("name",i.getAttribute("id")),i.setAttribute("src",o),i.setAttribute("onload",'frames["printFrame-'+t+'"].focus();frames["printFrame-'+t+'"].print();'),document.body.appendChild(i)}else window.print();var t,o,i},s=o(e,r);if(s){var c=a.getButtonInstanceFromPane(s);c&&(c.close(),i())}else i()}))})),i(e.querySelectorAll("a.share-press-this"),(function(e){e.addEventListener("click",(function(t){t.preventDefault(),t.stopPropagation();var n="";if(window.getSelection?n=window.getSelection():document.getSelection?n=document.getSelection():document.selection&&(n=document.selection.createRange().text),n){var o=e.getAttribute("href");e.setAttribute("href",o+"&sel="+encodeURI(n))}window.open(e.getAttribute("href"),"t","toolbar=0,resizable=1,scrollbars=1,status=1,width=720,height=570")||(document.location.href=e.getAttribute("href"))}))})),i(e.querySelectorAll("a.share-email"),(function(t){u(t,0);var n,o,r=t.getAttribute("data-email-share-nonce"),s=t.getAttribute("data-email-share-track-url");r&&s&&(n=s,o=window.location.protocol+"//"+window.location.hostname+"/",0===String(n).indexOf(o))&&t.addEventListener("click",(function(){var n;u(n=t,d(n)+1),d(t)>2&&function(e,t){var n=t.parentElement;if(n.classList.contains("sd-content")){i(n.querySelectorAll(".share-email-error"),(function(e){e.parentElement.removeChild(e)}));var o=document.createElement("div");o.className="share-email-error";var r=document.createElement("h6");r.className="share-email-error-title",r.innerText=e.getAttribute("data-email-share-error-title"),o.appendChild(r);var s=document.createElement("p");s.className="share-email-error-text",s.innerText=e.getAttribute("data-email-share-error-text"),o.appendChild(s),n.appendChild(o)}}(t,e),l(s,r)}))})))})),i(document.querySelectorAll("li.share-email, li.share-custom a.sharing-anchor"),(function(e){e.classList.add("share-service-visible")}))}"loading"!==document.readyState?h():document.addEventListener("DOMContentLoaded",h),document.body.addEventListener("is.post-load",p)}();;
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.