PageSourceSearch

https://activewords.com/wp-content/plugins/pp-edd-fastspring/assets/js/main.js?ver=1.15.8

js activewords.com collected 2026-10-03 19:41:56 UTC 8,744 bytes, 284 lines download raw bytes

1jQuery( function ( $ ) {
2
3	// Hide the EDD prices (display loader) until they are changed by FS prices.
4	$( 'a.edd-add-to-cart, button.edd-add-to-cart' ).each( function () {
5		var $button     = $( this );
6		var $parentForm = $button.closest( 'form.edd_download_purchase_form' );
7
8		if ( ! $button.hasClass( 'js-pp-edd-fs-show-original-price' ) ) {
9			// Show loader for purchase button.
10			$button.attr( 'data-edd-loading', '' );
11
12			// Hide the variable prices.
13			$parentForm.find( '.edd_price_options input[type="radio"], .edd_price_options input[type="checkbox"]' ).each( function () {
14				$( this ).siblings( '.edd_price_option_price' ).hide();
15			} );
16		}
17	} );
18
19	if ( 'undefined' !== typeof PPEDDFS_MAIN_FOOTER.payload && '' !== PPEDDFS_MAIN_FOOTER.payload && 'undefined' !== typeof PPEDDFS_MAIN_FOOTER.key && '' !== PPEDDFS_MAIN_FOOTER.key ) {
20		fastspring.builder.reset();
21		fastspring.builder.secure( PPEDDFS_MAIN_FOOTER.payload, PPEDDFS_MAIN_FOOTER.key );
22	}
23
24	/**
25	 * "Hijack" the EDD "Buy now" button to interrupt the redirect to EDD checkout
26	 * and use the FS popup or redirect to the external FS checkout page.
27	 */
28	$( document ).on( 'submit', '.edd_download_purchase_form', function ( event ) {
29		// Check if this is the "buy now" button.
30		if ( 'straight_to_gateway' === $( this ).find( '.edd_action_input' ).val() ) {
31			event.preventDefault();
32			var priceIDs   = [];
33			var quantities = [];
34			var quantity;
35			var priceID;
36
37			var downloadID = $( this ).find( 'input[name="download_id"]' ).val();
38
39			// Variable product purchase_link with set price ID.
40			priceID = $( this ).children( 'input[name="edd_options[price_id][]"]' ).val() || false;
41
42			if ( false !== priceID ) {
43				priceIDs.push( priceID );
44			}
45			else {
46				// Normal variable product purchase_link with radio options.
47				priceID = $( this ).find( '.edd_price_options input:radio:checked' ).val() || false;
48
49				if ( false !== priceID ) {
50					priceIDs.push( priceID );
51				}
52				else { // Multi select variable product purchase_link.
53					$( this ).find( '.edd_price_options.edd_multi_mode input:checkbox:checked' ).each( function () {
54						priceIDs.push( $( this ).val() );
55
56						quantity = $( this ).closest( 'li' ).find( 'input.edd-item-quantity' ).val() || 1;
57
58						quantities.push( quantity );
59					} );
60				}
61			}
62
63			// Don't send an empty price IDs array.
64			if( 0 === priceIDs.length ) {
65				priceIDs = false;
66			}
67
68			// Don't send an empty quantities array.
69			if( 0 === quantities.length ) {
70				quantity = $( this ).find( '.edd-item-quantity' ).val() || 1;
71
72				quantities.push( quantity );
73			}
74
75			$.ajax( {
76				method: 'GET',
77				url: PPEDDFS_MAIN.ajax_url,
78				data: {
79					action: 'pp_edd_fs_get_fs_order_data_for_buy_now',
80					edd_download_id: downloadID,
81					edd_download_price_ids: priceIDs,
82					edd_download_quantities: quantities,
83				},
84				xhrFields: {
85					withCredentials: true
86				}
87			} )
88			.done( function( response ) {
89				if ( 'undefined' !== typeof response.success && response.success ) {
90					fastspring.builder.reset();
91					fastspring.builder.secure( response.data.payload, response.data.key );
92
93					if ( 'undefined' !== typeof response.data.user_data ) {
94						fastspring.builder.recognize( response.data.user_data );
95					}
96
97					fastspring.builder.checkout();
98				}
99			});
100		}
101	} );
102
103} );
104
105
106/**
107 * Reset the EDD cart data (AJAX request).
108 */
109function resetEddCartDataAndRedirect() {
110	jQuery.ajax( {
111		method: 'POST',
112		url: PPEDDFS_MAIN.ajax_url,
113		data: {
114			action: 'pp_edd_fs_reset_edd_cart'
115		},
116		xhrFields: {
117			withCredentials: true
118		}
119	} )
120	.done( function( response ) {
121		if ( 'undefined' !== typeof response.success && response.success ) {
122			// Redirect to the thank you page or just refresh the page (to clear the checkout data).
123			if ( PPEDDFS_MAIN.thank_you_page_url ) {
124				window.location = PPEDDFS_MAIN.thank_you_page_url;
125			}
126			else {
127				window.location.reload( true );
128			}
129		}
130	});
131}
132
133
134/**
135 * Reset the EDD "Buy now" purchase button.
136 */
137function resetEddBuyNowPurchaseButtons() {
138	jQuery( '.edd_download_purchase_form a.edd-add-to-cart, .edd_download_purchase_form button.edd-add-to-cart' ).each( function() {
139		var $buyNowButton = jQuery( this );
140		var $parentForm   = $buyNowButton.closest( 'form.edd_download_purchase_form' );
141		var $formAction   = $parentForm.find( '.edd_action_input' );
142
143		if ( 'straight_to_gateway' === $formAction.val() ) {
144			$buyNowButton.prop( 'disabled', false );
145			$buyNowButton.removeAttr( 'data-edd-loading' );
146		}
147	} );
148}
149
150
151/**
152 * Change the purchase link lable price, with the FS localized price.
153 */
154function changeEDDPurchaseLinkPriceWithFSLocalizedPrice() {
155	jQuery( 'a.edd-add-to-cart, button.edd-add-to-cart' ).each( function () {
156		var $button     = jQuery( this );
157		var $parentForm = $button.closest( 'form.edd_download_purchase_form' );
158		var label       = $button.children('.edd-add-to-cart-label').html();
159
160		if ( label.indexOf( ' â€“ ' ) !== -1 && ! $button.hasClass( 'js-pp-edd-fs-show-original-price' ) ) {
161			var fsPrice = $parentForm.find( '.js-pp-edd-fs-product-price' ).val() || false;
162
163			// Check if this is a variable pricing product with set price_id.
164			var eddPriceId = $parentForm.find( 'input[name="edd_options[price_id][]"]' ).val() || false;
165
166			if ( eddPriceId ) {
167				fsPrice = $parentForm.find( '.js-pp-edd-fs-product-price[data-price-id=' + eddPriceId + ']' ).val() || false;
168			}
169
170			if ( fsPrice ) {
171				var textPieces = label.split( ' â€“ ' );
172
173				textPieces[0] = fsPrice;
174
175				$button.children('.edd-add-to-cart-label').text( textPieces.join( ' - ' ) );
176			}
177		}
178
179		$parentForm.find( '.edd_price_options input[type="radio"], .edd_price_options input[type="checkbox"]' ).each( function () {
180			var $option = jQuery( this );
181			var priceId = $option.val();
182
183			if ( priceId && ! $button.hasClass( 'js-pp-edd-fs-show-original-price' ) ) {
184				var newPrice = $parentForm.find( '.js-pp-edd-fs-product-price[data-price-id=' + priceId + ']' ).val() || false;
185
186				if ( newPrice ) {
187					$option.siblings( '.edd_price_option_price' ).text( newPrice ).show();
188				}
189			}
190		} );
191
192		// Hide the loader.
193		$button.removeAttr( 'data-edd-loading' );
194	});
195}
196
197
198/**
199 * FS builder error callback function, which will process the error from FS.
200 *
201 * Needs to be defined on a global scope.
202 *
203 * @see https://docs.fastspring.com/integrating-with-fastspring/store-builder-library/getting-started-with-store-builder-library
204 *
205 * @param errorCode
206 * @param errorMessage
207 */
208function fastspringErrorCallback( errorCode, errorMessage ) {
209	// Reset the EDD checkout button.
210	if ( typeof eddCheckoutResetPurchaseButton == 'function' ) {
211		eddCheckoutResetPurchaseButton();
212	}
213
214	// Reset the EDD "buy now" button.
215	resetEddBuyNowPurchaseButtons();
216
217	// Trigger custom event, so other user can hook to it.
218	jQuery( window ).trigger( 'ppeddfsFsError', [ errorCode, errorMessage ] );
219}
220
221
222/**
223 * FS builder popup closed callback function.
224 *
225 * Needs to be defined on a global scope.
226 *
227 * @see https://docs.fastspring.com/integrating-with-fastspring/store-builder-library/getting-started-with-store-builder-library
228 *
229 * @param object|null responseObject Response object with FS order id and reference on successfull purchase or null.
230 */
231function fastspringPopupClosedCallback( responseObject ) {
232	// Reset the EDD checkout button.
233	if ( typeof eddCheckoutResetPurchaseButton == 'function' ) {
234		eddCheckoutResetPurchaseButton( null );
235	}
236
237	// Reset the EDD "buy now" button.
238	resetEddBuyNowPurchaseButtons();
239
240	// Reset the EDD cart and redirect/refresh the page.
241	if ( null !== responseObject ) {
242		resetEddCartDataAndRedirect();
243	}
244
245	// Trigger custom event, so other user can hook to it.
246	jQuery( window ).trigger( 'ppeddfsFsPopupClosed', [ responseObject ] );
247}
248
249
250/**
251 * FS builder after markup callback function.
252 *
253 * Needs to be defined on a global scope.
254 *
255 * @see https://docs.fastspring.com/integrating-with-fastspring/store-builder-library/getting-started-with-store-builder-library
256 */
257function fastspringAfterMarkupCallback() {
258	changeEDDPurchaseLinkPriceWithFSLocalizedPrice();
259
260	// Trigger custom event, so other user can hook to it.
261	jQuery( window ).trigger( 'ppeddfsAfterFsMarkup' );
262}
263
264
265/**
266 * Decorate URL with the first Google Analytics tracker (if it exists)
267 *
268 * @param {string} url to the
269 *
270 * @see https://docs.fastspring.com/integrations/extensions-tab/google-universal-analytics
271 */
272function fastspringDecorateURLCallback ( url ) {
273	var linkerParam = null;
274
275	if ( window.hasOwnProperty( 'ga' ) ) {
276		ga( function() {
277			var trackers = ga.getAll();
278			linkerParam = trackers[0].get( 'linkerParam' );
279		} );
280		return ( linkerParam ? url + '?' + linkerParam : url );
281	}
282
283	return url;
284}

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.