PageSourceSearch

https://www.umiperformance.com/wp-content/plugins/woocommerce-cart-share-and-save/assets/js/wcss.js?ver=3.3.1

js umiperformance.com collected 2026-09-26 08:36:17 UTC 11,559 bytes, 527 lines download raw bytes

1;( function( $ ) {
2	'use strict';
3
4	/**
5	 * WooCommerce Cart Share & Save main object.
6	 *
7	 * @since 1.8.3
8	 */
9	const wcss = {
10		admin_url  : wcssObj.ajax_url,
11		loader     :'<div class="wcss-spinner">' +
12						'<div class="wcss-dot1"></div>' +
13						'<div class="wcss-dot2"></div>' +
14					'</div>',
15
16		/**
17		 * Initialize the object.
18		 *
19		 * @since 3.3.0
20		 *
21		 * @return void
22		 */
23		init: function() {
24			window.wcss = this;
25		},
26
27		show_loader: function() {
28			$( '.wcss-popup-ajax' ).html( this.loader );
29		},
30
31		/**
32		 * Open popup.
33		 *
34		 * @param {string} action Action to perform. Default is empty.
35		 *                        Possible values are 'save_cart', 'email_cart', 'print_cart', 'share_cart'.
36		 */
37		open: function( action = '' ) {
38			/**
39			 * Popup open trigger.
40			 *
41			 * @since 3.2.2
42			 */
43			$( document.body ).trigger( 'wcss_before_popup_open' );
44
45			$( '.wcss-popup-ajax' ).html( this.loader );
46			$( '.wcss-popup, .wcss-popup-overlay' ).show();
47			$( '.wcss-popup' ).attr( 'data-wcss-popup-status', '1' );
48
49			if ( 'save_cart' === action ) {
50				this.load_view( 'wcss_share_medium_ajax', function() {
51					$( '.wcss-share-medium' ).hide();
52					$( '.wcss-save-cart-form, .wcss-login-now' ).show();
53				} );
54			} else if ( 'email_cart' === action ) {
55				this.load_view( 'wcss_share_medium_ajax', function() {
56					$( '.wcss-share-medium' ).hide();
57					$( '.wcss-email-cart' ).show();
58				} );
59			} else if ( 'print_cart' === action ) {
60				this.load_view( 'wcss_share_medium_ajax', function() {
61					$( '[data-wcss-print-cart]' ).trigger( 'click' );
62				} );
63			} else if ( 'share_cart' === action ) {
64				this.load_view( 'wcss_share_medium_ajax' );
65			}
66
67			/**
68			 * Popup open trigger
69			 *
70			 * @since 1.8.3
71			 */
72			$( document.body ).trigger( 'wcss_popup_open' );
73		},
74
75		/**
76		 * Close popup.
77		 *
78		 * @return void
79		 */
80		close: function() {
81			$( '.wcss-popup-ajax' ).html( this.loader );
82			$( '.wcss-popup' ).attr( 'data-wcss-popup-status', '0' );
83			$( '.wcss-popup, .wcss-popup-overlay' ).hide();
84
85			/**
86			 * Popup close trigger
87			 *
88			 * @since 1.8.3
89			 */
90			$( document.body ).trigger( 'wcss_popup_close' );
91		},
92
93		/**
94		 * Trigger popup.
95		 *
96		 * If popup is open, close it. Otherwise, open it.
97		 *
98		 * @return void
99		 */
100		trigger: function() {
101			if ( '1' === $( '.wcss-popup' ).attr( 'data-wcss-popup-status' ) ) {
102				this.close();
103			} else {
104				this.open( 'share_cart' );
105			}
106		},
107
108		/**
109		 * Open share media popup.
110		 *
111		 * @return void
112		 */
113		open_share_media_popup() {
114			/**
115			 * Share media channels popup open trigger
116			 *
117			 * @since 1.8.3
118			 */
119			$( document.body ).trigger( 'wcss_share_media_popup_open' );
120
121			this.open( 'share_cart' );
122		},
123
124		/**
125		 * Open save cart popup.
126		 *
127		 * @return void
128		 */
129		open_save_cart_popup() {
130			/**
131			 * Save cart popup open trigger
132			 *
133			 * @since 1.8.3
134			 */
135			$( document.body ).trigger( 'wcss_save_cart_popup_open' );
136
137			this.open( 'save_cart' );
138		},
139
140		/**
141		 * Open email cart popup.
142		 *
143		 * @return void
144		 */
145		open_email_cart_popup() {
146			/**
147			 * Save cart popup open trigger
148			 *
149			 * @since 1.8.3
150			 */
151			$( document.body ).trigger( 'wcss_email_cart_popup_open' );
152
153			this.open( 'email_cart' );
154		},
155
156		/**
157		 * Open print cart popup.
158		 *
159		 * @return void
160		 */
161		print_cart() {
162			/**
163			 * Print cart popup open trigger.
164			 *
165			 * @since 2.0.1
166			 */
167			$( document.body ).trigger( 'wcss_print_cart_popup_open' );
168
169			this.open( 'print_cart' );
170		},
171
172		/**
173		 * Open saved cart popup.
174		 *
175		 * @param {string} cart_key Cart key.
176		 *
177		 * @return void
178		 */
179		open_saved_cart_popup( cart_key ) {
180			if ( ! cart_key ) {
181				return;
182			}
183
184			this.open();
185
186			$.ajax( {
187				url: this.admin_url,
188				type: 'POST',
189				data: {
190					'action': 'wcss_share_saved_cart_ajax',
191					'cart_key': cart_key,
192				},
193			} )
194			.done( function( response ) {
195				$( '.wcss-popup-ajax' ).html( response );
196			} );
197
198			/**
199			 * Saved cart popup open trigger
200			 *
201			 * @since 1.8.3
202			 */
203			$( document.body ).trigger( 'wcss_save_cart_popup_open' );
204		},
205
206		/**
207		 * Load view via AJAX.
208		 *
209		 * @param {string}   action   Action to perform.
210		 * @param {function} callback Optional. Callback function. Default is empty.
211		 *
212		 * @return void
213		 */
214		load_view: function( action, callback = '' ) {
215			$.ajax( {
216				url: this.admin_url,
217				type: 'GET',
218				data: {
219					'action': action,
220				},
221			} )
222			.done( function( response ) {
223				$( '.wcss-popup-ajax' ).html( response );
224
225				if ( typeof callback === 'function' ) {
226					callback();
227				}
228			} );
229		}
230
231	};
232
233	// Initialize the object.
234	wcss.init();
235
236	/**
237	 * Shaker animation.
238	 */
239	function shaker( selector ) {
240		$( selector ).addClass( 'wcss-shake-animation' );
241
242		setTimeout( function() {
243			$( selector ).removeClass( 'wcss-shake-animation' );
244		}, 300 );
245	}
246
247	/**
248	 * Open popup.
249	 */
250	$( document ).on( 'click', '[data-wcss-popup-open]', function( event ) {
251		event.preventDefault();
252
253		wcss.open_share_media_popup();
254	} );
255
256	/**
257	 * Close popup.
258	 */
259	$( document ).on( 'click', '[data-wcss-popup-close]', function( event ) {
260		event.preventDefault();
261
262		wcss.close();
263	} );
264
265	/**
266	 * Open save cart popup.
267	 */
268	$( document ).on( 'click', '[data-wcss-save-cart-btn]', function( e ) {
269		e.preventDefault();
270
271		wcss.open_save_cart_popup();
272	} );
273
274	/**
275	 * Open email cart popup.
276	 */
277	$( document ).on( 'click', '[data-wcss-email-cart-btn]', function( e ) {
278		e.preventDefault();
279
280		wcss.open_email_cart_popup();
281	} );
282
283	/**
284	 * Open print cart popup.
285	 */
286	 $( document ).on( 'click', '[data-wcss-print-cart-btn]', function( e ) {
287		e.preventDefault();
288
289		wcss.print_cart();
290	} );
291
292	/**
293	 * Share saved cart - my account page.
294	 */
295	$( document ).on( 'click', '[data-wcss-share-saved-cart]', function( event ) {
296		event.preventDefault();
297
298		var cartKey = $( this ).attr( 'data-wcss-share-saved-cart' );
299
300		wcss.open_saved_cart_popup( cartKey );
301	} );
302
303	// login now
304	$( document ).on( 'click', '[data-wcss-save-cart]', function( event ) {
305		event.preventDefault();
306
307		$( '.wcss-share-medium' ).hide();
308		$( '.wcss-save-cart-form, .wcss-login-now' ).show();
309	} );
310
311
312	// Disable share cart button if quantity updates
313	$( document ).on( 'change', '.qty', function() {
314		$( '[data-wcss-popup-open]' ).attr( 'disabled', 'disabled');
315		$( '[data-wcss-save-cart-btn]' ).attr( 'disabled', 'disabled');
316		$( '[data-wcss-email-cart-btn]' ).attr( 'disabled', 'disabled');
317		$( '[data-wcss-print-cart-btn]' ).attr( 'disabled', 'disabled');
318	} );
319
320	// Enable share cart buttons if quantity updates
321	$( document.body ).on( 'updated_cart_totals', function() {
322		$( '[data-wcss-popup-open]' ).removeAttr( 'disabled' );
323		$( '[data-wcss-save-cart-btn]' ).removeAttr( 'disabled' );
324		$( '[data-wcss-email-cart-btn]' ).removeAttr( 'disabled' );
325		$( '[data-wcss-print-cart-btn]' ).removeAttr( 'disabled' );
326	} );
327
328	/**
329	 * Copy To Clipboard
330	 */
331	new ClipboardJS( '[data-wcss-copy-link]' );
332
333	$( document ).on( 'click', '[data-wcss-copy-link]', function( e ) {
334		e.preventDefault();
335
336		var cart_link = $( this ).data( 'clipboard-text' );
337
338		/**
339		 * Copy link trigger.
340		 *
341		 * @since 1.8.3
342		 */
343		$( document.body ).trigger( 'wcss_copy_link', { cart_link : cart_link } );
344
345		$( '.wcss-popup-ajax' ).html( '<div class="wcss-copied-to-clipboard">' + wcssObj.icons.check + '</div>' );
346	} );
347
348	/**
349	 * Share cart with Web share API.
350	 *
351	 * @since 3.1.0
352	 */
353	$( document ).on( 'click', '[data-wcss-web-share]', function( e ) {
354		e.preventDefault();
355
356		var $this = $( this );
357
358		wcss.show_loader();
359
360		try {
361			navigator.share( {
362				url: $this.attr( 'data-wcss-web-share' ),
363			} );
364
365			wcss.close();
366		} catch ( err ) {
367			$( '.wcss-popup-ajax' ).html( '<p>' + wcssObj.i18n.web_share_incompatibility_message + '</p>' );
368		}
369	} );
370
371	/**
372	 * Print cart
373	 */
374	$( document ).on( 'click', '[data-wcss-print-cart]', function( event ) {
375		event.preventDefault();
376
377		var cart_key  = $( this ).attr( 'data-wcss-print-cart' );
378		var siteTitle = $( 'title' ).html();
379
380		wcss.show_loader();
381
382		$( '#wcss-print-cart' ).remove();
383		$( 'title' ).html( wcssObj.print_cart_args.file_name );
384
385		/**
386		 * Before print cart key trigger.
387		 *
388		 * @since 1.8.3
389		 */
390		$( document.body ).trigger( 'wcss_before_print_cart', { cart_key : cart_key } );
391
392		$.ajax( {
393			url: wcssObj.wc_ajax_url.toString().replace( '%%endpoint%%', 'wcss_print_cart_ajax' ),
394			type: 'POST',
395			data: {
396				'print_cart_key': cart_key,
397			},
398			success: function( response ) {
399				$( 'body' ).append( '<div id="wcss-print-cart">' + response + '</div>' );
400
401				$( '#wcss-print-cart' ).printThis( wcssObj.print_cart_args );
402
403				setTimeout( function() {
404
405					/**
406					 * After print cart key trigger.
407					 *
408					 * @since 1.8.3
409					 */
410					$( document.body ).trigger( 'wcss_after_print_cart', { cart_key : cart_key } );
411
412					wcss.close();
413				}, 1000 );
414
415				setTimeout( function() {
416					$( 'title' ).html( siteTitle );
417				}, 2000 );
418			}
419		} );
420	} );
421
422	/**
423	 * Show email cart view form
424	 */
425	 $( document ).on( 'click', '[data-wcss-email]', function( e ) {
426		e.preventDefault();
427
428		$( '.wcss-share-medium' ).hide();
429		$( '.wcss-email-cart' ).show();
430	} );
431
432	// Email cart send ajax call
433	$( document ).on( 'submit', '#wcss-email-cart-form', function( e )  {
434		e.preventDefault();
435
436		var form   = $( this );
437		var fields = form.find( ':input' );
438		var error  = false;
439
440		$( fields ).each( function() {
441			var field = $( this ).attr( 'required' );
442
443			// For some browsers, `attr` is undefined; for others, `attr` is false. Check for both.
444			if ( typeof field !== typeof undefined && field !== false ) {
445				if ( '' === $( this ).val() ) {
446					shaker( $( this ) );
447					error = true;
448					return false;
449				}
450			}
451		} );
452
453		// if any error.
454		if ( error === true ) {
455			return;
456		}
457
458		// display loader
459		wcss.show_loader();
460
461		$.ajax( {
462			url: wcssObj.wc_ajax_url.toString().replace( '%%endpoint%%', 'wcss_send_email_cart' ),
463			type: 'POST',
464			dataType: 'json',
465			data: form.serialize(),
466			success: function( response ) {
467				if ( true === response.success ) {
468					$( '.wcss-popup-ajax' ).html( '<div class="wcss-copied-to-clipboard">' + wcssObj.icons.check + '</div>' );
469
470					/**
471					 * Email cart trigger.
472					 *
473					 * @since 1.8.3
474					 */
475					$( document.body ).trigger( 'wcss_email_cart', { post_data : form.serialize() } );
476				}
477			}
478		} );
479	} );
480
481	/**
482	 * Save cart ajax handler.
483	 *
484	 * @since 1.9.3
485	 */
486	$( document ).on( 'submit', '#wcss-save-cart-form', function( e ) {
487		e.preventDefault();
488
489		wcss.show_loader();
490
491		$.ajax( {
492			url: wcssObj.ajax_url,
493			type: 'post',
494			data: $( this ).serialize() + '&action=wcss_save_cart_ajax',
495			success: function() {
496				if ( wcssObj.saved_cart_endpoint_url ) {
497					window.location.href = wcssObj.saved_cart_endpoint_url;
498				}
499
500				$( '.wcss-popup-ajax' ).html( '<div class="wcss-copied-to-clipboard">' + wcssObj.icons.check + '</div>' );
501
502				/**
503				 * Saved cart trigger
504				 *
505				 * @since 1.9.3
506				 */
507				$( document.body ).trigger( 'wcss_saved_cart' );
508			}
509		} );
510	} );
511
512	/**
513	 * My-account saved cart search handler.
514	 *
515	 * @since 3.0.2
516	 */
517	$( '#wcss-saved-cart-search input' ).on( 'keyup keydown keypress', function() {
518		var search = $( this ).val().toLowerCase();
519
520		$( '.wcss-saved-cart-table tbody tr' ).each( function( i, e ) {
521			var text = $( e ).find( '[data-wcss-cart-name]' ).text().toLowerCase();
522
523			( -1 === text.indexOf( search ) ) ? $( e ).hide() : $( e ).show();
524		} );
525	} );
526
527} )( jQuery );

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.