(function (){
var anchorTargets={
'prueba-privada-anonima': {
selectors: ['.paternity-private-section'],
headingPattern: /Prueba de Paternidad Privada An[oó]nima/i
},
'prueba-privada-con-valor-legal': {
selectors: ['.paternity-legal-section'],
headingPattern: /Prueba de Paternidad Privada con Valor Legal/i
},
'prueba-judicial': {
selectors: ['.paternity-judicial-section'],
headingPattern: /Prueba (Judicial|de Paternidad Judicial)/i
},
'prueba-prenatal': {
selectors: ['.paternity-prenatal-section'],
headingPattern: /Prueba de Paternidad Prenatal/i
},
'prueba-de-maternidad': {
selectors: ['.dna-tests-intro-title'],
headingPattern: /Pruebas? de Maternidad/i
},
'prueba-de-hermandad': {
selectors: [],
headingPattern: /Pruebas? de Hermandad/i
},
'prueba-de-avuncular': {
selectors: [],
headingPattern: /Prueba Avuncular/i
},
'prueba-de-abuelidad': {
selectors: [],
headingPattern: /Prueba de Abuelidad/i
},
'prueba-de-cromosoma-y': {
selectors: [],
headingPattern: /Cromosoma Y/i
},
'adn-mitocondrial': {
selectors: [],
headingPattern: /ADN Mitocondrial/i
},
'perfil-genetico': {
selectors: ['.dna-tests-profile-title'],
headingPattern: /Perfil Gen[eé]tico/i
}};
function normalizePath(pathname){
if(!pathname||pathname==='/'){
return '/';
}
return pathname.replace(/\/+$/, '');
}
function getHeaderOffset(){
if(window.matchMedia&&window.matchMedia('(max-width: 781px)').matches){
return 16;
}
var header=document.querySelector('.site-header');
if(!header){
return 112;
}
return Math.round(header.getBoundingClientRect().height) + 28;
}
function getAnchorKey(hash){
return (hash||'').replace(/^#/, '').toLowerCase();
}
function getHeadingTarget(pattern){
if(!pattern){
return null;
}
var headings=Array.from(document.querySelectorAll('h1, h2, h3, h4'));
var heading=headings.find(function (node){
return pattern.test((node.textContent||'').trim());
});
if(!heading){
return null;
}
return heading;
}
function getScrollTarget(hash){
var anchorKey=getAnchorKey(hash);
var config=anchorTargets[anchorKey];
if(!config){
return null;
}
var headingTarget=getHeadingTarget(config.headingPattern);
if(headingTarget){
return headingTarget;
}
for (var i=0; i < config.selectors.length; i +=1){
var directTarget=document.querySelector(config.selectors[i]);
if(directTarget){
return directTarget;
}}
return null;
}
function scrollToAnchor(hash, behavior){
var target=getScrollTarget(hash);
if(!target){
return false;
}
var y=target.getBoundingClientRect().top + window.scrollY - getHeaderOffset();
window.scrollTo({
top: Math.max(y, 0),
behavior: behavior||'smooth'
});
return true;
}
function isResponsiveMenuOpen(link){
if(!link) return false;
var c=link.closest('.wp-block-navigation__responsive-container');
return !!(c&&c.classList.contains('is-menu-open'));
}
function closeResponsiveMenu(link){
if(!link){
return;
}
var responsiveContainer=link.closest('.wp-block-navigation__responsive-container');
if(!responsiveContainer||!responsiveContainer.classList.contains('is-menu-open')){
return;
}
var closeButton=responsiveContainer.querySelector('.wp-block-navigation__responsive-container-close');
if(closeButton){
closeButton.click();
}}
function bindAnchorLinks(){
document.querySelectorAll('.paternity-nav-item a[href*="#"], .dna-tests-nav-item a[href*="#"]').forEach(function (link){
var url;
try {
url=new URL(link.href, window.location.origin);
} catch (error){
return;
}
var anchorKey=getAnchorKey(url.hash);
if(!anchorTargets[anchorKey]){
return;
}
link.addEventListener('click', function (event){
var samePath=normalizePath(url.pathname)===normalizePath(window.location.pathname);
if(samePath){
event.preventDefault();
history.replaceState(null, '', url.hash);
if(isResponsiveMenuOpen(link)){
closeResponsiveMenu(link);
var attempts=0;
var poll=window.setInterval(function (){
attempts +=1;
var locked=document.documentElement.classList.contains('has-modal-open');
if(!locked||attempts > 50){
window.clearInterval(poll);
window.requestAnimationFrame(function (){
window.requestAnimationFrame(function (){
scrollToAnchor(url.hash, 'smooth');
});
});
}}, 20);
}else{
scrollToAnchor(url.hash, 'smooth');
}
return;
}
sessionStorage.setItem('adn-site-anchor-hash', url.hash);
});
});
}
function handleInitialHash(){
var currentHash=window.location.hash;
var pendingHash=sessionStorage.getItem('adn-site-anchor-hash');
var selectedHash=anchorTargets[getAnchorKey(currentHash)]
? currentHash
: pendingHash;
if(!selectedHash){
return;
}
var tries=0;
var timer=window.setInterval(function (){
tries +=1;
if(scrollToAnchor(selectedHash, tries===1 ? 'auto':'smooth')){
history.replaceState(null, '', selectedHash);
sessionStorage.removeItem('adn-site-anchor-hash');
window.clearInterval(timer);
return;
}
if(tries >=14){
window.clearInterval(timer);
}}, 180);
}
function initAnchorNav(){
bindAnchorLinks();
handleInitialHash();
}
if(document.readyState==='loading'){
document.addEventListener('DOMContentLoaded', initAnchorNav);
}else{
initAnchorNav();
}})();