PageSourceSearch

https://volunteeralberta.ab.ca/_scripts/_hi5/hi5-cart.js?v=321.2

js volunteeralberta.ab.ca collected 2026-09-26 05:32:12 UTC 10,388 bytes, 394 lines download raw bytes

1$(document).ready(function() {
2	
3	$('#btn-paypal-submit').click(function(e){
4		e.preventDefault();
5		
6		var form = document.getElementById('paypal-pay');
7		
8		if(form) {
9			PopupCenter('about:blank', 'PayPal_Payment', 600, 600, 'menubar=no,status=no,titlebar=no,toolbar=no');
10			form.target = 'PayPal_Payment';
11			form.submit();
12		}
13	});
14	
15	$(".Hi5PriceList tr:not('.in-cart') .Hi5AddToCart[data-sku], .Hi5PriceList tr .Hi5AddToCart[data-type='donation'], .Hi5PriceList .Hi5AddToCart[data-sku].not-in-cart").on("click", function(event) {
16		
17		CartItemAdd(this);
18		
19	});
20	
21	$(".Hi5PriceList tr.in-cart .Hi5AddToCart:not([data-type='donation'])").on("click", function(event) {
22		
23		CartItemAdjust(this);
24		
25	});
26	
27	$("tr.not-available .Hi5AddToCart").prop("disabled", true)
28	$("tr.not-available").data('toggle', 'tooltip').prop('title', strLang_NotAvail);
29	
30	$(".Hi5Cart .remove_item button").on("click", function(event) {
31		
32		CartItemRemove(this, "item");
33		
34	});
35	
36	$(".Hi5PriceList .currency-selector").on("change", function(event) {
37		
38		var pkCat = $(this).attr('data-price-list');
39		var pkSelected = $(this).val();
40		
41		$('.Hi5PriceList .currency-selector').val(pkSelected);
42		
43		$(".Hi5PriceList tr:not(." + pkSelected + ")").addClass("hidden");
44		$(".Hi5PriceList tr." + pkSelected).removeClass("hidden");	
45		
46	});	
47	
48	$('.Hi5PriceList .currency-selector').prop('disabled', false);
49	
50	$('#use-saved-card').on('change', function () {
51	
52	    const $fields = $('#new-card-fields')
53	        .find('input, select, textarea');
54	
55	    if (this.checked) {
56	
57	        $fields.each(function () {
58	            if (this.required) {
59	                $(this)
60	                    .prop('required', false)
61	                    .attr('data-required', 'true');
62	            }
63	        });
64	
65	        $('#new-card-fields').slideUp();
66	
67	    } else {
68	
69	        $fields.each(function () {
70	            if ($(this).attr('data-required') === 'true') {
71	                $(this)
72	                    .prop('required', true)
73	                    .removeAttr('data-required');
74	            }
75	        });
76	
77	        $('#new-card-fields').slideDown();
78	    }
79	});
80	
81});
82
83function CartItemRemove(objButton, strType) {
84	
85	var strSKU = $(objButton).data(strType);
86	
87	var baseHref = document.getElementsByTagName('base')[0].href;
88
89		var strRequest = "cart/add/?qty=0&item=" + strSKU + "&enumLang=" + ($('html')[0].lang);
90		
91		console.log("AJAX request: " + baseHref + strRequest);
92	
93		$.ajax({
94			
95			url: strRequest
96		
97		, success: function(result) {
98			
99			CartItemRemoved($(objButton).parent().parent().id, result.summary);
100			
101		}
102		
103		, error: function(result) {
104			
105			var response = JSON.parse(result.responseText);
106			
107			console.log(response);
108			
109			CartItemNotRemoved(response.item, result.statusText);
110			
111		}
112			
113	});		
114	
115}
116
117function CartItemRemoved(strID, strSummary) {
118	
119	$("#Hi5Cart-Summary").html(strSummary);
120	
121	$("#row-"+strID).remove();
122	
123	window.location.reload();
124	
125}
126
127function CartItemNotRemoved(strID, strError) {
128	
129	window.alert("Sorry, the item could not be removed from the cart:\n\n" + strError);
130	
131}
132
133function CartItemAdjust(objButton) {
134	
135	var qty = objButton.dataset.qty;
136	
137	qty = Math.abs(parseInt(prompt(strLang_AdjustQty, qty)));
138	
139	if(qty!=null && !isNaN(qty)) {
140
141		$("#"+objButton.id).off("click");
142		$("#"+objButton.id+" .cart-loaded").removeClass("visible").addClass("not-visible");
143		$("#"+objButton.id+" .add-to-cart").removeClass("visible").addClass("not-visible");
144		$("#"+objButton.id+" .cart-loading").removeClass("not-visible").addClass("visible");
145		
146		var baseHref = document.getElementsByTagName('base')[0].href;
147		var strSKU = $(objButton).attr('data-sku');
148		var enumType = $(objButton).attr('data-type');
149		var strRequest = "cart/add/?item=" + strSKU + "&qty=" + qty + "&enumLang=" + ($('html')[0].lang);
150		
151		console.log("AJAX request: " + baseHref + strRequest);
152	
153		$.ajax({
154			
155			url: strRequest
156			
157			, success: function(result) {
158				
159	    		CartItemAdded(objButton.id, result.summary, qty, enumType);
160				
161			}
162			
163			, error: function(result) {
164				
165				var response = JSON.parse(result.responseText);
166	    		CartItemNotAdjusted(objButton.id, response.statusText, enumType);
167				
168			}
169				
170		});		
171	
172	}
173	
174}
175
176function CartItemAdd(objButton) {
177
178	$("#"+objButton.id).off("click");
179	
180	$("#"+objButton.id+" .add-to-cart").removeClass("visible").addClass("not-visible");
181	
182	$("#"+objButton.id+" .cart-loading").removeClass("not-visible").addClass("visible");
183	
184	var baseHref = document.getElementsByTagName('base')[0].href;
185	
186	var strCurrency = $(objButton).attr('data-currency');
187	var enumType = $(objButton).attr('data-type');
188	
189	if(strCurrency=='CAD') strCurrency = '';
190	
191	var strSKU = $(objButton).attr('data-sku');
192	var blnProrate = $(objButton).attr('data-prorate');
193	
194	var strFunds = "";
195	
196	if(enumType=="donation") strFunds = $('#donation-form').serialize();
197
198	var strRequest = "cart/add/?item=" + strSKU + (blnProrate ? "&prorate=1" : "") + "&enumLang=" + ($('html')[0].lang) + (strCurrency ? '&strCurrency='+strCurrency : '') + (enumType ? '&type='+enumType+(strFunds ? '&'+strFunds: '') : '');
199	
200	console.log("AJAX request: " + baseHref + strRequest);
201
202	$.ajax({
203		
204		url: strRequest
205
206		, success: function(result) {
207			
208    		CartItemAdded(objButton.id, result.summary, 1, enumType);
209			
210		}
211		
212		, error: function(result) {
213			
214			var response = JSON.parse(result.responseText);
215			console.log(response);
216    		CartItemNotAdded(objButton.id, response.statusText, enumType);
217			
218		}
219			
220	});
221		
222}
223
224function CartItemNotAdjusted(strID, strError, enumType) {
225	
226	window.alert("Sorry, this item could not be adjusted:\n\n" + strError);
227	
228	$("#"+strID+" .cart-loading").removeClass("visible").addClass("not-visible");
229	
230	$("#"+strID+" .add-to-cart").removeClass("not-visible").addClass("visible");	
231	
232	$("#"+strID).on("click", function(event) {
233		
234		if(enumType=="donation") CartItemAdd(this);
235		else CartItemAdjust(this);
236		
237	});
238	
239}
240
241function CartItemNotAdded(strID, strError, enumType) {
242	
243	window.alert("Sorry, the item could not be added to the cart:\n\n" + strError);
244	
245	$("#"+strID+" .cart-loading").removeClass("visible").addClass("not-visible");
246	$("#"+strID+" .add-to-cart").removeClass("not-visible").addClass("visible");	
247	
248	$("#"+strID).on("click", function(event) {
249		
250		if(enumType=="donation") CartItemAdd(this);
251		else CartItemAdjust(this);
252		
253	});
254	
255}
256
257function CartItemAdded(strID, strSummary, qty, enumType) {
258	
259	qty = typeof qty !== 'undefined' ? qty : 1;
260	
261	if(enumType=="donation") {
262		
263		$("#"+strID+" .button-caption").html(strLang_CartUpdated);
264		if(blnReloadOnAddtoCart) window.location.reload();
265
266	} else {
267	
268		$("#"+strID+" .button-caption").html("<span class=\"badge cart-quantity\">"+ qty +"</span> " + strLang_InCart);
269		
270	}
271	
272	$("#"+strID).attr('data-qty', qty);
273	
274	$("#"+strID+" .cart-loading").removeClass("visible").addClass("not-visible");
275	
276	$("#"+strID+".Hi5AddToCart[data-sku].not-in-cart").removeClass("not-in-cart").addClass("hidden d-none");
277	$("#"+strID+"-checkout").removeClass("hidden d-none");
278	
279	if(qty>0) {
280	
281		$("#"+strID+" .cart-loaded").removeClass("not-visible").addClass("visible");
282		
283		$("#"+strID).on("click", function(event) {
284			
285			if(enumType=="donation") CartItemAdd(this);
286			else CartItemAdjust(this);
287			
288		});		
289		
290	} else {
291		
292		$("#"+strID+" .cart-loading").removeClass("visible").addClass("not-visible");
293		
294		$("#"+strID+" .add-to-cart").removeClass("not-visible").addClass("visible");	
295		
296		$("#"+strID).on("click", function(event) {
297			
298			CartItemAdd(this);
299			
300		});
301		
302	}
303	
304	$(".Hi5PriceList tfoot .btn").removeClass("not-visible").addClass("visible");
305	
306	$(".Hi5Cart").removeClass("cart-empty");
307	
308	$("#Hi5Cart-Summary").html(strSummary);
309	
310}
311
312/**
313 * PopupCenter
314 *
315 * Opens a centered popup window on the user's screen.
316 * Commonly used for external flows such as PayPal checkout.
317 *
318 * Behavior:
319 * - Calculates screen position to center the popup
320 * - Supports dual-screen setups
321 * - Applies custom window specs (toolbar, menubar, etc.)
322 * - Focuses the popup if successfully opened
323 *
324 * Parameters:
325 * @param {string} url   The URL to load (use 'about:blank' if submitting a form into it)
326 * @param {string} title The window name (also used as the form target)
327 * @param {number} w     Width of the popup window
328 * @param {number} h     Height of the popup window
329 * @param {string} specs Additional window features (e.g. 'menubar=no,status=no,...')
330 *
331 * Returns:
332 * @return {Window|null} Reference to the popup window, or null if blocked
333 *
334 * Notes:
335 * - Must be called directly within a user interaction (e.g. click event)
336 *   to avoid popup blockers
337 * - When used with forms, ensure the form's target matches the popup title
338 *
339 * Example:
340 * PopupCenter('about:blank', 'PayPal_Payment', 600, 600, 'menubar=no,status=no');
341 * form.target = 'PayPal_Payment';
342 * form.submit();
343 */
344
345function PopupCenter(url, title, w, h, specs) {
346	
347	var dualScreenLeft = (typeof window.screenLeft !== 'undefined') ? window.screenLeft : screen.left;
348	var dualScreenTop = (typeof window.screenTop !== 'undefined') ? window.screenTop : screen.top;
349
350	var width = window.innerWidth || document.documentElement.clientWidth || screen.width;
351	var height = window.innerHeight || document.documentElement.clientHeight || screen.height;
352
353	var left = ((width / 2) - (w / 2)) + dualScreenLeft;
354	var top = ((height / 2) - (h / 2)) + dualScreenTop;
355
356	var newWindow = window.open(
357		url,
358		title,
359		specs + ',width=' + w + ',height=' + h + ',top=' + top + ',left=' + left
360	);
361
362	if(newWindow && window.focus) {
363		newWindow.focus();
364	}
365	
366	return newWindow;
367}
368function toggleApplyCredit(blnApply) {
369	
370	if(blnApply) {
371		
372		$('.apply-credit-rows').removeClass('hidden');
373		$('input[name="blnApplyCredit"]').attr('value', '1');
374		
375		$('#balance-owing').html('<strong>' + $('#tx-balance').html() +'</strong>');
376		
377		var decBalance = $('#tx-balance').text();
378		decBalance = Number(decBalance.replace(/[^0-9\.]+/g,""));
379		$('#ssl_amount').val(decBalance);
380		
381	} else {
382		
383		$('.apply-credit-rows').addClass('hidden');
384		$('input[name="blnApplyCredit"]').attr('value', '0');
385		
386		$('#balance-owing').html('<strong>' + $('#tx-total').html() +'</strong>');
387		
388		var decBalance = $('#tx-total').text();
389		decBalance = Number(decBalance.replace(/[^0-9\.]+/g,""));
390		$('#ssl_amount').val(decBalance);
391		
392	}
393	
394}

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.