SHARE
TWEET

main.js

a guest Oct 25th, 2017 196 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. init();
  2.  
  3. function init() {
  4.     hideMobileNavOnClick();
  5. }
  6.  
  7. function hideMobileNavOnClick() {
  8.     var $ = jQuery,
  9.         menu = $('.main-navigation'),
  10.         inlineLinks = menu.find('a[href*="#"]');
  11.  
  12.     if (inlineLinks.length !== 0) {
  13.         inlineLinks.each(function() {
  14.             var link = $(this),
  15.                 linkHref = link.attr('href'),
  16.                 linkHash = linkHref.substr(linkHref.indexOf("#")),
  17.                 // Search ID or Name attributes
  18.                 target = $(linkHash).add('[name="' + linkHash.substr(1) + '"]');
  19.  
  20.             if (target.length !== 0) {
  21.                 // Enable keyboard support
  22.                 target.attr('tabindex', '-1');
  23.  
  24.                 link.on('click', function(event) {
  25.                     var menuBtn = menu.find('.menu-toggle');
  26.  
  27.                     // If mobile
  28.                     if (!menuBtn.is(':hidden')) {
  29.                         // Hide the menu
  30.                         menuBtn.click();
  31.                     }
  32.  
  33.                 });
  34.             }
  35.         });
  36.     }
  37. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top