PageSourceSearch

https://unitvnetwork.org/wp-content/themes/page-builder-framework/…/woocommerce/js/woocommerce.js?ver=2.11.8

js unitvnetwork.org collected 2026-09-27 02:01:15 UTC 3,654 bytes, 129 lines download raw bytes

1(function ($) {
2
3	function init() {
4		window.addEventListener('load', function () {
5			setupProductQuantities();
6			quantityChange();
7			setupQuickView();
8		});
9
10		// Make the code work after executing AJAX.
11		$(document).ajaxComplete(function () {
12			setupProductQuantities();
13			quantityChange();
14		});
15	}
16
17	/**
18	 * The Quickview content is taken via AJAX request.
19	 * Currently we manually waiting for the Quickview content to be ready.
20	 *
21	 * In the future, we might want to add event to the "Premium Add-On",
22	 * so we can just listen to the event.
23	 */
24	function setupQuickView() {
25		var quickViews = document.querySelectorAll('.wpbf-woo-quick-view');
26
27		if (!quickViews.length) return;
28
29		[].slice.call(quickViews).forEach(function (quickView) {
30
31			var maxWait = 3000; // Max wait of the ajax request of quickview modal.
32			var currentWait = 0;
33
34			quickView.addEventListener('click', waitForQuickViewReponse);
35
36			function waitForQuickViewReponse() {
37				if (!document.querySelector('.wpbf-woo-quick-view-modal-content .type-product')) {
38					/**
39					 * The content of the quickview is taken from ajax response.
40					 * Let's wait until ready (but with maximum waiting time).
41					 */
42					if (currentWait <= maxWait) {
43						setTimeout(function () {
44							waitForQuickViewReponse();
45							currentWait += 300;
46						}, 300);
47					}
48				} else {
49					setupProductQuantitiesOnQuickView();
50				}
51			}
52		});
53	}
54
55	function setupProductQuantitiesOnQuickView() {
56		var quantities = document.querySelectorAll('.wpbf-woo-quick-view-modal-content .quantity');
57
58		if (!quantities.length) return;
59
60		[].slice.call(quantities).forEach(function (quantity) {
61			setupProductQuantity(quantity);
62		});
63	}
64
65	function setupProductQuantities() {
66		var quantities;
67
68		quantities = document.querySelectorAll('.quantity');
69
70		if (!quantities.length) return;
71
72		[].slice.call(quantities).forEach(function (quantity) {
73			setupProductQuantity(quantity);
74		});
75	}
76
77	function setupProductQuantity(quantity) {
78		var qty = quantity.querySelector('.qty');
79		var decrease = quantity.querySelector('.wpbf-qty-decrease');
80		var increase = quantity.querySelector('.wpbf-qty-increase');
81
82		if (!qty || !decrease || !increase) return;
83
84		qty.parentNode.classList.add('wpbf-quantity');
85	}
86
87	function quantityChange() {
88		$(document).off("click", ".wpbf-qty-control").on( "click", ".wpbf-qty-control", function() {
89
90			// Find quantity input field corresponding to increment button clicked.
91			var qty = $( this ).parent().find( '.qty' );
92			// Read value and attributes min, max, step.
93			var val = parseFloat(qty.val());
94			var max = parseFloat(qty.attr( "max" ));
95			var min = parseFloat(qty.attr( "min" ));
96			var step = parseFloat(qty.attr( "step" ));
97
98			// Change input field value if result is in min and max range.
99			// If the result is above max then change to max and alert user about exceeding max stock.
100			// If the field is empty, fill with min for "-" (0 possible) and step for "+".
101			if ( $( this ).is( ".wpbf-qty-increase" ) ) {
102				if ( val === max ) return false;
103				if( isNaN(val) ) {
104					qty.val( step );
105				} else if ( val + step > max ) {
106					qty.val( max );
107				} else {
108					qty.val( val + step );
109				}
110			} else {
111				if ( val === min ) return false;
112				if( isNaN(val) ) {
113					qty.val( min );
114				} else if ( val - step < min ) {
115					qty.val( min );
116				} else {
117					qty.val( val - step );
118				}
119			}
120
121			qty.val( Math.round( qty.val() * 100 ) / 100 );
122			qty.trigger("change");
123
124		});
125	}
126
127	init();
128
129})(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.