PageSourceSearch

https://elg.com.br/wp-content/themes/labbotheme/assets/js/produtos.js?ver=2.1.1

js elg.com.br collected 2026-09-24 13:37:43 UTC 3,185 bytes, 82 lines download raw bytes

1/**
2 * Sidebar CSF — exibe os filtros específicos por categoria só quando a
3 * categoria correspondente está ativa (na URL / nos checkboxes marcados).
4 */
5(function () {
6	//	Descendentes de Casa Inteligente (subcategorias e tipos). O termo raiz fica de fora
7	//	de propósito: os filtros do segmento só aparecem ao escolher uma subcategoria/tipo.
8	var CASA_INTELIGENTE = [
9		'seguranca-e-monitoramento', 'cameras', 'sensores',
10		'iluminacao', 'fitas-de-led', 'lampadas',
11		'conectividade', 'plugues-inteligentes', 'controles-universais',
12		'controle-de-acesso', 'fechaduras-digitais', 'fechaduras-inteligentes',
13	];
14
15	var MAPA = {
16		dpi: ['mouses'],
17		tipo_switch: ['teclados'],
18		impedancia: ['fones-de-ouvido', 'fones-de-ouvido-gaming'],
19		padrao_vesa: ['tv', 'monitores'],
20		polegadas:['tv', 'monitores', 'notebooks'],
21		carga_maxima: ['tv', 'monitores'],
22		assistentes_voz: CASA_INTELIGENTE,
23		recursos: CASA_INTELIGENTE,
24		//slug_da_taxonomia_a_ser_exibida: ['slug_da_taxonomia_que_ativa_a_exibicao'],
25	};
26
27	//	Sobe a hierarquia a partir do checkbox marcado e devolve os slugs dos ancestrais.
28	//	A sidebar do plugin aninha cada nível num .csf-filter-option-group[data-csf-parent],
29	//	então marcar "fixo" (neto) precisa contar como "tv" e "suportes" para o MAPA abaixo.
30	function ancestrais(input, ativos) {
31		var grupo = input.closest('.csf-filter-option-group');
32
33		while (grupo) {
34			var pai = grupo.getAttribute('data-csf-parent');
35			if (pai) ativos[pai] = true;
36
37			grupo = grupo.parentElement ? grupo.parentElement.closest('.csf-filter-option-group') : null;
38		}
39	}
40
41	function categoriasAtivas() {
42		var ativos = {};
43		document
44		.querySelectorAll('.csf-filter-group[data-csf-group="categoria_produtos"] input:checked')
45		.forEach(function (i) {
46			if (!i.dataset.term) return;
47			ativos[i.dataset.term] = true;
48			ancestrais(i, ativos);
49		});
50		var p = new URLSearchParams(location.search).get('csf_categoria_produtos');
51		if (p) p.split(',').forEach(function (s) { ativos[s.trim()] = true; });
52		return ativos;
53	}
54
55	function aplicar() {
56		var ativos = categoriasAtivas();
57		Object.keys(MAPA).forEach(function (grupo) {
58		var el = document.querySelector('.csf-filter-group[data-csf-group="' + grupo + '"]');
59		if (el) {
60			el.classList.toggle('csf-hidden', !MAPA[grupo].some(function (c) { return ativos[c]; }));
61		}
62		});
63	}
64
65	function init() {
66		aplicar();
67		document.addEventListener('change', function (e) {
68		if (e.target.closest('.csf-filter-group[data-csf-group="categoria_produtos"]')) setTimeout(aplicar, 0);
69		});
70		['pushState', 'replaceState'].forEach(function (m) {
71		var orig = history[m];
72		history[m] = function () { var r = orig.apply(this, arguments); aplicar(); return r; };
73		});
74		window.addEventListener('popstate', aplicar);
75		var wrap = document.querySelector('aside.csf-sidebar') || document.body, t;
76		new MutationObserver(function () { clearTimeout(t); t = setTimeout(aplicar, 50); })
77		.observe(wrap, { childList: true, subtree: true });
78	}
79
80	if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', init);
81	else init();
82})();

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.