Advertisement
Guest User

Untitled

a guest
Apr 21st, 2015
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * navigation.js
  3.  *
  4.  * Handles toggling the navigation menu for small screens.
  5.  */
  6. ( function() {
  7.     var container, button, menu, link;
  8.  
  9.     container = document.getElementById( 'site-navigation' );
  10.     if ( ! container ) {
  11.         return;
  12.     }
  13.  
  14.     button = container.getElementsByTagName( 'button' )[0];
  15.     if ( 'undefined' === typeof button ) {
  16.         return;
  17.     }
  18.  
  19.     menu = container.getElementsByTagName( 'ul' )[0];
  20.    
  21.     link = container.getElementsByTagName( 'li' )[0];
  22.  
  23.     // Hide menu toggle button if menu is empty and return early.
  24.     if ( 'undefined' === typeof menu ) {
  25.         button.style.display = 'none';
  26.         return;
  27.     }
  28.  
  29.     menu.setAttribute( 'aria-expanded', 'false' );
  30.  
  31.     if ( -1 === menu.className.indexOf( 'nav-menu' ) ) {
  32.         menu.className += ' nav-menu';
  33.     }
  34.  
  35.     button.onclick = function() {
  36.         if ( -1 !== container.className.indexOf( 'toggled' ) ) {
  37.             container.className = container.className.replace( ' toggled', '' );
  38.             button.setAttribute( 'aria-expanded', 'false' );
  39.             menu.setAttribute( 'aria-expanded', 'false' );
  40.         } else {
  41.             container.className += ' toggled';
  42.             button.setAttribute( 'aria-expanded', 'true' );
  43.             menu.setAttribute( 'aria-expanded', 'true' );
  44.         }
  45.     };
  46.    
  47.     link.onclick = function() {
  48.         container.className = container.className.replace( ' toggled', '' );
  49.         button.setAttribute( 'aria-expanded', 'false' );
  50.         menu.setAttribute( 'aria-expanded', 'false' );
  51.     };
  52. } )();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement