PageSourceSearch

https://johnpistelli.com/_static/??-eJx9TtEKwjAM/CG3IAymD+KnjJiGrV…Ip1BnTAxAaNWd6rlb72Vta4q78c21N7bpp1xidwLmj5

js johnpistelli.com collected 2026-10-02 05:04:09 UTC 19,836 bytes, 368 lines download raw bytes

1/**
2 * This PaypalExpressCheckout global is included by wp_enqueue_script( 'jetpack-paypal-express-checkout' );
3 * It handles communication with Paypal Express checkout and public-api.wordpress.com for the purposes
4 * of simple-payments module.
5 */
6
7/* global paypal */
8/* exported PaypalExpressCheckout */
9const PaypalExpressCheckout = {
10	primaryCssClassName: 'jetpack-simple-payments',
11	messageCssClassName: 'jetpack-simple-payments-purchase-message',
12
13	wpRestAPIHost: 'https://public-api.wordpress.com',
14	wpRestAPIVersion: '/wpcom/v2',
15
16	getEnvironment: function () {
17		if (
18			localStorage &&
19			localStorage.getItem &&
20			localStorage.getItem( 'simple-payments-env' ) === 'sandbox'
21		) {
22			return 'sandbox';
23		}
24		return 'production';
25	},
26
27	getCreatePaymentEndpoint: function ( blogId ) {
28		return (
29			PaypalExpressCheckout.wpRestAPIHost +
30			PaypalExpressCheckout.wpRestAPIVersion +
31			'/sites/' +
32			blogId +
33			'/simple-payments/paypal/payment'
34		);
35	},
36
37	getExecutePaymentEndpoint: function ( blogId, paymentId ) {
38		return (
39			PaypalExpressCheckout.wpRestAPIHost +
40			PaypalExpressCheckout.wpRestAPIVersion +
41			'/sites/' +
42			blogId +
43			'/simple-payments/paypal/' +
44			paymentId +
45			'/execute'
46		);
47	},
48
49	getNumberOfItems: function ( field, enableMultiple ) {
50		if ( enableMultiple !== '1' ) {
51			return 1;
52		}
53
54		const numberField = document.getElementById( field );
55
56		if ( ! numberField ) {
57			return 1;
58		}
59
60		const number = Number( numberField.value );
61
62		if ( isNaN( number ) ) {
63			return 1;
64		}
65		return number;
66	},
67
68	/**
69	 * Get the DOM element-placeholder used to show message
70	 * about the transaction. If it doesn't exist then the function will create a new one.
71	 *
72	 * @param {string} domId - domId id of the payment button placeholder
73	 * @return {Element} the dom element to print the message
74	 */
75	getMessageContainer: function ( domId ) {
76		return document.getElementById( domId + '-message-container' );
77	},
78
79	/**
80	 * Show a messange close to the Paypal button.
81	 * Use this function to give feedback to the user according
82	 * to the transaction result.
83	 *
84	 * @param {string}  message   - message to show
85	 * @param {string}  domId     - paypal-button element dom identifier
86	 * @param {boolean} [isError] - defines if it's a message error. Not TRUE as default.
87	 */
88	showMessage: function ( message, domId, isError ) {
89		const domEl = PaypalExpressCheckout.getMessageContainer( domId );
90
91		// set css classes
92		let cssClasses = PaypalExpressCheckout.messageCssClassName + ' show ';
93		cssClasses += isError ? 'error' : 'success';
94
95		// show message 1s after PayPal popup is closed
96		setTimeout( function () {
97			domEl.innerHTML = message;
98			domEl.setAttribute( 'class', cssClasses );
99		}, 1000 );
100	},
101
102	showError: function ( message, domId ) {
103		PaypalExpressCheckout.showMessage( message, domId, true );
104	},
105
106	processErrorMessage: function ( errorResponse ) {
107		const error = errorResponse ? errorResponse.responseJSON : null;
108		const defaultMessage = 'There was an issue processing your payment.';
109
110		if ( ! error ) {
111			return '<p>' + defaultMessage + '</p>';
112		}
113
114		if ( error.additional_errors ) {
115			const messages = [];
116			error.additional_errors.forEach( function ( additionalError ) {
117				if ( additionalError.message ) {
118					messages.push( '<p>' + additionalError.message.toString() + '</p>' );
119				}
120			} );
121			return messages.join( '' );
122		}
123
124		return '<p>' + ( error.message || defaultMessage ) + '</p>';
125	},
126
127	processSuccessMessage: function ( successResponse ) {
128		const message = successResponse.message;
129		const defaultMessage = 'Thank you. Your purchase was successful!';
130
131		if ( ! message ) {
132			return '<p>' + defaultMessage + '</p>';
133		}
134
135		return '<p>' + message + '</p>';
136	},
137
138	cleanAndHideMessage: function ( domId ) {
139		const domEl = PaypalExpressCheckout.getMessageContainer( domId );
140		domEl.setAttribute( 'class', PaypalExpressCheckout.messageCssClassName );
141		domEl.innerHTML = '';
142	},
143
144	renderButton: function ( blogId, buttonId, domId, enableMultiple ) {
145		const env = PaypalExpressCheckout.getEnvironment();
146
147		if ( ! paypal ) {
148			throw new Error( 'PayPal module is required by PaypalExpressCheckout' );
149		}
150
151		const buttonDomId = domId + '_button';
152
153		paypal.Button.render(
154			{
155				env: env,
156				commit: true,
157
158				style: {
159					label: 'pay',
160					shape: 'rect',
161					color: 'silver',
162					size: 'responsive',
163					fundingicons: true,
164				},
165
166				payment: function () {
167					PaypalExpressCheckout.cleanAndHideMessage( domId );
168
169					const payload = {
170						number: PaypalExpressCheckout.getNumberOfItems( domId + '_number', enableMultiple ),
171						buttonId: buttonId,
172						env: env,
173					};
174
175					return new paypal.Promise( function ( resolve, reject ) {
176						// eslint-disable-next-line no-undef
177						jQuery
178							.post( PaypalExpressCheckout.getCreatePaymentEndpoint( blogId ), payload )
179							.done( function ( paymentResponse ) {
180								if ( ! paymentResponse ) {
181									PaypalExpressCheckout.showError(
182										PaypalExpressCheckout.processErrorMessage(),
183										domId
184									);
185									return reject( new Error( 'server_error' ) );
186								}
187
188								resolve( paymentResponse.id );
189							} )
190							.fail( function ( paymentError ) {
191								const paymentErrorMessage =
192									PaypalExpressCheckout.processErrorMessage( paymentError );
193								PaypalExpressCheckout.showError( paymentErrorMessage, domId );
194
195								const code =
196									paymentError.responseJSON && paymentError.responseJSON.code
197										? paymentError.responseJSON.code
198										: 'server_error';
199
200								reject( new Error( code ) );
201							} );
202					} );
203				},
204
205				onAuthorize: function ( onAuthData ) {
206					const payload = {
207						buttonId: buttonId,
208						payerId: onAuthData.payerID,
209						env: env,
210					};
211					return new paypal.Promise( function ( resolve, reject ) {
212						// eslint-disable-next-line no-undef
213						jQuery
214							.post(
215								PaypalExpressCheckout.getExecutePaymentEndpoint( blogId, onAuthData.paymentID ),
216								payload
217							)
218							.done( function ( authResponse ) {
219								if ( ! authResponse ) {
220									PaypalExpressCheckout.showError(
221										PaypalExpressCheckout.processErrorMessage(),
222										domId
223									);
224									return reject( new Error( 'server_error' ) );
225								}
226
227								PaypalExpressCheckout.showMessage(
228									PaypalExpressCheckout.processSuccessMessage( authResponse ),
229									domId
230								);
231								resolve();
232							} )
233							.fail( function ( authError ) {
234								const authErrorMessage = PaypalExpressCheckout.processErrorMessage( authError );
235								PaypalExpressCheckout.showError( authErrorMessage, domId );
236
237								const code =
238									authError.responseJSON && authError.responseJSON.code
239										? authError.responseJSON.code
240										: 'server_error';
241
242								reject( new Error( code ) );
243							} );
244					} );
245				},
246			},
247			buttonDomId
248		);
249	},
250};
251;
252( function () {
253	'use strict';
254
255	if ( typeof window.wpcom === 'undefined' ) {
256		window.wpcom = {};
257	}
258
259	if ( window.wpcom.carousel ) {
260		return;
261	}
262
263	var prebuilt_widths = jetpackCarouselStrings.widths;
264	var pageviews_stats_args = jetpackCarouselStrings.stats_query_args;
265
266	var findFirstLargeEnoughWidth = function ( original_w, original_h, dest_w, dest_h ) {
267		var inverse_ratio = original_h / original_w;
268
269		for ( var i = 0; i < prebuilt_widths.length; ++i ) {
270			if ( prebuilt_widths[ i ] >= dest_w || prebuilt_widths[ i ] * inverse_ratio >= dest_h ) {
271				return prebuilt_widths[ i ];
272			}
273		}
274
275		return original_w;
276	};
277
278	var removeResizeFromImageURL = function ( url ) {
279		return removeArgFromURL( url, 'resize' );
280	};
281
282	var removeArgFromURL = function ( url, arg ) {
283		var re = new RegExp( '[\\?&]' + arg + '(=[^?&]+)?' );
284		if ( url.match( re ) ) {
285			return url.replace( re, '' );
286		}
287		return url;
288	};
289
290	var addWidthToImageURL = function ( url, width ) {
291		width = parseInt( width, 10 );
292		// Give devices with a higher devicePixelRatio higher-res images (Retina display = 2, Android phones = 1.5, etc)
293		if ( 'undefined' !== typeof window.devicePixelRatio && window.devicePixelRatio > 1 ) {
294			width = Math.round( width * window.devicePixelRatio );
295		}
296		url = addArgToURL( url, 'w', width );
297		url = addArgToURL( url, 'h', '' );
298		return url;
299	};
300
301	var addArgToURL = function ( url, arg, value ) {
302		var re = new RegExp( arg + '=[^?&]+' );
303		if ( url.match( re ) ) {
304			return url.replace( re, arg + '=' + value );
305		} else {
306			var divider = url.indexOf( '?' ) !== -1 ? '&' : '?';
307			return url + divider + arg + '=' + value;
308		}
309	};
310
311	var stat = function ( names ) {
312		if ( typeof names !== 'string' ) {
313			names = names.join( ',' );
314		}
315
316		new Image().src = window.location.protocol +
317			'//pixel.wp.com/g.gif?v=wpcom-no-pv' +
318			'&x_carousel=' + names +
319			'&baba=' + Math.random();
320	};
321
322	var lastTrackedPostId = null;
323
324	var pageview = function ( post_id ) {
325		// Prevent duplicate tracking of the same post during slide transitions
326		if ( post_id === lastTrackedPostId ) {
327			return;
328		}
329
330		lastTrackedPostId = post_id;
331
332		new Image().src = window.location.protocol +
333			'//pixel.wp.com/g.gif?host=' + encodeURIComponent( window.location.host ) +
334			'&ref=' + encodeURIComponent( document.referrer ) +
335			'&rand=' + Math.random() +
336			'&' + pageviews_stats_args +
337			'&post=' + encodeURIComponent( post_id );
338	};
339
340	var generateImgSrc = function ( srcItem, max ) {
341		var origSize = srcItem.getAttribute( 'data-orig-size' ) || '';
342
343		var src = srcItem.getAttribute( 'src' ) || srcItem.getAttribute( 'original' ) || srcItem.getAttribute( 'data-original' ) || srcItem.getAttribute( 'data-lazy-src' );
344		if ( src.indexOf( 'imgpress' ) !== -1 ) {
345			src = srcItem.getAttribute( 'data-orig-file' );
346		}
347		// Square/Circle galleries use a resize param that needs to be removed.
348		src = removeResizeFromImageURL( src );
349		src = addWidthToImageURL(
350			src,
351			findFirstLargeEnoughWidth( origSize.width, origSize.height, max.width, max.height )
352		);
353
354		return src;
355	};
356
357	window.wpcom.carousel = {
358		findFirstLargeEnoughWidth: findFirstLargeEnoughWidth,
359		removeResizeFromImageURL: removeResizeFromImageURL,
360		addWidthToImageURL: addWidthToImageURL,
361		stat: stat,
362		pageview: pageview,
363		generateImgSrc: generateImgSrc
364	};
365
366} )();
367;
368!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,s=".sharing-hidden .inner",a="data-sharing-more-button-id";function c(e){this.button=e,this.pane=o(e,"div").querySelector(s),this.openedBy=null,this.recentlyOpenedByHover=!1,c.instances.push(this),this.pane.setAttribute(a,c.instances.length-1),this.attachHandlers()}if(c.instances=[],c.hoverOpenDelay=200,c.recentOpenDelay=400,c.hoverCloseDelay=300,c.instantiateOrReuse=function(e){var t=o(e,"div").querySelector(s),n=t&&t.getAttribute(a),i=c.instances[n];return i||new c(e)},c.getButtonInstanceFromPane=function(e){var t=e&&e.getAttribute(a);return c.instances[t]},c.closeAll=function(){for(var e=0;e<c.instances.length;e++)c.instances[e].close()},c.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")},c.prototype.close=function(){var e;(e=this.pane)&&(e.style.display="none"),this.openedBy=null},c.prototype.toggle=function(){var e;(e=this.pane)&&"none"!==e.style.display?this.close():this.open()}
368,c.prototype.nonHoverOpen=function(){clearTimeout(this.openTimer),clearTimeout(this.closeTimer),this.recentlyOpenedByHover?(this.recentlyOpenedByHover=!1,clearTimeout(this.hoverOpenTimer),this.open()):this.toggle()},c.prototype.resetCloseTimer=function(){clearTimeout(this.closeTimer),this.closeTimer=setTimeout(this.close.bind(this),c.hoverCloseDelay)},c.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),c.recentOpenDelay)}.bind(this),c.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 u={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===u.done_urls[o]){for(i in n={pinterest:[window.location.protocol+"//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&&u.bump_sharing_count_stat(i)}u.done_urls[o]=!0}},update_pinterest_count:function(e){void 0!==e.count&&1*e.count>0&&u.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");i.className="share-count",i.textContent=u.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+"//pixel.wp.com/g.gif?v=wpcom-no-pv&x_sharing-count-request="+e+"&r="+Math.random()}};window.WPCOMSharing=u}function d(e,t){e.setAttribute("jetpack-share-click-count",t)}function l(e){var t=e.getAttribute("jetpack-share-click-count");return null===t?0:parseInt(t,10)}function h(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 p(){m()}function m(){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){c.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}
368,r=o(e,s);if(r){var a=c.getButtonInstanceFromPane(r);a&&(a.close(),i())}else i()})}),i(e.querySelectorAll("a.share-press-this"),function(e){var t="wp-press-this-"+Math.random().toString(36).slice(2);e.addEventListener("click",function(n){n.preventDefault(),n.stopPropagation();var o="";if(window.getSelection?o=window.getSelection():document.getSelection?o=document.getSelection():document.selection&&(o=document.selection.createRange().text),o){var i=e.getAttribute("href");e.setAttribute("href",i+"&sel="+encodeURI(o))}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){d(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;d(n=t,l(n)+1),l(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),h(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?p():document.addEventListener("DOMContentLoaded",p),document.body.addEventListener("is.post-load",m);var f={};!0!==window.WPCOM_sharing_popups_bound&&(document.body.addEventListener("click",function(e){var t=e.target;if(t&&1===t.nodeType){var n=function(e){if("A"===e.nodeName)return e;var t=e.parentNode;return t&&"A"===t.nodeName?t:null}(t);if(n){var o=function(e){var t=window.WPCOM_sharing_popups;if(!t)return null;for(var n="share-",o=(e.getAttribute("class")||"").split(/\s+/),i=0;i<o.length;i++)if(0===o[i].indexOf(n)){var r=o[i].slice(6);if("string"==typeof t[r])return r}return null}(n);o&&(e.preventDefault(),r&&r.close(),r=window.open(n.getAttribute("href"),function(e){return"string"!=typeof f[e]&&(f[e]="wpcom"+e+"-"+Math.random().toString(36).slice(2)),f[e]}(o),window.WPCOM_sharing_popups[o]))}}}),window.WPCOM_sharing_popups_bound=!0)}();;

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.