PageSourceSearch

https://www.skateoakville.ca/js/utils/utils.js?1790193087

js skateoakville.ca collected 2026-09-25 08:59:57 UTC 5,343 bytes, 176 lines download raw bytes

1/**
2 * Created by luis on 03/05/16.
3 */
4
5var UP = window.UP || {};
6
7UP.Services = UP.Services || {};
8(function () {
9
10	let requestCount = 0;
11
12	function ajaxCall(fullUrl, dataObj, callbackFunction, beforeSendCustomLoading, completeCustomLoading, type, dataType, multipart, cache) {
13		if (dataObj instanceof FormData && navigator.userAgent.match(/version\/11((\.[0-9]*)*)? .*safari/i)) {
14			try {
15				eval(
16					"for (var pair of dataObj.entries()) {\
17						if (pair[1] instanceof File && pair[1].name === '' && pair[1].size === 0) {\
18							dataObj.delete(pair[0]);\
19						}\
20					}"
21				);
22			} catch (e) { }
23		}
24		if (!dataObj.lang && lang) {
25			dataObj.lang = lang;
26		}
27		var config = {
28			url: fullUrl,
29			cache: cache || false,
30			data: dataObj,
31			dataType: dataType,
32			type: type,
33			beforeSend: function () {
34				if (typeof beforeSendCustomLoading === "function") {
35					beforeSendCustomLoading();
36				}
37				else {
38					requestCount++;
39					$.fancybox.showLoading();
40				}
41			},
42			success: function (response) {
43				if (typeof response === 'object' && response !== null && response.sessionExpired) {
44					if (dataObj.ajaxLogin) {
45						var callback = function() {
46							ajaxCall(fullUrl, dataObj, callbackFunction, beforeSendCustomLoading, completeCustomLoading, type, dataType, multipart);
47						};
48						UP.Services.login(callback);
49
50						return false;
51					} else {
52						alert(response.message);
53						if(response.redirect) {
54							window.parent.location = response.redirect;
55						}
56						return false;
57					}
58				} else if (typeof callbackFunction === 'function') {
59					callbackFunction(response);
60				}
61			},
62			error: function (XMLHttpRequest, textStatus, errorThrown) {
63				//don't alert of errors if the request was just cancelled
64				if(XMLHttpRequest.status !== 0) {
65					if (dataObj.ajaxLogin) {
66						window.parent.location = "/";
67					} else {
68						//console.log("error :" + XMLHttpRequest.responseText);
69						alert(jsmsgErrorUnexpected);
70					}
71				}
72			},
73			complete: function () {
74				if(beforeSendCustomLoading !== 'function') {
75					requestCount--;
76					if (requestCount <= 0) {
77						$.fancybox.hideLoading();
78					}
79				}
80				if (typeof completeCustomLoading === "function") {
81					completeCustomLoading();
82				}
83			}
84		};
85		if (multipart) {
86			config.processData = false;
87			config.contentType = false;
88		}
89		return $.ajax(config);
90	}
91
92	UP.Services.login = function(callback) {
93		let fancyBoxOptions = {
94			type: 'iframe',
95			href: '/ajax/login.php'
96		};
97		let fancyBox2ToFancyBox1 = {
98			afterClose: 'onClosed',
99			onCancel: 'onCancel'
100		};
101		let callbacks = {
102			afterClose: function () {
103				if (window.viewUser && typeof callback === 'function') {
104					callback();
105				} else if(window.queueReload) {
106					window.location.reload()
107				} else if (typeof window.enableAddToCartButton === 'function') {
108					window.enableAddToCartButton();
109					window.enableAddToCartButton = null;
110				} else if (window.viewUser && !window.viewUser.address && window['require_address']) {
111					setTimeout(function () {
112						let modal = new AddAccountAddress();
113						modal.open().then(function (response) {
114							if (response['account_address']) {
115								viewUser.address = response['account_address'].address;
116							}
117							$.fancybox.close();
118						});
119					});
120				}
121			},
122			onCancel: function () {
123				if (typeof window.enableAddToCartButton === 'function') {
124					window.enableAddToCartButton();
125					window.enableAddToCartButton = null;
126				}
127			}
128		};
129		if (typeof $.fancybox.version === 'undefined') {
130			Object.keys(callbacks).forEach(function (key) {
131				fancyBoxOptions[fancyBox2ToFancyBox1[key]] = callbacks[key];
132			}) ;
133		} else {
134			Object.keys(callbacks).forEach(function (key) {
135				fancyBoxOptions[key] = callbacks[key];
136			}) ;
137		}
138		$.fancybox(fancyBoxOptions);
139	};
140
141	UP.Services.CacheAjaxGetCall = function (fullUrl, dataObj, callbackFunction, beforeSendCustomLoading, completeCustomLoading) {
142		return ajaxCall(fullUrl, dataObj, callbackFunction, beforeSendCustomLoading, completeCustomLoading, 'get', 'json', false, true);
143	};
144	
145	UP.Services.AjaxPostCall = function (fullUrl, dataObj, callbackFunction, beforeSendCustomLoading, completeCustomLoading) {
146		return ajaxCall(fullUrl, dataObj, callbackFunction, beforeSendCustomLoading, completeCustomLoading, 'post', 'json', false);
147	};
148	
149	UP.Services.AjaxGetCall = function (fullUrl, dataObj, callbackFunction, beforeSendCustomLoading, completeCustomLoading) {
150		return ajaxCall(fullUrl, dataObj, callbackFunction, beforeSendCustomLoading, completeCustomLoading, 'get', 'json', false);
151	};
152	
153	UP.Services.AjaxPostMultipartForm = function (fullUrl, dataObj, callbackFunction, beforeSendCustomLoading, completeCustomLoading) {
154		return ajaxCall(fullUrl, dataObj, callbackFunction, beforeSendCustomLoading, completeCustomLoading, 'post', 'json', true);
155	};
156
157	function silentAjaxCall (fullUrl, dataObj, callbackFunction, type, dataType) {
158		$.ajax({
159			url: fullUrl,
160			cache: false,
161			data: dataObj,
162			dataType: dataType,
163			type: type,
164			success: function (response) {
165				if (typeof callbackFunction === 'function') {
166					callbackFunction(response);
167				}
168			}
169		});
170	}
171
172	UP.Services.silentAjaxPostCall = function (fullUrl, dataObj, callbackFunction) {
173		return silentAjaxCall(fullUrl, dataObj, callbackFunction,'post', 'json');
174	};
175	
176})();

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.