• Resolved KTS915

    (@kts915)


    This is a very useful plugin, but it suffers from being inaccessible to those with visual impairments. To make it WAI-ARIA compliant, I’d suggest the following modifications:

    In cm-tooltip-glossary-frontend.php, change line 684 to read:

    $content .= '<div id="' . $glossary_list_id . '-nav" class="listNav" role="tablist"></div>';

    Then change line 713 to this:

    $content .= '<ul class="glossaryList" role="tabpanel" id="' . $glossary_list_id . '">';

    In jquery.listnav.glossary.js change lines 201-17 to this:

    `function createLettersHtml () {
    var html = [];
    for(var i = 0; i < letters.length; i++){
    if (html.length == 0) {
    html.push(‘<a class=”ln-all” role=”tab” aria-controls=”panel-all” href=”#”>ALL</a>’);
    if (opts.includeNums) {
    html.push(‘<a class=”ln-_” tabindex=”-1″ role=”tab” aria-controls=”panel-_” href=”#”>0-9</a>’);
    }
    }
    if (letters[i] === ‘_’)
    {
    continue;
    }
    html.push(‘<a class=”ln-‘ + (letters[i] === ‘-‘ ? ‘-‘ : i) + ‘ lnletter-‘ + letters[i].toLowerCase() + ‘” tabindex=”-1″ role=”tab” aria-controls=”panel-‘ + letters[i].toLowerCase() + ‘” href=”#”>’ + ((letters[i] === ‘-‘) ? ‘…’ : letters[i].toUpperCase()) + ‘</a>’);
    }
    return ‘<div class=”ln-letters”>’ + html.join(”) + ‘</div>’ + ((opts.showCounts) ? ‘<div class=”ln-letter-count” style=”display:none; position:absolute; top:0; left:0; min-width:20px;”>0</div>’ : ”);
    }`

    Finally, change listnav.js to this:

    /*
     * Inside this closure we use $ instead of jQuery in case jQuery is reinitialized again before document.ready()
     */
    (function ($) {
        "use strict";
    
        $(document).ready(function () {
    
            if (window.cmtt_listnav_data !== undefined && window.cmtt_listnav_data.listnav && window.cmtt_listnav_data.list_id) {
                $(document).ready(function ($) {
                    $("#" + window.cmtt_listnav_data.list_id).listnav(window.cmtt_listnav_data.listnav);
                });
            }
     
    		// Prevent scroll down when spacebar pressed
    		document.getElementById('glossaryList-nav').addEventListener('keydown', function(e) {
    			if ( (e.keycode || e.which) == 32) {
    				e.preventDefault();
    			}
    		}, false);
            
            $('.listNav').keydown(function(e) {
    			if (e.which == 39) { // 'right' arrow pressed
    				e.preventDefault();
    				$('.ln-letters a:focus').attr('tabindex','-1'); // restore letter from which clicking to non-tabbable state
    				$('.ln-letters a:focus').next().focus().attr('tabindex','0'); // make receiving letter tabbable
    			}
    
    			if (e.which == 37) { // 'left' arrow pressed
    				e.preventDefault();
    				$('.ln-letters a:focus').attr('tabindex','-1'); // restore letter from which clicking to non-tabbable state
    				$('.ln-letters a:focus').prev().focus().attr('tabindex','0'); // make receiving letter tabbable
    			}
    
    			if (e.which == 13 || e.which == 32) { // space bar pressed
    				$(e.target).click().focus();
    			}
    			
    			$('.ln-letters a:first').attr('tabindex','0'); // first letter must always be tabbable
    
    		});
    
        });
    }(jQuery));
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author CreativeMindsSolutions

    (@creativemindssolutions)

    Thanks for your suggestion. We will consider adding this to the next version of the plugin after carefully reviewing the code and it’s implications

    Thread Starter KTS915

    (@kts915)

    That makes perfect sense. While you do that, I have worked out a couple of further code enhancements by adding the aria-selected attribute to the jquery.listnav.glossary.js file, as follows

    Lines 201-17 now read:

    
    function createLettersHtml () {
                    var html = [];
                    for(var i = 0; i < letters.length; i++){
                        if (html.length == 0) {
                            html.push('<a class="ln-all" role="tab" aria-controls="panel-all" aria-selected="false" href="#">ALL</a>');
                            if (opts.includeNums) {
                                html.push('<a class="ln-_" tabindex="-1" role="tab" aria-controls="panel-_" aria-selected="false" href="#">0-9</a>');
                            }
                        }
                        if (letters[i] === '_')
                        {
                            continue;
                        }
                        html.push('<a class="ln-' + (letters[i] === '-' ? '-' : i) + ' lnletter-' + letters[i].toLowerCase() + '" tabindex="-1" role="tab" aria-selected="false" aria-controls="panel-' + letters[i].toLowerCase() + '" href="#">' + ((letters[i] === '-') ? '...' : letters[i].toUpperCase()) + '</a>');
                    }
                    return '<div class="ln-letters">' + html.join('') + '</div>' + ((opts.showCounts) ? '<div class="ln-letter-count" style="display:none; position:absolute; top:0; left:0; min-width:20px;">0</div>' : '');
                }
    

    Line 68 now reads:

    
    $('.all', $letters).addClass('ln-selected').attr('aria-selected','true');
    

    Line 167 now reads:

    
    $('a.ln-selected', $letters).removeClass('ln-selected').attr('aria-selected','false');
    

    Line 192 now reads:

    
    $(this).addClass('ln-selected').attr('aria-selected','true');
    
Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Accessibility Enhancements’ is closed to new replies.