PageSourceSearch

https://dirtcheap.ca/wp-content/themes/Avada-Child-Theme/assets/js/dc-public.js?ver=1790790410

js dirtcheap.ca collected 2026-10-04 05:13:29 UTC 11,995 bytes, 388 lines download raw bytes

1jQuery( document ).ready(function( $ ) {
2        /* Start - Single Product pages fix quantity warnings */
3        var $form = $('.variations_form');
4
5        // 1. LOCK: Disable interaction immediately
6        $form.on('change', '.variations select', function() {
7            var $qtyContainer = $('.quantity.buttons_added');
8            $qtyContainer.css({ 'opacity': '0.3', 'pointer-events': 'none' });
9            $qtyContainer.find('input').prop('disabled', true);
10        });
11
12        // 2. THE SYNC: Use the variation object immediately
13        $form.on('show_variation', function(event, variation) {
14            setTimeout(function() {
15                var $qtyInput = $('.quantity.buttons_added input[type="number"]');
16                var $allInputs = $('.quantity.buttons_added input');
17
18                // SOURCE OF TRUTH: Using the keys from the object you provided
19                var targetMin  = parseFloat(variation.min_qty) || 1;
20                var targetMax  = parseFloat(variation.max_qty) || '';
21
22                /* If 'step' isn't in the object, we assume step = min_qty.
23                   This is standard for products sold in fractional increments (0.5, 1.5, etc.)
24                */
25                var targetStep = targetMin; 
26
27                var currentVal = parseFloat($qtyInput.val()) || 0;
28
29                // FORCE INJECT attributes into the HTML immediately to bypass the 4s lag
30                $qtyInput.attr('step', targetStep);
31                $qtyInput.attr('min', targetMin);
32                $qtyInput.attr('max', targetMax);
33
34                // SYNC VALUE: Integer Math to fix the 3.0 -> 3.5 jump
35                var v = Math.round(currentVal * 100);
36                var m = Math.round(targetMin * 100);
37                var s = Math.round(targetStep * 100);
38
39                if (v < m) {
40                    $qtyInput.val(targetMin);
41                } else {
42                    var remainder = (v - m) % s;
43                    if (remainder !== 0) {
44                        var adjustedVal = targetMin + (Math.ceil((v - m) / s) * targetStep);
45                        $qtyInput.val(adjustedVal);
46                    } else {
47                        // It's a perfect multiple (e.g., 3.0 is a multiple of 0.5), STAY AT 3.0
48                        $qtyInput.val(currentVal);
49                    }
50                }
51
52                // 3. UNLOCK
53                $('.quantity.buttons_added').css({ 'opacity': '1', 'pointer-events': 'auto' });
54                $allInputs.prop('disabled', false);
55
56                // Final trigger for price updates
57                $qtyInput.trigger('change');
58
59                console.log("Force Synced | Min: " + targetMin + " | Step: " + targetStep + " | Max: " + targetMax);
60            }, 10); 
61        });
62        /* End - Single Product pages fix quantity warnings */
63
64	/* On click view product button to create a cookie */
65	$(document).on('submit', '.dc-postalcode-form', function(e){
66
67		e.preventDefault();
68
69		var cls_form	= $(this).closest('form');
70		var postal_code = cls_form.find('.dc-postalcode').val();
71		var product_id	= cls_form.find('.dc-product-id').val();
72		var msg_cls		= 'dc-error';
73
74		cls_form.find('.dc-error').remove();
75		cls_form.find('.dc-view-product-btn').attr('disabled', 'disabled');
76		cls_form.find('.dc-error').remove();
77		cls_form.find('.dc-loader').removeClass('dc-hide');
78
79		var dc_postal_data	= {
80			'action'		: 'dc_postal_code_form_submit',
81			'postal_code'	: postal_code,
82			'product_id'	: product_id,
83		};
84
85		jQuery.post(DC_Public.dc_ajaxurl, dc_postal_data, function(response) {
86
87			if( response.success == 1 ) {
88				msg_cls	= 'dc-success';
89
90				/* Create a cookie for postal code */
91				dc_create_cookie( 'dc_postal_code', response.postcode, '30', 'day' );
92
93				//window.location = response.redirect_url;
94				window.location.reload(true);
95			}
96
97			cls_form.find('.dc-loader').addClass('dc-hide');
98			cls_form.append( '<div class="'+ msg_cls +'">' + response.msg + '</div>' );
99			cls_form.find('.dc-view-product-btn').removeAttr('disabled', 'disabled');
100		});
101	});
102
103	/* Process Contractor form submission */
104	$(document).on('submit', '.dc-contractor-form', function(e) {
105
106		e.preventDefault();
107
108		var this_ele	= $(this);
109		var cls_form 	= $(this).closest('form');
110
111		cls_form.find('.dc-contractor-submit').attr('disabled', 'disabled');
112		this_ele.find('.dc-loader').removeClass('dc-hide');
113
114		var contractor_data	= {
115			'action'	: 'dc_contractor_form_submit',
116			'form_data'	: cls_form.serialize(),
117		};
118
119		jQuery.post(DC_Public.dc_ajaxurl, contractor_data, function(response) {
120
121			if( response.success == 1 ) {
122				
123				cls_form.find('.dc-contractor-btn-wrap').append('<div class="dc-success">'+ response.msg +'</div>');
124				cls_form.find('.dc-contractor-field').val('');
125
126				setTimeout(function() {
127					cls_form.find('.dc-contractor-btn-wrap .dc-success').remove();
128				}, 3000 );
129			}
130
131			this_ele.find('.dc-loader').addClass('dc-hide');
132			cls_form.find('.dc-contractor-submit').removeAttr('disabled', 'disabled');
133		});
134
135		return false;
136	});
137	
138	/* Check billing phone code */
139	$('#billing_phone').on( 'input focusout', function() {
140		var p = $(this).val();
141
142		p = p.replace(/[^0-9]/g, '');
143		p = p.replace(/(\d{3})(\d{3})(\d{4})/, "$1-$2-$3");
144		$(this).val(p);
145	});
146	
147	/* Remove checkout error message after some time */
148	$(document.body).on( 'checkout_error', function(){
149		var wooError = $('.woocommerce-error');
150		setTimeout(function(){
151			wooError.fadeOut(300);
152		}, 5000);
153	});
154	
155	/* On change shape dropdown to change fields */
156	$(document).on('change', '.dc-cal-shape', function() {
157
158		var cls_ele		= $(this).closest('.dc-product-cal-wrap');
159		var shape_val	= cls_ele.find('.dc-cal-shape').val();
160		cls_ele.find('.dc-cal-inp').val('');
161		cls_ele.find('.dc-cubic-yard span').empty();
162
163		if( shape_val == 'circles' ) {
164
165			cls_ele.find('.dc-cal-gen-field').css('display', 'none');
166			cls_ele.find('.dc-cal-circle-field').css('display', 'block');
167
168		} else if( shape_val == 'squares' ) {
169			
170			cls_ele.find('.dc-cal-gen-field').css('display', 'block');
171			cls_ele.find('.dc-cal-width-field').css('display', 'none');
172			cls_ele.find('.dc-cal-circle-field').css('display', 'none');
173		} else {
174
175			cls_ele.find('.dc-cal-gen-field').css('display', 'block');
176			cls_ele.find('.dc-cal-circle-field').css('display', 'none');
177		}
178	});
179
180	/* On Enter keypress to calculate cubic yards */
181	$(document).on('keypress',function(e) {
182		if(e.which == 13) {
183			$('.dc-cal-calculate').trigger('click');
184		}
185	});
186
187	/* Calculator Initialize */
188	$(document).on('click', '.dc-cal-calculate', function() {
189
190		var cls_ele		= $(this).closest('.dc-product-cal-wrap');
191		var shape		= cls_ele.find('.dc-cal-shape').val();
192		var width		= cls_ele.find('.dc-cal-width').val();
193		var height		= cls_ele.find('.dc-cal-height').val();
194		var depth		= cls_ele.find('.dc-cal-depth').val();
195		var diameter	= cls_ele.find('.dc-cal-diameter').val();
196		var pi_val		= 3.14159265358979;
197
198		if( shape == 'circles' ) {
199
200			var cubic_yards	= ( pi_val * ( diameter / 2 ) * ( diameter / 2 ) ) * ( depth / 12 ) / 27;
201
202		} else {
203
204			var cubic_yards = ( height * width * ( depth / 12 ) ) / 27;
205		}			
206
207		/*var cubic_yards = Math.round( cubic_yards );
208		console.log( cubic_yards );*/
209		//cls_ele.find('.dc-cubic-yard span').text( cubic_yards.toFixed(2) + ' yd³' );
210		cls_ele.find('.dc-cubic-yard span').text( cubic_yards.toFixed(1) + ' yd³' );
211	});
212
213	/* Calculator field empty */
214	$(document).on('click', '.dc-cal-clear', function() {
215
216		var cls_ele = $(this).closest('.dc-product-cal-wrap');
217		cls_ele.find('input').val('');
218		cls_ele.find('.dc-cubic-yard span').empty();
219	});
220	if( $('#billing_delivery_instructions').length > 0 ) {
221		var maxLength = 60;
222
223		$('.dc-delivery-inst').append("<div class='dc-delivery-inst-text'><span class='dc-text-digit'>65</span> Characters Remaining</div>");
224
225		$('#billing_delivery_instructions').keyup(function() {
226			$(this).val($(this).val().substring(0, maxLength));
227			var tlength		= $(this).val().length;
228			var remain_char	= maxLength - parseInt(tlength);
229			$('.dc-text-digit').text( remain_char );
230		});
231	}	
232});
233
234/* Show product "Order more / Go to checkout" only when cart has items.
235 * Needed because product pages may be FastCGI-cached. */
236jQuery(function ($) {
237	var $actions = $('.dc-product-extra-btn');
238	if (!$actions.length) {
239		return;
240	}
241
242	function dcCartHasItems() {
243		var cookies = document.cookie ? document.cookie.split(';') : [];
244		for (var i = 0; i < cookies.length; i++) {
245			var part = $.trim(cookies[i]);
246			if (part.indexOf('woocommerce_items_in_cart=') === 0) {
247				return part.split('=')[1] === '1';
248			}
249		}
250		return false;
251	}
252
253	function dcToggleProductCartActions() {
254		if (dcCartHasItems()) {
255			$actions.removeAttr('hidden');
256		} else {
257			$actions.attr('hidden', true);
258		}
259	}
260
261	dcToggleProductCartActions();
262	$(document.body).on('added_to_cart removed_from_cart wc_fragments_refreshed wc_fragments_loaded', dcToggleProductCartActions);
263});
264
265/* Mobile sticky Order Now bar on single product pages */
266jQuery(function ($) {
267	var $body = $('body');
268	if (!$body.hasClass('single-product')) {
269		return;
270	}
271
272	var $bar = $('#dc-sticky-order-bar');
273	if (!$bar.length) {
274		return;
275	}
276
277	var mq = window.matchMedia('(max-width: 767px)');
278	var $cta = $('#dc-product-cta-zone');
279	if (!$cta.length) {
280		$cta = $('.dc-postalcode-form, form.cart').first();
281	}
282	if (!$cta.length) {
283		return;
284	}
285
286	function setBarVisible(show) {
287		if (!mq.matches) {
288			$bar.attr('hidden', true).removeClass('is-visible');
289			$body.removeClass('dc-sticky-order-bar-active');
290			return;
291		}
292
293		if (show) {
294			$bar.removeAttr('hidden').addClass('is-visible');
295			$body.addClass('dc-sticky-order-bar-active');
296		} else {
297			$bar.removeClass('is-visible');
298			$body.removeClass('dc-sticky-order-bar-active');
299			window.setTimeout(function () {
300				if (!$bar.hasClass('is-visible')) {
301					$bar.attr('hidden', true);
302				}
303			}, 250);
304		}
305	}
306
307	function updateBar() {
308		if (!mq.matches) {
309			setBarVisible(false);
310			return;
311		}
312
313		var rect = $cta[0].getBoundingClientRect();
314		// Show after the CTA zone has scrolled above the viewport.
315		setBarVisible(rect.bottom < 0);
316	}
317
318	if ('IntersectionObserver' in window) {
319		var observer = new IntersectionObserver(function (entries) {
320			if (!mq.matches) {
321				setBarVisible(false);
322				return;
323			}
324			var entry = entries[0];
325			setBarVisible(!entry.isIntersecting && entry.boundingClientRect.top < 0);
326		}, {
327			root: null,
328			threshold: 0
329		});
330		observer.observe($cta[0]);
331	} else {
332		$(window).on('scroll.dcStickyOrder resize.dcStickyOrder', updateBar);
333		updateBar();
334	}
335
336	if (typeof mq.addEventListener === 'function') {
337		mq.addEventListener('change', updateBar);
338	} else if (typeof mq.addListener === 'function') {
339		mq.addListener(updateBar);
340	}
341
342	$bar.on('click', '.dc-sticky-order-bar__btn', function () {
343		var $target = $('#dc-product-cta-zone');
344		if (!$target.length) {
345			$target = $('.dc-postalcode-form, form.cart').first();
346		}
347		if (!$target.length) {
348			return;
349		}
350
351		var offset = $target.offset().top - 80;
352		$('html, body').animate({ scrollTop: offset }, 300);
353
354		var $focus = $target.find('.dc-view-product-btn, .single_add_to_cart_button, #dc-postalcode').first();
355		if ($focus.length) {
356			window.setTimeout(function () {
357				$focus.trigger('focus');
358			}, 320);
359		}
360	});
361});
362
363/* Create Cookie */
364function dc_create_cookie(name, value, time_val, type) {
365	var date, expires;
366
367	time_val	= time_val	? time_val	: false;
368	type		= type		? type		: 'day';
369
370	if( type == 'hour' ) {
371		expire_time = (time_val * 60 * 60 * 1000);
372
373	} else if( type == 'minutes' ) {
374		expire_time = (time_val * 60 * 1000);
375
376	} else {
377		expire_time = (time_val * 24 * 60 * 60 * 1000);
378	}
379
380	if ( time_val ) {
381		date = new Date();
382		date.setTime( date.getTime() + expire_time );
383		expires = "; expires="+date.toGMTString();
384	} else {
385		expires = "";
386	}
387	document.cookie = encodeURIComponent(name) + "=" + encodeURIComponent(value) + expires + "; path=/";
388}

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.