Skip to content

Commit

Permalink
Release v0.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
dpilafian committed Jun 18, 2023
1 parent a4ee5de commit 2cebc89
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 36 deletions.
4 changes: 2 additions & 2 deletions dist/hamburger-menu.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! hamburger-menu v0.5.2 ☰ https://github.com/center-key/hamburger-menu ☰ MIT License */
/*! hamburger-menu v0.6.0 ☰ https://github.com/center-key/hamburger-menu ☰ MIT License */

/*
Structure for HamburgerMenu:
Expand Down Expand Up @@ -63,7 +63,7 @@ nav.hamburger-menu aside ul ul li span {
font-size: 0.8rem;
padding: 4px 0px 4px 30px;
}
@media (max-width: 667px) { /* selects iPhone 6/6s/7/8/SE(2020) landscape and anything narrower */
@media (max-width: 667px) { /* selects iPhone 6/6s/7/8/SE2/SE3 landscape and anything narrower */
html body {
padding: 35px 10px 0px 10px;
cursor: pointer; /* enables closing menu */
Expand Down
86 changes: 59 additions & 27 deletions dist/hamburger-menu.js
Original file line number Diff line number Diff line change
@@ -1,50 +1,82 @@
//! hamburger-menu v0.5.2 ☰ https://github.com/center-key/hamburger-menu ☰ MIT License
//! hamburger-menu v0.6.0 ☰ https://github.com/center-key/hamburger-menu ☰ MIT License

const hamburgerMenu = {
// <nav class=hamburger-menu>
// <a class=hamburger href=#>&#9776;</a>
// <aside>
// <ul>
// <li><a href=.>Home</a></li>
// <li><a href=page1.html>Page 1</a></li>
// <li><a href=page2.html>Page 2</a></li>
// <li><a href=page3.html>Page 3</a></li>
// </ul>
// </aside>
// </nav>

version: '0.5.2',
version: '0.6.0',

selectItem(event) {
const item = $(event.target).closest('li');
item.closest('aside').find('li').removeClass('current');
item.addClass('current');
const nav = item.closest('.hamburger-menu').addClass('collapse-menu');
const eventRoutes = {};
selectItem(elem) {
const menuItem = elem.closest('li');
const navMenu = menuItem.closest('.hamburger-menu');
const reset = (elem) => elem.classList.remove('current');
menuItem.closest('aside').querySelectorAll('li').forEach(reset);
menuItem.classList.add('current');
navMenu.classList.add('collapse-menu');
navMenu.dataset.menuCollapsed = String(Date.now());
const restoreAllowExand = () => {
nav.removeClass('collapse-menu');
console.log('restoreAllowExand');
$(globalThis.document).off(eventRoutes);
navMenu.classList.remove('collapse-menu');
globalThis.document.removeEventListener('click', restoreAllowExand);
globalThis.document.removeEventListener('mousemove', restoreAllowExand);
};
const listen = () => {
globalThis.document.addEventListener('click', restoreAllowExand);
globalThis.document.addEventListener('mousemove', restoreAllowExand);
};
eventRoutes.click = restoreAllowExand;
eventRoutes.mousemove = restoreAllowExand;
const afterCurrentClick = 100;
globalThis.setTimeout(() => $(globalThis.document).on(eventRoutes), afterCurrentClick);
globalThis.setTimeout(listen, afterCurrentClick);
},

setup() {
$(globalThis.document).on({ click: $.noop }); //workaround for sticky hover on mobile
const nav = $('nav.hamburger-menu');
globalThis.document.addEventListener('click', () => {}); //workaround for sticky hover on mobile
const navMenu = globalThis.document.querySelector('.hamburger-menu');
const aside = navMenu?.querySelector('aside');
const autoHighlightMultiPage = () => {
const current = {
url: new globalThis.URL(globalThis.location.href),
path: globalThis.location.pathname.replace(/\/$/, ''),
};
const isCurrent = (i, elem) => {
const linkUrl = new globalThis.URL($(elem).attr('href'), current.url);
return linkUrl.pathname.replace(/\/$/, '') === current.path;
const currentUrl = new globalThis.URL(globalThis.location.href);
const currentPath = globalThis.location.pathname.replace(/\/$/, '');
const setCurrent = (elem) => {
const linkUrl = new globalThis.URL(elem.href, currentUrl);
const isCurrent = linkUrl.pathname.replace(/\/$/, '') === currentPath;
elem.parentElement.classList.add(isCurrent ? 'current' : 'other-page');
};
nav.find('li >a').filter(isCurrent).first().closest('li').addClass('current');
navMenu.querySelectorAll('li >a').forEach(setCurrent);
};
const delegateSelectItem = (event) => {
const elem = event.target.closest('.hamburger-menu li');
if (elem)
hamburgerMenu.selectItem(elem);
};
const autoHighlightSinglePageApp = () =>
nav.find('>aside li').on({ click: hamburgerMenu.selectItem });
globalThis.document.addEventListener('click', delegateSelectItem);
const autoHighlight = () => {
autoHighlightMultiPage();
autoHighlightSinglePageApp();
};
if (!nav.find('>aside').hasClass('disable-auto-highlight'))
if (aside && !aside.classList.contains('disable-auto-highlight'))
autoHighlight();
},

dom: {
onReady(callback) {
// Calls the specified function once the web page is loaded and ready.
// Example (execute myApp.setup() as soon as the DOM is interactive):
// hamburgerMenu.dom.onReady(myApp.setup);
if (globalThis.document.readyState === 'complete')
callback();
else
globalThis.window.addEventListener('DOMContentLoaded', callback);
},
},

};

$(hamburgerMenu.setup);
hamburgerMenu.dom.onReady(hamburgerMenu.setup);
2 changes: 1 addition & 1 deletion dist/hamburger-menu.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions dist/hamburger-menu.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/hamburger-menu.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! hamburger-menu v0.5.2 ☰ https://github.com/center-key/hamburger-menu ☰ MIT License */
/*! hamburger-menu v0.6.0 ☰ https://github.com/center-key/hamburger-menu ☰ MIT License */

/*
Structure for HamburgerMenu:
Expand Down
4 changes: 2 additions & 2 deletions docs/hamburger-menu.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! hamburger-menu v0.5.2 ☰ https://github.com/center-key/hamburger-menu ☰ MIT License
//! hamburger-menu v0.6.0 ☰ https://github.com/center-key/hamburger-menu ☰ MIT License

const hamburgerMenu = {
// <nav class=hamburger-menu>
Expand All @@ -13,7 +13,7 @@ const hamburgerMenu = {
// </aside>
// </nav>

version: '0.5.2',
version: '0.6.0',

selectItem(elem) {
const menuItem = elem.closest('li');
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hamburger-menu",
"version": "0.5.2",
"version": "0.6.0",
"description": "☰ A responsive CSS solution for a hamburger menu ☰",
"license": "MIT",
"type": "module",
Expand Down

0 comments on commit 2cebc89

Please sign in to comment.