PageSourceSearch

https://www.arteche.com/themes/custom/bilbomatica/js/facets.js?tm8grx

js arteche.com collected 2026-10-02 10:36:20 UTC 7,291 bytes, 268 lines download raw bytes

1jQuery(document).ready(function() {
2	// facetas();
3
4	selectorProductoDocs();
5});
6
7function selectorProductoDocs() {
8	var categoriasIds = [],
9		idiomaId = jQuery('#idioma-docs option:selected').val(),
10		total = {};
11
12	jQuery.each(jQuery("input[name='categorias']:checked"), function(){
13		categoriasIds.push(jQuery(this).val());
14	});
15
16	categoriasIds.forEach((item) => {
17		total[item] = 0;
18	})
19
20	jQuery('.catsCheckTotal').on('change', function() {
21		jQuery('.catsCheck').prop('checked', this.checked).trigger('change');
22	});
23
24	jQuery('.catsCheck').on('change', function() {
25		var val = jQuery(this).val(),
26			allChecked = jQuery('.catsCheck:checked').length == jQuery('.catsCheck').length,
27			rows = jQuery('.atc-tabla-defecto').find(`tr[data-idioma-id='${idiomaId}'][data-categoria-id='${val}']`);
28
29		if (this.checked) {
30			categoriasIds.push(val);
31			rows.show();
32		} else {
33			var index = categoriasIds.indexOf(val);
34
35			if (index !== -1) categoriasIds.splice(index, 1);
36			rows.hide();
37		}
38
39		jQuery('.catsCheckTotal').prop('checked', allChecked);
40	});
41
42	jQuery('#idioma-docs').on('change', function() {
43		var newIdiomaId = jQuery(this).val(),
44			allRows = jQuery('.atc-tabla-defecto').find(`tr`),
45			rows = jQuery('.atc-tabla-defecto').find(`tr[data-idioma-id='${newIdiomaId}']`),
46			numSpTotal = jQuery(`.num-sp-total`),
47			counts = {},
48			totalNum = 0;
49
50		idiomaId = newIdiomaId;
51		allRows.hide();
52		rows.each(function(index) {
53			var dataCategoriaId = jQuery(this).attr('data-categoria-id');
54				
55			if (categoriasIds.includes(dataCategoriaId)) {
56				jQuery(this).show();
57			} else {
58				jQuery(this).hide();
59			}
60
61			counts[dataCategoriaId] = (counts[dataCategoriaId] || 0) + 1;
62		});
63
64		categoriasIds.forEach(function(categoriasId) {
65			var numSp = jQuery(`.num-sp-${categoriasId}`),
66				num = counts[categoriasId]? counts[categoriasId] : 0;
67
68			numSp.html(num);
69			totalNum = totalNum + num;
70		});
71
72		numSpTotal.html(totalNum);
73	});
74}
75
76
77
78
79
80
81
82
83
84
85
86function facetas() {
87	jQuery(".catsCheck").each(function() { 
88		jQuery(this).click(function() {
89			ocultaTodo();
90			if(jQuery(this).hasClass("todas")) {
91				if(jQuery(this).is(':checked')) {
92					mostrarTodas();
93				} else {
94					var catsSeleccionadas=obtenerCategoriasSeleccionadas();
95					var idioma=jQuery("#idioma_documento option:selected").val();
96					for(i=0;i<catsSeleccionadas.length;i++) {
97						var idCat=catsSeleccionadas[i];
98						jQuery(".divCats").each(function() {
99							if((jQuery(this).hasClass(idCat) && jQuery(this).prev().hasClass(idioma)) || (jQuery(this).hasClass(idCat) && jQuery("#idioma_documento").val()=="all"))  {
100								jQuery(this).parent().parent().show();
101							} else {
102								jQuery(this).parent().parent().hide();
103							}
104						});
105					}
106				}
107			} else {
108				/*TIENE QUE MOSTRAR LAS QUE CONTENGA CUALQUIERA DE LAS MARCADAS --> REVISAR */
109				jQuery(".todas").prop("checked",false);
110				var catsSeleccionadas=obtenerCategoriasSeleccionadas();
111				var idioma=jQuery("#idioma_documento option:selected").val();
112
113				jQuery(".divCats").each(function() {
114					var tieneTodasCats=1;
115					for(i=0;i<catsSeleccionadas.length;i++) {
116						var idCat=catsSeleccionadas[i];
117						if(jQuery(this).hasClass(idCat)) {
118							tieneTodasCats++;
119						} else {
120							
121						}
122					}
123					if((tieneTodasCats>1 && jQuery(this).prev().hasClass(idioma)) || (tieneTodasCats>1 && jQuery("#idioma_documento").val()=="all"))  {
124						jQuery(this).parent().parent().show();
125					} else {
126						jQuery(this).parent().parent().hide();
127					}
128				});
129			}
130			
131		});
132	});
133	cambioIdioma();
134	contar();
135}
136function mostrarTodas() {
137	//quito los checks a todos
138	jQuery(".catsCheck").each(function() { 
139		jQuery(this).removeAttr("checked");
140	});
141	jQuery(".todas").prop("checked",true);
142
143	var idioma=jQuery("#idioma_documento option:selected").val();
144	jQuery("tr").each(function() {
145		if(jQuery("#documento_idioma",this).hasClass(idioma) || jQuery("#idioma_documento").val()=="all") {
146			jQuery(this).show();
147		} else {
148			jQuery(this).hide();
149		}
150	});
151}
152function cambioIdioma() {
153	jQuery("#idioma_documento").change(function() {
154		ocultaTodo();
155
156		if(jQuery(".todas").is(':checked')) {
157			mostrarTodas();
158		} else {
159			var catsSeleccionadas=obtenerCategoriasSeleccionadas();
160			var idioma=jQuery("#idioma_documento option:selected").val();
161			for(i=0;i<catsSeleccionadas.length;i++) {
162				var idCat=catsSeleccionadas[i];
163				jQuery(".divCats").each(function() {
164					if((jQuery(this).hasClass(idCat) && jQuery(this).prev().hasClass(idioma)) || (jQuery(this).hasClass(idCat) && jQuery("#idioma_documento").val()=="all"))  {
165						jQuery(this).parent().parent().show(); 
166					} else {
167						jQuery(this).parent().parent().hide();
168					}
169				});
170			}
171			if(catsSeleccionadas.length==0) {
172				jQuery(".divCats").each(function() {
173					if(jQuery(this).prev().hasClass(idioma) || jQuery("#idioma_documento").val()=="all") {
174						jQuery(this).prev().prev().show();
175					}
176				});
177			}
178		}
179		contar();
180	});
181
182	//pongo por defecto el idioma que tiene el usuario
183	var idioma=jQuery("#langH").val();
184	var idiomaCombo="";
185	switch(idioma) {
186		case "es": idiomaCombo="idIdioma_492";
187				break;
188		case "pt-pt": idiomaCombo="idIdioma_493";
189				break;
190		case "en": idiomaCombo="idIdioma_575";
191				break;
192		case "fr": idiomaCombo="idIdioma_495";
193				break;
194		case "de": idiomaCombo="idIdioma_496";
195				break;
196	}
197	jQuery("#idioma_documento option").each(function() {
198		jQuery(this).removeAttr("selected");
199	});
200	jQuery("#idioma_documento option[value='"+idiomaCombo+"']").attr("selected","selected").trigger("change");
201}
202function ocultaTodo() {
203	jQuery("table tr").each(function() {
204		jQuery(this).hide();
205	});
206}
207function obtenerCategoriasSeleccionadas() {
208	var arrayCats=new Array();
209	jQuery(".catsCheck").each(function() {
210	  if(jQuery(this).is(':checked')) {
211	    var valor=jQuery(this).val();
212	    arrayCats.push(valor);
213	  }
214	});
215	return arrayCats;
216}
217
218
219
220function contar() {
221	jQuery(".numSP").each(function() {
222		jQuery(this).remove();
223	});
224	var idioma=jQuery("#idioma_documento option:selected").val();
225	jQuery(".catsCheck").each(function() { 
226		var valor=jQuery(this).val();
227		var num=0;
228		jQuery(".col-md-8 ."+valor).each(function() {
229			if(jQuery(this).prev().hasClass(idioma) || jQuery("#idioma_documento").val()=="all") {
230				num++;
231			}
232		});
233		jQuery(this).next().html(jQuery(this).next().html()+" <span class='numSP'>("+num+")</span>");//hay que tener en cuenta el idioma
234	});
235
236	//el de todas lo cuento aparte
237	var numTodas=0;
238	jQuery(".numSP").each(function() {
239		var texto=jQuery(this).text();
240		texto=texto.replace("(","");
241		texto=texto.replace(")","");
242		var num=parseInt(texto);
243		numTodas=numTodas+num;
244	})
245	jQuery(".todas").next().find(".numSP").text("("+numTodas+")");
246
247	jQuery(".catsCheck").each(function() {
248		if(jQuery(this).is(':checked')) {
249			jQuery(this).parent().addClass("activo");
250		} else {
251			jQuery(this).parent().removeClass("activo");
252		}
253	});
254	ocultaNoresultados();
255}
256function ocultaNoresultados() {
257	//oculta las categorías en las facets de productos que tienen como suma 0 elementos
258	if(jQuery("#lCategorias").length>0) {
259		jQuery("#lCategorias li").each(function() {
260			var num=jQuery(".numSP",this).text();
261			if(num=="(0)") {
262				jQuery(this).hide();
263			} else {
264				jQuery(this).show();
265			}
266		});
267	}
268}

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.