Difference between revisions of "ARIA Menu"

From Level Access Web Labs
Jump to navigation Jump to search
(Blanked the page)
Line 1: Line 1:
 +
<html lang="en">
 +
  <head>
 +
  <title>
 +
    ARIA menus
 +
  </title>
 +
  <style type="text/css">
 +
    #l1, #l2  {
 +
      float:left;
 +
      width:10em;
 +
      background-color:darkblue;
 +
      color:white;
 +
      padding:.2em;
 +
    }
 +
    li {
 +
      list-style-type:none;
 +
    }
 +
    #label1 {
 +
    }
 +
    #u1, #u2 {
 +
      display:none;
 +
    }
 +
.focus {
 +
  outline: dotted;
 +
}
 +
  </style>
 +
  <script type="text/javascript">
 +
    function showHide(evt) {
 +
      var e = window.event ? window.event : evt;
  
 +
obj = e.target;
 +
toggle(obj,1);
 +
    }
 +
 +
function visible(obj) {
 +
if (window.getComputedStyle(obj,null).display == "none")
 +
return false;
 +
else
 +
  return true;
 +
}
 +
 +
// set force to 1 to force only that one to be displayed
 +
    function toggle(obj, force) {
 +
 +
if (obj.tagName == "SPAN")
 +
  obj = obj.parentNode;
 +
 +
    if (obj.id == "l1" || obj.id == "l2") {
 +
    obj = obj.children[1]
 +
      }
 +
 +
      if (obj.tagName == "UL") {
 +
    if (force) {
 +
var o = document.getElementsByClassName('menu')
 +
for (var i=0; i < o.length; i++) {
 +
 +
  o[i].style.display = "none";
 +
}
 +
      obj.style.display = "block";
 +
        }
 +
    else if (!visible(obj))
 +
      obj.style.display = "block";
 +
    else
 +
    obj.style.display = "none";
 +
      }
 +
      else if (obj.tagName == "LI") {
 +
        obj.onclick();
 +
      }
 +
    }
 +
 +
    function drawFocus() {
 +
removeFocus();
 +
 +
      var id = document.getElementById('m1').getAttribute('aria-activedescendant');
 +
var obj = document.getElementById(id);
 +
 +
      if (!visible(obj)) {
 +
        toggle(obj,0);
 +
      }
 +
 +
  if (!visible(obj.parentNode)) {
 +
        toggle(obj.parentNode,0);
 +
      }
 +
 +
if (document.getElementById(id).className)
 +
document.getElementById(id).className += " focus";
 +
else
 +
  document.getElementById(id).className = "focus";
 +
    }
 +
 +
    function removeFocus() {
 +
var o = document.getElementsByClassName('focus')
 +
 +
for(var i = 0; i < o.length; i++) {
 +
    o[i].className = o[i].className.replace( /(?:^|\s)focus(?!\S)/g,'');
 +
}
 +
 +
    }
 +
    function keystroke(evt) {
 +
      var e = window.event ? window.event : evt;
 +
var activeID = document.getElementById('m1').getAttribute('aria-activedescendant');
 +
 +
if (e.which == 13) { // enter
 +
toggle(document.getElementById(activeID),0);
 +
}
 +
else if (e.which == 40) { // down arrow
 +
          document.getElementById('m1').setAttribute('aria-activedescendant',document.getElementById(activeID).getAttribute('data-next'));
 +
          drawFocus();
 +
}
 +
else if (e.which == 38) {  // up arrow
 +
          document.getElementById('m1').setAttribute('aria-activedescendant',document.getElementById(activeID).getAttribute('data-previous'));
 +
          drawFocus();
 +
}
 +
else if (e.which == 39) { // right arrow
 +
if (activeID.indexOf("l1") > -1) {
 +
          toggle(document.getElementById('l2'),1);
 +
            document.getElementById('m1').setAttribute('aria-activedescendant',"l2");
 +
          }
 +
          else {
 +
          toggle(document.getElementById('l1'),1);
 +
            document.getElementById('m1').setAttribute('aria-activedescendant',"l1");
 +
          }
 +
          drawFocus();
 +
}
 +
else if (e.which == 37) { // left arrow
 +
if (activeID.indexOf("l1") > -1) {
 +
          toggle(document.getElementById('l2'),1);
 +
            document.getElementById('m1').setAttribute('aria-activedescendant',"l2");
 +
          }
 +
          else {
 +
        toggle(document.getElementById('l1'),1);
 +
            document.getElementById('m1').setAttribute('aria-activedescendant',"l1");
 +
          }
 +
          drawFocus();
 +
}
 +
    }
 +
  </script>
 +
  </head>
 +
<body>
 +
 +
<h2>Menubar with menu items that contain menus with other menu itemsr</h2>
 +
<div>
 +
<ul tabindex="0" onclick="showHide(event);" onkeyup="keystroke(event);" id="m1" onfocus="drawFocus();" onblur="removeFocus();" role="menubar" aria-activedescendant="l1" >
 +
  <li tabindex="-1" id="l1" role="menuitem" aria-haspopup="true" aria-labelledby="label1" data-next="l1a" data-previous="l1c"><span id="label1" >WCAG 2 &#9660;</span>
 +
    <ul role="menu" id="u1" class="menu" >
 +
      <li id="l1a" data-next="l1b" data-previous="l1" tabindex="-1" onclick="window.location = 'http://www.w3.org/TR/2008/REC-WCAG20-20081211/';" role="menuitem">WCAG 2.0</li>
 +
      <li id="l1b" tabindex="-1" data-next="l1c" data-previous="l1a" onclick="window.location = 'http://www.w3.org/TR/UNDERSTANDING-WCAG20/';" role="menuitem">Understanding WCAG</li>
 +
      <li id="l1c" tabindex="-1" data-next="l1" data-previous="l1b" onclick="window.location = 'http://www.w3.org/WAI/WCAG20/quickref/';" role="menuitem">How to Meet WCAG</li>
 +
    </ul>
 +
  </li>
 +
  <li id="l2" tabindex="-1" role="menuitem" aria-haspopup="true" aria-labeleldby="label2" data-next="l2a" data-previous="l2c"><span id="label2">Section 508 &#9660;</span>
 +
    <ul role="menu" id="u2" class="menu" >
 +
      <li id="l2a" data-next="l2b" data-previous="l2" tabindex="-1" onclick="window.location ='http://www.access-board.gov/guidelines-and-standards/communications-and-it/about-the-section-508-standards/section-508-standards';" role="menuitem">The Standards</li>
 +
      <li id="l2b" data-next="l2c" data-previous="l2a" tabindex="-1" onclick="window.location ='http://www.access-board.gov/guidelines-and-standards/communications-and-it/about-the-section-508-standards/section-508-standards#subpart_b';" role="menuitem">Technical Standards</li>
 +
      <li id="l2c" data-next="l2" data-previous="l2b" tabindex="-1" onclick="window.location ='http://www.access-board.gov/guidelines-and-standards/communications-and-it/about-the-section-508-standards/section-508-standards#subpart_c';" role="menuitem">Functional Standards</li>
 +
    </ul>
 +
  </li>
 +
</ul>
 +
</div>
 +
 +
<div style="clear:both; padding-top:4em;">&nbsp;</div>
 +
</html>

Revision as of 14:56, 4 September 2014

ARIA menus

Menubar with menu items that contain menus with other menu itemsr