Skip to content

Instantly share code, notes, and snippets.

@MonteLogic
Created October 3, 2022 02:22
Show Gist options
  • Save MonteLogic/d409f667838fff1e2311e0bf1eb94aa8 to your computer and use it in GitHub Desktop.
Save MonteLogic/d409f667838fff1e2311e0bf1eb94aa8 to your computer and use it in GitHub Desktop.
documenting a function attachToggleActionToButtons(menus) -getwid-megamenu - src/frontend.js
function attachToggleActionToButtons(menus) {
menus.each((index, menu) => {
// I think(?) this is for the larger menu on mobile and not
// the submenu. Have to test that out.
$(menu).on('click', '.gw-mm__toggle', function (event) {
toggleMobileMenu($(this), $(menu));
});
// I could write an if statement here but I still don't know
// the full jurisdictions of the this operator below.
// I know that this operator is a param which finds a
// class within the DOM.
$(menu).on('click', '.gw-mm-item__toggle', function (event) {
// I think we're in the menu DOM right now because the function is called menus.
// But lets run a console.log
console.log($(this));
// The console log for that was this:
// Object { 0: button.gw-mm-item__toggle, length: 1 }
// 0: <button class="gw-mm-item__toggle is-opened">
// length: 1
// <prototype>: Object { jquery: "3.6.0", constructor: S(e, t), length: 0, … }
// frontend.js:83:13
let dropdown = $(this).closest('.gw-mm-item').find('.gw-mm-item__dropdown-wrapper');
toggleMobileMenu($(this), $(dropdown));
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment