Advertisement
Guest User

Untitled

a guest
Jan 24th, 2015
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //http://codepen.io/mesuva/pen/Kozvn
  2. // on document ready
  3. $(document).ready(function() {
  4.    
  5.     // show/hide the mobile menu based on class added to container
  6.     $('.menu-icon').click(function(){
  7.         $(this).parent().toggleClass('is-tapped');
  8.          return false;
  9.     });
  10.  
  11.     // handle touch device events on drop down, first tap adds class, second navigates
  12.     $('.touch .sitenavigation li.nav-dropdown > a').on('touchend',
  13.         function(e){
  14.         if ($('.menu-icon').is(':hidden')) {
  15.             var parent = $(this).parent();
  16.               $(this).find('.clicked').removeClass('clicked');
  17.                 if (parent.hasClass('clicked')) {
  18.                      window.location.href = $(this).attr('href');
  19.                 } else {
  20.                     $(this).addClass('linkclicked');
  21.                    
  22.           // close other open menus at this level
  23.                   $(this).parent().parent().find('.clicked').removeClass('clicked');
  24.          
  25.           parent.addClass('clicked');
  26.                     e.preventDefault();
  27.                 }
  28.             }  
  29.     });
  30.    
  31.     // handle the expansion of mobile menu drop down nesting
  32.     $('.sitenavigation li.nav-dropdown').click(
  33.         function(event){
  34.             if(event.stopPropagation) {
  35.                 event.stopPropagation();
  36.             } else {
  37.                 event.cancelBubble = true; 
  38.             }
  39.            
  40.             if ($('.menu-icon').is(':visible')) {
  41.                 $(this).find('> ul').toggle();
  42.                 $(this).toggleClass('expanded');
  43.             }
  44.          }
  45.     );
  46.    
  47.    
  48.     // prevent links for propagating click/tap events that may trigger hiding/unhiding
  49.     $('.sitenavigation a.nav-dropdown, .sitenavigation li.nav-dropdown a').click(
  50.         function(event){
  51.             if(event.stopPropagation) {
  52.                 event.stopPropagation();
  53.             } else {
  54.                 event.cancelBubble = true; 
  55.             }
  56.         }
  57.     );
  58.    
  59.     // javascript fade in and out of dropdown menu
  60.     $('.no-touch .sitenavigation li').hover(
  61.         function() {
  62.             if (!$('.menu-icon').is(':visible')) {
  63.                 $(this).find('> ul').fadeIn(150);
  64.             }
  65.         },
  66.         function() {
  67.             if (!$('.menu-icon').is(':visible')) {
  68.                  $(this).find('> ul').fadeOut(150);
  69.             }
  70.         }  
  71.     );
  72. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement