433 lines
15 KiB
JavaScript
433 lines
15 KiB
JavaScript
(function () {
|
|
'use strict';
|
|
/**==============================================
|
|
* HEAder
|
|
*=============================================**/
|
|
function initHeader() {
|
|
var header = document.querySelector('[data-site-header]');
|
|
if (!header) return;
|
|
|
|
var menuButton = header.querySelector('[data-menu-toggle]');
|
|
var navigation = header.querySelector('[data-primary-nav]');
|
|
var submenuParent = header.querySelector('[data-submenu-parent]');
|
|
var submenuButton = header.querySelector('[data-submenu-toggle]');
|
|
var mobileMedia = window.matchMedia('(max-width: 1024px)');
|
|
|
|
function setMenu(open) {
|
|
if (!menuButton || !navigation) return;
|
|
menuButton.setAttribute('aria-expanded', open ? 'true' : 'false');
|
|
menuButton.setAttribute('aria-label', open ? 'Cerrar menú principal' : 'Abrir menú principal');
|
|
navigation.classList.toggle('is-open', open);
|
|
document.documentElement.classList.toggle('menu-is-open', open && mobileMedia.matches);
|
|
}
|
|
|
|
function setSubmenu(open) {
|
|
if (!submenuParent || !submenuButton) return;
|
|
submenuParent.classList.toggle('is-open', open);
|
|
submenuButton.setAttribute('aria-expanded', open ? 'true' : 'false');
|
|
submenuButton.setAttribute('aria-label', open ? 'Ocultar servicios' : 'Mostrar servicios');
|
|
}
|
|
|
|
if (menuButton && navigation) {
|
|
menuButton.addEventListener('click', function () {
|
|
setMenu(menuButton.getAttribute('aria-expanded') !== 'true');
|
|
});
|
|
|
|
navigation.addEventListener('click', function (event) {
|
|
if (mobileMedia.matches && event.target.closest('a')) setMenu(false);
|
|
});
|
|
}
|
|
|
|
if (submenuButton && submenuParent) {
|
|
submenuButton.addEventListener('click', function () {
|
|
setSubmenu(submenuButton.getAttribute('aria-expanded') !== 'true');
|
|
});
|
|
}
|
|
|
|
document.addEventListener('keydown', function (event) {
|
|
if (event.key !== 'Escape') return;
|
|
setSubmenu(false);
|
|
setMenu(false);
|
|
if (menuButton && mobileMedia.matches) menuButton.focus();
|
|
});
|
|
|
|
function resetResponsiveState(event) {
|
|
if (!event.matches) setMenu(false);
|
|
setSubmenu(false);
|
|
}
|
|
|
|
if (typeof mobileMedia.addEventListener === 'function') {
|
|
mobileMedia.addEventListener('change', resetResponsiveState);
|
|
} else {
|
|
mobileMedia.addListener(resetResponsiveState);
|
|
}
|
|
}
|
|
|
|
if (document.readyState === 'loading') {
|
|
document.addEventListener('DOMContentLoaded', initHeader);
|
|
} else {
|
|
initHeader();
|
|
}
|
|
/**============================================
|
|
* Termina header // Empieza Footer
|
|
*=============================================**/
|
|
|
|
function initFooter() {
|
|
var scrollButton = document.querySelector('[data-scroll-top]');
|
|
if (scrollButton) {
|
|
scrollButton.addEventListener('click', function () {
|
|
window.scrollTo({
|
|
top: 0,
|
|
behavior: window.matchMedia('(prefers-reduced-motion: reduce)').matches ? 'auto' : 'smooth'
|
|
});
|
|
});
|
|
}
|
|
|
|
var popup = document.querySelector('#global-popup');
|
|
var closePopup = document.querySelector('#close-popup-global');
|
|
if (!popup || !closePopup) return;
|
|
|
|
var desktopPopup = window.matchMedia('(min-width: 768px)');
|
|
var closedByUser = false;
|
|
|
|
function setPopup(open) {
|
|
popup.classList.toggle('is-active', open);
|
|
popup.setAttribute('aria-hidden', open ? 'false' : 'true');
|
|
popup.inert = !open;
|
|
}
|
|
|
|
function syncPopup() {
|
|
setPopup(desktopPopup.matches && !closedByUser);
|
|
}
|
|
|
|
closePopup.addEventListener('click', function () {
|
|
closedByUser = true;
|
|
setPopup(false);
|
|
});
|
|
|
|
document.addEventListener('keydown', function (event) {
|
|
if (event.key === 'Escape' && popup.classList.contains('is-active')) {
|
|
closedByUser = true;
|
|
setPopup(false);
|
|
}
|
|
});
|
|
|
|
if (typeof desktopPopup.addEventListener === 'function') {
|
|
desktopPopup.addEventListener('change', syncPopup);
|
|
} else {
|
|
desktopPopup.addListener(syncPopup);
|
|
}
|
|
|
|
syncPopup();
|
|
}
|
|
|
|
if (document.readyState === 'loading') {
|
|
document.addEventListener('DOMContentLoaded', initFooter);
|
|
} else {
|
|
initFooter();
|
|
}
|
|
|
|
function initHero() {
|
|
var slider = document.querySelector('[data-hero-slider]');
|
|
if (!slider) return;
|
|
|
|
var slides = Array.prototype.slice.call(slider.querySelectorAll('[data-hero-slide]'));
|
|
var dots = Array.prototype.slice.call(slider.querySelectorAll('[data-hero-dot]'));
|
|
var previousButton = slider.querySelector('[data-hero-prev]');
|
|
var nextButton = slider.querySelector('[data-hero-next]');
|
|
var current = 0;
|
|
var timer = null;
|
|
var reduceMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
|
|
|
|
if (slides.length < 2) return;
|
|
|
|
function showSlide(index) {
|
|
current = (index + slides.length) % slides.length;
|
|
|
|
slides.forEach(function (slide, slideIndex) {
|
|
var active = slideIndex === current;
|
|
slide.classList.toggle('is-active', active);
|
|
slide.setAttribute('aria-hidden', active ? 'false' : 'true');
|
|
});
|
|
|
|
dots.forEach(function (dot, dotIndex) {
|
|
var active = dotIndex === current;
|
|
dot.classList.toggle('is-active', active);
|
|
dot.setAttribute('aria-current', active ? 'true' : 'false');
|
|
});
|
|
}
|
|
|
|
function stopAutoplay() {
|
|
if (timer) window.clearInterval(timer);
|
|
timer = null;
|
|
}
|
|
|
|
function startAutoplay() {
|
|
stopAutoplay();
|
|
if (reduceMotion || document.hidden) return;
|
|
timer = window.setInterval(function () {
|
|
showSlide(current + 1);
|
|
}, 6500);
|
|
}
|
|
|
|
function selectSlide(index) {
|
|
showSlide(index);
|
|
startAutoplay();
|
|
}
|
|
|
|
if (previousButton) previousButton.addEventListener('click', function () { selectSlide(current - 1); });
|
|
if (nextButton) nextButton.addEventListener('click', function () { selectSlide(current + 1); });
|
|
|
|
dots.forEach(function (dot) {
|
|
dot.addEventListener('click', function () {
|
|
selectSlide(parseInt(dot.getAttribute('data-hero-dot'), 10));
|
|
});
|
|
});
|
|
|
|
slider.addEventListener('mouseenter', stopAutoplay);
|
|
slider.addEventListener('mouseleave', startAutoplay);
|
|
slider.addEventListener('focusin', stopAutoplay);
|
|
slider.addEventListener('focusout', startAutoplay);
|
|
slider.addEventListener('keydown', function (event) {
|
|
if (event.key === 'ArrowLeft') selectSlide(current - 1);
|
|
if (event.key === 'ArrowRight') selectSlide(current + 1);
|
|
});
|
|
|
|
document.addEventListener('visibilitychange', function () {
|
|
if (document.hidden) stopAutoplay();
|
|
else startAutoplay();
|
|
});
|
|
|
|
showSlide(0);
|
|
startAutoplay();
|
|
}
|
|
|
|
if (document.readyState === 'loading') {
|
|
document.addEventListener('DOMContentLoaded', initHero);
|
|
} else {
|
|
initHero();
|
|
}
|
|
|
|
/**============================================
|
|
* Termina Footer
|
|
*=============================================**/
|
|
})();
|
|
|
|
// One responsive tab set, enhanced only when JavaScript is available.
|
|
(function () {
|
|
'use strict';
|
|
function initSolutions() {
|
|
document.querySelectorAll('[data-solutions]').forEach(function (section) {
|
|
var tablist = section.querySelector('[data-solutions-tabs]');
|
|
var tabs = Array.from(tablist.querySelectorAll('[role="tab"]'));
|
|
var panels = Array.from(section.querySelectorAll('[data-solution-panel]'));
|
|
function selectTab(index, focus) {
|
|
tabs.forEach(function (tab, i) {
|
|
var active = i === index;
|
|
tab.setAttribute('aria-selected', String(active));
|
|
tab.tabIndex = active ? 0 : -1;
|
|
panels[i].hidden = !active;
|
|
});
|
|
if (focus) tabs[index].focus();
|
|
}
|
|
panels.forEach(function (panel, i) {
|
|
panel.setAttribute('role', 'tabpanel');
|
|
panel.setAttribute('aria-labelledby', tabs[i].id);
|
|
panel.removeAttribute('aria-label');
|
|
panel.tabIndex = 0;
|
|
});
|
|
tabs.forEach(function (tab, index) {
|
|
tab.addEventListener('click', function () { selectTab(index, false); });
|
|
tab.addEventListener('keydown', function (event) {
|
|
var next = index;
|
|
if (event.key === 'ArrowRight') next = (index + 1) % tabs.length;
|
|
else if (event.key === 'ArrowLeft') next = (index + tabs.length - 1) % tabs.length;
|
|
else if (event.key === 'Home') next = 0;
|
|
else if (event.key === 'End') next = tabs.length - 1;
|
|
else return;
|
|
event.preventDefault();
|
|
selectTab(next, true);
|
|
});
|
|
});
|
|
selectTab(0, false);
|
|
tablist.hidden = false;
|
|
});
|
|
}
|
|
if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', initSolutions);
|
|
else initSolutions();
|
|
})();
|
|
|
|
(function () {
|
|
'use strict';
|
|
function initClients() {
|
|
document.querySelectorAll('[data-clients]').forEach(function (section) {
|
|
var track = section.querySelector('[data-clients-track]');
|
|
var controls = section.querySelector('[data-clients-dots]');
|
|
var positions = [];
|
|
var current = 0;
|
|
function update() {
|
|
current = positions.reduce(function (best, position, index) {
|
|
return Math.abs(position - track.scrollLeft) < Math.abs(positions[best] - track.scrollLeft) ? index : best;
|
|
}, 0);
|
|
Array.from(controls.children).forEach(function (button, index) {
|
|
button.setAttribute('aria-current', String(index === current));
|
|
});
|
|
}
|
|
function go(index) {
|
|
index = Math.max(0, Math.min(index, positions.length - 1));
|
|
track.scrollTo({ left: positions[index], behavior: window.matchMedia('(prefers-reduced-motion: reduce)').matches ? 'auto' : 'smooth' });
|
|
}
|
|
function rebuild() {
|
|
var width = track.clientWidth;
|
|
if (!width) return;
|
|
var count = Math.ceil(track.scrollWidth / width - 0.01);
|
|
positions = Array.from({ length: count }, function (_, i) { return Math.min(i * width, track.scrollWidth - width); });
|
|
if (controls.children.length !== count) {
|
|
controls.replaceChildren();
|
|
positions.forEach(function (_, index) {
|
|
var button = document.createElement('button');
|
|
button.type = 'button';
|
|
button.className = 'client-dot';
|
|
button.setAttribute('aria-label', 'Mostrar grupo de clientes ' + (index + 1) + ' de ' + count);
|
|
button.setAttribute('aria-controls', track.id);
|
|
button.addEventListener('click', function () { go(index); });
|
|
controls.appendChild(button);
|
|
});
|
|
}
|
|
update();
|
|
}
|
|
track.addEventListener('scroll', update, { passive: true });
|
|
track.addEventListener('keydown', function (event) {
|
|
if (event.key === 'ArrowRight') go(current + 1);
|
|
else if (event.key === 'ArrowLeft') go(current - 1);
|
|
else if (event.key === 'Home') go(0);
|
|
else if (event.key === 'End') go(positions.length - 1);
|
|
else return;
|
|
event.preventDefault();
|
|
});
|
|
new ResizeObserver(rebuild).observe(track);
|
|
rebuild();
|
|
});
|
|
}
|
|
if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', initClients);
|
|
else initClients();
|
|
})();
|
|
|
|
// Two continuously deforming vector fields, matching the reference's noise parameters.
|
|
(function () {
|
|
'use strict';
|
|
function initCertificationWaves() {
|
|
document.querySelectorAll('[data-certification-waves]').forEach(function (canvas) {
|
|
var section = canvas.parentElement;
|
|
var ctx = canvas.getContext('2d');
|
|
if (!ctx) return;
|
|
import(canvas.dataset.noiseSrc).then(function (module) {
|
|
var noise = module.createNoise3D();
|
|
var reduced = window.matchMedia('(prefers-reduced-motion: reduce)');
|
|
var width = 0, height = 0, ratio = 1, frame = 0, previous = 0, elapsed = 0;
|
|
var visible = false;
|
|
function lines(offset, amplitude, color, size, shift, factor, curve) {
|
|
ctx.beginPath();
|
|
for (var i = 0; i < 60; i++) {
|
|
var bend = Math.cos(i / 59 * Math.PI + offset) * curve;
|
|
for (var j = 0; j < 35; j++) {
|
|
var t = j / 34;
|
|
var x = t * (width + 20) - width / 2 - 10;
|
|
var y = noise(t, offset, bend) * height / 2 * factor + shift + height * (1 - factor) / 4;
|
|
if (j) ctx.lineTo(x, y); else ctx.moveTo(x, y);
|
|
}
|
|
offset += amplitude;
|
|
}
|
|
ctx.strokeStyle = color;
|
|
ctx.lineWidth = size;
|
|
ctx.stroke();
|
|
}
|
|
function draw(time) {
|
|
ctx.setTransform(ratio, 0, 0, ratio, 0, 0);
|
|
ctx.fillStyle = '#ffffff';
|
|
ctx.fillRect(0, 0, width, height);
|
|
ctx.translate(width / 2, height / 2);
|
|
var stroke = Math.max(0.35, width / 1920);
|
|
lines(time * 0.00015, 0.005, '#F8B334', stroke, 0, 0.33, 0.15);
|
|
lines(time * 0.00007, 0.02, '#EAEAEA', stroke * (0.75 + Math.sin(time * 0.002) * 0.25), -100, 1, 0.1);
|
|
}
|
|
function tick(time) {
|
|
if (previous) elapsed += Math.min(time - previous, 50);
|
|
previous = time;
|
|
draw(elapsed);
|
|
frame = requestAnimationFrame(tick);
|
|
}
|
|
function sync() {
|
|
cancelAnimationFrame(frame);
|
|
frame = 0;
|
|
previous = 0;
|
|
if (reduced.matches) draw(0);
|
|
else if (visible && !document.hidden) frame = requestAnimationFrame(tick);
|
|
}
|
|
function resize() {
|
|
width = section.clientWidth;
|
|
height = section.clientHeight;
|
|
ratio = Math.min(window.devicePixelRatio || 1, 2);
|
|
canvas.width = Math.round(width * ratio);
|
|
canvas.height = Math.round(height * ratio);
|
|
draw(reduced.matches ? 0 : elapsed);
|
|
}
|
|
new ResizeObserver(resize).observe(section);
|
|
new IntersectionObserver(function (entries) { visible = entries[0].isIntersecting; sync(); }).observe(section);
|
|
reduced.addEventListener('change', sync);
|
|
document.addEventListener('visibilitychange', sync);
|
|
resize();
|
|
}).catch(function () {
|
|
// The WordPress background image remains visible if the module cannot load.
|
|
canvas.hidden = true;
|
|
});
|
|
});
|
|
}
|
|
if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', initCertificationWaves);
|
|
else initCertificationWaves();
|
|
})();
|
|
|
|
// Reveal Subfactory products once they enter the viewport.
|
|
(function () {
|
|
function initSubfactoryProducts() {
|
|
if (!('IntersectionObserver' in window) || window.matchMedia('(prefers-reduced-motion: reduce)').matches) return;
|
|
var observer = new IntersectionObserver(function (entries) {
|
|
entries.forEach(function (entry) {
|
|
if (!entry.isIntersecting) return;
|
|
entry.target.animate([
|
|
{ opacity: 0, transform: 'translateY(28px)' },
|
|
{ opacity: 1, transform: 'translateY(0)' }
|
|
], { duration: 800, easing: 'ease-out' });
|
|
observer.unobserve(entry.target);
|
|
});
|
|
}, { threshold: 0.12 });
|
|
document.querySelectorAll('[data-subfactory-reveal], [data-scroll-reveal]').forEach(function (element) { observer.observe(element); });
|
|
}
|
|
if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', initSubfactoryProducts);
|
|
else initSubfactoryProducts();
|
|
})();
|
|
|
|
(function () {
|
|
function initCaseDialogs() {
|
|
document.querySelectorAll('[data-case-open]').forEach(function (button) {
|
|
var dialog = document.getElementById(button.dataset.caseOpen);
|
|
if (!dialog) return;
|
|
button.addEventListener('click', function () {
|
|
dialog.showModal();
|
|
document.documentElement.classList.add('case-dialog-open');
|
|
});
|
|
dialog.querySelector('[data-case-close]').addEventListener('click', function () { dialog.close(); });
|
|
dialog.addEventListener('click', function (event) {
|
|
var rect = dialog.getBoundingClientRect();
|
|
if (event.target === dialog && (event.clientX < rect.left || event.clientX > rect.right || event.clientY < rect.top || event.clientY > rect.bottom)) dialog.close();
|
|
});
|
|
dialog.addEventListener('close', function () {
|
|
document.documentElement.classList.remove('case-dialog-open');
|
|
button.focus({ preventScroll: true });
|
|
});
|
|
});
|
|
}
|
|
if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', initCaseDialogs);
|
|
else initCaseDialogs();
|
|
})();
|