Files
gureametsabilagun/wp-content/themes/gure-ametsa/assets/js/main.js
Josep Piguillem 9a6bcd56e5 Tema: nuevos botones, campos, casillas, tarjetas, selector, interruptor, cabecera y pie
- Botones: borde que se dibuja al pasar el ratón o con el teclado (color según variante) y sombra.
- Campos: subrayados con etiqueta flotante y degradado principal → acento al enfocar; flecha
  propia en los desplegables. Formularios de contacto, cuestionario y finales felices adaptados.
- Casillas: marca «a mano» que se dibuja al marcarlas (ga_checkmark()), accesibles con teclado.
- Tarjetas de animales y finales felices: marco de 2 px con resplandor de acento en la esquina.
- Selector segmentado (.ga-segmented) con píldora deslizante; se usa en las pestañas Perros / Gatos
  y sirve también para grupos de radios.
- Interruptor (.ga-toggle, ga_toggle_ui()) listo para usar.
- Cabecera translúcida con borde al hacer scroll, enlaces en píldora, desplegable animado con
  descripción de cada elemento y fondo oscurecido mientras está abierto.
- Pie: nombre gigante en bajorrelieve que se descubre al final de la página (opción en el
  personalizador, «Bilagun» por defecto).
- Versión del tema 2.3.0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-27 15:11:17 +02:00

134 lines
5.4 KiB
JavaScript

( function () {
// Cabecera: borde y sombra al desplazarse (se nota con la cabecera fija).
var header = document.querySelector( '.ga-header' );
if ( header ) {
var onScroll = function () { header.classList.toggle( 'is-scrolled', window.scrollY > 8 ); };
window.addEventListener( 'scroll', onScroll, { passive: true } );
onScroll();
}
var toggle = document.querySelector( '.ga-menu-toggle' );
var nav = document.getElementById( 'ga-nav' );
if ( toggle && nav ) {
toggle.addEventListener( 'click', function () {
var open = nav.classList.toggle( 'is-open' );
toggle.setAttribute( 'aria-expanded', open ? 'true' : 'false' );
} );
document.addEventListener( 'keydown', function ( e ) {
if ( e.key === 'Escape' && nav.classList.contains( 'is-open' ) ) {
nav.classList.remove( 'is-open' );
toggle.setAttribute( 'aria-expanded', 'false' );
toggle.focus();
}
} );
}
// Pestañas segmentadas con enlaces: la píldora se desliza a la pulsada mientras carga la página.
document.querySelectorAll( '.ga-segmented' ).forEach( function ( group ) {
group.addEventListener( 'click', function ( e ) {
var tab = e.target.closest( '.ga-tab' );
if ( ! tab || e.metaKey || e.ctrlKey || e.shiftKey ) { return; }
group.querySelectorAll( '.ga-tab' ).forEach( function ( t ) { t.classList.toggle( 'is-active', t === tab ); } );
} );
} );
// Filtros del listado: los <select> envían el formulario al cambiar.
document.querySelectorAll( '.ga-filters select' ).forEach( function ( select ) {
select.addEventListener( 'change', function () {
select.form.submit();
} );
} );
} )();
// Vídeo de portada: se detiene si el usuario prefiere menos movimiento.
( function () {
var video = document.querySelector( '.ga-hero__bg video' );
if ( video && window.matchMedia && window.matchMedia( '(prefers-reduced-motion: reduce)' ).matches ) {
video.removeAttribute( 'autoplay' );
video.pause();
}
} )();
// Carruseles: desplazamiento con botones, ratón/táctil nativo (scroll-snap) y teclado.
( function () {
document.querySelectorAll( '[data-ga-carousel]' ).forEach( function ( carousel ) {
var track = carousel.querySelector( '.ga-carousel__track' );
var buttons = carousel.querySelectorAll( '.ga-carousel__btn' );
if ( ! track ) {
return;
}
function update() {
var max = track.scrollWidth - track.clientWidth - 2;
buttons[ 0 ].disabled = track.scrollLeft <= 2;
buttons[ 1 ].disabled = track.scrollLeft >= max;
carousel.classList.toggle( 'is-static', max <= 0 );
}
buttons.forEach( function ( button ) {
button.addEventListener( 'click', function () {
track.scrollBy( { left: track.clientWidth * 0.9 * Number( button.dataset.dir ), behavior: 'smooth' } );
} );
} );
track.addEventListener( 'keydown', function ( e ) {
if ( e.key === 'ArrowRight' || e.key === 'ArrowLeft' ) {
e.preventDefault();
track.scrollBy( { left: ( e.key === 'ArrowRight' ? 1 : -1 ) * track.clientWidth * 0.9, behavior: 'smooth' } );
}
} );
track.addEventListener( 'scroll', update, { passive: true } );
window.addEventListener( 'resize', update );
update();
} );
} )();
// Ficha: miniaturas de la galería y copiar enlace.
( function () {
var main = document.querySelector( '[data-ga-gallery-main] img' );
document.querySelectorAll( '.ga-thumbs button' ).forEach( function ( btn ) {
btn.addEventListener( 'click', function () {
if ( ! main ) { return; }
main.src = btn.dataset.full;
main.removeAttribute( 'srcset' );
document.querySelectorAll( '.ga-thumbs button' ).forEach( function ( b ) { b.removeAttribute( 'aria-current' ); } );
btn.setAttribute( 'aria-current', 'true' );
} );
} );
document.querySelectorAll( '[data-copy]' ).forEach( function ( btn ) {
btn.addEventListener( 'click', function () {
if ( navigator.clipboard ) {
navigator.clipboard.writeText( btn.dataset.copy ).then( function () { btn.textContent = btn.dataset.done; } );
}
} );
} );
} )();
// Formulario: campo «día y hora» solo cuando el motivo es pedir cita.
( function () {
document.querySelectorAll( '.ga-form select[name="motivo"]' ).forEach( function ( select ) {
var field = select.form.querySelector( '.ga-form__visit' );
if ( ! field ) { return; }
select.addEventListener( 'change', function () { field.hidden = select.value !== 'visita'; } );
} );
} )();
// Cuestionario: guarda el borrador en este navegador hasta que se envía.
( function () {
var done = document.querySelector( '[data-ga-clear-draft]' );
try {
if ( done ) { Object.keys( localStorage ).filter( function ( k ) { return k.indexOf( 'ga-cuestionario-' ) === 0; } ).forEach( function ( k ) { localStorage.removeItem( k ); } ); }
} catch ( e ) {}
document.querySelectorAll( 'form[data-ga-draft]' ).forEach( function ( form ) {
var key = form.dataset.gaDraft, saved = {};
try { saved = JSON.parse( localStorage.getItem( key ) || '{}' ); } catch ( e ) {}
Array.prototype.forEach.call( form.elements, function ( el ) {
if ( el.name && el.type !== 'hidden' && el.type !== 'checkbox' && saved[ el.name ] && ! el.value ) { el.value = saved[ el.name ]; }
} );
form.addEventListener( 'input', function () {
var data = {};
Array.prototype.forEach.call( form.elements, function ( el ) {
if ( el.name && el.type !== 'hidden' && el.type !== 'checkbox' && el.name !== 'web' ) { data[ el.name ] = el.value; }
} );
try { localStorage.setItem( key, JSON.stringify( data ) ); } catch ( e ) {}
} );
} );
} )();