Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #1486274

    It is important that in accessibility in America and EU the forms having labels.

    I tried with an own function without the sucess.

    • This topic was modified 5 hours, 57 minutes ago by Raphael.
    #1486278
    
    function footer_js_accessibility() { 
        ?> 
        <script>
          jQuery(document).ready(function($) {
            
            // Überprüfe, ob das übergeordnete Element die korrekte Rolle hat
            var menu = document.querySelector('.av-main-nav');
            if (menu && !menu.hasAttribute('role')) {
                menu.setAttribute('role', 'menu');
            }
            // Setze die korrekte Rolle für jedes menuitem, falls nicht vorhanden
            var menuItems = document.querySelectorAll('.menu-item');
            menuItems.forEach(function (item) {
                if (!item.hasAttribute('role')) {
                    item.setAttribute('role', 'menuitem');
                }
            });
    
            // Überprüfe das zweite Menü und setze die entsprechende Rolle
            var aviaMenu = document.getElementById('avia-menu');
            if (aviaMenu && !aviaMenu.hasAttribute('role')) {
                aviaMenu.setAttribute('role', 'menu');
            }
    
            var aviaMenuItems = document.querySelectorAll('#avia-menu > li');
            aviaMenuItems.forEach(function (item) {
                if (!item.hasAttribute('role')) {
                    item.setAttribute('role', 'menuitem');
                }
            });
            //  unabhängig von avia-menu
            $('li[role="menuitem"]').each(function() {
                var $this = $(this);
                var $parentMenu = $this.closest('ul');
    
                if ($parentMenu.length && !$parentMenu.attr('role')) {
                    $parentMenu.attr('role', 'menu');
                }
            });
            // Setze Alt-Text für Bilder
            $('img').each(function() {
                if (!$(this).attr('alt') || $(this).attr('alt').trim() === '') {
                    var extraText = 'zur Seite';  
                    var pageTitle = document.title.trim(); 
                    pageTitle = pageTitle.split('-')[0].trim(); 
                    $(this).attr('alt', 'Bilddarstellung ' + extraText + ' ' + pageTitle);
                }
            });
    
            // Setze aria-labels für Links ohne aria-label
            $('a:not([aria-label])').each(function() {
                var linkText = $(this).text().trim(); 
                if (linkText) {
                    $(this).attr('aria-label', 'Verlinkung auf die Seite ' + linkText);
                } else {
                    $(this).attr('aria-label', 'Verlinkung für weitere Informationen');
                }
            });
    
            // Setze aria-labels für Links, die nur Zahlen enthalten
            $('a').each(function() {
                var linkText = $(this).text().trim();
                if (/^\d+$/.test(linkText)) {
                    var ariaLabel = "Gehe zu Quelle Nummer " + linkText; 
                    $(this).attr('aria-label', ariaLabel);
                }
            });
          });
        </script> 
        <?php
    } 
    add_action( 'wp_footer', 'footer_js_accessibility', 10, 10000 );
    
    
Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.