add_action('wp_head', function(){
// Fallback-Styles für SR-Text (falls Theme nix hat)
?>
<style>
.screen-reader-text{
position:absolute !important; width:1px; height:1px; padding:0; margin:-1px;
overflow:hidden; clip:rect(0,0,0,0); white-space:nowrap; border:0;
}
.screen-reader-text:focus{
clip:auto; width:auto; height:auto; margin:0; padding:.5rem;
position:static; white-space:normal; z-index:100000;
}
</style>
<?php
}, 99);
add_action('wp_footer', function(){
?>
<script>
(function(){
function patch(root){
var nodes = root.querySelectorAll('a.jet-woo-product-overlay-link');
if(!nodes.length) return;
nodes.forEach(function(a){
// Schon behoben? -> skip
if(a.hasAttribute('aria-label') || a.getAttribute('aria-hidden') === 'true') return;
// Produkt-Titel finden
var card = a.closest('.jet-woo-product, .jet-woo-products__item');
var titleEl = card && (card.querySelector('.jet-woo-product-title a') || card.querySelector('.jet-woo-product-title'));
var title = titleEl ? (titleEl.textContent || '').trim() : '';
if(title){
var txt = 'Produkt ansehen: ' + title;
a.setAttribute('aria-label', txt);
// SR-Text einfügen, falls innen wirklich nichts steht
if(!a.querySelector('.screen-reader-text') && !a.textContent.trim()){
var sr = document.createElement('span');
sr.className = 'screen-reader-text';
sr.textContent = txt;
a.appendChild(sr);
}
} else {
// Fallback: aus A11y-Baum nehmen, damit kein "Empty link"
a.setAttribute('aria-hidden','true');
a.setAttribute('tabindex','-1');
}
});
}
// Initial
document.readyState === 'loading'
? document.addEventListener('DOMContentLoaded', function(){ patch(document); })
: patch(document);
// Re-Applikation bei AJAX/Lazy Load (Elementor/JetWoo lädt gern nach)
var mo = new MutationObserver(function(muts){
muts.forEach(function(m){
m.addedNodes.forEach(function(n){ if(n.nodeType === 1) patch(n); });
});
});
mo.observe(document.documentElement, {childList:true, subtree:true});
})();
</script>
<?php
}, 99);