PageSourceSearch

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

js lojaintt.com.br collected 2026-09-26 10:10:15 UTC 9,736 bytes, 413 lines download raw bytes

1var helper = {};
2
3// 
4helper.moneyFormat = function(value) {
5	if (value == null) {
6		return;
7	}
8	var result = null;
9	if (value == 0) {
10		result = "Gratuito";
11		return result;
12	}
13	if (value == null) {
14		return "--"
15	}
16	if (typeof value === 'string') {
17		value = +value;
18	}
19	var options = {
20		style: 'currency',
21		currency: 'BRL',
22		minimumFractionDigits: 2,
23		maximumFractionDigits: 2
24	}
25
26	result = value.toLocaleString('pt-BR', options);
27
28	return result;
29}
30
31helper.getBaseUrl = function () {
32	var _url = window.location;
33	if (_url.host == "www.devserver" || _url.host == "devserver") {
34		return _url.protocol + "//" + _url.host + "/" + _url.pathname.split('/')[1] + "/" + _url.pathname.split('/')[2];
35	}
36	if (_url.host == "www.localhost" || _url.host == "localhost") {
37		return _url.protocol + "//" + _url.host + "/" + _url.pathname.split('/')[1];
38	}
39	if (_url.host == "www.dockerdev" || _url.host == "dockerdev") {
40		return _url.protocol + "//" + _url.host + "/" + _url.pathname.split('/')[1];
41	}
42	if (_url.host == "www.servidor" || _url.host == "servidor") {
43		return _url.protocol + "//" + _url.host + "/" + _url.pathname.split('/')[1];
44	}
45	if (_url.host == "www.dockerdev" || _url.host == "dockerdev") {
46		return _url.protocol + "//" + _url.host + "/" + _url.pathname.split('/')[1];
47	}
48	if (_url.host.slice(-9) == "dockerdev") {
49		return _url.protocol + "//" + _url.host + "/" + _url.pathname.split('/')[1];
50	}
51	if (_url.host.slice(-9) == "devserver") {
52		return _url.protocol + "//" + _url.host + "/" + _url.pathname.split('/')[1] + "/" + _url.pathname.split('/')[2] + "/" + _url.pathname.split('/')[3];
53	}
54	if (_url.host == "www.dev.liveecommerce.com.br") {
55		if (_url.pathname.indexOf('developers') != -1) {
56			return _url.protocol + "//" + _url.host + "/" + _url.pathname.split('/')[1] + "/" + _url.pathname.split('/')[2] + "/" + _url.pathname.split('/')[3];
57		}
58		return _url.protocol + "//" + _url.host + "/" + _url.pathname.split('/')[1];
59	}
60	
61	return _url.protocol + "//" + _url.host;
62}
63
64helper.getUrlParams = function () {
65	var queryString = window.location.search;
66	var keyValPairs = [];
67	var params = {};
68	queryString = queryString.replace(/.*?\?/,"");
69
70	if (queryString.length) {
71		keyValPairs = queryString.split('&');
72		for (pairNum in keyValPairs) {
73			var key = keyValPairs[pairNum].split('=')[0];
74			if (!key.length) continue;
75
76			if (typeof params[key] === 'undefined')
77				params[key] = [];
78
79			params[key].push(keyValPairs[pairNum].split('=')[1]);
80		}
81	}
82	return params;
83}
84
85helper.redirect = function (url) {
86	if (window.isCacheable) {
87		$(document).on('ajaxcache.ended', () => {
88			window.location.href = url;
89		});
90
91		$(document).trigger({type: "ajaxcache.needupdate", url: url});
92
93		return;
94	}
95
96	window.location.href = url;
97}
98
99helper.getFormData = function($form) {
100	var unindexedArray = $form.serializeArray();
101	var indexedArray = {};
102
103	$.map(unindexedArray, function(n, i) {
104		indexedArray[n['name']] = n['value'];
105	});
106
107	return indexedArray;
108}
109
110helper.htmlEncode = function(value) {
111	return $('<div/>').text(value).html();
112}
113
114helper.htmlDecode = function(value) {
115	return $('<div/>').html(value).text();
116}
117
118helper.isCartPage = function () {
119	var cartPage = $("#cart-page");
120	return cartPage.length == 0 ? false : true;
121}
122
123helper.isCheckoutPage = function () {
124	var checkoutPage = $("#checkout-page");
125	if (checkoutPage.length == 0){
126		return false;
127	}
128	return true;
129}
130
131helper.isSummaryPage = function () {
132	var summaryPage = $("#summary-page");
133
134	if (summaryPage.length == 0){
135		return false;
136	}
137	return true;
138}
139
140
141helper.viewUrl = function(targetElement, urlViewer, section) {
142	$(document).on('input', targetElement, function () {
143		$(section).show();
144
145		let url = $(targetElement).val();
146
147		if (!url) {
148			$(section).hide();
149			return;
150		}
151
152		try {
153			url = new URL(url);
154		} catch (e) {
155			fixedText = $(urlViewer).attr('fixed-text');
156			url = `${fixedText}${url}`;
157			$(targetElement).val(url);
158		}
159
160		$(urlViewer).text(`${url}`);
161	});
162};
163
164helper.defineCookie = function (name, value = "", days = 0) {
165	let expires = "";
166	if (days) {
167		let date = new Date();
168		date.setTime(date.getTime() + (days*24*60*60*1000));
169		expires = `; expires=${date.toUTCString()}`;
170	}
171
172	let cookie = `${name}=${value}${expires}; path=/`;
173	console.log(cookie);
174	document.cookie = cookie;
175}
176
177helper.getDate = function(addDays = 0) {
178	actualDate = new Date();
179
180	if (addDays <= 0) {
181		return actualDate.toLocaleDateString("pt-BR");
182	}
183
184	summedDate = new Date();
185	summedDate.setDate(actualDate.getDate() + addDays);
186	return summedDate.toLocaleDateString("pt-BR");
187}
188
189helper.getCookie = function(cookieName) {
190	let cookie = {};
191
192	document.cookie.split(';').forEach(function(element) {
193		let [key,value] = element.split('=');
194		cookie[key.trim()] = value;
195	});
196
197	return cookie[cookieName];
198}
199
200helper.isCustomerPage = function () {
201	var customerPage = $("#new-checkout.customer-panel");
202	if (customerPage.length == 0){
203		return false;
204	}
205	return true;
206}
207
208helper.getMonths = function () {
209	var months = {
210		'data': [
211			{ 'value': 1, 'display': '01' },
212			{ 'value': 2, 'display': '02' },
213			{ 'value': 3, 'display': '03' },
214			{ 'value': 4, 'display': '04' },
215			{ 'value': 5, 'display': '05' },
216			{ 'value': 6, 'display': '06' },
217			{ 'value': 7, 'display': '07' },
218			{ 'value': 8, 'display': '08' },
219			{ 'value': 9, 'display': '09' },
220			{ 'value': 10, 'display': '10' },
221			{ 'value': 11, 'display': '11' },
222			{ 'value': 12, 'display': '12' },
223		]
224	};
225	return months; 
226}
227
228helper.closeModal = function () {
229	$('.modal.fade').modal('hide');
230}
231
232helper.defineValidationRules = function(container, rules) {
233	var selectors = container + ' input, ' + container + ' select';
234
235	if ($(selectors).length == 0) {
236		return;
237	}
238
239	$(selectors).each(function() {
240		var name = $(this).attr('name');
241
242		if (typeof rules[name] !== 'undefined') {
243			$(this).rules('add', rules[name]);
244		}
245	});
246}
247
248// Verify if content is empty or null than if is an empty string
249helper.isEmpty = function (data) {
250    return (!data || 0 === data.length);
251}
252
253helper.functionExists = function (data) {
254	return typeof data === 'function';
255}
256
257helper.getBrowserName = function () {
258	var browserName = '';
259	var userAgent = navigator.userAgent;
260
261	if(userAgent.indexOf('Chrome') > -1) {
262		browserName = 'Google Chrome';
263	} else if (userAgent.indexOf('Safari') > -1) {
264		browserName = 'Apple Safari';
265	} else if (userAgent.indexOf('Opera') > -1) {
266		browserName = 'Opera';
267	} else if (userAgent.indexOf('Firefox') > -1) {
268		browserName = 'Mozilla Firefox';
269	} else if (userAgent.indexOf('MSIE') > -1) {
270		browserName = 'Microsoft Internet Explorer';
271	} else {
272		browserName = userAgent;
273	}
274
275	return browserName;
276}
277
278helper.getPlatform = function () {
279	return navigator.platform;
280}
281
282helper.inputValueCopy = function () {
283	var sourceSelector = '[data-value-source]';
284	
285	$(sourceSelector).each(function (index, element) {
286		var targetSelector = '[data-value-target="'+ element.name +'"]';
287		$(targetSelector).val(element.value);
288	});
289}
290
291helper.strstr = function (haystack, needle, inversed) {
292	var pos = 0;
293
294	haystack += "";
295	pos = haystack.indexOf(needle);
296	if (pos == -1) {
297		return false;
298	}
299
300	if (inversed) {
301		return haystack.substr(0, pos);
302	}
303
304	return haystack.slice(pos);
305}
306
307helper.exists = function(selector) {
308	if (helper.isEmpty(selector)) {
309		return false;
310	}
311
312	return $(selector).length > 0;
313}
314
315helper.hasAttr = function (context, name) {
316	var attr = $(context).attr(name);
317
318	return typeof attr !== typeof undefined && attr !== false;
319}
320
321helper.screenWidth = function () {
322	return (window.innerWidth > 0) ? window.innerWidth : screen.width;
323}
324
325helper.isObject = function (obj) {
326	return obj === Object(obj);
327}
328
329helper.isNumeric = function (n) {
330	return !isNaN(parseFloat(n)) && isFinite(n);
331}
332
333helper.dataCopy = function (targetButton, targetSelector) {
334	$(document).on('click', targetButton, function () {
335		keyCopy = $(targetSelector).attr("text-target");
336		try {
337			var keyElement = document.createElement('textarea');
338			keyElement.value = keyCopy;
339
340			keyElement.style.display = 'none !important';
341
342			document.body.appendChild(keyElement);
343			keyElement.select();
344			keyElement.setSelectionRange(0, 99999);
345
346			// Now that we've selected the anchor text, execute the copy command
347			document.execCommand('copy');
348			document.body.removeChild(keyElement);
349
350			alert("Copiado para a área de transferência: " + keyCopy);
351		} catch(err) {
352			console.log('Oops, unable to copy');
353		}
354
355		// Remove the selections - NOTE: Should use
356		// removeRange(range) when it is supported
357		window.getSelection().removeAllRanges();
358	});
359}
360
361helper.changeElementExhibition = function (selector, action) {
362	switch (action.toLowerCase()) {
363		case 'hide':
364			$(selector).hide();
365			break;
366		case 'show':
367			$(selector).show();
368			break;
369		default:
370			console.log('invalid action: ' + action + ', ' + selector);
371			break;
372	}
373}
374
375helper.downloadFile = function(url) {
376	window.location.href = url + '?forcesave=true&v=' + new Date().getTime();
377}
378
379helper.charCount = function(haystack, needle) {
380	if (!typeof haystack === "string" || !typeof needle === "string") {
381		return;
382	}
383
384	let trimedHaystack = haystack.trim();
385	let counter = 0;
386
387	for (let index = 0; index < trimedHaystack.length; index++) {
388		const element = trimedHaystack[index];
389
390		if (element === needle) {
391			counter++;
392		}
393	}
394
395	return counter;
396}
397
398helper.removeSpecialChars = function() {
399	$(document).on('keyup', '.form-control', function() {
400		if ($(this).attr('accept-special-chars') == "true") {
401			return;
402		}
403
404		var text = $(this).val();
405		var clearedText = text.replace(/[^a-zA-ZÀ-ú-0-9\-\_\@\.\(\)\s\"\'\:\/\\#\$\%]/g, '');
406		$(this).val(clearedText);
407
408	});
409}
410
411$(function() {
412	helper.removeSpecialChars();
413})

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.