/*! Pushy - v1.1.0 - 2017-1-30 * Pushy is a responsive off-canvas navigation menu using CSS transforms & transitions. * https://github.com/christophery/pushy/ * by Christopher Yee */ /*! * jQuery Migrate - v1.4.1 - 2016-05-19 * Copyright jQuery Foundation and other contributors */ (function ($) { $( document ).ready(function() { var pushy = $('.pushy'), //menu css class body = $('body'), container = $('#container'), //container css class push = $('.push'), //css class to add pushy capability pushL = $('.pushL'), //css class to add pushy capability pushR = $('.pushR'), //css class to add pushy capability pushyLeft = 'pushy-left', //css class for left menu position pushyOpenLeft = 'pushy-open-left', //css class when menu is open (left position) pushyOpenRight = 'pushy-open-right', //css class when menu is open (right position) siteOverlay = $('.site-overlay'), //site overlay menuBtn = $('.menu-btn, .pushy-link'), //css classes to toggle the menu menuBtnFocus = $('.menu-btn'), //css class to focus when menu is closed w/ esc key pushyR = $('.pushy-poz-right'), pushyL = $('.pushy-poz-left'), menuLinkFocusR = $(pushyR.data('focus')), //focus on link when menu is open menuLinkFocusL = $(pushyL.data('focus')), //focus on link when menu is open menuLinkFocus = $(pushy.data('focus')), //focus on link when menu is open menuSpeed = 200, //jQuery fallback menu speed menuWidthR = pushyR.width() + 'px', //jQuery fallback menu width menuWidthL = pushyL.width() + 'px', //jQuery fallback menu width menuWidth = pushy.width() + 'px', //jQuery fallback menu width submenuClass = '.pushy-submenu', submenuClassClick = '.dropdown-toggle', submenuOpenClass = 'pushy-submenu-open', submenuClosedClass = 'pushy-submenu-closed', submenu = $(submenuClass), poz = 'left'; //close menu w/ esc key $(document).keyup(function(e) { //check if esc key is pressed if (e.keyCode == 27) { //check if menu is open if( body.hasClass(pushyOpenLeft) || body.hasClass(pushyOpenRight) ){ if(cssTransforms3d){ closePushy(); //close pushy }else{ closePushyFallback(); opened = false; //set menu state } //focus on menu button after menu is closed if(menuBtnFocus){ menuBtnFocus.focus(); } } } }); function togglePushy(){ //add class to body based on menu position if( poz == 'left'){ body.toggleClass(pushyOpenLeft); }else{ body.toggleClass(pushyOpenRight); } //focus on link in menu after css transition ends if(menuLinkFocusL){ if( poz == 'left' ){ pushyL.one('transitionend', function() { menuLinkFocusL.focus(); }); } else { pushyR.one('transitionend', function() { menuLinkFocusR.focus(); }); } } } function closePushy(){ // if( poz == 'left'){ body.removeClass(pushyOpenLeft); // }else{ body.removeClass(pushyOpenRight); // } } function openPushyFallback(){ //animate menu position based on CSS class if( poz == 'left' ){ body.addClass(pushyOpenLeft); pushyL.animate({left: "0px"}, menuSpeed); container.animate({left: menuWidthL}, menuSpeed); //css class to add pushy capability pushL.animate({left: menuWidthL}, menuSpeed); }else{ body.addClass(pushyOpenRight); pushyR.animate({right: '0px'}, menuSpeed); container.animate({right: menuWidthR}, menuSpeed); pushR.animate({right: menuWidthR}, menuSpeed); } //focus on link in menu if(menuLinkFocusL){ menuLinkFocusL.focus(); } } function closePushyFallback(){ //animate menu position based on CSS class // if(poz == 'left'){ body.removeClass(pushyOpenLeft); pushyL.animate({left: "-" + menuWidthL}, menuSpeed); container.animate({left: "0px"}, menuSpeed); //css class to add pushy capability pushL.animate({left: "0px"}, menuSpeed); // } else { body.removeClass(pushyOpenRight); pushyR.animate({right: "-" + menuWidthR}, menuSpeed); container.animate({right: "0px"}, menuSpeed); pushR.animate({right: "0px"}, menuSpeed); // } } function toggleSubmenu(){ //hide submenu by default $(submenuClass).addClass(submenuClosedClass); $(submenuClass).on('click', function(){ var selected = $(this); if( selected.hasClass(submenuClosedClass) ) { //hide opened submenus $(submenuClass).addClass(submenuClosedClass).removeClass(submenuOpenClass); //show submenu selected.removeClass(submenuClosedClass).addClass(submenuOpenClass); } else { //hide submenu selected.addClass(submenuClosedClass).removeClass(submenuOpenClass); } }); } //checks if 3d transforms are supported removing the modernizr dependency var cssTransforms3d = (function csstransforms3d(){ var el = document.createElement('p'), supported = false, transforms = { 'webkitTransform':'-webkit-transform', 'OTransform':'-o-transform', 'msTransform':'-ms-transform', 'MozTransform':'-moz-transform', 'transform':'transform' }; if(document.body !== null) { // Add it to the body to get the computed style document.body.insertBefore(el, null); for(var t in transforms){ if( el.style[t] !== undefined ){ el.style[t] = 'translate3d(1px,1px,1px)'; supported = window.getComputedStyle(el).getPropertyValue(transforms[t]); } } document.body.removeChild(el); return (supported !== undefined && supported.length > 0 && supported !== "none"); }else{ return false; } })(); if(cssTransforms3d){ //toggle submenu toggleSubmenu(); //toggle menu menuBtn.on('click', function(){ poz = $(this).attr('poz'); togglePushy(); }); //close menu when clicking site overlay siteOverlay.on('click', function(){ togglePushy(); }); } else { //add css class to body body.addClass('no-csstransforms3d'); //hide menu by default if( poz == 'left' ){ pushyL.css({left: "-" + menuWidthL}); }else{ pushyR.css({right: "-" + menuWidthR}); } //fixes IE scrollbar issue container.css({"overflow-x": "hidden"}); //keep track of menu state (open/close) var opened = false; //toggle submenu toggleSubmenu(); //toggle menu menuBtn.on('click', function(){ poz = $(this).attr('poz'); if (opened) { closePushyFallback(); opened = false; } else { openPushyFallback(); opened = true; } }); //close menu when clicking site overlay siteOverlay.on('click', function(){ poz = $(this).attr('poz'); if (opened) { closePushyFallback(); opened = false; } else { openPushyFallback(); opened = true; } }); } }); }(jQuery));