mmenu-js
Advanced tools
Comparing version 8.5.13 to 8.5.14
@@ -10,3 +10,3 @@ import Mmenu from '../../core/oncanvas/mmenu.oncanvas'; | ||
Mmenu.configs.classNames.counters = { | ||
counter: 'Counter' | ||
counter: 'Counter', | ||
}; | ||
@@ -13,0 +13,0 @@ export default function () { |
@@ -8,5 +8,13 @@ import * as pack from '../../../package.json'; | ||
import * as media from '../../_modules/matchmedia'; | ||
import { type, extend, transitionend, uniqueId, valueOrFn, } from '../../_modules/helpers'; | ||
import { | ||
type, | ||
extend, | ||
transitionend, | ||
uniqueId, | ||
valueOrFn, | ||
} from '../../_modules/helpers'; | ||
// Add the translations. | ||
translate(); | ||
/** | ||
@@ -26,2 +34,3 @@ * Class for a mobile menu. | ||
this.conf = extend(configs, Mmenu.configs); | ||
// Methods to expose in the API. | ||
@@ -37,2 +46,3 @@ this._api = [ | ||
]; | ||
// Storage objects for nodes, variables, hooks and click handlers. | ||
@@ -43,2 +53,3 @@ this.node = {}; | ||
this.clck = []; | ||
// Get menu node from string or element. | ||
@@ -88,3 +99,5 @@ this.node.menu = | ||
// Open current and all vertical parent panels. | ||
DOM.parents(panel, '.mm-listitem_vertical').forEach(function (listitem) { | ||
DOM.parents(panel, '.mm-listitem_vertical').forEach(function ( | ||
listitem | ||
) { | ||
listitem.classList.add('mm-listitem_opened'); | ||
@@ -96,3 +109,7 @@ DOM.children(listitem, '.mm-panel').forEach(function (panel) { | ||
// Open first non-vertical parent panel. | ||
var parents = DOM.parents(panel, '.mm-panel').filter(function (panel) { return !panel.parentElement.matches('.mm-listitem_vertical'); }); | ||
var parents = DOM.parents(panel, '.mm-panel').filter(function ( | ||
panel | ||
) { | ||
return !panel.parentElement.matches('.mm-listitem_vertical'); | ||
}); | ||
this.trigger('openPanel:start', [panel]); | ||
@@ -104,14 +121,16 @@ if (parents.length) { | ||
// Open a "horizontal" panel. | ||
} | ||
else { | ||
} else { | ||
if (panel.matches('.mm-panel_opened')) { | ||
return; | ||
} | ||
var panels = DOM.children(this.node.pnls, '.mm-panel'), current_1 = DOM.children(this.node.pnls, '.mm-panel_opened')[0]; | ||
var panels = DOM.children(this.node.pnls, '.mm-panel'), | ||
current_1 = DOM.children(this.node.pnls, '.mm-panel_opened')[0]; | ||
// Close all child panels. | ||
panels | ||
.filter(function (parent) { return parent !== panel; }) | ||
.filter(function (parent) { | ||
return parent !== panel; | ||
}) | ||
.forEach(function (parent) { | ||
parent.classList.remove('mm-panel_opened-parent'); | ||
}); | ||
parent.classList.remove('mm-panel_opened-parent'); | ||
}); | ||
// Open all parent panels. | ||
@@ -122,3 +141,5 @@ var parent_1 = panel['mmParent']; | ||
if (parent_1) { | ||
if (!parent_1.parentElement.matches('.mm-listitem_vertical')) { | ||
if ( | ||
!parent_1.parentElement.matches('.mm-listitem_vertical') | ||
) { | ||
parent_1.classList.add('mm-panel_opened-parent'); | ||
@@ -134,7 +155,11 @@ } | ||
panels | ||
.filter(function (hidden) { return hidden !== current_1; }) | ||
.filter(function (hidden) { return hidden !== panel; }) | ||
.filter(function (hidden) { | ||
return hidden !== current_1; | ||
}) | ||
.filter(function (hidden) { | ||
return hidden !== panel; | ||
}) | ||
.forEach(function (hidden) { | ||
hidden.classList.add('mm-hidden'); | ||
}); | ||
hidden.classList.add('mm-hidden'); | ||
}); | ||
panel.classList.remove('mm-hidden'); | ||
@@ -152,4 +177,3 @@ /** Start opening the panel. */ | ||
panel.classList.remove('mm-panel_opened-parent'); | ||
} | ||
else { | ||
} else { | ||
if (current_1) { | ||
@@ -177,9 +201,12 @@ current_1.classList.add('mm-panel_opened-parent'); | ||
// Callback | ||
transitionend(panel, function () { | ||
openPanelFinish_1(); | ||
}, _this.conf.transitionDuration); | ||
transitionend( | ||
panel, | ||
function () { | ||
openPanelFinish_1(); | ||
}, | ||
_this.conf.transitionDuration | ||
); | ||
openPanelStart_1(); | ||
}, this.conf.openingInterval); | ||
} | ||
else { | ||
} else { | ||
openPanelStart_1(); | ||
@@ -224,3 +251,4 @@ openPanelFinish_1(); | ||
// Close all "horizontal" panels. | ||
var panels = DOM.children(this.node.pnls, '.mm-panel'), opened = panel ? panel : panels[0]; | ||
var panels = DOM.children(this.node.pnls, '.mm-panel'), | ||
opened = panel ? panel : panels[0]; | ||
DOM.children(this.node.pnls, '.mm-panel').forEach(function (panel) { | ||
@@ -247,5 +275,7 @@ if (panel !== opened) { | ||
if (listitem.matches('.mm-listitem_vertical')) { | ||
this[listitem.matches('.mm-listitem_opened') | ||
? 'closePanel' | ||
: 'openPanel'](panel); | ||
this[ | ||
listitem.matches('.mm-listitem_opened') | ||
? 'closePanel' | ||
: 'openPanel' | ||
](panel); | ||
} | ||
@@ -261,3 +291,5 @@ }; | ||
// First, remove the selected class from all listitems. | ||
DOM.find(this.node.menu, '.mm-listitem_selected').forEach(function (li) { | ||
DOM.find(this.node.menu, '.mm-listitem_selected').forEach(function ( | ||
li | ||
) { | ||
li.classList.remove('mm-listitem_selected'); | ||
@@ -361,19 +393,27 @@ }); | ||
Object.keys(this.opts.extensions).forEach(function (query) { | ||
var classnames = _this.opts.extensions[query].map(function (extension) { return 'mm-menu_' + extension; }); | ||
var classnames = _this.opts.extensions[query].map(function ( | ||
extension | ||
) { | ||
return 'mm-menu_' + extension; | ||
}); | ||
if (classnames.length) { | ||
media.add(query, function () { | ||
// IE11: | ||
classnames.forEach(function (classname) { | ||
_this.node.menu.classList.add(classname); | ||
}); | ||
// Better browsers: | ||
// this.node.menu.classList.add(...classnames); | ||
}, function () { | ||
// IE11: | ||
classnames.forEach(function (classname) { | ||
_this.node.menu.classList.remove(classname); | ||
}); | ||
// Better browsers: | ||
// this.node.menu.classList.remove(...classnames); | ||
}); | ||
media.add( | ||
query, | ||
function () { | ||
// IE11: | ||
classnames.forEach(function (classname) { | ||
_this.node.menu.classList.add(classname); | ||
}); | ||
// Better browsers: | ||
// this.node.menu.classList.add(...classnames); | ||
}, | ||
function () { | ||
// IE11: | ||
classnames.forEach(function (classname) { | ||
_this.node.menu.classList.remove(classname); | ||
}); | ||
// Better browsers: | ||
// this.node.menu.classList.remove(...classnames); | ||
} | ||
); | ||
} | ||
@@ -399,4 +439,6 @@ }); | ||
DOM.children(this.node.menu).forEach(function (panel) { | ||
if (_this.conf.panelNodetype.indexOf(panel.nodeName.toLowerCase()) > | ||
-1) { | ||
if ( | ||
_this.conf.panelNodetype.indexOf(panel.nodeName.toLowerCase()) > | ||
-1 | ||
) { | ||
panels.append(panel); | ||
@@ -427,6 +469,9 @@ } | ||
if (panel && panel.matches('.mm-panel')) { | ||
if (anchor.parentElement.matches('.mm-listitem_vertical')) { | ||
if ( | ||
anchor.parentElement.matches( | ||
'.mm-listitem_vertical' | ||
) | ||
) { | ||
_this.togglePanel(panel); | ||
} | ||
else { | ||
} else { | ||
_this.openPanel(panel); | ||
@@ -436,4 +481,3 @@ } | ||
} | ||
} | ||
catch (err) { } | ||
} catch (err) {} | ||
} | ||
@@ -467,7 +511,17 @@ } | ||
// Find panel > panel | ||
children_1.push.apply(children_1, DOM.children(panel, '.' + this.conf.classNames.panel)); | ||
children_1.push.apply( | ||
children_1, | ||
DOM.children(panel, '.' + this.conf.classNames.panel) | ||
); | ||
// Find panel listitem > panel | ||
DOM.children(panel, '.mm-listview').forEach(function (listview) { | ||
DOM.children(listview, '.mm-listitem').forEach(function (listitem) { | ||
children_1.push.apply(children_1, DOM.children(listitem, panelNodetype)); | ||
DOM.children(panel, '.mm-listview').forEach(function ( | ||
listview | ||
) { | ||
DOM.children(listview, '.mm-listitem').forEach(function ( | ||
listitem | ||
) { | ||
children_1.push.apply( | ||
children_1, | ||
DOM.children(listitem, panelNodetype) | ||
); | ||
}); | ||
@@ -505,3 +559,4 @@ }); | ||
// Vertical panel. | ||
var vertical = panel.matches('.' + this.conf.classNames.vertical) || | ||
var vertical = | ||
panel.matches('.' + this.conf.classNames.vertical) || | ||
!this.opts.slidingSubmenus; | ||
@@ -530,4 +585,3 @@ panel.classList.remove(this.conf.classNames.vertical); | ||
} | ||
} | ||
else { | ||
} else { | ||
this.node.pnls.append(panel); | ||
@@ -546,3 +600,5 @@ } | ||
/** The open link. */ | ||
var button = DOM.create('a.mm-btn.mm-btn_next.mm-listitem__btn'); | ||
var button = DOM.create( | ||
'a.mm-btn.mm-btn_next.mm-listitem__btn' | ||
); | ||
button.setAttribute('href', '#' + panel.id); | ||
@@ -554,3 +610,6 @@ // If the item has no link, | ||
button.innerHTML = item.innerHTML; | ||
parent.insertBefore(button, item.nextElementSibling); | ||
parent.insertBefore( | ||
button, | ||
item.nextElementSibling | ||
); | ||
item.remove(); | ||
@@ -560,3 +619,6 @@ } | ||
else { | ||
parent.insertBefore(button, DOM.children(parent, '.mm-panel')[0]); | ||
parent.insertBefore( | ||
button, | ||
DOM.children(parent, '.mm-panel')[0] | ||
); | ||
} | ||
@@ -592,3 +654,6 @@ } | ||
if (panel.getAttribute('data-mm-parent')) { | ||
parentPanel = DOM.find(this.node.pnls, panel.getAttribute('data-mm-parent'))[0]; | ||
parentPanel = DOM.find( | ||
this.node.pnls, | ||
panel.getAttribute('data-mm-parent') | ||
)[0]; | ||
} | ||
@@ -643,5 +708,5 @@ // if (panel.dataset.mmParent) { // IE10 has no dataset | ||
panel.getAttribute('data-mm-title') || | ||
(opener ? opener.textContent : '') || | ||
this.i18n(this.opts.navbar.title) || | ||
this.i18n('Menu'); | ||
(opener ? opener.textContent : '') || | ||
this.i18n(this.opts.navbar.title) || | ||
this.i18n('Menu'); | ||
switch (this.opts.navbar.titleLink) { | ||
@@ -677,3 +742,7 @@ case 'anchor': | ||
listitem.classList.add('mm-listitem'); | ||
DOM.reClass(listitem, _this.conf.classNames.selected, 'mm-listitem_selected'); | ||
DOM.reClass( | ||
listitem, | ||
_this.conf.classNames.selected, | ||
'mm-listitem_selected' | ||
); | ||
DOM.children(listitem, 'a, span').forEach(function (item) { | ||
@@ -696,3 +765,5 @@ if (!item.matches('.mm-btn')) { | ||
/** The selected listitem(s). */ | ||
var listitems = this.node.pnls.querySelectorAll('.mm-listitem_selected'); | ||
var listitems = this.node.pnls.querySelectorAll( | ||
'.mm-listitem_selected' | ||
); | ||
/** The last selected listitem. */ | ||
@@ -725,52 +796,78 @@ var lastitem = null; | ||
this.trigger('initAnchors:before'); | ||
document.addEventListener('click', function (evnt) { | ||
/** The clicked element. */ | ||
var target = evnt.target.closest('a[href]'); | ||
if (!target) { | ||
return; | ||
} | ||
/** Arguments passed to the bound methods. */ | ||
var args = { | ||
inMenu: target.closest('.mm-menu') === _this.node.menu, | ||
inListview: target.matches('.mm-listitem > a'), | ||
toExternal: target.matches('[rel="external"]') || | ||
target.matches('[target="_blank"]'), | ||
}; | ||
var onClick = { | ||
close: null, | ||
setSelected: null, | ||
preventDefault: target.getAttribute('href').slice(0, 1) == '#', | ||
}; | ||
// Find hooked behavior. | ||
for (var c = 0; c < _this.clck.length; c++) { | ||
var click = _this.clck[c].call(_this, target, args); | ||
if (click) { | ||
if (typeof click == 'boolean') { | ||
document.addEventListener( | ||
'click', | ||
function (evnt) { | ||
/** The clicked element. */ | ||
var target = evnt.target.closest('a[href]'); | ||
if (!target) { | ||
return; | ||
} | ||
/** Arguments passed to the bound methods. */ | ||
var args = { | ||
inMenu: target.closest('.mm-menu') === _this.node.menu, | ||
inListview: target.matches('.mm-listitem > a'), | ||
toExternal: | ||
target.matches('[rel="external"]') || | ||
target.matches('[target="_blank"]'), | ||
}; | ||
var onClick = { | ||
close: null, | ||
setSelected: null, | ||
preventDefault: | ||
target.getAttribute('href').slice(0, 1) == '#', | ||
}; | ||
// Find hooked behavior. | ||
for (var c = 0; c < _this.clck.length; c++) { | ||
var click = _this.clck[c].call(_this, target, args); | ||
if (click) { | ||
if (typeof click == 'boolean') { | ||
evnt.preventDefault(); | ||
return; | ||
} | ||
if (type(click) == 'object') { | ||
onClick = extend(click, onClick); | ||
} | ||
} | ||
} | ||
// Default behavior for anchors in lists. | ||
if (args.inMenu && args.inListview && !args.toExternal) { | ||
// Set selected item, Default: true | ||
if ( | ||
valueOrFn( | ||
target, | ||
_this.opts.onClick.setSelected, | ||
onClick.setSelected | ||
) | ||
) { | ||
_this.setSelected(target.parentElement); | ||
} | ||
// Prevent default / don't follow link. Default: false. | ||
if ( | ||
valueOrFn( | ||
target, | ||
_this.opts.onClick.preventDefault, | ||
onClick.preventDefault | ||
) | ||
) { | ||
evnt.preventDefault(); | ||
return; | ||
} | ||
if (type(click) == 'object') { | ||
onClick = extend(click, onClick); | ||
// Close menu. Default: false | ||
if ( | ||
valueOrFn( | ||
target, | ||
_this.opts.onClick.close, | ||
onClick.close | ||
) | ||
) { | ||
if ( | ||
_this.opts.offCanvas && | ||
typeof _this.close == 'function' | ||
) { | ||
_this.close(); | ||
} | ||
} | ||
} | ||
} | ||
// Default behavior for anchors in lists. | ||
if (args.inMenu && args.inListview && !args.toExternal) { | ||
// Set selected item, Default: true | ||
if (valueOrFn(target, _this.opts.onClick.setSelected, onClick.setSelected)) { | ||
_this.setSelected(target.parentElement); | ||
} | ||
// Prevent default / don't follow link. Default: false. | ||
if (valueOrFn(target, _this.opts.onClick.preventDefault, onClick.preventDefault)) { | ||
evnt.preventDefault(); | ||
} | ||
// Close menu. Default: false | ||
if (valueOrFn(target, _this.opts.onClick.close, onClick.close)) { | ||
if (_this.opts.offCanvas && | ||
typeof _this.close == 'function') { | ||
_this.close(); | ||
} | ||
} | ||
} | ||
}, true); | ||
}, | ||
true | ||
); | ||
// Invoke "after" hook. | ||
@@ -802,3 +899,3 @@ this.trigger('initAnchors:after'); | ||
return Mmenu; | ||
}()); | ||
})(); | ||
export default Mmenu; |
{ | ||
"name": "mmenu-js", | ||
"version": "8.5.13", | ||
"version": "8.5.14", | ||
"main": "dist/mmenu.js", | ||
@@ -38,5 +38,5 @@ "module": "src/mmenu.js", | ||
"gulp-typescript": "^5.0.1", | ||
"typescript": "^3.8.3", | ||
"typescript": "^3.9.7", | ||
"webpack-stream": "^5.2.1" | ||
} | ||
} |
@@ -10,3 +10,3 @@ import Mmenu from '../../core/oncanvas/mmenu.oncanvas'; | ||
export default function(this: Mmenu) { | ||
export default function (this: Mmenu) { | ||
if (!this.opts.offCanvas) { | ||
@@ -30,3 +30,3 @@ return; | ||
'.mm-panel_opened, .mm-panel_opened-parent' | ||
).forEach(panel => { | ||
).forEach((panel) => { | ||
states.push('#' + panel.id); | ||
@@ -51,3 +51,3 @@ }); | ||
window.addEventListener('popstate', evnt => { | ||
window.addEventListener('popstate', (evnt) => { | ||
if (this.vars.opened) { | ||
@@ -70,3 +70,3 @@ if (states.length) { | ||
if (options.open) { | ||
window.addEventListener('popstate', evnt => { | ||
window.addEventListener('popstate', (evnt) => { | ||
if (!this.vars.opened && location.hash == _menu) { | ||
@@ -73,0 +73,0 @@ this.open(); |
@@ -12,6 +12,6 @@ import Mmenu from '../../core/oncanvas/mmenu.oncanvas'; | ||
Mmenu.configs.classNames.counters = { | ||
counter: 'Counter' | ||
counter: 'Counter', | ||
}; | ||
export default function(this: Mmenu) { | ||
export default function (this: Mmenu) { | ||
var options = extendShorthandOptions(this.opts.counters); | ||
@@ -25,3 +25,3 @@ this.opts.counters = extend(options, Mmenu.options.counters); | ||
counters.forEach(counter => { | ||
counters.forEach((counter) => { | ||
DOM.reClass(counter as HTMLElement, cntrclss, 'mm-counter'); | ||
@@ -57,3 +57,3 @@ }); | ||
panels.forEach(panel => { | ||
panels.forEach((panel) => { | ||
var parent: HTMLElement = panel['mmParent']; | ||
@@ -71,3 +71,3 @@ | ||
var listitems: HTMLElement[] = []; | ||
DOM.children(panel, '.mm-listview').forEach(listview => { | ||
DOM.children(panel, '.mm-listview').forEach((listview) => { | ||
listitems.push(...DOM.children(listview)); | ||
@@ -74,0 +74,0 @@ }); |
Sorry, the diff of this file is too big to display
744645
13316