( function () { 'use strict'; if ( typeof window.wpcom === 'undefined' ) { window.wpcom = {}; } if ( window.wpcom.carousel ) { return; } var prebuilt_widths = jetpackCarouselStrings.widths; var pageviews_stats_args = jetpackCarouselStrings.stats_query_args; var findFirstLargeEnoughWidth = function ( original_w, original_h, dest_w, dest_h ) { var inverse_ratio = original_h / original_w; for ( var i = 0; i < prebuilt_widths.length; ++i ) { if ( prebuilt_widths[ i ] >= dest_w || prebuilt_widths[ i ] * inverse_ratio >= dest_h ) { return prebuilt_widths[ i ]; } } return original_w; }; var removeResizeFromImageURL = function ( url ) { return removeArgFromURL( url, 'resize' ); }; var removeArgFromURL = function ( url, arg ) { var re = new RegExp( '[\\?&]' + arg + '(=[^?&]+)?' ); if ( url.match( re ) ) { return url.replace( re, '' ); } return url; }; var addWidthToImageURL = function ( url, width ) { width = parseInt( width, 10 ); // Give devices with a higher devicePixelRatio higher-res images (Retina display = 2, Android phones = 1.5, etc) if ( 'undefined' !== typeof window.devicePixelRatio && window.devicePixelRatio > 1 ) { width = Math.round( width * window.devicePixelRatio ); } url = addArgToURL( url, 'w', width ); url = addArgToURL( url, 'h', '' ); return url; }; var addArgToURL = function ( url, arg, value ) { var re = new RegExp( arg + '=[^?&]+' ); if ( url.match( re ) ) { return url.replace( re, arg + '=' + value ); } else { var divider = url.indexOf( '?' ) !== -1 ? '&' : '?'; return url + divider + arg + '=' + value; } }; var stat = function ( names ) { if ( typeof names !== 'string' ) { names = names.join( ',' ); } new Image().src = window.location.protocol + '//pixel.wp.com/g.gif?v=wpcom-no-pv' + '&x_carousel=' + names + '&baba=' + Math.random(); }; var pageview = function ( post_id ) { new Image().src = window.location.protocol + '//pixel.wp.com/g.gif?host=' + encodeURIComponent( window.location.host ) + '&ref=' + encodeURIComponent( document.referrer ) + '&rand=' + Math.random() + '&' + pageviews_stats_args + '&post=' + encodeURIComponent( post_id ); }; var generateImgSrc = function ( srcItem, max ) { var origSize = srcItem.getAttribute( 'data-orig-size' ) || ''; var src = srcItem.getAttribute( 'src' ) || srcItem.getAttribute( 'original' ) || srcItem.getAttribute( 'data-original' ) || srcItem.getAttribute( 'data-lazy-src' ); if ( src.indexOf( 'imgpress' ) !== -1 ) { src = srcItem.getAttribute( 'data-orig-file' ); } // Square/Circle galleries use a resize param that needs to be removed. src = removeResizeFromImageURL( src ); src = addWidthToImageURL( src, findFirstLargeEnoughWidth( origSize.width, origSize.height, max.width, max.height ) ); return src; }; window.wpcom.carousel = { findFirstLargeEnoughWidth: findFirstLargeEnoughWidth, removeResizeFromImageURL: removeResizeFromImageURL, addWidthToImageURL: addWidthToImageURL, stat: stat, pageview: pageview, generateImgSrc: generateImgSrc }; } )(); ; !function(){var e=document.currentScript;function t(t){var n=document.createElement("script"),i=e||document.getElementsByTagName("script")[0];n.setAttribute("async",!0),n.setAttribute("src",t),i.parentNode.insertBefore(n,i)}function n(e,t){if(Element.prototype.matches)return e.matches(t);if(Element.prototype.msMatchesSelector)return e.msMatchesSelector(t)}function i(e,t){if(e.closest)return e.closest(t);var i=e;do{if(n(i,t))return i;i=i.parentElement||i.parentNode}while(null!==i&&1===i.nodeType);return null}function o(e,t){for(var n=0;n0)c.inject_share_count("sharing-pinterest-"+WPCOM_sharing_counts[e.url],e.count)},inject_share_count:function(e,t){o(document.querySelectorAll("a[data-shared="+e+"] > span"),(function(e){!function(e){if(e&&e.parentNode)e.parentNode.removeChild(e)}(e.querySelector(".share-count"));var n=document.createElement("span");n.className="share-count",n.textContent=c.format_count(t),e.appendChild(n)}))},format_count:function(e){if(e<1e3)return e;if(e>=1e3&&e<1e4)return String(e).substring(0,1)+"K+";else return"10K+"},bump_sharing_count_stat:function(e){(new Image).src=document.location.protocol+"//pixel.wp.com/g.gif?v=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 l(e){var t=e.getAttribute("jetpack-share-click-count");if(null===t)return 0;else return parseInt(t,10)}function d(e,t){var n,i=new XMLHttpRequest;i.open("POST",e,!0),i.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8"),i.setRequestHeader("x-requested-with","XMLHttpRequest"),i.send((n=t,(encodeURIComponent("email-share-nonce")+"="+encodeURIComponent(n)).replace(/%20/g,"+")))}function h(){p()}if("loading"!==document.readyState)h();else document.addEventListener("DOMContentLoaded",h);function p(){if(window.WPCOMSharing)window.WPCOMSharing.get_counts();if(o(document.querySelectorAll(".sharedaddy a"),(function(e){var t=e.getAttribute("href");if(t&&-1!==t.indexOf("share=")&&-1===t.indexOf("&nb=1"))e.setAttribute("href",t+"&nb=1")})),o(document.querySelectorAll(".sharedaddy a.sharing-anchor"),(function(e){a.instantiateOrReuse(e)})),void 0!==document.ontouchstart)document.body.classList.add("jp-sharing-input-touch");o(document.querySelectorAll(".sharedaddy ul"),(function(e){if("true"!==e.getAttribute("data-sharing-events-added"))e.setAttribute("data-sharing-events-added","true"),o(e.querySelectorAll("a.share-print"),(function(e){e.addEventListener("click",(function(t){t.preventDefault(),t.stopPropagation();var n=e.getAttribute("href")||"",o=function(){if(-1===n.indexOf("#print")){var e=(new Date).getTime();t=e,i=n,(o=document.createElement("iframe")).setAttribute("style","position:fixed; top:100; left:100; height:1px; width:1px; border:none;"),o.setAttribute("id","printFrame-"+t),o.setAttribute("name",o.getAttribute("id")),o.setAttribute("src",i),o.setAttribute("onload",'frames["printFrame-'+t+'"].focus();frames["printFrame-'+t+'"].print();'),document.body.appendChild(o)}else window.print();var t,i,o},s=i(e,r);if(s){var c=a.getButtonInstanceFromPane(s);if(c)c.close(),o()}else o()}))})),o(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();else if(document.getSelection)n=document.getSelection();else if(document.selection)n=document.selection.createRange().text;if(n){var i=e.getAttribute("href");e.setAttribute("href",i+"&sel="+encodeURI(n))}if(!window.open(e.getAttribute("href"),"t","toolbar=0,resizable=1,scrollbars=1,status=1,width=720,height=570"))document.location.href=e.getAttribute("href")}))})),o(e.querySelectorAll("a.share-email"),(function(t){u(t,0);var n,i,r=t.getAttribute("data-email-share-nonce"),s=t.getAttribute("data-email-share-track-url");if(r&&s&&(n=s,i=window.location.protocol+"//"+window.location.hostname+"/",0===String(n).indexOf(i)))t.addEventListener("click",(function(){var n;if(u(n=t,l(n)+1),l(t)>2)!function(e,t){var n=t.parentElement;if(n.classList.contains("sd-content")){o(n.querySelectorAll(".share-email-error"),(function(e){e.parentElement.removeChild(e)}));var i=document.createElement("div");i.className="share-email-error";var r=document.createElement("h6");r.className="share-email-error-title",r.innerText=e.getAttribute("data-email-share-error-title"),i.appendChild(r);var s=document.createElement("p");s.className="share-email-error-text",s.innerText=e.getAttribute("data-email-share-error-text"),i.appendChild(s),n.appendChild(i)}}(t,e);d(s,r)}))}))})),o(document.querySelectorAll("li.share-email, li.share-custom a.sharing-anchor"),(function(e){e.classList.add("share-service-visible")}))}document.body.addEventListener("is.post-load",p)}();;