PageSourceSearch

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

js lojaintt.com.br collected 2026-09-26 10:10:17 UTC 3,965 bytes, 180 lines download raw bytes

1/*
2Como utilizar:
3
4Definir parametros:
5	var param = {
6		var1: 'valor 1',
7		var2: {
8			attr1: 'atributo 1',
9			attr2: 'atributo 2'
10		}
11	}
12
13Chamar a função:
14	var meuTpl = template.getTemplate = function ('caminho/nome_do_arquivo', params);
15
16Como fica: 
17	No template: 
18	<span>{{var1}}</span>
19	<span>{{var2.attr1}}</span>
20	<span>{{var2.attr2}}</span>
21
22	Resultado:
23	<span>valor 1</span>
24	<span>atributo 1</span>
25	<span>atributo 2</span>
26
27*/
28
29var template = [];
30
31// Urls
32var ajaxTemplateService = helper.getBaseUrl() + '/ajax/services/template.php';
33
34template.getRawTemplatesAjax = function () {
35	templateData = {
36		act: 'gettemplates'
37	}
38
39	loading.show();
40	ajax.enqueue(ajax.POST, ajaxTemplateService, templateData, 'template.formatResponse');
41}
42
43template.getRawTemplates = function () {
44	if (typeof rawTemplates === 'undefined' || !rawTemplates) {
45		return null;
46	}
47
48	return rawTemplates;
49}
50
51template.loadTpls = function () {
52	$(document).ready(function () {
53		$(document).trigger('templates.loading');
54
55		var tpls = template.getRawTemplates();
56		if (!helper.isEmpty(tpls)) {
57			template.setTemplates(tpls);
58		} else {
59			template.getRawTemplatesAjax();
60		}
61	});
62}
63
64template.loadAjaxFunctionTpls = function () {
65	if (!window.isCacheable) {
66		$(document).ready(function () {
67			template.executeCodificatedAjax();
68		});
69	}
70
71	$(document).on("ajaxcache.needupdate", function(event) {
72		template.executeCodificatedAjax();
73
74		if (event.url != undefined) {
75			$(document).on('ajaxcache.redirect', function() {
76				window.location.href = event.url;
77			});
78		}
79	});
80}
81
82template.executeCodificatedAjax = function() {
83	let codes = [];
84
85	$(document).trigger("ajaxcache.started");
86
87	$('.ajaxFunction').each(function(i, e) {
88		codes.push(e.attributes.code.value);
89	});
90
91	var data = {
92		act: 'executecodificatedfunction',
93		code: codes
94	}
95
96	ajax.send(ajax.POST, ajaxTemplateService, data, 'template.appendAjaxResult');
97
98}
99
100template.appendAjaxResult = function(response) {
101	if (response.error) {
102		return;
103	}
104
105	let needsLazyLoad = false;
106	$(response.data.data).each(function(i ,e)  {
107		let content = e.content;
108		let code = e.code;
109
110		var responses = null;
111		if (window.isCacheable != undefined && window.isCacheable) {
112			responses = $(`[code=${code}]`).html(content);
113		} else {
114			responses = $(`[code=${code}]`).replaceWith(content);
115		}
116
117		if (typeof content != 'undefined' && content.includes('data-src')) {
118			needsLazyLoad = true;
119		}
120	
121		responses.find('script').each(function(){
122			eval($(this).text());
123		});
124	});
125
126	//esse tratamento é para somente lojas que tenham o lazy loading, é chamado o loadIamges pois após a imagem
127	//ser carregada pela resposta do ajax ela precisa ser iniciada pelo lazy loading para ser exibida
128	if (typeof lazyLoad != 'undefined' && needsLazyLoad) {
129		lazyLoad.loadImages();
130	}
131
132	$(document).trigger("ajaxcache.ended");
133}
134
135template.formatResponse = function(response) {
136	loading.hide();
137	if (response.error) {
138		console.error('Não foi possível carregar os templates');
139		console.error(response);
140		return;
141	}
142
143	var _response = response.data.data;
144	var _tpls = 'templates' in _response ? _response.templates : null;
145
146	if (_tpls == null) {
147		return null;
148	}
149
150	template.setTemplates(_tpls);
151}
152
153template.setTemplates = function(templates) {
154	ajax.busy = true;
155	$.each(templates, function (key, tpl) {
156		template[key] = tpl;
157	})
158	ajax.busy = false;
159
160	$(document).trigger('templates.loaded');
161}
162
163template.getTemplate = function (key, params) {
164	if (typeof(template[key]) === 'undefined') {
165		return null;
166	}
167	params = params || {};
168	output = Mustache.render(template[key], params);
169
170	return output;
171}
172
173template.hasTemplate = function(key) {
174	return typeof(template[key]) !== 'undefined';
175}
176
177$(function() {
178	template.loadTpls();
179	template.loadAjaxFunctionTpls();
180});

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.