PageSourceSearch

https://oil-testing.com/wp-content/plugins/woopack/assets/js/frontend.js?ver=1.5.7.1

js oil-testing.com collected 2026-09-25 03:24:21 UTC 17,140 bytes, 560 lines download raw bytes

1(function($) {
2	var quickView = {
3		css: '',
4		js: '',
5		html: {},
6		height: {},
7		node: ''
8	};
9	var scriptsEnqueued = {
10		css: false,
11		js: false,
12	};
13
14    // Product quick view.
15    $('body').on('click', '.woopack-product-quick-view', function(e) {
16        e.preventDefault();
17        e.stopPropagation();
18
19		var nodeId      = $(this).parents('.fl-module').attr('data-node'),
20			products	= $('.fl-node-' + nodeId).find('.woopack-products');
21        var product     = $(this).parents('.product'),
22			productId   = product.data('product-id') || $(this).data('product'),
23			template	= $(this).data('template') || false,
24			processAjax = true;
25
26		quickView.node = $('.fl-node-' + nodeId);
27
28		if ( 'undefined' !== typeof quickView.html[productId] ) {
29			processAjax = false;
30		}
31
32		// Stop carousel autoplay.
33		if ( products.hasClass('owl-carousel') ) {
34			products.trigger('stop.owl.autoplay');
35		}
36
37		new WooPackModal({
38            source: 'ajax',
39            ajaxUrl: woopack_config.ajaxurl,
40            ajaxData: {
41                action: 'woopack_product_quick_view',
42                node_id: nodeId,
43				product_id: productId,
44				template: template,
45				templateJS: '' === quickView.js,
46				templateCSS: '' === quickView.css,
47			},
48			processAjax: processAjax,
49			breakpoint: 767,
50			animationSpeed: 0,
51			cssClass: 'woopack-modal-' + nodeId,
52			responseHandler: function( response, object ) {
53				var contentWrap = object.contentWrap;
54				// set height.
55				if ( 'undefined' !== typeof quickView.height[productId] ) {
56					//contentWrap.css( 'max-height', quickView.height[productId] + 'px' );
57				}
58
59				if ( '' === quickView.css && 'undefined' !== typeof response.css ) {
60					quickView.css = response.css;
61				}
62				if ( '' === quickView.js && 'undefined' !== typeof response.js ) {
63					quickView.js = response.js;
64				}
65				if ( ! scriptsEnqueued.css ) {
66					$('head').prepend( quickView.css );
67					scriptsEnqueued.css = true;
68				}
69
70				if ( 'undefined' !== typeof quickView.html[productId] ) {
71					contentWrap.html( quickView.html[productId] );
72				} else {
73					contentWrap.html( response.html );
74					quickView.html[productId] = response.html;
75				}
76				
77				if ( template ) {
78					//$('body').append( contentWrap.find('.pswp').addClass('woopack-pswp') );
79					contentWrap.imagesLoaded(function() {
80						if ( ! scriptsEnqueued.js ) {
81							$('body').append( quickView.js );
82							scriptsEnqueued.js = true;
83						} else {
84							// Initialize all galleries, tabs, and ratings.
85							contentWrap.find( '.woocommerce-product-gallery' ).each( function() {
86								$( this ).trigger( 'wc-product-gallery-before-init', [ this, wc_single_product_params ] );
87								$( this ).wc_product_gallery( wc_single_product_params );
88								$( this ).trigger( 'wc-product-gallery-after-init', [ this, wc_single_product_params ] );
89							} );
90							contentWrap.find('.wc-tabs-wrapper, .woocommerce-tabs, #rating').trigger('init');
91						}
92
93						// Cache HTML after load.
94						$(quickView.html[productId]).find('.woopack-product').html( contentWrap.find('.woopack-product').html() );
95
96						object._resetHeight();
97
98						setTimeout(function() {
99							object.wrapper.addClass( 'woopack-ajax-loaded' );
100						}, 100);
101					});
102				} else {
103					setTimeout(function() {
104						object.wrapper.addClass( 'woopack-ajax-loaded' );
105					}, 100);
106				}
107			},
108            onAjaxLoad: function(object) {
109				var wrapper = object.wrapper;
110				// Cache height of the wrapper in case if default template is used.
111				if ( 'undefined' === typeof quickView.height[productId] ) {
112					quickView.height[productId] = wrapper.find('.woopack-modal-inner').outerHeight();
113				}
114
115				//object._resetHeight();
116
117				wrapper.find('.woocommerce-product-gallery .woocommerce-product-gallery__image a').on('click', function(e) {
118					e.preventDefault();
119					e.stopPropagation();
120	
121					var imageEl = $(this).parents('.woocommerce-product-gallery__image');
122					var firstEl = imageEl.parents('.woocommerce-product-gallery').find('.woocommerce-product-gallery__image:first');
123					imageEl.insertBefore(firstEl);
124				});
125	
126				// Trigger variation form
127				if ( typeof $.fn.wc_variation_form !== 'undefined' ) {
128					if ( wrapper.find('form.variations_form').length > 0 ) {
129						wrapper.find('form.variations_form').wc_variation_form();
130					}
131				}
132	
133				// Add target="_blank" to external product
134				wrapper.find('.product-type-external form.cart').attr( 'target', '_blank' );
135
136				// Fix for WooVariationGallery.
137				if ( wrapper.find('.woo-variation-gallery-wrapper').length > 0 && 'undefined' !== typeof jQuery.fn.WooVariationGallery ) {
138					wrapper.find('.woo-variation-gallery-wrapper').WooVariationGallery();
139				}
140				// Fix for WooVariationSwatches.
141				if ( wrapper.find('.form.variations_form').length > 0 && 'undefined' !== typeof jQuery.fn.WooVariationSwatches ) {
142					if ( wrapper.find('.woo-variation-items-wrapper').length > 0 ) {
143						wrapper.find('.form.variations_form').WooVariationSwatches();
144					}
145				}
146
147				// WooCommerce Product Addons
148				wrapper.trigger( 'quick-view-displayed' );
149
150				$('body').trigger( 'woopack.quickview.ajaxload', [wrapper] );
151			},
152            onClose: function(wrapper) {
153				wrapper.removeClass('woopack-modal-' + nodeId);
154				wrapper.removeClass('woopack-ajax-loaded');
155				wrapper.removeClass( 'woopack-images-loaded' );
156				$('body').remove( 'woopack-pswp' );
157				//wrapper.find('.woopack-modal-content').prop('style').removeProperty('height');
158				//wrapper.find('.woopack-modal-content').prop('style').removeProperty('max-height');
159				//wrapper.find('.woopack-modal-inner').prop('style').removeProperty('max-height');
160				
161				// Start carousel autoplay.
162				setTimeout(function() {
163					if ( products.hasClass('owl-carousel') ) {
164						products.trigger('refresh.owl.carousel');
165					}
166				}, 500);
167			},
168		});
169	});
170
171    $(window).on('resize', function() {
172        if ( window.innerWidth > 767 ) {
173            $('.woopack-modal .woopack-modal-inner').css({
174                height: 'auto'
175            });
176        }
177    });
178
179	// Close quick view modal after product has added to the cart.
180	$( document ).on( 'added_to_cart', function(e, fragments, cart_hash, $button ) {
181		if ( $button && $button.length > 0 && $button.parents( '.woopack-modal' ).length > 0 ) {
182			if ( '' !== quickView.node && quickView.node.length > 0 && quickView.node.hasClass( 'woopack-qv-close-on-add' ) ) {
183				setTimeout(function() {
184					$button.parents( '.woopack-modal' ).fadeOut(function() {
185						$(this).find( '.woopack-modal-close' ).trigger( 'click' )
186					});
187				}, 500);
188			}		
189		}
190	} );
191
192    // Quantity input.
193    $('body').on('change keyup blur', '.woopack-products .quantity input.qty', function() {
194        var qty = parseFloat($(this).val());
195        
196        // it should be above 0
197        qty = ( 0 === qty || '' === qty ) ? 1 : qty;
198        
199        $(this).val(qty);
200        $(this).parents('.woopack-product-action').find('a.button').attr('data-quantity', qty);
201	});
202
203	if ( 'undefined' === typeof wc_add_to_cart_params ) {
204		return false;
205	}
206
207	var getAjaxExtraData = function() {
208		var data = {};
209
210		if ( 'undefined' !== typeof wc_cart_fragments_params ) {
211			var ajaxUrl = wc_cart_fragments_params.wc_ajax_url;
212
213			var fragments = ajaxUrl.split( '&' );
214			fragments = fragments.slice(1, fragments.length);
215
216			fragments.forEach( function( item ) {
217				var queryArg = item.split( '=' );
218				var value = 'undefined' === typeof queryArg[1] ? true : queryArg[1];
219				data[ queryArg[0] ] = value;
220			} );
221		}
222
223		return data;
224	};
225
226	// Quick View add-to-cart AJAX
227	$('body').on('submit', '.woopack-modal form.cart, .woopack-single-product form.cart', function(e) {
228
229		if ( $(this).hasClass('variations_form') && typeof $.fn.wc_variation_form === 'undefined' ) {
230			return;
231		}
232
233		if ( $(this).parents('.product-type-external').length > 0 ) {
234			return;
235		}
236
237		if ( $(this).parents('.woopack-no-ajax').length > 0 ) {
238			return;
239		}
240
241		e.preventDefault();
242		e.stopPropagation();
243
244		var form = $(this);
245		var grouped = $(this).hasClass('grouped_form');
246		var $thisbutton = $(this).find('button[type="submit"]');
247
248		if ( grouped ) {
249			$(this).find('.woocommerce-grouped-product-list tr').each(function() {
250				var qty = $(this).find('input.qty').val();
251				var productId = $(this).attr('id').split('-')[1];
252
253				if ( qty > 0 ) {
254					var data = {
255						'quantity': qty,
256						'product_id': productId,
257					};
258
259					$thisbutton.removeClass( 'added' );
260					$thisbutton.addClass( 'loading' );
261
262					// Trigger event.
263					$( document.body ).trigger( 'adding_to_cart', [ $thisbutton, data ] );
264
265					// Ajax action.
266					addToCart( $thisbutton, data );
267				}
268			});
269		} else {
270			if ( $(this).find('input[name="variation_id"]').length > 0 ) {
271				handleVariationForm( $(this) );
272			} else {
273				var data = {
274					'action': 'woopack_add_to_cart',
275					'quantity': $(this).find('.qty').val(),
276					'product_id': $(this).find('.single_add_to_cart_button').val(),
277				};
278
279				var formData = form.serializeArray();
280
281				formData.forEach(function( field, index ) {
282					if ( 'undefined' !== typeof field && 'undefined' === typeof data[field.name] && 'add-to-cart' !== field.name ) {
283						data[field.name] = field.value;
284					}
285				});
286
287				// WooCommerce Bookings support.
288				if ( form.find( '.wc-bookings-booking-form' ).length > 0 ) {
289					data.product_id = form.find('.wc-booking-product-id').val();
290				}
291
292				// WooCommerce Appointments support.
293				if ( form.find( '.wc-appointment-product-id' ).length > 0 ) {
294					data.product_id = form.find( '.wc-appointment-product-id' ).val();
295				}
296
297				$thisbutton.removeClass( 'added' );
298				$thisbutton.addClass( 'loading' );
299
300				// Trigger event.
301				$( document.body ).trigger( 'adding_to_cart', [ $thisbutton, data ] );
302
303				addToCart( $thisbutton, data );
304			}
305		}
306	});
307
308	
309	// Variation Add to Cart AJAX - Loop
310	$('body').on('submit', '.woopack-products .product .variations_form, .woopack-product-add-to-cart .variations_form', function(e) {
311		if ( typeof wc_add_to_cart_params === 'undefined' ) {
312			return;
313		}
314		
315		if ( $(this).parents( '.woopack-no-ajax' ).length > 0 ) {
316			return;
317		}
318
319		e.preventDefault();
320		e.stopPropagation();
321
322		handleVariationForm( $(this) );
323	});
324
325	// Grouped product - add to cart
326	$('body').on('submit', '.woopack-products .product .grouped_form', function(e) {
327		e.preventDefault();
328		e.stopPropagation();
329
330		var $thisbutton = $(this).find('button[type="submit"]');
331
332		$(this).find('.woocommerce-grouped-product-list tr').each(function() {
333			var qty = $(this).find('input.qty').val();
334			var productId = $(this).attr('id').split('-')[1];
335
336			if ( qty > 0 ) {
337				var data = {
338					'quantity': qty,
339					'product_id': productId,
340				};
341
342				$thisbutton.removeClass( 'added' );
343				$thisbutton.addClass( 'loading' );
344
345				// Trigger event.
346				$( document.body ).trigger( 'adding_to_cart', [ $thisbutton, data ] );
347
348				// Ajax action.
349				addToCart( $thisbutton, data );
350			}
351		});
352	});
353
354	var handleVariationForm = function( $form ) {
355		var data = {
356			'action': 'woopack_add_to_cart',
357			'quantity': $form.find('.qty').val(),
358			'product_id': $form.find('input[name="product_id"]').val(),
359			'variation_id': $form.find('input[name="variation_id"]').val(),
360		};
361
362		var variations = $form.data('product_variations')[0];
363		var attributes = [];
364		var attrKeys = [];
365
366		if ( variations && 'undefined' !== typeof variations.attributes ) {
367			Object.keys( variations.attributes ).map( function( attr ) {
368				if ( $form.find( '[name="' + attr + '"]' ).length > 0 ) {
369					var attr_string = attr + '|' + $form.find( '[name="' + attr + '"]' ).val();
370					attributes.push( attr_string );
371					attrKeys.push( attr );
372				}
373			} );
374
375			data['variation'] = attributes;
376		}
377
378		var formData = $form.serializeArray();
379
380		formData.forEach(function( d, i ) {
381			if ( 'undefined' !== typeof d && 'undefined' === typeof data[d.name] && 'add-to-cart' !== d.name && -1 === $.inArray( d.name, attrKeys ) ) {
382				data[d.name] = d.value;
383			}
384		});
385
386		var $thisbutton = $form.find('button[type="submit"]');
387
388		$thisbutton.removeClass( 'added' );
389		$thisbutton.addClass( 'loading' );
390
391		// Trigger event.
392		$( document.body ).trigger( 'adding_to_cart', [ $thisbutton, data ] );
393
394		addToCart( $thisbutton, data );
395	};
396
397	var addToCart = function( $thisbutton, data ) {
398		
399		var url = wc_add_to_cart_params.wc_ajax_url.toString().replace( '%%endpoint%%', 'add_to_cart' );
400
401		if ( typeof data.action !== 'undefined' ) {
402			url = woopack_config.ajaxurl;
403
404			data = $.extend( data, getAjaxExtraData() );
405		}
406
407		// Ajax action.
408		$.post( url, data, function( response ) {
409			if ( ! response ) {
410				return;
411			}
412
413			if ( response.error && response.product_url ) {
414				window.location = response.product_url;
415				return;
416			}
417
418			// Redirect to cart option
419			if ( wc_add_to_cart_params.cart_redirect_after_add === 'yes' ) {
420				window.location = wc_add_to_cart_params.cart_url;
421				return;
422			}
423
424			// Trigger event so themes can refresh other areas.
425			$( document.body ).trigger( 'added_to_cart', [ response.fragments, response.cart_hash, $thisbutton ] );
426		});
427	};
428
429	// Set the height to auto if equal height is enabled.
430	// $( document.body ).on( 'added_to_cart', function( e, fragments, cart_hash, $button ) {
431	// 	$button.parents( '.woopack-product-carousel.product' ).css('height', 'auto');
432	// } );
433
434	// Update product image on variation dropdown change
435	$('body').on('change', '.woopack-products .product .variations_form select, .woopack-single-product .variations_form select', function() {
436		var $this = $(this), attr = $this.attr('name'), val = $this.val(),
437			form = $this.parents('.variations_form');
438		if ( $this.parents('.woopack-product-grid.product').length > 0 ) {
439			var img = $this.parents('.woopack-product-grid.product').find('.woopack-product-image img');
440		} else {
441			var img = $this.parents('.woopack-single-product').find('.single-product-image img');
442		}
443		var variations = form.data('product_variations');
444
445		if ( ! variations ) {
446			return;
447		}
448
449		variations.forEach(function (item) {
450			if ( 'undefined' !== typeof item.attributes[ attr ] && val === item.attributes[ attr ] ) {
451				if ( 'undefined' !== typeof item.image ) {
452					img.attr('src', item.image.thumb_src);
453					img.attr('srcset', item.image.srcset);
454				}
455				// Update varition id
456				// if ( 'undefined' !== typeof item.variation_id ) {
457				// 	form.find('input[name="variation_id"]').val( item.variation_id );
458				// }
459			}
460		});
461	});
462
463	// Fix View Cart button appearance
464	$(document).on('wc_cart_button_updated', function(e, $button) {
465		if ( $button && $button.length > 0 ) {
466			$button.parent().find('a.added_to_cart').addClass('button alt');
467		}
468	});
469
470	var w = $('.woopack-product-image').find('.woopack-product-featured-image').attr('width');
471	$('.woopack-product-image').find('.woocommerce-placeholder.wp-post-image').width(w);
472
473	// Custom Quantity input.
474	var setCustomQty = function() {
475		if ( $('.woopack-qty-custom').length > 0 && $('.woopack-qty-custom .qty-minus').length === 0 ) {
476			var minus = '<span class="qty-minus"></span>';
477			var plus = '<span class="qty-plus"></span>';
478			$('.woopack-qty-custom input.qty').each(function() {
479				if ( ! $(this).parent().hasClass('woopack-qty-input') ) {
480					$(this).parent().addClass('woopack-qty-input');
481				}
482	
483				$(minus).insertBefore( $(this) );
484				$(plus).insertAfter( $(this) );
485	
486				var qty = $(this);
487				$(this).parent().find( '.qty-minus' ).on('click', function() {
488					qty[0].stepDown();
489					qty.trigger('change');
490				});
491				$(this).parent().find( '.qty-plus' ).on('click', function() {
492					qty[0].stepUp();
493					qty.trigger('change');
494				});
495			});
496		}
497	};
498	setCustomQty();
499
500	$(document).on('woopack.grid.rendered', function() {
501		setCustomQty();
502	});
503
504	// Checkout form handling.
505	$('.woopack-checkout.style-enhanced button[name="apply_coupon"]').on( 'click', function(e) {
506		e.preventDefault();
507
508		if ( ! wc_checkout_params ) {
509			return;
510		}
511
512		var $form = $(this).parents( '.woopack-checkout-coupon' );
513
514		startFormProcessing( $form );
515
516		var data = {
517			security: wc_checkout_params.apply_coupon_nonce,
518			coupon_code: $form.find('input[name="coupon_code"]').val()
519		};
520
521		$.ajax({
522			type: 'POST',
523			url: wc_checkout_params.wc_ajax_url.toString().replace('%%endpoint%%', 'apply_coupon'),
524			context: this,
525			data,
526			success: function(code) {
527			  $('.woocommerce-error, .woocommerce-message').remove();
528			  stopFormProcessing( $form );
529	  
530			  if (code) {
531				$form.append( code );
532				$form.find('input[name="coupon_code"]').val('');
533				$('body').trigger('applied_coupon_in_checkout', [data.coupon_code]);
534				$('body').trigger('update_checkout', {
535				  update_shipping_method: false
536				});
537			  }
538			},
539	  
540			dataType: 'html'
541		});
542	} );
543
544	var startFormProcessing = function($form) {
545		if ($form.is('.processing')) {
546			return;
547		}
548		$form.addClass('processing').block({
549			message: null,
550			overlayCSS: {
551			  background: '#fff',
552			  opacity: 0.6
553			}
554		});
555	}
556
557	var stopFormProcessing = function($form) {
558		$form.removeClass('processing').unblock();
559	};
560})(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.