advanced-menus
Advanced tools
Comparing version 1.0.10 to 1.0.11
@@ -1,1 +0,1 @@ | ||
!function(e){function t(n){if(s[n])return s[n].exports;var i=s[n]={i:n,l:!1,exports:{}};return e[n].call(i.exports,i,i.exports,t),i.l=!0,i.exports}var s={};t.m=e,t.c=s,t.i=function(e){return e},t.d=function(e,s,n){t.o(e,s)||Object.defineProperty(e,s,{configurable:!1,enumerable:!0,get:n})},t.n=function(e){var s=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(s,"a",s),s},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=1)}([function(e,t,s){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(t,"__esModule",{value:!0});var i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},o=function(){function e(e,t){for(var s=0;s<t.length;s++){var n=t[s];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,s,n){return s&&e(t.prototype,s),n&&e(t,n),t}}(),u=function(){function e(t){n(this,e),this.config(t);var s=this.settings.selectors;if(this.menu=document.getElementById(s.menu_id),!this.menu)return void console.error("unable to find the menu with selector: "+s.menu_id);if(this.menuitems=this.menu.querySelectorAll(s.menuitem+" a"),this.submenus=this.menu.querySelectorAll(s.submenu),this.submenus.length)for(var i=0;i<this.submenus.length;i++)this.submenus[i].parentNode.classList.add("am-has-children");var o;if(this.settings.options.parent_clickable?(this.initHandles(),o=this.menu.querySelectorAll(s.menuitem+" .handle")):o=this.menu.querySelectorAll(s.menuitem+" a"),this.registerEventAll(o,"click",this.onMenuItemClick),this.submenus.length)for(var i=0;i<this.submenus.length;i++)this.initSubmenu(this.submenus[i]);this.toggleButtons=document.querySelectorAll(s.toggle_button),this.registerEventAll(this.toggleButtons,"click",this.toggle),this.openButtons=document.querySelectorAll(s.open_button),this.registerEventAll(this.openButtons,"click",this.open),this.closeButtons=document.querySelectorAll(s.close_button),this.registerEventAll(this.closeButtons,"click",this.close),document.addEventListener("touchstart",this.onTouchStart.bind(this),!1),document.addEventListener("touchmove",this.onTouchMove.bind(this),!1),this.settings.options.autoclose&&document.addEventListener("mousedown",this.documentClick.bind(this))}return o(e,[{key:"config",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=this.settings||{options:{disable_page_scroll:!1,autoclose:!0,parent_clickable:!1},events:{swipeLeft:function(){},swipeRight:function(){},swipeUp:function(){},swipeDown:function(){}},selectors:{menu_id:"main-menu",menuitem:"li",submenu:"li > ul",toggle_button:!1,open_button:!1,close_button:!1}};for(var s in t)if("object"==i(t[s])&&e[s])for(var n in t[s])void 0!==e[s][n]&&(t[s][n]=e[s][n]);return this.settings=t,this}},{key:"onMenuItemClick",value:function(e){for(var t=e.target.parentNode.classList.contains("active"),s=e.target.parentNode.parentNode.querySelectorAll(".am-has-children"),n=0;n<s.length;n++)s[n].classList.remove("active");t||e.target.parentNode.classList.add("active");var i=e.target.parentNode.querySelector(this.settings.selectors.submenu);if(!i)return void this.close();e.preventDefault(),e.target.parentNode.removeAttribute("style"),this.toggleSubmenu(i)}},{key:"toggle",value:function(){if(this.menu.classList.toggle("active"),document.body.classList.toggle("am-menu-active"),document.body.classList.toggle("menu-"+this.settings.selectors.menu_id+"-active"),this.settings.options.disable_page_scroll&&document.body.classList.toggle("scroll-disabled"),!this.menu.classList.contains("active"))for(var e=0;e<this.submenus.length;e++)this.closeSubmenu(this.submenus[e])}},{key:"open",value:function(){this.menu.classList.add("active"),document.body.classList.add("am-menu-active"),document.body.classList.add("menu-"+this.settings.selectors.menu_id+"-active"),this.settings.options.disable_page_scroll&&document.body.classList.add("scroll-disabled")}},{key:"close",value:function(){for(var e=this.menu.querySelectorAll(".am-has-children"),t=0;t<e.length;t++)e[t].classList.remove("active");for(var t=0;t<this.submenus.length;t++)this.closeSubmenu(this.submenus[t]);this.menu.classList.contains("active")&&(this.menu.classList.remove("active"),document.body.classList.remove("am-menu-active"),document.body.classList.remove("menu-"+this.settings.selectors.menu_id+"-active"),this.settings.options.disable_page_scroll&&document.body.classList.remove("scroll-disabled"))}},{key:"toggleSubmenu",value:function(e){e.classList.contains("active")||this.can_open_multiple(this.closest(e,e.className)),e.classList.toggle("active")}},{key:"openSubmenu",value:function(e){this.can_open_multiple(),e.classList.add("active")}},{key:"closeSubmenu",value:function(e){e.classList.remove("active")}},{key:"onTouchStart",value:function(e){this.xDown=e.touches[0].clientX,this.yDown=e.touches[0].clientY}},{key:"onTouchMove",value:function(e){if(this.xDown&&this.yDown){var t=e.touches[0].clientX,s=e.touches[0].clientY,n=this.xDown-t,i=this.yDown-s;Math.abs(n)>Math.abs(i)?n>0?this.settings.events.swipeLeft(this,e):this.settings.events.swipeRight(this,e):i>0?this.settings.events.swipeUp(this,e):this.settings.events.swipeDown(this,e),this.xDown=null,this.yDown=null}}},{key:"can_open_multiple",value:function(e){for(var t=0;t<this.submenus.length;t++)e!=this.submenus[t]&&this.closeSubmenu(this.submenus[t])}},{key:"initSubmenu",value:function(e){e.classList.add("active");for(var t=0;t<this.menuitems.length;t++){if(this.closest(this.menuitems[t],"sub-menu"))var s=this.menuitems[t].offsetHeight;s+=parseInt(window.getComputedStyle(this.menuitems[t]).getPropertyValue("margin-top")),s+=parseInt(window.getComputedStyle(this.menuitems[t]).getPropertyValue("margin-bottom")),this.menuitems[t].parentNode.style.maxHeight=s+"px"}e.classList.remove("active")}},{key:"closest",value:function(e,t){return!(!e.parentNode||!e.parentNode.className)&&(-1!=e.parentNode.className.indexOf(t)?e.parentNode:this.closest(e.parentNode,t))}},{key:"documentClick",value:function(e){for(var t=!0,s=0;s<e.path.length;s++)(e.path[s].id==this.settings.selectors.menu_id||e.path[s].classList&&e.path[s].classList.contains("menu-toggle-button"))&&(t=!1);t&&this.close()}},{key:"registerEventAll",value:function(e,t,s){if(e.length)for(var n=0;n<e.length;n++)e[n].addEventListener(t,s.bind(this))}},{key:"initHandles",value:function(){for(var e=this.menu.querySelectorAll(".am-has-children"),t=0;t<e.length;t++){var s=document.createElement("span");s.classList.add("handle"),e[t].insertBefore(s,e[t].children[1])}}}]),e}();t.default=u},function(e,t,s){"use strict";var n=s(0);e.exports=n.default}]); | ||
!function(e){function t(n){if(s[n])return s[n].exports;var i=s[n]={i:n,l:!1,exports:{}};return e[n].call(i.exports,i,i.exports,t),i.l=!0,i.exports}var s={};t.m=e,t.c=s,t.i=function(e){return e},t.d=function(e,s,n){t.o(e,s)||Object.defineProperty(e,s,{configurable:!1,enumerable:!0,get:n})},t.n=function(e){var s=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(s,"a",s),s},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=1)}([function(e,t,s){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(t,"__esModule",{value:!0});var i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},o=function(){function e(e,t){for(var s=0;s<t.length;s++){var n=t[s];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,s,n){return s&&e(t.prototype,s),n&&e(t,n),t}}(),u=function(){function e(t){n(this,e),this.config(t);var s=this.settings.selectors;if(this.menu=document.getElementById(s.menu_id),!this.menu)return void console.error("unable to find the menu with selector: "+s.menu_id);if(this.menuitems=this.menu.querySelectorAll(s.menuitem+" a"),this.submenus=this.menu.querySelectorAll(s.submenu),this.submenus.length)for(var i=0;i<this.submenus.length;i++)this.submenus[i].parentNode.classList.add("am-has-children");var o;if(this.settings.options.parent_clickable?(this.initHandles(),o=this.menu.querySelectorAll(s.menuitem+" .handle")):o=this.menu.querySelectorAll(s.menuitem+" a"),this.registerEventAll(o,"click",this.onMenuItemClick),this.submenus.length)for(var i=0;i<this.submenus.length;i++)this.initSubmenu(this.submenus[i]);this.toggleButtons=document.querySelectorAll(s.toggle_button),this.registerEventAll(this.toggleButtons,"click",this.toggle),this.openButtons=document.querySelectorAll(s.open_button),this.registerEventAll(this.openButtons,"click",this.open),this.closeButtons=document.querySelectorAll(s.close_button),this.registerEventAll(this.closeButtons,"click",this.close),document.addEventListener("touchstart",this.onTouchStart.bind(this),!1),document.addEventListener("touchmove",this.onTouchMove.bind(this),!1),this.settings.options.autoclose&&document.addEventListener("mousedown",this.documentClick.bind(this))}return o(e,[{key:"config",value:function(e){var t=this.settings||{options:{disable_page_scroll:!1,autoclose:!0,parent_clickable:!1},events:{swipeLeft:function(){},swipeRight:function(){},swipeUp:function(){},swipeDown:function(){}},selectors:{menu_id:"main-menu",menuitem:"li",submenu:"li > ul",toggle_button:!1,open_button:!1,close_button:!1}};for(var s in t)if("object"==i(t[s])&&e[s])for(var n in t[s])void 0!==e[s][n]&&(t[s][n]=e[s][n]);return this.settings=t,this}},{key:"onMenuItemClick",value:function(e){for(var t=e.target.parentNode.classList.contains("active"),s=e.target.parentNode.parentNode.querySelectorAll(".am-has-children"),n=0;n<s.length;n++)s[n].classList.remove("active");t||e.target.parentNode.classList.add("active");var i=e.target.parentNode.querySelector(this.settings.selectors.submenu);if(!i)return void this.close();e.preventDefault(),e.target.parentNode.removeAttribute("style"),this.toggleSubmenu(i)}},{key:"toggle",value:function(){if(this.menu.classList.toggle("active"),document.body.classList.toggle("am-menu-active"),document.body.classList.toggle("menu-"+this.settings.selectors.menu_id+"-active"),this.settings.options.disable_page_scroll&&document.body.classList.toggle("scroll-disabled"),!this.menu.classList.contains("active"))for(var e=0;e<this.submenus.length;e++)this.closeSubmenu(this.submenus[e])}},{key:"open",value:function(){this.menu.classList.add("active"),document.body.classList.add("am-menu-active"),document.body.classList.add("menu-"+this.settings.selectors.menu_id+"-active"),this.settings.options.disable_page_scroll&&document.body.classList.add("scroll-disabled")}},{key:"close",value:function(){for(var e=this.menu.querySelectorAll(".am-has-children"),t=0;t<e.length;t++)e[t].classList.remove("active");for(var t=0;t<this.submenus.length;t++)this.closeSubmenu(this.submenus[t]);this.menu.classList.contains("active")&&(this.menu.classList.remove("active"),document.body.classList.remove("am-menu-active"),document.body.classList.remove("menu-"+this.settings.selectors.menu_id+"-active"),this.settings.options.disable_page_scroll&&document.body.classList.remove("scroll-disabled"))}},{key:"toggleSubmenu",value:function(e){e.classList.contains("active")||this.can_open_multiple(this.closest(e,e.className)),e.classList.toggle("active")}},{key:"openSubmenu",value:function(e){this.can_open_multiple(),e.classList.add("active")}},{key:"closeSubmenu",value:function(e){e.classList.remove("active")}},{key:"onTouchStart",value:function(e){this.xDown=e.touches[0].clientX,this.yDown=e.touches[0].clientY}},{key:"onTouchMove",value:function(e){if(this.xDown&&this.yDown){var t=e.touches[0].clientX,s=e.touches[0].clientY,n=this.xDown-t,i=this.yDown-s;Math.abs(n)>Math.abs(i)?n>0?this.settings.events.swipeLeft(this,e):this.settings.events.swipeRight(this,e):i>0?this.settings.events.swipeUp(this,e):this.settings.events.swipeDown(this,e),this.xDown=null,this.yDown=null}}},{key:"can_open_multiple",value:function(e){for(var t=0;t<this.submenus.length;t++)e!=this.submenus[t]&&this.closeSubmenu(this.submenus[t])}},{key:"initSubmenu",value:function(e){e.classList.add("active");for(var t=0;t<this.menuitems.length;t++){if(this.closest(this.menuitems[t],"sub-menu"))var s=this.menuitems[t].offsetHeight;s+=parseInt(window.getComputedStyle(this.menuitems[t]).getPropertyValue("margin-top")),s+=parseInt(window.getComputedStyle(this.menuitems[t]).getPropertyValue("margin-bottom")),this.menuitems[t].parentNode.style.maxHeight=s+"px"}e.classList.remove("active")}},{key:"closest",value:function(e,t){return!(!e.parentNode||!e.parentNode.className)&&(-1!=e.parentNode.className.indexOf(t)?e.parentNode:this.closest(e.parentNode,t))}},{key:"documentClick",value:function(e){for(var t=!0,s=e.path||e.composedPath(),n=0;n<s.length;n++)(s[n].id==this.settings.selectors.menu_id||s[n].classList&&s[n].classList.contains("toggle-mainmenu-button"))&&(t=!1);t&&this.close()}},{key:"registerEventAll",value:function(e,t,s){if(e.length)for(var n=0;n<e.length;n++)e[n].addEventListener(t,s.bind(this))}},{key:"initHandles",value:function(){for(var e=this.menu.querySelectorAll(".am-has-children"),t=0;t<e.length;t++){var s=document.createElement("span");s.classList.add("handle"),e[t].insertBefore(s,e[t].children[1])}}}]),e}();t.default=u},function(e,t,s){"use strict";var n=s(0);e.exports=n.default}]); |
@@ -1,2 +0,2 @@ | ||
var Menu = require("./module/Menu") | ||
var Menu = require("./module/menu") | ||
module.exports = Menu.default; |
export default class Menu { | ||
constructor(args){ | ||
constructor(args) { | ||
this.config(args); | ||
@@ -8,83 +8,89 @@ var selectors = this.settings.selectors; | ||
this.menu = document.getElementById(selectors.menu_id); | ||
if(!this.menu) { | ||
console.error("unable to find the menu with selector: " + selectors.menu_id); | ||
if (!this.menu) { | ||
console.error( | ||
"unable to find the menu with selector: " + selectors.menu_id | ||
); | ||
return; | ||
}; | ||
} | ||
this.menuitems = this.menu.querySelectorAll(selectors.menuitem + ' a') | ||
this.menuitems = this.menu.querySelectorAll(selectors.menuitem + " a"); | ||
//init submenus | ||
this.submenus = this.menu.querySelectorAll(selectors.submenu); | ||
if(this.submenus.length) | ||
for(var i=0; i < this.submenus.length; i++){ | ||
this.submenus[i].parentNode.classList.add('am-has-children') | ||
} | ||
if (this.submenus.length) | ||
for (var i = 0; i < this.submenus.length; i++) { | ||
this.submenus[i].parentNode.classList.add("am-has-children"); | ||
} | ||
//init menuitems | ||
var handles; | ||
if(this.settings.options.parent_clickable){ | ||
if (this.settings.options.parent_clickable) { | ||
this.initHandles(); | ||
handles = this.menu.querySelectorAll(selectors.menuitem + ' .handle'); | ||
}else{ | ||
handles = this.menu.querySelectorAll(selectors.menuitem + ' a'); | ||
handles = this.menu.querySelectorAll(selectors.menuitem + " .handle"); | ||
} else { | ||
handles = this.menu.querySelectorAll(selectors.menuitem + " a"); | ||
} | ||
this.registerEventAll(handles, 'click', this.onMenuItemClick); | ||
this.registerEventAll(handles, "click", this.onMenuItemClick); | ||
if(this.submenus.length) | ||
for(var i=0; i < this.submenus.length; i++){ | ||
this.initSubmenu(this.submenus[i]); | ||
} | ||
if (this.submenus.length) | ||
for (var i = 0; i < this.submenus.length; i++) { | ||
this.initSubmenu(this.submenus[i]); | ||
} | ||
// init toggleButtons | ||
this.toggleButtons = document.querySelectorAll(selectors.toggle_button); | ||
this.registerEventAll(this.toggleButtons, 'click', this.toggle); | ||
this.registerEventAll(this.toggleButtons, "click", this.toggle); | ||
// init openButtons | ||
this.openButtons = document.querySelectorAll(selectors.open_button); | ||
this.registerEventAll(this.openButtons, 'click', this.open); | ||
this.registerEventAll(this.openButtons, "click", this.open); | ||
// init closeButtons | ||
this.closeButtons = document.querySelectorAll(selectors.close_button); | ||
this.registerEventAll(this.closeButtons, 'click', this.close); | ||
this.registerEventAll(this.closeButtons, "click", this.close); | ||
//init swiping | ||
document.addEventListener('touchstart', this.onTouchStart.bind(this), false); | ||
document.addEventListener('touchmove', this.onTouchMove.bind(this), false); | ||
document.addEventListener( | ||
"touchstart", | ||
this.onTouchStart.bind(this), | ||
false | ||
); | ||
document.addEventListener("touchmove", this.onTouchMove.bind(this), false); | ||
//document click | ||
if(this.settings.options.autoclose) | ||
document.addEventListener('mousedown', this.documentClick.bind(this)) | ||
if (this.settings.options.autoclose) | ||
document.addEventListener("mousedown", this.documentClick.bind(this)); | ||
} | ||
config (args = {}) { | ||
config(args) { | ||
var defaultConfig = this.settings || { | ||
options:{ | ||
options: { | ||
disable_page_scroll: false, | ||
autoclose: true, | ||
parent_clickable: false, | ||
parent_clickable: false | ||
}, | ||
events: { | ||
swipeLeft: function(){}, | ||
swipeRight: function(){}, | ||
swipeUp: function(){}, | ||
swipeDown: function(){} | ||
swipeLeft: function() {}, | ||
swipeRight: function() {}, | ||
swipeUp: function() {}, | ||
swipeDown: function() {} | ||
}, | ||
selectors:{ | ||
menu_id: 'main-menu', | ||
menuitem: 'li', | ||
submenu: 'li > ul', | ||
selectors: { | ||
menu_id: "main-menu", | ||
menuitem: "li", | ||
submenu: "li > ul", | ||
toggle_button: false, | ||
open_button: false, | ||
close_button: false, | ||
close_button: false | ||
} | ||
} | ||
}; | ||
for (var config in defaultConfig){ | ||
if(typeof defaultConfig[config] == "object" && args[config]) | ||
for (var opt in defaultConfig[config]){ | ||
if(typeof args[config][opt] != "undefined") { | ||
defaultConfig[config][opt] = args[config][opt]; | ||
for (var config in defaultConfig) { | ||
if (typeof defaultConfig[config] == "object" && args[config]) | ||
for (var opt in defaultConfig[config]) { | ||
if (typeof args[config][opt] != "undefined") { | ||
defaultConfig[config][opt] = args[config][opt]; | ||
} | ||
} | ||
} | ||
} | ||
@@ -96,11 +102,15 @@ | ||
onMenuItemClick (e){ | ||
onMenuItemClick(e) { | ||
var is_active = e.target.parentNode.classList.contains("active"); | ||
var submenuitems = e.target.parentNode.parentNode.querySelectorAll('.am-has-children') | ||
for(var i = 0; i < submenuitems.length; i++){ | ||
submenuitems[i].classList.remove('active') | ||
var submenuitems = e.target.parentNode.parentNode.querySelectorAll( | ||
".am-has-children" | ||
); | ||
for (var i = 0; i < submenuitems.length; i++) { | ||
submenuitems[i].classList.remove("active"); | ||
} | ||
if(!is_active) e.target.parentNode.classList.add("active"); | ||
var submenu = e.target.parentNode.querySelector(this.settings.selectors.submenu); | ||
if(!submenu) { | ||
if (!is_active) e.target.parentNode.classList.add("active"); | ||
var submenu = e.target.parentNode.querySelector( | ||
this.settings.selectors.submenu | ||
); | ||
if (!submenu) { | ||
this.close(); | ||
@@ -111,16 +121,18 @@ return; | ||
e.preventDefault(); | ||
e.target.parentNode.removeAttribute("style") | ||
e.target.parentNode.removeAttribute("style"); | ||
this.toggleSubmenu(submenu); | ||
} | ||
toggle(){ | ||
this.menu.classList.toggle('active') | ||
document.body.classList.toggle('am-menu-active'); | ||
document.body.classList.toggle('menu-'+ this.settings.selectors.menu_id + '-active'); | ||
toggle() { | ||
this.menu.classList.toggle("active"); | ||
document.body.classList.toggle("am-menu-active"); | ||
document.body.classList.toggle( | ||
"menu-" + this.settings.selectors.menu_id + "-active" | ||
); | ||
if(this.settings.options.disable_page_scroll) | ||
document.body.classList.toggle('scroll-disabled'); | ||
if (this.settings.options.disable_page_scroll) | ||
document.body.classList.toggle("scroll-disabled"); | ||
if(!this.menu.classList.contains('active')){ | ||
for(var i = 0; i < this.submenus.length; i++){ | ||
if (!this.menu.classList.contains("active")) { | ||
for (var i = 0; i < this.submenus.length; i++) { | ||
this.closeSubmenu(this.submenus[i]); | ||
@@ -131,47 +143,51 @@ } | ||
open(){ | ||
this.menu.classList.add('active') | ||
document.body.classList.add('am-menu-active'); | ||
document.body.classList.add('menu-'+ this.settings.selectors.menu_id + '-active'); | ||
open() { | ||
this.menu.classList.add("active"); | ||
document.body.classList.add("am-menu-active"); | ||
document.body.classList.add( | ||
"menu-" + this.settings.selectors.menu_id + "-active" | ||
); | ||
if(this.settings.options.disable_page_scroll) | ||
document.body.classList.add('scroll-disabled'); | ||
if (this.settings.options.disable_page_scroll) | ||
document.body.classList.add("scroll-disabled"); | ||
} | ||
close(){ | ||
var submenuitems = this.menu.querySelectorAll('.am-has-children') | ||
for(var i = 0; i < submenuitems.length; i++){ | ||
submenuitems[i].classList.remove('active') | ||
close() { | ||
var submenuitems = this.menu.querySelectorAll(".am-has-children"); | ||
for (var i = 0; i < submenuitems.length; i++) { | ||
submenuitems[i].classList.remove("active"); | ||
} | ||
for(var i = 0; i < this.submenus.length; i++){ | ||
for (var i = 0; i < this.submenus.length; i++) { | ||
this.closeSubmenu(this.submenus[i]); | ||
} | ||
if(this.menu.classList.contains('active')){ | ||
this.menu.classList.remove('active') | ||
document.body.classList.remove('am-menu-active'); | ||
document.body.classList.remove('menu-'+ this.settings.selectors.menu_id + '-active'); | ||
if (this.menu.classList.contains("active")) { | ||
this.menu.classList.remove("active"); | ||
document.body.classList.remove("am-menu-active"); | ||
document.body.classList.remove( | ||
"menu-" + this.settings.selectors.menu_id + "-active" | ||
); | ||
if(this.settings.options.disable_page_scroll) | ||
document.body.classList.remove('scroll-disabled'); | ||
if (this.settings.options.disable_page_scroll) | ||
document.body.classList.remove("scroll-disabled"); | ||
} | ||
} | ||
toggleSubmenu(submenu){ | ||
if(!submenu.classList.contains('active')) | ||
this.can_open_multiple(this.closest(submenu, submenu.className)); | ||
submenu.classList.toggle('active'); | ||
toggleSubmenu(submenu) { | ||
if (!submenu.classList.contains("active")) | ||
this.can_open_multiple(this.closest(submenu, submenu.className)); | ||
submenu.classList.toggle("active"); | ||
} | ||
openSubmenu(submenu){ | ||
openSubmenu(submenu) { | ||
this.can_open_multiple(); | ||
submenu.classList.add('active') | ||
submenu.classList.add("active"); | ||
} | ||
closeSubmenu(submenu){ | ||
submenu.classList.remove('active') | ||
closeSubmenu(submenu) { | ||
submenu.classList.remove("active"); | ||
} | ||
onTouchStart (e) { | ||
onTouchStart(e) { | ||
this.xDown = e.touches[0].clientX; | ||
@@ -181,4 +197,4 @@ this.yDown = e.touches[0].clientY; | ||
onTouchMove (evt) { | ||
if ( ! this.xDown || ! this.yDown ) { | ||
onTouchMove(evt) { | ||
if (!this.xDown || !this.yDown) { | ||
return; | ||
@@ -193,4 +209,4 @@ } | ||
if ( Math.abs( xDiff ) > Math.abs( yDiff ) ) { | ||
if ( xDiff > 0 ) { | ||
if (Math.abs(xDiff) > Math.abs(yDiff)) { | ||
if (xDiff > 0) { | ||
this.settings.events.swipeLeft(this, evt); | ||
@@ -201,3 +217,3 @@ } else { | ||
} else { | ||
if ( yDiff > 0 ) { | ||
if (yDiff > 0) { | ||
this.settings.events.swipeUp(this, evt); | ||
@@ -214,6 +230,5 @@ } else { | ||
can_open_multiple(parentMenu){ | ||
for(var i = 0; i < this.submenus.length; i++){ | ||
if(parentMenu != this.submenus[i]) | ||
this.closeSubmenu(this.submenus[i]); | ||
can_open_multiple(parentMenu) { | ||
for (var i = 0; i < this.submenus.length; i++) { | ||
if (parentMenu != this.submenus[i]) this.closeSubmenu(this.submenus[i]); | ||
} | ||
@@ -223,26 +238,32 @@ } | ||
initSubmenu(submenu) { | ||
submenu.classList.add('active'); | ||
submenu.classList.add("active"); | ||
for (var i = 0; i< this.menuitems.length; i++){ | ||
if(this.closest(this.menuitems[i], 'sub-menu')) | ||
var elHeight = this.menuitems[i].offsetHeight; | ||
elHeight += parseInt(window.getComputedStyle(this.menuitems[i]).getPropertyValue('margin-top')); | ||
elHeight += parseInt(window.getComputedStyle(this.menuitems[i]).getPropertyValue('margin-bottom')); | ||
for (var i = 0; i < this.menuitems.length; i++) { | ||
if (this.closest(this.menuitems[i], "sub-menu")) | ||
var elHeight = this.menuitems[i].offsetHeight; | ||
elHeight += parseInt( | ||
window | ||
.getComputedStyle(this.menuitems[i]) | ||
.getPropertyValue("margin-top") | ||
); | ||
elHeight += parseInt( | ||
window | ||
.getComputedStyle(this.menuitems[i]) | ||
.getPropertyValue("margin-bottom") | ||
); | ||
this.menuitems[i].parentNode.style.maxHeight = elHeight + "px" | ||
this.menuitems[i].parentNode.style.maxHeight = elHeight + "px"; | ||
} | ||
submenu.classList.remove('active'); | ||
submenu.classList.remove("active"); | ||
} | ||
closest(el, classname) { | ||
if(el.parentNode && el.parentNode.className){ | ||
if(el.parentNode.className.indexOf(classname) != -1){ | ||
if (el.parentNode && el.parentNode.className) { | ||
if (el.parentNode.className.indexOf(classname) != -1) { | ||
return el.parentNode; | ||
} | ||
else{ | ||
} else { | ||
return this.closest(el.parentNode, classname); | ||
} | ||
} | ||
else{ | ||
} else { | ||
return false; | ||
@@ -252,32 +273,35 @@ } | ||
documentClick (e){ | ||
documentClick(e) { | ||
var hide = true; | ||
for(var i = 0; i < e.path.length; i++ ){ | ||
if( | ||
e.path[i].id == this.settings.selectors.menu_id || | ||
e.path[i].classList && e.path[i].classList.contains('menu-toggle-button') | ||
) | ||
hide = false; | ||
var path = e.path || e.composedPath(); | ||
for (var i = 0; i < path.length; i++) { | ||
// alert(path[i].classList); | ||
if ( | ||
path[i].id == this.settings.selectors.menu_id || | ||
// path[i].classList && path[i].classList.contains('menu-toggle-button') | ||
(path[i].classList && | ||
path[i].classList.contains("toggle-mainmenu-button")) | ||
) { | ||
hide = false; | ||
} | ||
} | ||
if(hide) this.close(); | ||
if (hide) this.close(); | ||
} | ||
registerEventAll (elements, eventname, callback){ | ||
if(elements.length) | ||
for(var i=0; i < elements.length; i++){ | ||
elements[i].addEventListener(eventname, callback.bind(this)); | ||
} | ||
registerEventAll(elements, eventname, callback) { | ||
if (elements.length) | ||
for (var i = 0; i < elements.length; i++) { | ||
elements[i].addEventListener(eventname, callback.bind(this)); | ||
} | ||
} | ||
initHandles(){ | ||
var menuitems = this.menu.querySelectorAll('.am-has-children'); | ||
for (var i=0; i < menuitems.length; i++){ | ||
var handle = document.createElement('span'); | ||
handle.classList.add('handle'); | ||
initHandles() { | ||
var menuitems = this.menu.querySelectorAll(".am-has-children"); | ||
for (var i = 0; i < menuitems.length; i++) { | ||
var handle = document.createElement("span"); | ||
handle.classList.add("handle"); | ||
menuitems[i].insertBefore(handle, menuitems[i].children[1]); | ||
} | ||
} | ||
} |
{ | ||
"name": "advanced-menus", | ||
"version": "1.0.10", | ||
"version": "1.0.11", | ||
"description": "Easy to use and configurable HTML5 Menus", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -0,0 +0,0 @@ # Menu Package for Webpack. |
@@ -0,0 +0,0 @@ var path = require('path'); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
240111
296
21
1