-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor submenu JS to remove jquery dep and move to wagtail-client (#…
- Loading branch information
1 parent
722321c
commit 4ef9919
Showing
7 changed files
with
63 additions
and
33 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/** | ||
* Initialises the Submenus within the primary Wagtail menu (excluding the Explorer menu) | ||
*/ | ||
|
||
const initSubmenus = () => { | ||
const primaryNavContainer = document.querySelector('[data-nav-primary]'); | ||
|
||
if (!primaryNavContainer) { | ||
return; | ||
} | ||
|
||
const subMenuTriggers = document.querySelectorAll( | ||
'[data-nav-primary-submenu-trigger]' | ||
); | ||
const activeClass = 'submenu-active'; | ||
|
||
[...subMenuTriggers].forEach(subMenuTrigger => { | ||
subMenuTrigger.addEventListener('click', clickEvent => { | ||
const submenuContainer = subMenuTrigger.parentNode; | ||
|
||
primaryNavContainer.classList.remove(activeClass); | ||
[...subMenuTriggers].forEach(sm => sm.classList.remove(activeClass)); | ||
|
||
primaryNavContainer.classList.toggle(activeClass); | ||
submenuContainer.classList.toggle(activeClass); | ||
|
||
document.addEventListener('mousedown', e => { | ||
if ( | ||
!submenuContainer.contains(e.target) && | ||
subMenuTrigger !== e.target | ||
) { | ||
primaryNavContainer.classList.remove(activeClass); | ||
submenuContainer.classList.remove(activeClass); | ||
} | ||
}); | ||
|
||
document.addEventListener('keydown', e => { | ||
// IE11 uses "Esc" instead of "Escape" | ||
if (e.key === 'Escape' || e.key === 'Esc') { | ||
primaryNavContainer.classList.remove(activeClass); | ||
submenuContainer.classList.remove(activeClass); | ||
} | ||
}); | ||
|
||
clickEvent.preventDefault(); | ||
}); | ||
}); | ||
}; | ||
|
||
export { initSubmenus }; |
This file contains 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
This file contains 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
This file contains 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
This file was deleted.
Oops, something went wrong.
This file contains 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
2 changes: 1 addition & 1 deletion
2
wagtail/admin/templates/wagtailadmin/shared/menu_submenu_item.html
This file contains 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