PageSourceSearch

https://motiondesign.school/wp-content/plugins/woocommerce-side-ca…/assets/js/xoo-wsc-main.js?ver=1785948877

js motiondesign.school collected 2026-09-25 19:11:01 UTC 24,752 bytes, 1,017 lines download raw bytes

1jQuery(document).ready(function($){
2
3	var isCartPage 		= xoo_wsc_params.isCart == '1',
4		isCheckoutPage 	= xoo_wsc_params.isCheckout == '1';
5
6	var get_wcurl = function( endpoint ) {
7		return xoo_wsc_params.wc_ajax_url.toString().replace(
8			'%%endpoint%%',
9			endpoint
10		);
11	};
12
13
14	class Notice{
15
16		constructor( $modal ){
17			this.$modal = $modal;
18			this.timeout = null;
19		}
20
21		add( notice, type = 'success', clearPrevious = true ){
22
23			var $noticeCont = this.$modal.find('.xoo-wsc-notice-container');
24
25			if( clearPrevious ){
26				$noticeCont.html('');
27			}
28
29			var noticeHTML = type === 'success' ? xoo_wsc_params.html.successNotice.toString().replace( '%s%', notice ) : xoo_wsc_params.html.errorNotice.toString().replace( '%s%', notice );
30
31			$noticeCont.html( noticeHTML );
32
33		}
34
35		showNotification(){
36
37			var $noticeCont = this.$modal.find('.xoo-wsc-notice-container');
38
39			if( !$noticeCont.length || $noticeCont.children().length === 0 ) return;
40
41			$noticeCont.slideDown();
42			
43			clearTimeout(this.timeout);
44
45			this.timeout = setTimeout(function(){
46				$noticeCont.slideUp('slow',function(){
47					//$noticeCont.html('');
48				});
49			},xoo_wsc_params.notificationTime )
50
51		}
52
53		hideNotification(){
54			this.$modal.find('.xoo-wsc-notice-container').hide();
55		}
56	}
57
58
59	class Container{
60
61		constructor( $modal, container ){
62			this.$modal 	= $modal;
63			this.container 	= container || 'cart';
64			this.notice 	= new Notice( this.$modal );
65		}
66
67		eventHandlers(){
68			$(document.body).on( 'wc_fragments_refreshed updated_checkout', this.onCartUpdate.bind(this) );
69		}
70
71		onCartUpdate(){
72			this.unblock();
73			this.notice.showNotification();
74		}
75
76		setAjaxData( data, noticeSection ){
77
78			var ajaxData = {
79				container: this.container,
80				noticeSection: noticeSection || this.noticeSection || this.container,
81				isCheckout: isCheckoutPage,
82				isCart: isCartPage
83			}
84
85
86			if( typeof data === 'object' ){
87
88				$.extend( ajaxData, data );
89
90			}
91			else{
92
93				var serializedData = data;
94
95				$.each( ajaxData, function( key, value ){
96					serializedData += ( '&'+key+'='+value );
97				} )
98		
99				ajaxData = serializedData;
100
101			}
102
103			return ajaxData;
104		}
105
106
107		toggle( type ){
108
109			var $activeEls 	= this.$modal.add('html').add( 'body' ),
110				activeClass = 'xoo-wsc-'+ this.container +'-active';
111
112			if( type === 'show' ){
113				$activeEls.addClass(activeClass);
114			}
115			else if( type === 'hide' ){
116				$activeEls.removeClass(activeClass);
117				this.notice.hideNotification();
118			}
119			else{
120				$activeEls.toggleClass(activeClass);
121			}
122
123			$(document.body).trigger( 'xoo_wsc_' + this.container + '_toggled', [ type ] );
124
125		}
126
127
128		block(){
129			this.$modal.addClass('xoo-wsc-loading');
130		}
131
132		unblock(){
133			this.$modal.removeClass('xoo-wsc-loading');
134		}
135
136
137		refreshMyFragments(){
138
139			if( xoo_wsc_params.refreshCart === "yes" && typeof wc_cart_fragments_params !== 'undefined' ){
140				$( document.body ).trigger( 'wc_fragment_refresh' );
141				return;
142			}
143
144			this.block();
145
146			$.ajax({
147				url: get_wcurl( 'xoo_wsc_refresh_fragments' ),
148				type: 'POST',
149				context: this,
150				data: {},
151				success: function( response ){
152					this.updateFragments(response);
153				},
154				complete: function(){
155					this.unblock();
156				}
157			})
158
159		}
160
161
162		updateCartCheckoutPage(){
163
164			//Refresh checkout page
165			if( isCheckoutPage ){
166				if( $( 'form.checkout' ).length === 0 ){
167					location.reload();
168					return;
169				}
170				$(document.body).trigger("update_checkout");
171			}
172
173			//Refresh Cart page
174			if( isCartPage ){
175				$(document.body).trigger("wc_update_cart");
176			}
177
178		}
179
180		updateFragments( response ){
181
182			if( response.fragments ){
183
184				$( document.body ).trigger( 'xoo_wsc_before_loading_fragments', [ response ] );
185
186				this.block();
187
188				//Set fragments
189		   		$.each( response.fragments, function( key, value ) {
190					$( key ).replaceWith( value );
191				});
192
193		   		if( typeof wc_cart_fragments_params !== 'undefined' && ( 'sessionStorage' in window && window.sessionStorage !== null ) ){
194
195		   			sessionStorage.setItem( wc_cart_fragments_params.fragment_name, JSON.stringify( response.fragments ) );
196					localStorage.setItem( wc_cart_fragments_params.cart_hash_key, response.cart_hash );
197					sessionStorage.setItem( wc_cart_fragments_params.cart_hash_key, response.cart_hash );
198
199					if ( response.cart_hash ) {
200						sessionStorage.setItem( 'wc_cart_created', ( new Date() ).getTime() );
201					}
202
203				}
204
205				$( document.body ).trigger( 'wc_fragments_refreshed' );
206
207				this.unblock();
208
209			}
210
211			if( xoo_wsc_params.refreshCart === "yes" && typeof wc_cart_fragments_params !== 'undefined' ){
212				this.block();
213				$( document.body ).trigger( 'wc_fragment_refresh' );
214				return;
215			}
216
217		}
218
219	}
220
221
222	class Cart extends Container{
223
224		constructor( $modal ){
225
226			super( $modal, 'cart' );
227
228			this.baseQty 		= 1;
229			this.qtyUpdateDelay = null;
230
231			this.refreshFragmentsOnPageLoad();
232			this.eventHandlers();
233			this.initSlider();
234
235		}
236
237
238		refreshFragmentsOnPageLoad(){
239			setTimeout(function(){
240				this.refreshMyFragments();
241			}.bind(this), xoo_wsc_params.fetchDelay )
242		}
243
244		eventHandlers(){
245
246			super.eventHandlers();
247
248			this.$modal.on( 'click', '.xoo-wsc-chng', this.toggleQty.bind(this) );
249			this.$modal.on( 'change', '.xoo-wsc-qty', this.changeInputQty.bind(this) );
250			this.$modal.on( 'click', '.xoo-wsc-undo-item', this.undoItem.bind(this) );
251			this.$modal.on( 'focusin', '.xoo-wsc-qty', this.saveQtyFocus.bind(this) );
252			this.$modal.on( 'click', '.xoo-wsc-smr-del', this.deleteIconClick.bind(this) );
253			this.$modal.on( 'click', '.xoo-wsch-close, .xoo-wsc-opac, .xoo-wsc-cart-close', this.closeCartOnClick.bind(this) );
254			this.$modal.on( 'click', '.xoo-wsc-basket', this.toggle.bind(this) );
255
256			$( document.body ).on( 'click', '.xoo-wsc-ecl', this.emptyCart.bind(this) );
257
258			$(document.body).on( 'xoo_wsc_cart_updated', this.updateCartCheckoutPage.bind(this) );
259			$(document.body).on( 'click', 'a.added_to_cart, .xoo-wsc-cart-trigger', this.openCart.bind(this) );
260			$(document.body).on( 'added_to_cart', this.addedToCart.bind(this) );
261
262			if( xoo_wsc_params.autoOpenCart === 'yes' && xoo_wsc_params.addedToCart === 'yes' && !isCheckoutPage){
263				this.openCart();
264			}
265
266			if( xoo_wsc_params.ajaxAddToCart === 'yes' ){
267				$(document.body).on( 'submit', 'form.cart', this.addToCartFormSubmit.bind(this) );
268			}
269
270			if( typeof wc_cart_fragments_params === 'undefined' ){
271				$( window ).on( 'pageshow' , this.onPageShow );
272			}
273
274
275			if( isCheckoutPage || isCartPage ){
276				$(document.body).on( 'updated_shipping_method', this.refreshMyFragments.bind(this) );
277			}
278
279			//Animate shipping bar
280			$(document.body).on( 'xoo_wsc_before_loading_fragments', this.storeShippingBarWidth.bind(this) );
281
282		}
283
284
285		openCart(e){
286			if( e ){
287				e.preventDefault();
288			}
289			this.toggle('show');
290		}
291
292		addToCartFormSubmit(e){
293
294			var $form = $(e.currentTarget);
295
296			if( $form.closest('.product').hasClass('product-type-external') ) return;
297
298			e.preventDefault();
299
300			var $button  		= $form.find( 'button[type="submit"]'),
301				productData 	= $form.serializeArray(),
302				hasProductId 	= false;
303
304			//Check for woocommerce custom quantity code 
305			//https://docs.woocommerce.com/document/override-loop-template-and-show-quantities-next-to-add-to-cart-buttons/
306			$.each( productData, function( key, form_item ){
307				if( form_item.name === 'productID' || form_item.name === 'add-to-cart' ){
308					if( form_item.value ){
309						hasProductId = true;
310						return false;
311					}
312				}
313			})
314
315			//If no product id found , look for the form action URL
316			if( !hasProductId && $form.attr('action') ){
317				var is_url = $form.attr('action').match(/add-to-cart=([0-9]+)/),
318					productID = is_url ? is_url[1] : false; 
319			}
320
321			// if button as name add-to-cart get it and add to form
322	        if( $button.attr('name') && $button.attr('name') == 'add-to-cart' && $button.attr('value') ){
323	            var productID = $button.attr('value');
324	        }
325
326	        if( productID ){
327	        	productData.push({name: 'add-to-cart', value: productID});
328	        }
329
330	        productData.push({name: 'action', value: 'xoo_wsc_add_to_cart'});
331
332			this.addToCartAjax( $button, productData );//Ajax add to cart
333		}
334
335
336		addToCartAjax( $button, productData ){
337
338			this.block();
339
340			$button.addClass('loading');
341
342			// Trigger event.
343			$( document.body ).trigger( 'adding_to_cart', [ $button, productData ] );
344
345			$.ajax({
346				url: get_wcurl( 'xoo_wsc_add_to_cart' ),
347				type: 'POST',
348				context: this,
349				data: $.param(productData),
350			    success: function(response){
351
352					if(response.fragments){
353						// Trigger event so themes can refresh other areas.
354						$( document.body ).trigger( 'added_to_cart', [ response.fragments, response.cart_hash, $button ] );
355					}else{
356						window.location.reload();
357					}
358
359			    },
360			    complete: function(){
361			    	this.unblock();
362			    	$button
363			    		.removeClass('loading')
364			    		.addClass('added');
365			    }
366			})
367		}
368
369		addedToCart( e, response, hash, $button ){
370
371			this.updateFragments( { fragments: response } );
372
373			this.onCartUpdate();
374
375			$(document.body).trigger( 'xoo_wsc_cart_updated', [response] );
376	
377			var _this = this;
378
379			this.flyToCart( $button, function(){
380				if( xoo_wsc_params.autoOpenCart === "yes" ){
381					setTimeout(function(){
382						_this.openCart();	
383					},20 )
384				}
385			} );
386		}
387
388
389		flyToCart( $atcEL, callback ){
390
391			var $basket = this.$modal.find('.xoo-wsc-basket').length ? this.$modal.find('.xoo-wsc-basket') : $(document.body).find('.xoo-wsc-sc-cont');
392
393			if( !$basket.length || xoo_wsc_params.flyToCart !== 'yes' || !$atcEL || !$atcEL.length ){
394				callback();
395				return;
396			}
397
398			var customDragImgClass 	= xoo_wsc_params.productFlyClass,
399				$dragIMG 			= null,
400				$product 			= $atcEL.closest('.product');
401
402
403			//If has product container
404			if( $product.length ){
405
406				$product = $($product[0]);
407
408				var $productGallery = $product.find('.woocommerce-product-gallery');
409
410				if( customDragImgClass && $product.find( customDragImgClass ).length ){
411					$dragIMG = $product.find( customDragImgClass );
412				}
413				else if( $product.find( 'img[data-xooWscFly="fly"]' ).length ){
414					if( $productGallery.length ){
415						$dragIMG = $productGallery.find( '.flex-active-slide img[data-xooWscFly="fly"]' ).length ? $productGallery.find( '.flex-active-slide img[data-xooWscFly="fly"]' ) : $productGallery.find( 'img[data-xooWscFly="fly"]' )
416					}
417					else{
418						$dragIMG = $product.find( 'img[data-xooWscFly="fly"]' );
419					}
420				}
421				else if( $productGallery.length ){
422					$dragIMG = $productGallery;
423				}
424				else{
425					$dragIMG = $product;
426				}
427
428			}
429			else if( customDragImgClass ){
430				var moveUp = 4;
431				for ( var i = moveUp; i >= 0; i-- ) {
432					var $foundImg = $atcEL.parent().find( customDragImgClass );
433					if( $foundImg.length ){
434						$dragIMG = $foundImg;
435						return false;
436					}
437				}
438			}
439
440
441			if( !$dragIMG || !$dragIMG.length ){
442				callback();
443				return;
444			}
445
446			$dragIMG = $dragIMG.eq(0);
447
448			var $imgclone = $dragIMG
449				.clone()
450	    		.offset({
451		            top: $dragIMG.offset().top,
452		            left: $dragIMG.offset().left
453		        })
454	        	.addClass( 'xoo-wsc-fly-animating' )
455	            .appendTo( $('body') )
456	            .animate({
457	            	'top': $basket.offset().top - 20,
458		            'left': $basket.offset().left - 20,
459		            'width': 75,
460		            'height': 75
461		        }, parseInt( xoo_wsc_params.flyToCartTime ), 'easeInOutExpo' );
462	        
463	        setTimeout(function () {
464	        	callback()
465	        }, parseInt( xoo_wsc_params.flyToCartTime ) );
466
467	        $imgclone.animate({
468	        	'width': 0,
469	        	'height': 0
470	        }, function () {
471	        	$(this).detach();
472	        });
473
474		}
475
476
477		toggleQty(e){
478
479			var $toggler 	= $(e.currentTarget),
480				$input 		= $toggler.siblings('.xoo-wsc-qty');
481
482			if( !$input.length ) return;
483
484			var baseQty = this.baseQty = parseFloat( $input.val() ),
485				step 	= parseFloat( $input.attr('step') ),
486				action 	= $toggler.hasClass( 'xoo-wsc-plus' ) ? 'add' : 'less',
487				newQty 	= action === 'add' ? baseQty + step : baseQty - step;
488
489			
490			$input.val(newQty).trigger('change');
491
492		}
493
494		changeInputQty(e){
495
496			this.notice.hideNotification();
497
498			var $_this	= this,
499 				$input 	= $(e.currentTarget),
500				newQty 	= parseFloat( $input.val() ),
501				step 	= parseFloat( $input.attr('step') ),
502				min 	= parseFloat( $input.attr('min') ),
503				max 	= parseFloat( $input.attr('max') ),
504				invalid = false,
505				message = false;
506
507
508			//Validation
509			
510			if( isNaN( newQty )  || newQty < 0 || newQty < min  ){
511				invalid = true;
512			}
513			else if( newQty > max ){
514				invalid = true;
515				message = xoo_wsc_params.strings.maxQtyError.replace( '%s%', max );
516			}
517			else if( ( newQty % step ) !== 0 ){
518				invalid = true;
519				message = xoo_wsc_params.strings.stepQtyError.replace( '%s%', step );
520			}
521			
522			//Set back to default quantity
523			if( invalid ){
524				$input.val( this.baseQty );
525				if( message ){
526					this.notice.add( message, 'error' );
527					this.notice.showNotification();
528				}
529				return;
530			}
531
532			//Update
533			$input.val( newQty );
534
535			clearTimeout( this.qtyUpdateDelay );
536
537			this.qtyUpdateDelay = setTimeout(function(){
538				$_this.updateItemQty( $input.parents('.xoo-wsc-product').data('key'), newQty )
539			}, xoo_wsc_params.qtyUpdateDelay );
540			
541			
542		}
543
544		updateItemQty( cart_key, qty ){
545
546			if( !cart_key || qty === undefined ) return;
547
548			this.block();
549
550			var formData = {
551				cart_key: cart_key,
552				qty: qty
553			}
554
555			$.ajax({
556				url: get_wcurl( 'xoo_wsc_update_item_quantity' ),
557				type: 'POST',
558				context: this,
559				data: this.setAjaxData(formData),
560				success: function(response){
561					this.updateFragments( response );
562					$(document.body).trigger( 'xoo_wsc_quantity_updated', [response] );
563					$(document.body).trigger( 'xoo_wsc_cart_updated', [response] );
564					this.unblock();
565				}
566
567			})
568		}
569
570
571		closeCartOnClick(e){
572			e.preventDefault();
573			this.toggle( 'hide' );
574		}
575
576
577		saveQtyFocus(e){
578			this.baseQty = $(e.currentTarget).val();
579		}
580
581
582		onPageShow(e){
583			if ( e.originalEvent.persisted ) {
584				this.refreshMyFragments();
585				$( document.body ).trigger( 'wc_fragment_refresh' );
586			}
587		}
588
589		deleteIconClick(e){
590			this.updateItemQty( $( e.currentTarget ).parents('.xoo-wsc-product').data('key'), 0 );
591		}
592
593		undoItem(e){
594
595			var $undo 		= $(e.currentTarget),
596				formData 	= {
597					cart_key: $undo.data('key')
598				}
599
600			this.block();
601
602			$.ajax({
603				url: get_wcurl('xoo_wsc_undo_item'),
604				type: 'POST',
605				context: this,
606				data: this.setAjaxData(formData),
607				success: function(response){
608					this.updateFragments( response );
609					$(document.body).trigger( 'xoo_wsc_item_restored', [response] );
610					$(document.body).trigger( 'xoo_wsc_cart_updated', [response] );
611					this.unblock();
612				}
613
614			})
615		}
616
617		storeShippingBarWidth( e ){
618			var $bar = $(document.body).find( '.xoo-wsc-sb-bar > span' );
619			if( !$bar.length ) return;
620			this.shippingBarWidth = $bar.prop('style').width;
621		}
622
623		onCartUpdate(){
624
625			if(this.$modal.find('.xoo-wsc-product').length == 0 && isCheckoutPage) {
626				$('.empty-cart-notice').show();
627				$('.coupon-form').hide();
628			}
629
630			super.onCartUpdate();
631			this.animateShippingBar();
632			this.initSlider();
633			this.showBasket();
634		}
635
636		showBasket(){
637
638			var $basket = $('.xoo-wsc-basket'),
639				show 	= xoo_wsc_params.showBasket;
640
641			if( show === "always_show" ){
642				$basket.show();	
643			}
644			else if( show === "hide_empty" ){
645				if( this.$modal.find('.xoo-wsc-product').length ){
646					$basket.show();
647				}
648				else{
649					$basket.hide();
650				}
651			}
652			else{
653				$basket.hide();
654			}
655		}
656
657		animateShippingBar(){
658			if( isCartPage || isCheckoutPage ) return;
659			var $bar = $(document.body).find( '.xoo-wsc-sb-bar > span' );
660			if( !$bar.length || !this.shippingBarWidth ) return;
661			var newWidth = $bar.prop('style').width;
662			$bar
663				.width( this.shippingBarWidth )
664				.animate({ width: newWidth }, 400, 'linear')
665		}
666
667
668		emptyCart(){
669
670			this.block();
671
672			$.ajax({
673				url: get_wcurl( 'xoo_wsc_empty_cart' ),
674				type: 'POST',
675				context: this,
676				data: {},
677			    success: function(response){
678					this.updateFragments( response );
679					// Trigger event.
680					$( document.body ).trigger( 'xoo_wsc_cart_emptied' );
681					$(document.body).trigger( 'xoo_wsc_cart_updated', [response] );
682			    },
683			    complete: function(){
684			    	this.unblock();
685			    }
686			})
687		}
688
689
690		initSlider(){
691
692			if( !$.isFunction( $.fn.lightSlider ) ) return;
693
694			if($('.xoo-wsc-sp-slider').hasClass('lightSlider') && $('.xoo-wsc-sp-slider .xoo-wsc-sp-product').first().width() > 0) {
695				return;
696			}
697
698			var slider = $('ul.xoo-wsc-sp-slider').lightSlider({
699				item: 1,
700				loop: true,
701				controls: false
702			});
703
704			$('#goToPrevSlide').on('click', function () {
705				slider.goToPrevSlide();
706			});
707			$('#goToNextSlide').on('click', function () {
708				slider.goToNextSlide();
709			});
710
711			window.globals = {
712				cart_similar_items: slider
713			};
714			
715		}
716
717	}
718
719	
720
721	class Slider extends Container{
722
723		constructor( $modal ){
724
725			super( $modal, 'slider' );
726
727			if( xoo_wsc_params.sliderAutoClose ) this.noticeSection = 'cart';
728
729			this.eventHandlers();
730
731			this.shipping = xoo_wsc_params.shippingEnabled ? Shipping.init( this ) : null;
732		}
733
734		eventHandlers(){
735
736			super.eventHandlers();
737
738
739			$( document.body ).on( 'click', '.xoo-wsc-toggle-slider', this.triggerSlider.bind(this) );
740			$( document.body ).on( 'xoo_wsc_cart_toggled', this.closeSliderOnCartClose.bind(this) );
741
742			if( xoo_wsc_params.sliderAutoClose ){
743				$( document.body ).on( 'xoo_wsc_coupon_applied xoo_wsc_shipping_calculated updated_shipping_method xoo_wsc_coupon_removed', this.closeSlider.bind(this) );
744			}
745
746			this.$modal.on( 'submit', 'form.xoo-wsc-sl-apply-coupon', this.submitCouponForm.bind(this) );
747			this.$modal.on( 'click', '.xoo-wsc-coupon-apply-btn', this.applyCouponFromBtn.bind(this) );
748			$(document.body).on( 'click', '.xoo-wsc-remove-coupon', this.removeCoupon.bind(this) );
749
750			$(document.body).on("click", '.apply_tokens_discount', this.applyTokenCoupon.bind(this) );
751
752		}
753
754		applyTokenCoupon(e) {
755			e.preventDefault();
756
757			var $this 	= $(e.currentTarget);
758
759			$this.prop('disabled', true);
760		
761			var selectedTokens = $('.token-discount-selection').find(':selected').val();
762
763			self = this;
764
765			$.ajax({
766				type: "post",
767				dataType: "json",
768				url: theme_vars.ajaxurl,
769				data: {
770					action: "apply_tokens_discount",
771					selected_tokens: selectedTokens,
772				},
773				beforeSend: function() {
774					$this.html('Please wait...');
775				},
776				success: function(response) {
777					$this.prop('disabled', false);
778					self.applyCoupon(response.data.coupon_code);
779				},
780			});
781
782			
783
784		}
785
786
787		removeCoupon(e){
788
789			e.preventDefault();
790
791			var $removeEl 	= $(e.currentTarget),
792				coupon 		= $removeEl.data('code'),
793				formData 	= {
794					coupon: coupon
795				};
796
797			this.block();	
798
799			$.ajax( {
800				url: get_wcurl( 'xoo_wsc_remove_coupon' ),
801				type: 'POST',
802				context: this,
803				data: this.setAjaxData( formData, cart.$modal.find( $removeEl ).length ? 'cart' : 'slider' ),
804				success: function( response ) {
805					this.updateFragments(response);
806				},
807				complete: function() {
808					this.unblock();
809					this.updateCartCheckoutPage();
810					$( document.body ).trigger( 'xoo_wsc_coupon_removed' );
811				}
812			} );
813		}
814
815		onCartUpdate(){
816			super.onCartUpdate();
817			this.toggleContent();
818		}
819
820		closeSlider(){
821			this.toggle('hide');
822		}
823
824
825		applyCouponFromBtn(e){
826			this.applyCoupon( $(e.currentTarget).val() );
827		}
828
829		submitCouponForm(e){
830
831			e.preventDefault();
832
833			var $form = $(e.currentTarget);
834
835			this.applyCoupon( $form.find('input[name="xoo-wsc-slcf-input"]').val() );
836
837		}
838
839
840		closeSliderOnCartClose(e){
841
842			var $this = $(e.currentTarget); 
843
844			if( !cart.$modal.hasClass('xoo-wsc-cart-active') ){
845				this.toggle('hide');
846			}
847
848		}
849
850
851		triggerSlider(e){
852
853			var $toggler 	= $(e.currentTarget),
854 				slider 		= $toggler.data('slider');
855
856			if( slider === 'shipping' && isCheckoutPage ){
857				this.notice.add( xoo_wsc_params.strings.calculateCheckout, 'error' );
858				this.notice.showNotification();
859				return;
860			}
861
862
863			this.$modal.attr( 'data-slider', slider );
864			
865			this.toggle();
866
867			this.toggleContent();
868		}
869
870
871		toggleContent(){
872
873			var activeSlider = '';
874
875			$('.xoo-wsc-sl-content').hide();
876			
877			var activeSlider 	= this.$modal.attr('data-slider'),
878				$toggleEl 		= $('.xoo-wsc-sl-content[data-slider="'+activeSlider+'"]');
879	
880			if( $toggleEl.length ) $toggleEl.show();
881
882			$( document.body ).trigger( 'xoo_wsc_slider_data_toggled', [activeSlider] );
883		}
884
885
886		applyCoupon( coupon ){
887
888			if( !coupon ){
889				this.notice.add( xoo_wsc_params.strings.couponEmpty, 'error' );
890				this.notice.showNotification();
891				return;
892			}
893
894			this.block();
895
896			var formData = {
897				'coupon': coupon,
898			}
899
900			$.ajax( {
901				url: get_wcurl('xoo_wsc_apply_coupon'),
902				type: 'POST',
903				context: this,
904				data: this.setAjaxData( formData ),
905				success: function( response ) {
906					this.updateFragments(response);
907				},
908				complete: function() {
909					this.unblock();
910					this.updateCartCheckoutPage();
911					$( document.body ).trigger( 'xoo_wsc_coupon_applied' );
912				}
913			} );
914
915		}
916
917	}
918
919	
920
921	var Shipping = {
922
923		init: function( slider ){
924			slider.$modal.on( 'change', 'input.xoo-wsc-shipping-method', this.shippingMethodChange );
925			slider.$modal.on( 'submit', 'form.woocommerce-shipping-calculator', this.shippingCalculatorSubmit );
926			slider.$modal.on( 'click', '.shipping-calculator-button', this.toggleCalculator );
927			$(document.body).on( 'wc_fragments_refreshed wc_fragments_loaded xoo_wsc_slider_data_toggled', this.initSelect2 );
928		},
929
930		toggleCalculator: function(e){
931
932			e.preventDefault();
933			e.stopImmediatePropagation();
934
935			$(this).siblings('.shipping-calculator-form').slideToggle();
936			$( document.body ).trigger( 'country_to_state_changed' );
937		},
938
939		shippingCalculatorSubmit: function(e){
940
941			e.preventDefault();
942			e.stopImmediatePropagation();
943
944			var $form = $(this);
945
946			slider.block();
947
948			// Provide the submit button value because wc-form-handler expects it.
949			$( '<input />' )
950				.attr( 'type', 'hidden' )
951				.attr( 'name', 'calc_shipping' )
952				.attr( 'value', 'x' )
953				.appendTo( $form );
954
955			var formData = $form.serialize();
956
957			// Make call to actual form post URL.
958			$.ajax( {
959				url: get_wcurl( 'xoo_wsc_calculate_shipping' ),
960				type: 'POST',
961				context: this,
962				data: slider.setAjaxData(formData),
963				success: function( response ) {
964					slider.updateFragments(response);
965				},
966				complete: function() {
967					slider.unblock();
968					slider.updateCartCheckoutPage();
969					$( document.body ).trigger( 'xoo_wsc_shipping_calculated' );
970				}
971			} );
972
973		},
974
975		shippingMethodChange: function(e){
976
977			e.preventDefault();
978			e.stopImmediatePropagation();
979
980			var shipping_methods = {};
981
982			slider.block();
983
984			$( 'select.shipping_method, :input[name^=xoo-wsc-shipping_method][type=radio]:checked, :input[name^=shipping_method][type=hidden]' ).each( function() {
985				shipping_methods[ $( this ).data( 'index' ) ] = $( this ).val();
986			} );
987
988			var formData = {
989				shipping_method: shipping_methods,
990			}
991
992			$.ajax( {
993				type:     'POST',
994				url:      get_wcurl( 'xoo_wsc_update_shipping_method' ),
995				data:     slider.setAjaxData( formData ),
996				success:  function( response ) {
997					slider.updateFragments(response);
998				},
999				complete: function() {
1000					slider.unblock();
1001					slider.updateCartCheckoutPage();
1002					$( document.body ).trigger( 'updated_shipping_method' );
1003				}
1004			} );
1005
1006		},
1007
1008		initSelect2: function(e){
1009			$( document.body ).trigger( 'country_to_state_changed' );
1010		},
1011	}
1012
1013
1014	var cart 	= new Cart( $('.xoo-wsc-modal') ),
1015		slider 	= new Slider( $('.xoo-wsc-slider-modal') );
1016
1017})

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.