Created
June 5, 2018 13:51
-
-
Save ckpicker/6d52d3c93ed01ca1c1ddad9b029a01b4 to your computer and use it in GitHub Desktop.
Using vanilla js instead of jquery
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import delegate from 'delegate'; | |
const el = { | |
siteHeader: document.querySelector('.site-header'), | |
}; | |
/** | |
* @function toggleMenu | |
* @description Toggle the menu open and closed | |
*/ | |
const toggleMenu = () => { | |
const searchItems = document.querySelector('.site-header__midstrip--search-items'); | |
const iconHeaderMenu = document.querySelector('.icon-header-menu'); | |
if (searchItems && iconHeaderMenu) { | |
searchItems.classList.toggle('is--active'); | |
iconHeaderMenu.classList.toggle('mobile-item--color--grey'); | |
} | |
}; | |
/** | |
* @function bindEvents | |
* @description Bind the events for this module here. | |
*/ | |
const bindEvents = () => { | |
delegate(el.siteHeader, '[data-js="site-header__nav-menu--btn"]', 'click', toggleMenu); | |
}; | |
/** | |
* @module Navigation | |
* @description Javascript opening and closing menu | |
*/ | |
const navigationMenu = () => { | |
bindEvents(); | |
}; | |
export default navigationMenu; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment