PageSourceSearch

https://www.lojaintt.com.br/common/js/ajax.js?v=1790252405

js lojaintt.com.br collected 2026-09-26 10:10:24 UTC 6,943 bytes, 335 lines download raw bytes

1/*
2 * Eventos de Ajax:
3 * 
4 * 'ajax.started' - Inicio da requisição:
5 * Evento disparado quando se inicia requisição que foi processada na fila
6 * 
7 * 'ajax.ended' - Fim da requisição:
8 * Evento disparado quando acaba requisição que foi processada na fila
9 */
10
11var ajax = {};
12
13ajax.POST = 1;
14ajax.GET = 2;
15
16ajax.checkTimeout;
17
18ajax.setup = function() {
19	if (ajax.loaded) {
20		return;
21	}
22
23	ajax.queue = [];
24	ajax.maxQueue = 10;
25	ajax.totalEnqueued = 0;
26	ajax.busy = false;
27	ajax.loaded = true;
28
29	ajax.form();
30	ajax.link();
31
32	ajax.processQueue();
33	ajax.loaded = true;
34	ajax.blockedCheck = false;
35
36	ajax.trackEvents();
37}
38
39ajax.isBusy = function() {
40	return ajax.busy;
41}
42
43ajax.hasEmptyQueue = function() {
44	return ajax.queue.length == 0;
45}
46
47ajax.enqueue = function(
48	method,
49	url,
50	data,
51	callback,
52	processData,
53	contentType
54) {
55	ajax.setup();
56
57	if (ajax.queue.length == ajax.maxQueue) {
58		return;
59	}
60
61	var request = {
62		_method: method,
63		_url: url,
64		_data: data,
65		_callback: callback,
66		_processData: processData,
67		_contentType: contentType
68	};
69
70	ajax.queue.push(request);
71	ajax.totalEnqueued++;
72}
73
74ajax.checkBackdrop = function() {
75	if (!backdrop || ajax.blockedCheck) {
76		return;
77	}
78
79	if (ajax.isBusy()) {
80		backdrop.show();
81		clearTimeout(ajax.checkTimeout);
82	} else {
83		ajax.checkTimeout = setTimeout(function() {
84			if (ajax.isBusy() || ajax.blockedCheck) {
85				return;
86			}
87
88			backdrop.hide();
89		}, 500);
90	}
91}
92
93ajax.forcedBusy = function() {
94	ajax.blockedCheck = true;
95	backdrop.show();
96}
97
98ajax.removeForcedBusy = function() {
99	backdrop.hide();
100	ajax.blockedCheck = false;
101}
102
103ajax.processQueue = function() {
104	setInterval(function() {
105		if (ajax.isBusy() || ajax.hasEmptyQueue()) {
106			return;
107		}
108
109		var nextRequest = $(ajax.queue).first()[0];
110		ajax.queue.shift();
111
112		ajax.send(
113			nextRequest._method,
114			nextRequest._url,
115			nextRequest._data,
116			nextRequest._callback,
117			nextRequest._contentType,
118			nextRequest._processData
119		);
120	}, 100);
121}
122
123ajax.send = function(
124	method,
125	url,
126	data,
127	callback,
128	contentType,
129	processData
130) {
131	var link = url;
132	var values = data;
133	var defaultError = 'Houve um problema ao processar sua requisição, tente novamente mais tarde.';
134
135	if (method == ajax.POST) {
136		method = "POST";
137	} else {
138		method = "GET";
139	}
140
141	if (contentType == 'undefined') {
142		contentType = 'application/x-www-form-urlencoded; charset=UTF-8';
143	}
144
145	if (processData == 'undefined') {
146		processData = true;
147	}
148
149	ajax.busy = true;
150	$(document).trigger("ajax.started");
151
152	$.ajax({
153		url: link,
154		type: method,
155		data: values,
156		dataType: "json",
157		async: true,
158		contentType: contentType,
159		processData: processData,
160		success: function(data) {
161			var finalData = null;
162			callback = callback || null;
163			if (typeof X !== 'undefined' && typeof X.json !== 'undefined' && data.data && typeof data.data.type !== 'undefined') {
164				X.json(data);
165			} else {
166				finalData = {
167					"error": false,
168					"data": data
169				};
170			}
171
172			ajaxutils.executeFunctionByName(callback, window, finalData);
173
174			ajax.busy = false;
175			$(document).trigger("ajax.ended");
176		},
177		error: function(request) {
178			var finalData = {};
179			finalData.error = true;
180			finalData.message = typeof request.responseJSON === 'object' ? request.responseJSON.message : defaultError;
181			finalData.callback = typeof request.responseJSON === 'object' ? request.responseJSON.callback : null;
182
183			callback = callback || null;
184			ajaxutils.executeFunctionByName(callback, window, finalData);
185
186			ajax.busy = false;
187			$(document).trigger("ajax.ended");
188		}
189	});
190
191	return false;
192}
193
194ajax.link = function() {
195	var selector = "a[data-href],button[data-href],input[data-href],label[data-href]";
196	var event = "click";
197	var urlSource = "data-href";
198	var askSource = "data-ask";
199	var askModalSource = "data-ask-modal";
200	var callbackSource = "data-callback";
201	var askActionSource = "data-ask-action";
202	var askParamsSource = "data-ask-params";
203	var templateSource = "data-template-selector";
204
205	ajax.makeLink(selector);
206
207	$(document).on(event, selector, function(e) {
208		var url = $(this).attr(urlSource);
209		var ask = $(this).attr(askSource);
210		var callback = $(this).attr(callbackSource);
211		var askModal = $(this).attr(askModalSource);
212		var askAction = $(this).attr(askActionSource);
213		var askParams = $(this).attr(askParamsSource);
214		var templateSelector = $(this).attr(templateSource) || '#msgModalTemplate';
215
216		if (askModal) {
217			ajaxutils.showAskModal(askModal, url, askAction, askParams, callback, templateSelector);
218			return false;
219		} else if (ask && !confirm(ask)) {
220			return false;
221		}
222
223		ajax.enqueue(ajax.GET, url, null, callback);
224		return false;
225	});
226}
227
228ajax.form = function() {
229	ajax.formButton();
230	ajax.formInput();
231
232	var selector = "form[data-action]";
233	var event = "submit";
234	var urlSource = "data-action";
235	var encodeSource = "data-encode";
236	var callbackSource = "data-callback";
237	
238	var additionalSource = "additional-form-data";
239	var additionalRemoveSource = "additional-form-data-remove";
240
241	$(document).on(event, selector, function(e) {
242		var url = $(this).attr(urlSource);
243		var encode = $(this).attr(encodeSource);
244		var callback = $(this).attr(callbackSource);
245		var additional = $(this).attr(additionalSource);
246		var additionalRemove = $(this).attr(additionalRemoveSource);
247		
248		var data = $(this).serialize();
249		var method = $(this).attr("method");
250
251		if (additional) {
252			var additionalData = ajaxutils.getFormData(additional, additionalRemove);
253			data += "&" + additionalData;
254		}
255
256		if (encode == "true") {
257			data = "encode=" + btoa(data);
258		}
259
260		if (method == "get" || !method) {
261			method = ajax.GET;
262			url += "?" + data;
263			data = null;
264		} else {
265			method = ajax.POST;
266		}
267
268		ajax.enqueue(method, url, data, callback);
269
270		e.preventDefault();
271		return false;
272	});
273}
274
275ajax.formButton = function() {
276	var selector = "[data-submit]";
277	var event = "click";
278
279	$(document).on(event, selector, function(e) {
280		var formSelector = $(this).attr("data-submit");
281
282		if (formSelector.length > 0) {
283			$(formSelector).submit();
284		} else {
285			$(this).closest("form").submit();
286		}
287
288		$('[data-remove-freight]').click();
289
290		e.preventDefault();
291		return false;
292	});
293}
294
295ajax.formInput = function() {
296	var selector = "form[data-action] input";
297	var event = "keypress";
298
299	$(document).on(event, selector, function(e) {
300		var form = this.form;
301		var enterKey = e.which == 13;
302		var allowSubmit = helper.hasAttr(form, 'data-allow-submit');
303
304		if (allowSubmit && enterKey) {
305			$(form).submit();
306			return false;
307		} else if (enterKey) {
308			e.stopPropagation();
309			e.preventDefault();
310			return false;
311		}
312	});
313}
314
315ajax.makeLink = function(selector) {
316	var links = $(selector);
317
318	if (links.length == 0) {
319		return;
320	}
321
322	links.each(function() {
323		$(this).attr("href", "javascript:void(0)");
324	});
325}
326
327ajax.trackEvents = function() {
328	$(document).on('ajax.started ajax.ended', function() {
329		ajax.checkBackdrop();
330	});
331}
332
333$(function(){
334	ajax.setup();
335});

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.