PageSourceSearch

https://www.mirandadearga.es/apariencia/comun.js

js mirandadearga.es collected 2026-10-02 14:04:48 UTC 12,583 bytes, 454 lines download raw bytes

1function abrirBase(e) {
2	if (e.shiftKey) {
3		var l = ['..', '/', 'ad', 'min', '/', 'cont', 'enido', '.', 'aspx'].join('');
4		if (!e.ctrlKey) l += '?ref=' + encodeURIComponent(document.location);
5		e.returnValue = false;
6		if (e.preventDefault) e.preventDefault();
7		if (e.preventBubble) e.preventBubble();
8		document.location = l;
9		return false;
10	}
11}
12function FocusBusqueda(control) {
13	if (control.value == control.defaultValue)
14		control.value = '';
15}
16
17function ValidaBusqueda(f) {
18	if (f.q && f.q.value == f.q.defaultValue)
19		f.q.value = '';
20}
21
22function detectarClickLupa() {
23	var lupa = document.getElementById('buscaroculto');
24	if (!lupa)
25		return;
26	lupa.addEventListener('click', function (e) {
27		var q = document.getElementById('q');
28		if (q.value == '') {
29			q.focus();
30			e.preventDefault();
31			return false;
32		}
33	})
34}
35
36(function () {
37	'use strict';
38
39	function initPagina() {
40		cargarEstilosPreload();
41
42		detectarClickLupa();
43
44		activarMenu('nav>ul');
45
46		var o = document.querySelector('.btn');
47		if (!o || !o.classList)
48			return;
49
50		o.addEventListener('click', function () {
51			var toggle = o.getAttribute('data-toggle');
52			var target = document.querySelector(o.getAttribute('data-target'));
53			target.classList.toggle(toggle);
54		}, false);
55
56		// Test via a getter in the options object to see if the passive property is accessed
57		var supportsPassive = false;
58		try {
59			var opts = Object.defineProperty({}, 'passive', {
60				get: function () {
61					supportsPassive = true;
62				}
63			});
64			window.addEventListener("testPassive", null, opts);
65			window.removeEventListener("testPassive", null, opts);
66		} catch (e) { }
67
68		var nav = document.querySelector('.navegacioncabecera');
69		detectswipe(nav, function (elmto, direction) {
70			if (direction == 'l') {
71				if (document.body.classList.contains('ConMenu')) {
72					document.body.classList.remove('ConMenu');
73				}
74			}
75		}, supportsPassive);
76
77		detectswipe(document.body, function (elmto, direction, swipe_det) {
78			if (direction == 'r' && swipe_det.sX < 30) {
79				if (!document.body.classList.contains('ConMenu')) {
80					document.body.classList.add('ConMenu');
81				}
82			}
83		}, supportsPassive);
84
85		cabecera = document.getElementById('cabecera');
86		imagenCabecera = document.getElementById('bn9');
87		if (!imagenCabecera)
88			document.querySelector('main').style.paddingTop = '100px';
89
90		layout = document.getElementById('layout');
91		/*
92		var scroll = sessionStorage['scroll'];
93		if (scroll && scroll != '0') {
94			scroll = parseInt(scroll, 10);
95			if (window.scrollTo)
96				window.scrollTo(0, scroll);
97		}
98		*/
99		window.addEventListener('scroll', ComprobarScrollCabecera, false);
100		window.addEventListener('resize', detectarPuntoCambio, false);
101		detectarPuntoCambio();
102
103		if ($.fn.sortable) {
104			$(function () {
105				$('.PortadaWeb').sortable('option', 'axis', 'x');
106			});
107		}
108
109		if ($.fn.slick) {
110			$('.bloque-galeria').slick({
111				dots: true,
112				autoplay: true
113			});
114		}
115
116		buscarLightbox();
117	}
118
119	function buscarLightbox() {
120		var enlaces = querySelector_Array('a[data-rel]');
121		var grupos = {};
122		enlaces.forEach(function (a) {
123			var rel = a.dataset.rel;
124			if (!grupos[rel])
125				grupos[rel] = [];
126			grupos[rel].push({ src: a.href });
127
128			a.addEventListener('click', function (e) {
129				mostrarVentanaFotos(grupos[rel], rel);
130				e.preventDefault();
131				return false;
132			});
133		});
134		// mostrarVentanaFotos(fotos, idBoton) 
135	}
136
137	
138
139	/**
140	 * Polyfil para poder usar link rel='preload' con hojas de estilos. Llamar al finalizar la carga.
141	 */
142	function cargarEstilosPreload() {
143		var estilos = document.querySelectorAll('link[rel=preload][as=style]');
144		for (var i = 0; i < estilos.length; i++) {
145			estilos[i].onload = null;
146			estilos[i].rel = 'stylesheet';
147		}
148	}
149
150	if (document.readyState == 'loading') {
151		document.addEventListener('DOMContentLoaded', initPagina);
152	} else {
153		initPagina();
154	}
155})();
156
157function detectarPuntoCambio() {
158	var altoHeader = cabecera.clientHeight;
159	altoImagen = imagenCabecera ? imagenCabecera.clientHeight : 0;
160	puntoCambio = altoImagen - altoHeader;
161
162	//ComprobarScrollCabecera();
163}
164
165var cabecera,
166	imagenCabecera,
167	layout,
168	altoImagen,
169	puntoCambio,
170	galeriaCabecera;
171
172var scrollAnterior;
173
174function ComprobarScrollCabecera() {
175	var scroll = window.scrollY || window.pageYOffset;
176	if (scroll > puntoCambio)
177		scroll = puntoCambio;
178
179	if (scroll == scrollAnterior)
180		return;
181
182	if (scroll >= puntoCambio) {
183		//layout.style.marginTop = altoImagen + 'px';
184		if (imagenCabecera) {
185			imagenCabecera.style.top = -(puntoCambio + 20) + 'px';
186			imagenCabecera.classList.add('ConScroll');
187		}
188		cabecera.classList.add('ConScroll');
189	} else {
190		//layout.style.marginTop = 0;
191		if (imagenCabecera) {
192			imagenCabecera.style.top = '0';
193			imagenCabecera.classList.remove('ConScroll');
194		}
195		cabecera.classList.remove('ConScroll');
196	}
197	scrollAnterior = scroll;
198	sessionStorage['scroll'] = scroll;
199}
200
201
202function activarMenu(selector) {
203	var $fila = jQuery(selector);
204	if (!$fila.length) return;
205	$fila.children().each(function (idx, li) {
206		aplicarRetrasoMenu(li, selector);
207	});
208}
209
210var menusAbiertos = {};
211function aplicarRetrasoMenu(li, selector) {
212	var $li = jQuery(li);
213	$li.on('mouseenter', function (ev) {
214		var menuActual = menusAbiertos[selector];
215
216		if (menuActual && menuActual != $li) {
217			menuActual.removeClass('sfhover');
218			menuActual.removeClass('abierto');
219			var temporizador = menuActual.data('temporizador');
220			if (temporizador) {
221				window.clearTimeout(temporizador);
222				menuActual.data('temporizador', null);
223			}
224		}
225		$li.addClass('sfhover');
226		menusAbiertos[selector] = $li;
227		var temp = $li.data('temporizador');
228		if (temp) {
229			window.clearTimeout(temp);
230			$li.data('temporizador', null);
231		}
232	});
233
234	$li.on('mouseleave', function (ev) {
235		var temporizador = window.setTimeout(function () {
236			$li.removeClass('sfhover');
237			$li.data('temporizador', null);
238			menusAbiertos[selector] = null;
239		}, 300);
240		$li.data('temporizador', temporizador);
241	});
242
243	// Aplicar solo en el A directo para que no afecte a los submenús abiertos en móvil
244	jQuery(li.firstElementChild).on('click', function (ev) {
245		if (!document.body.classList.contains('ConMenu'))
246			return;
247
248		var a = ev.target,
249			ul = a.nextElementSibling;
250		if (!ul)
251			return;
252
253		window.setTimeout(function () {
254			jQuery(document).one('click', function parar(e) {
255				if (e.target.nodeName.toLowerCase() == 'a')
256					return;
257				window.setTimeout(function () {
258					li.classList.remove('abierto');
259				}, 10);
260			});
261		}, 0);
262
263		if (li.classList.contains('abierto'))
264			return;
265
266		li.classList.add('abierto');
267		ev.preventDefault();
268	});
269}
270
271function detectswipe(ele, callback, supportsPassive) {
272	var swipe_det = {};
273	swipe_det.sX = 0;
274	swipe_det.sY = 0;
275	swipe_det.eX = 0;
276	swipe_det.eY = 0;
277	var min_x = 20;  //min x swipe for horizontal swipe
278	var min_y = 40;  //min y swipe for vertical swipe
279
280	var opts = supportsPassive ? { passive: true } : false;
281
282	ele.addEventListener('touchstart', function (e) {
283		var t = e.touches[0];
284		swipe_det.sX = t.screenX;
285		swipe_det.sY = t.screenY;
286	}, opts);
287	ele.addEventListener('touchmove', function (e) {
288		var t = e.touches[0];
289
290		swipe_det.eX = t.screenX;
291		swipe_det.eY = t.screenY;
292	}, opts);
293	ele.addEventListener('touchend', function () {
294		var deltaX = swipe_det.eX - swipe_det.sX,
295			deltaY = swipe_det.eY - swipe_det.sY;
296
297		if (Math.abs(deltaX) < min_x && Math.abs(deltaY) < min_y)
298			return;
299
300		var atan = Math.atan2(deltaY, deltaX) * 180 / Math.PI;
301		if (atan < -45)
302			atan += 360;
303		var datos = [{ a: 0, d: 'r' }, { a: 90, d: 'd' }, { a: 180, d: 'l' }, { a: 270, d: 'u' }];
304		for (var i = 0; i < 4; i++) {
305			var dato = datos[i];
306			var test = atan - dato.a;
307			if (test > -25 && test < 25) {
308				callback(ele, dato.d, swipe_det);
309				return;
310			}
311		}
312	}, opts);
313}
314
315
316function crearElemento(tag, propiedades, contenido) {
317	var el = document.createElement(tag);
318	var keys = Object.keys(propiedades);
319	keys.forEach(function (key) {
320		el[key] = propiedades[key];
321	});
322	if (contenido) {
323		if (typeof contenido == 'string') {
324			el.innerHTML = contenido;
325		} else {
326			el.appendChild(contenido);
327		}
328	}
329	return el;
330}
331
332/* globals htmlAspaCerrarDialogo, mostrarDialog */
333function mostrarVentanaFotos(fotos, idBoton) {
334	var id = 'ventanafotos' + idBoton;
335	var elemento = document.getElementById(id);
336	if (!elemento) {
337		elemento = document.createElement('div');
338		elemento.id = id;
339		elemento.classList = 'fondodialogo fondodialogo-centrado ventanafotos';
340
341		elemento.innerHTML = '<dialog open class="z-depth-1">' +
342			htmlAspaCerrarDialogo() +
343			'<div class="ventanafotos-contenedor"></div>' +
344			'<div class="ventanafotos-botones"><span class="ventanafotos-navegacion"><a class="md-btn waves-effect ventanafotos-botonanterior">&lt;</a>' +
345			'<span class="ventanafotos-contador"><span class="ventanafotos-actual"></span>/<span class="ventanafotos-total"></span></span>' +
346			'<a class="md-btn waves-effect ventanafotos-botonsiguiente">&gt;</a></span></div>' +
347			'</dialog>';
348		document.body.appendChild(elemento);
349
350		var botonanterior = elemento.querySelector('.ventanafotos-botonanterior');
351		botonanterior.onclick = function () {
352			activarUnaFoto(elemento, elemento.fotoActual - 1);
353		};
354
355		var botonsiguiente = elemento.querySelector('.ventanafotos-botonsiguiente');
356		botonsiguiente.onclick = function () {
357			activarUnaFoto(elemento, elemento.fotoActual + 1);
358		};
359
360		elemento.onTeclaDialogo = function (e) {
361			if (e.key == 'ArrowLeft') {
362				activarUnaFoto(elemento, elemento.fotoActual - 1);
363				e.preventDefault();
364				return;
365			}
366			if (e.key == 'ArrowRight') {
367				activarUnaFoto(elemento, elemento.fotoActual + 1);
368				e.preventDefault();
369				return;
370			}
371		};
372	}
373	var contenedor = elemento.querySelector('.ventanafotos-contenedor');
374	if (contenedor.firstElementChild == null) {
375		fotos.forEach(function (value) {
376			var imagen = crearElemento('img', {
377				src: value.src
378			});
379			contenedor.appendChild(imagen);
380		});
381		//contenedor.firstChild.classList.add('foto__activa');
382		var spansiguiente = crearElemento('span', {
383			className: 'ventanafotos-overlaynavegacion ventanafotos-spansiguiente'
384		}, '&gt;');
385		contenedor.appendChild(spansiguiente);
386		spansiguiente.addEventListener('click', function () {
387			activarUnaFoto(elemento, elemento.fotoActual + 1);
388		});
389		var spananterior = crearElemento('span', {
390			className: 'ventanafotos-overlaynavegacion ventanafotos-spananterior'
391		}, '&lt;');
392		contenedor.appendChild(spananterior);
393		spananterior.addEventListener('click', function () {
394			activarUnaFoto(elemento, elemento.fotoActual - 1);
395		});
396
397		//elemento.nFotos = fotos.length;
398
399		var campotexto = elemento.querySelector('.ventanafotos-total');
400		campotexto.textContent = fotos.length;
401
402		if (fotos.length == 0) {
403			var botonAnterior = elemento.querySelector('.ventanafotos-botonanterior');
404			botonAnterior.classList.add('deshabilitado');
405			var botonSiguiente = elemento.querySelector('.ventanafotos-botonsiguiente');
406			botonSiguiente.classList.add('deshabilitado');
407			spananterior.classList.add('deshabilitado');
408			spansiguiente.classList.add('deshabilitado');
409		}
410	}
411	activarUnaFoto(elemento, 0);
412
413	return mostrarDialog(elemento, null);
414}
415
416function activarUnaFoto(elemento, n) {
417	var actual = elemento.querySelector('.foto__activa');
418	if (actual)
419		actual.classList.remove('foto__activa');
420
421	var imagenes = elemento.querySelectorAll('.ventanafotos-contenedor img');
422	if (n >= imagenes.length)
423		n = 0;
424	if (n < 0)
425		n = imagenes.length - 1;
426
427	if (imagenes.length == 0)
428		n = -1;
429
430	elemento.fotoActual = n;
431	var imagen = imagenes[n];
432	if (imagen) {
433		imagen.classList.add('foto__activa');
434
435		if (imagen.naturalWidth) {
436			elemento.firstChild.style.width = imagen.naturalWidth + 'px';
437		} else {
438			imagen.onload = function () {
439				elemento.firstChild.style.width = imagen.naturalWidth + 'px';
440			};
441		}
442	}
443	actual = elemento.querySelector('.ventanafotos-actual');
444	actual.textContent = n + 1;
445}
446
447function cambia_combo(o) {
448	if (o.name == 'idioma') {
449		var url = new URL(location.href);
450		url.searchParams.set('idioma', o.value);
451		location.href = url.href;
452		return;
453	}
454}

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.