( function ( g ) {
var t = {
PLATFORM_WINDOWS: 'windows',
PLATFORM_IPHONE: 'iphone',
PLATFORM_IPOD: 'ipod',
PLATFORM_IPAD: 'ipad',
PLATFORM_BLACKBERRY: 'blackberry',
PLATFORM_BLACKBERRY_10: 'blackberry_10',
PLATFORM_SYMBIAN: 'symbian_series60',
PLATFORM_SYMBIAN_S40: 'symbian_series40',
PLATFORM_J2ME_MIDP: 'j2me_midp',
PLATFORM_ANDROID: 'android',
PLATFORM_ANDROID_TABLET: 'android_tablet',
PLATFORM_FIREFOX_OS: 'firefoxOS',
PLATFORM_MOBILE_GENERIC: 'mobile_generic',
userAgent : false, // Shortcut to the browser User Agent String.
matchedPlatformName : false, // Matched platform name. False otherwise.
matchedUserAgentName : false, // Matched UA String. False otherwise.
init: function() {
try {
t.userAgent = g.navigator.userAgent.toLowerCase();
t.getPlatformName();
t.getMobileUserAgentName();
} catch ( e ) {
console.error( e );
}
},
initForTest: function( userAgent ) {
t.matchedPlatformName = false;
t.matchedUserAgentName = false;
try {
t.userAgent = userAgent.toLowerCase();
t.getPlatformName();
t.getMobileUserAgentName();
} catch ( e ) {
console.error( e );
}
},
/**
* This method detects the mobile User Agent name.
*/
getMobileUserAgentName: function() {
if ( t.matchedUserAgentName !== false )
return t.matchedUserAgentName;
if ( t.userAgent === false )
return false;
if ( t.isChromeForIOS() )
t.matchedUserAgentName = 'chrome-for-ios';
else if ( t.isTwitterForIpad() )
t.matchedUserAgentName = 'twitter-for-ipad';
else if ( t.isTwitterForIphone() )
t.matchedUserAgentName = 'twitter-for-iphone';
else if ( t.isIPhoneOrIPod() )
t.matchedUserAgentName = 'iphone';
else if ( t.isIPad() )
t.matchedUserAgentName = 'ipad';
else if ( t.isAndroidTablet() )
t.matchedUserAgentName = 'android_tablet';
else if ( t.isAndroid() )
t.matchedUserAgentName = 'android';
else if ( t.isBlackberry10() )
t.matchedUserAgentName = 'blackberry_10';
else if ( has( 'blackberry' ) )
t.matchedUserAgentName = 'blackberry';
else if ( t.isBlackberryTablet() )
t.matchedUserAgentName = 'blackberry_tablet';
else if ( t.isWindowsPhone7() )
t.matchedUserAgentName = 'win7';
else if ( t.isWindowsPhone8() )
t.matchedUserAgentName = 'winphone8';
else if ( t.isOperaMini() )
t.matchedUserAgentName = 'opera-mini';
else if ( t.isOperaMobile() )
t.matchedUserAgentName = 'opera-mobi';
else if ( t.isKindleFire() )
t.matchedUserAgentName = 'kindle-fire';
else if ( t.isSymbianPlatform() )
t.matchedUserAgentName = 'series60';
else if ( t.isFirefoxMobile() )
t.matchedUserAgentName = 'firefox_mobile';
else if ( t.isFirefoxOS() )
t.matchedUserAgentName = 'firefoxOS';
else if ( t.isFacebookForIphone() )
t.matchedUserAgentName = 'facebook-for-iphone';
else if ( t.isFacebookForIpad() )
t.matchedUserAgentName = 'facebook-for-ipad';
else if ( t.isWordPressForIos() )
t.matchedUserAgentName = 'ios-app';
else if ( has( 'iphone' ) )
t.matchedUserAgentName = 'iphone-unknown';
else if ( has( 'ipad' ) )
t.matchedUserAgentName = 'ipad-unknown';
return t.matchedUserAgentName;
},
/**
* This method detects the mobile platform name.
*/
getPlatformName : function() {
if ( t.matchedPlatformName !== false )
return t.matchedPlatformName;
if ( t.userAgent === false )
return false;
if ( has( 'windows ce' ) || has( 'windows phone' ) ) {
t.matchedPlatformName = t.PLATFORM_WINDOWS;
} else if ( has( 'ipad' ) ) {
t.matchedPlatformName = t.PLATFORM_IPAD;
} else if ( has( 'ipod' ) ) {
t.matchedPlatformName = t.PLATFORM_IPOD;
} else if ( has( 'iphone' ) ) {
t.matchedPlatformName = t.PLATFORM_IPHONE;
} else if ( has( 'android' ) ) {
if ( t.isAndroidTablet() )
t.matchedPlatformName = t.PLATFORM_ANDROID_TABLET;
else
t.matchedPlatformName = t.PLATFORM_ANDROID;
} else if ( t.isKindleFire() ) {
t.matchedPlatformName = t.PLATFORM_ANDROID_TABLET;
} else if ( t.isBlackberry10() ) {
t.matchedPlatformName = t.PLATFORM_BLACKBERRY_10;
} else if ( has( 'blackberry' ) ) {
t.matchedPlatformName = t.PLATFORM_BLACKBERRY;
} else if ( t.isBlackberryTablet() ) {
t.matchedPlatformName = t.PLATFORM_BLACKBERRY;
} else if ( t.isSymbianPlatform() ) {
t.matchedPlatformName = t.PLATFORM_SYMBIAN;
} else if ( t.isSymbianS40Platform() ) {
t.matchedPlatformName = t.PLATFORM_SYMBIAN_S40;
} else if ( t.isJ2MEPlatform() ) {
t.matchedPlatformName = t.PLATFORM_J2ME_MIDP;
} else if ( t.isFirefoxOS() ) {
t.matchedPlatformName = t.PLATFORM_FIREFOX_OS;
} else if ( t.isFirefoxMobile() ) {
t.matchedPlatformName = t.PLATFORM_MOBILE_GENERIC;
}
return t.matchedPlatformName;
},
/**
* Detect the BlackBerry OS version.
*
* Note: This is for smartphones only. Does not work on BB tablets.
*/
getBlackBerryOSVersion : check( function() {
if ( t.isBlackberry10() )
return '10';
if ( ! has( 'blackberry' ) )
return false;
var rv = -1; // Return value assumes failure.
var re;
if ( has( 'webkit' ) ) { // Detecting the BB OS version for devices running OS 6.0 or higher
re = /Version\/([\d\.]+)/i;
} else {
// BlackBerry devices <= 5.XX
re = /BlackBerry\w+\/([\d\.]+)/i;
}
if ( re.exec( t.userAgent ) != null )
rv = RegExp.$1.toString();
return rv === -1 ? false : rv;
} ),
/**
* Detects if the current UA is iPhone Mobile Safari or another iPhone or iPod Touch Browser.
*/
isIPhoneOrIPod : check( function() {
return has( 'safari' ) && ( has( 'iphone' ) || has( 'ipod' ) );
} ),
/**
* Detects if the current device is an iPad.
*/
isIPad : check( function() {
return has( 'ipad' ) && has( 'safari' );
} ),
/**
* Detects if the current UA is Chrome for iOS
*/
isChromeForIOS : check( function() {
return t.isIPhoneOrIPod() && has( 'crios/' );
} ),
/**
* Detects if the current browser is the Native Android browser.
*/
isAndroid : check( function() {
if ( has( 'android' ) ) {
return ! ( t.isOperaMini() || t.isOperaMobile() || t.isFirefoxMobile() );
}
} ),
/**
* Detects if the current browser is the Native Android Tablet browser.
*/
isAndroidTablet : check( function() {
if ( has( 'android' ) && ! has( 'mobile' ) ) {
return ! ( t.isOperaMini() || t.isOperaMobile() || t.isFirefoxMobile() );
}
} ),
/**
* Detects if the current browser is Opera Mobile
*/
isOperaMobile : check( function() {
return has( 'opera' ) && has( 'mobi' );
} ),
/**
* Detects if the current browser is Opera Mini
*/
isOperaMini : check( function() {
return has( 'opera' ) && has( 'mini' );
} ),
/**
* isBlackberry10() can be used to check the User Agent for a BlackBerry 10 device.
*/
isBlackberry10 : check( function() {
return has( 'bb10' ) && has( 'mobile' );
} ),
/**
* isBlackberryTablet() can be used to check the User Agent for a RIM blackberry tablet
*/
isBlackberryTablet : check( function() {
return has( 'playbook' ) && has( 'rim tablet' );
} ),
/**
* Detects if the current browser is a Windows Phone 7 device.
*/
isWindowsPhone7 : check( function () {
return has( 'windows phone os 7' );
} ),
/**
* Detects if the current browser is a Windows Phone 8 device.
*/
isWindowsPhone8 : check( function () {
return has( 'windows phone 8' );
} ),
/**
* Detects if the device platform is J2ME.
*/
isJ2MEPlatform : check( function () {
return has( 'j2me/midp' ) || ( has( 'midp' ) && has( 'cldc' ) );
} ),
/**
* Detects if the device platform is the Symbian Series 40.
*/
isSymbianS40Platform : check( function() {
if ( has( 'series40' ) ) {
return has( 'nokia' ) || has( 'ovibrowser' ) || has( 'nokiabrowser' );
}
} ),
/**
* Detects if the device platform is the Symbian Series 60.
*/
isSymbianPlatform : check( function() {
if ( has( 'webkit' ) ) {
// First, test for WebKit, then make sure it's either Symbian or S60.
return has( 'symbian' ) || has( 'series60' );
} else if ( has( 'symbianos' ) && has( 'series60' ) ) {
return true;
} else if ( has( 'nokia' ) && has( 'series60' ) ) {
return true;
} else if ( has( 'opera mini' ) ) {
return has( 'symbianos' ) || has( 'symbos' ) || has( 'series 60' );
}
} ),
/**
* Detects if the current browser is the Kindle Fire Native browser.
*/
isKindleFire : check( function() {
return has( 'silk/' ) && has( 'silk-accelerated=' );
} ),
/**
* Detects if the current browser is Firefox Mobile (Fennec)
*/
isFirefoxMobile : check( function() {
return has( 'fennec' );
} ),
/**
* Detects if the current browser is the native FirefoxOS browser
*/
isFirefoxOS : check( function() {
return has( 'mozilla' ) && has( 'mobile' ) && has( 'gecko' ) && has( 'firefox' );
} ),
/**
* Detects if the current UA is Facebook for iPad
*/
isFacebookForIpad : check( function() {
if ( ! has( 'ipad' ) )
return false;
return has( 'facebook' ) || has( 'fbforiphone' ) || has( 'fban/fbios;' );
} ),
/**
* Detects if the current UA is Facebook for iPhone
*/
isFacebookForIphone : check( function() {
if ( ! has( 'iphone' ) )
return false;
return ( has( 'facebook' ) && ! has( 'ipad' ) ) ||
( has( 'fbforiphone' ) && ! has( 'tablet' ) ) ||
( has( 'fban/fbios;' ) && ! has( 'tablet' ) ); // FB app v5.0 or higher
} ),
/**
* Detects if the current UA is Twitter for iPhone
*/
isTwitterForIphone : check( function() {
if ( has( 'ipad' ) )
return false;
return has( 'twitter for iphone' );
} ),
/**
* Detects if the current UA is Twitter for iPad
*/
isTwitterForIpad : check( function() {
return has( 'twitter for ipad' ) || ( has( 'ipad' ) && has( 'twitter for iphone' ) );
} ),
/**
* Detects if the current UA is WordPress for iOS
*/
isWordPressForIos : check( function() {
return has( 'wp-iphone' );
} )
};
function has( str ) {
return t.userAgent.indexOf( str ) != -1;
}
function check( fn ) {
return function() {
return t.userAgent === false ? false : fn() || false;
}
}
g.wpcom_mobile_user_agent_info = t;
} )( typeof window !== 'undefined' ? window : this );
;
/* global wpcom_reblog */
var jetpackLikesWidgetBatch = [];
var jetpackLikesMasterReady = false;
// Due to performance problems on pages with a large number of widget iframes that need to be loaded,
// we are limiting the processing at any instant to unloaded widgets that are currently in viewport,
// plus this constant that will allow processing of widgets above and bellow the current fold.
// This aim of it is to improve the UX and hide the transition from unloaded to loaded state from users.
var jetpackLikesLookAhead = 2000; // pixels
// Keeps track of loaded comment likes widget so we can unload them when they are scrolled out of view.
var jetpackCommentLikesLoadedWidgets = [];
var jetpackLikesDocReadyPromise = new Promise( resolve => {
if ( document.readyState !== 'loading' ) {
resolve();
} else {
window.addEventListener( 'DOMContentLoaded', () => resolve() );
}
} );
function JetpackLikesPostMessage( message, target ) {
if ( typeof message === 'string' ) {
try {
message = JSON.parse( message );
} catch ( e ) {
return;
}
}
if ( target && typeof target.postMessage === 'function' ) {
try {
target.postMessage(
JSON.stringify( {
type: 'likesMessage',
data: message,
} ),
'*'
);
} catch ( e ) {
return;
}
}
}
function JetpackLikesBatchHandler() {
const requests = [];
document.querySelectorAll( 'div.jetpack-likes-widget-unloaded' ).forEach( widget => {
if ( jetpackLikesWidgetBatch.indexOf( widget.id ) > -1 ) {
return;
}
if ( ! jetpackIsScrolledIntoView( widget ) ) {
return;
}
jetpackLikesWidgetBatch.push( widget.id );
var regex = /like-(post|comment)-wrapper-(\d+)-(\d+)-(\w+)/,
match = regex.exec( widget.id ),
info;
if ( ! match || match.length !== 5 ) {
return;
}
info = {
blog_id: match[ 2 ],
width: widget.width,
};
if ( 'post' === match[ 1 ] ) {
info.post_id = match[ 3 ];
} else if ( 'comment' === match[ 1 ] ) {
info.comment_id = match[ 3 ];
}
info.obj_id = match[ 4 ];
requests.push( info );
} );
if ( requests.length > 0 ) {
JetpackLikesPostMessage(
{ event: 'initialBatch', requests: requests },
window.frames[ 'likes-master' ]
);
}
}
function JetpackLikesMessageListener( event ) {
let message = event && event.data;
if ( typeof message === 'string' ) {
try {
message = JSON.parse( message );
} catch ( err ) {
return;
}
}
const type = message && message.type;
const data = message && message.data;
if ( type !== 'likesMessage' || typeof data.event === 'undefined' ) {
return;
}
// We only allow messages from one origin
const allowedOrigin = 'https://widgets.wp.com';
if ( allowedOrigin !== event.origin ) {
return;
}
switch ( data.event ) {
case 'masterReady':
jetpackLikesDocReadyPromise.then( () => {
jetpackLikesMasterReady = true;
const stylesData = {
event: 'injectStyles',
};
const sdTextColor = document.querySelector( '.sd-text-color' );
const sdLinkColor = document.querySelector( '.sd-link-color' );
const sdTextColorStyles = ( sdTextColor && getComputedStyle( sdTextColor ) ) || {};
const sdLinkColorStyles = ( sdLinkColor && getComputedStyle( sdLinkColor ) ) || {};
// enable reblogs if they are enabled for the page
if ( document.body.classList.contains( 'jetpack-reblog-enabled' ) ) {
JetpackLikesPostMessage( { event: 'reblogsEnabled' }, window.frames[ 'likes-master' ] );
}
stylesData.textStyles = {
color: sdTextColorStyles[ 'color' ],
fontFamily: sdTextColorStyles[ 'font-family' ],
fontSize: sdTextColorStyles[ 'font-size' ],
direction: sdTextColorStyles[ 'direction' ],
fontWeight: sdTextColorStyles[ 'font-weight' ],
fontStyle: sdTextColorStyles[ 'font-style' ],
textDecoration: sdTextColorStyles[ 'text-decoration' ],
};
stylesData.linkStyles = {
color: sdLinkColorStyles[ 'color' ],
fontFamily: sdLinkColorStyles[ 'font-family' ],
fontSize: sdLinkColorStyles[ 'font-size' ],
textDecoration: sdLinkColorStyles[ 'text-decoration' ],
fontWeight: sdLinkColorStyles[ 'font-weight' ],
fontStyle: sdLinkColorStyles[ 'font-style' ],
};
JetpackLikesPostMessage( stylesData, window.frames[ 'likes-master' ] );
JetpackLikesBatchHandler();
} );
break;
case 'showLikeWidget': {
const placeholder = document.querySelector( `#${ data.id } .likes-widget-placeholder` );
if ( placeholder ) {
placeholder.style.display = 'none';
}
break;
}
case 'showCommentLikeWidget': {
const placeholder = document.querySelector( `#${ data.id } .likes-widget-placeholder` );
if ( placeholder ) {
placeholder.style.display = 'none';
}
break;
}
case 'killCommentLikes':
// If kill switch for comment likes is enabled remove all widgets wrappers and `Loading...` placeholders.
document
.querySelectorAll( '.jetpack-comment-likes-widget-wrapper' )
.forEach( wrapper => wrapper.remove() );
break;
case 'clickReblogFlair':
if ( wpcom_reblog && typeof wpcom_reblog.toggle_reblog_box_flair === 'function' ) {
wpcom_reblog.toggle_reblog_box_flair( data.obj_id, data.post_id );
}
break;
case 'hideOtherGravatars': {
hideLikersPopover();
break;
}
case 'showOtherGravatars': {
const container = document.querySelector( '#likes-other-gravatars' );
if ( ! container ) {
break;
}
const list = container.querySelector( 'ul' );
container.style.display = 'none';
list.innerHTML = '';
container
.querySelectorAll( '.likes-text span' )
.forEach( item => ( item.textContent = data.totalLikesLabel ) );
( data.likers || [] ).forEach( async ( liker, index ) => {
if ( liker.profile_URL.substr( 0, 4 ) !== 'http' ) {
// We only display gravatars with http or https schema
return;
}
const element = document.createElement( 'li' );
list.append( element );
element.innerHTML = `
`;
// Add some extra attributes through native methods, to ensure strings are sanitized.
element.classList.add( liker.css_class );
element.querySelector( 'img' ).alt = data.avatarAltTitle.replace( '%s', liker.name );
element.querySelector( 'span' ).innerText = liker.name;
if ( index === data.likers.length - 1 ) {
element.addEventListener( 'keydown', ( e ) => {
if ( e.key === 'Tab' && ! e.shiftKey ) {
e.preventDefault();
hideLikersPopover();
JetpackLikesPostMessage(
{ event: 'focusLikesCount', parent: data.parent },
window.frames[ 'likes-master' ]
);
}
} );
}
} );
const positionPopup = function() {
const containerStyle = getComputedStyle(container);
const isRtl = containerStyle.direction === 'rtl';
const el = document.querySelector( `*[name='${ data.parent }']` );
const rect = el.getBoundingClientRect();
const win = el.ownerDocument.defaultView;
const offset = {
top: rect.top + win.pageYOffset,
left: rect.left + win.pageXOffset,
};
// don't display yet or we get skewed window.innerWidth later
container.style.display = 'none';
let containerLeft = 0;
container.style.top = offset.top + data.position.top - 1 + 'px';
if ( isRtl ) {
const visibleAvatarsCount = data && data.likers ? Math.min( data.likers.length, 5 ) : 0;
// 24px is the width of the avatar + 4px is the padding between avatars
containerLeft = offset.left + data.position.left + 24 * visibleAvatarsCount + 4;
container.style.transform = 'translateX(-100%)';
} else {
containerLeft = offset.left + data.position.left;
}
container.style.left = containerLeft + 'px';
// Container width - padding
const initContainerWidth = data.width - 20;
const rowLength = Math.floor( initContainerWidth / 37 );
// # of rows + (avatar + avatar padding) + text above + container padding
let height = Math.ceil( data.likers.length / rowLength ) * 37 + 17 + 22;
if ( height > 204 ) {
height = 204;
}
// If the popup is overflows viewport width, we should show it on the next line
// Push it offscreen to calculated rendered width
const windowWidth = win.innerWidth;
container.style.left = '-9999px';
container.style.display = 'block';
// If the popup exceeds the viewport width,
// flip the position of the popup.
const containerWidth = container.offsetWidth;
const containerRight = containerLeft + containerWidth;
if ( containerRight > windowWidth && ! isRtl) {
containerLeft = rect.left + rect.width - containerWidth;
} else if ( containerLeft - containerWidth < 0 && isRtl ) {
container.style.transform = 'none';
containerLeft = rect.left;
}
// Set the container left
container.style.left = containerLeft + 'px';
container.setAttribute( 'aria-hidden', 'false' );
}
positionPopup();
container.focus();
const debounce = function( func, wait ) {
var timeout;
return function() {
var context = this;
var args = arguments;
clearTimeout( timeout );
timeout = setTimeout( function() {
func.apply( context, args );
}, wait );
};
};
const debouncedPositionPopup = debounce( positionPopup, 100 );
// Keep a reference of this function in the element itself
// so that we can destroy it later
container.__resizeHandler = debouncedPositionPopup;
// When window is resized, resize the popup.
window.addEventListener( "resize", debouncedPositionPopup );
}
}
}
window.addEventListener( 'message', JetpackLikesMessageListener );
function hideLikersPopover() {
const container = document.querySelector( '#likes-other-gravatars' );
if ( container ) {
container.style.display = 'none';
container.setAttribute( 'aria-hidden', 'true' );
// Remove the resize event listener and cleanup.
const resizeHandler = container.__resizeHandler;
if ( resizeHandler ) {
window.removeEventListener( "resize", resizeHandler );
delete container.__resizeHandler;
}
}
}
document.addEventListener( 'click', hideLikersPopover );
function JetpackLikesWidgetQueueHandler() {
var wrapperID;
if ( ! jetpackLikesMasterReady ) {
setTimeout( JetpackLikesWidgetQueueHandler, 500 );
return;
}
// Restore widgets to initial unloaded state when they are scrolled out of view.
jetpackUnloadScrolledOutWidgets();
var unloadedWidgetsInView = jetpackGetUnloadedWidgetsInView();
if ( unloadedWidgetsInView.length > 0 ) {
// Grab any unloaded widgets for a batch request
JetpackLikesBatchHandler();
}
for ( var i = 0, length = unloadedWidgetsInView.length; i <= length - 1; i++ ) {
wrapperID = unloadedWidgetsInView[ i ].id;
if ( ! wrapperID ) {
continue;
}
jetpackLoadLikeWidgetIframe( wrapperID );
}
}
function jetpackLoadLikeWidgetIframe( wrapperID ) {
if ( typeof wrapperID === 'undefined' ) {
return;
}
const wrapper = document.querySelector( '#' + wrapperID );
wrapper.querySelectorAll( 'iframe' ).forEach( iFrame => iFrame.remove() );
const placeholder = wrapper.querySelector( '.likes-widget-placeholder' );
// Post like iframe
if ( placeholder && placeholder.classList.contains( 'post-likes-widget-placeholder' ) ) {
const postLikesFrame = document.createElement( 'iframe' );
postLikesFrame.classList.add( 'post-likes-widget', 'jetpack-likes-widget' );
postLikesFrame.name = wrapper.dataset.name;
postLikesFrame.src = wrapper.dataset.src;
postLikesFrame.height = '55px';
postLikesFrame.width = '100%';
postLikesFrame.frameBorder = '0';
postLikesFrame.scrolling = 'no';
postLikesFrame.title = wrapper.dataset.title;
placeholder.after( postLikesFrame );
}
// Comment like iframe
if ( placeholder.classList.contains( 'comment-likes-widget-placeholder' ) ) {
const commentLikesFrame = document.createElement( 'iframe' );
commentLikesFrame.class = 'comment-likes-widget-frame jetpack-likes-widget-frame';
commentLikesFrame.name = wrapper.dataset.name;
commentLikesFrame.src = wrapper.dataset.src;
commentLikesFrame.height = '18px';
commentLikesFrame.width = '100%';
commentLikesFrame.frameBorder = '0';
commentLikesFrame.scrolling = 'no';
wrapper.querySelector( '.comment-like-feedback' ).after( commentLikesFrame );
jetpackCommentLikesLoadedWidgets.push( commentLikesFrame );
}
wrapper.classList.remove( 'jetpack-likes-widget-unloaded' );
wrapper.classList.add( 'jetpack-likes-widget-loading' );
wrapper.querySelector( 'iframe' ).addEventListener( 'load', e => {
JetpackLikesPostMessage(
{ event: 'loadLikeWidget', name: e.target.name, width: e.target.width },
window.frames[ 'likes-master' ]
);
wrapper.classList.remove( 'jetpack-likes-widget-loading' );
wrapper.classList.add( 'jetpack-likes-widget-loaded' );
} );
}
function jetpackGetUnloadedWidgetsInView() {
const unloadedWidgets = document.querySelectorAll( 'div.jetpack-likes-widget-unloaded' );
return [ ...unloadedWidgets ].filter( item => jetpackIsScrolledIntoView( item ) );
}
function jetpackIsScrolledIntoView( element ) {
const top = element.getBoundingClientRect().top;
const bottom = element.getBoundingClientRect().bottom;
// Allow some slack above and bellow the fold with jetpackLikesLookAhead,
// with the aim of hiding the transition from unloaded to loaded widget from users.
return top + jetpackLikesLookAhead >= 0 && bottom <= window.innerHeight + jetpackLikesLookAhead;
}
function jetpackUnloadScrolledOutWidgets() {
for ( let i = jetpackCommentLikesLoadedWidgets.length - 1; i >= 0; i-- ) {
const currentWidgetIframe = jetpackCommentLikesLoadedWidgets[ i ];
if ( ! jetpackIsScrolledIntoView( currentWidgetIframe ) ) {
const widgetWrapper =
currentWidgetIframe &&
currentWidgetIframe.parentElement &&
currentWidgetIframe.parentElement.parentElement;
// Restore parent class to 'unloaded' so this widget can be picked up by queue manager again if needed.
widgetWrapper.classList.remove( 'jetpack-likes-widget-loaded' );
widgetWrapper.classList.remove( 'jetpack-likes-widget-loading' );
widgetWrapper.classList.add( 'jetpack-likes-widget-unloaded' );
// Bring back the loading placeholder into view.
widgetWrapper
.querySelectorAll( '.comment-likes-widget-placeholder' )
.forEach( item => ( item.style.display = 'block' ) );
// Remove it from the list of loaded widgets.
jetpackCommentLikesLoadedWidgets.splice( i, 1 );
// Remove comment like widget iFrame.
currentWidgetIframe.remove();
}
}
}
var jetpackWidgetsDelayedExec = function ( after, fn ) {
var timer;
return function () {
clearTimeout( timer );
timer = setTimeout( fn, after );
};
};
var jetpackOnScrollStopped = jetpackWidgetsDelayedExec( 250, JetpackLikesWidgetQueueHandler );
// Load initial batch of widgets, prior to any scrolling events.
JetpackLikesWidgetQueueHandler();
// Add event listener to execute queue handler after scroll.
window.addEventListener( 'scroll', jetpackOnScrollStopped, true );
;
!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(),L()}}function f(){s=!0}function v(){s=!1}function y(e){e.role="button",e.tabIndex=0,e.ariaLabel=jetpackCarouselStrings.image_label}function w(){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].forEach((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;L()}else if(i)L();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 j(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 j(jetpackCarouselStrings.no_comment_email,!1);if(!c.author.length)return void j(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 j(jetpackCarouselStrings.comment_post_error,!1)}"approved"===e.comment_status?j(jetpackCarouselStrings.comment_approved,!0):"unapproved"===e.comment_status?j(jetpackCarouselStrings.comment_unapproved,!0):j(jetpackCarouselStrings.comment_post_error,!1),H(),A(a),l.value=jetpackCarouselStrings.post_comment,r.hide(n),s.classList.remove("jp-carousel-is-disabled")}else j(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 j(e,t){var o=p.overlay.querySelector("#jp-carousel-comment-post-results"),a="jp-carousel-comment-post-"+(t?"success":"error");o.innerHTML=''+e+"",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 b(){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&&(y(e),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?E(t,r,o):o.onload=function(){E(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=q(e.caption)||"",l=q(e.title)||"",s=q(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.stripHTML(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=k(a);break;case"aperture":a="f/"+a}r+="