From 1dfced9398be12cb1fc0b032f55347233e31be65 Mon Sep 17 00:00:00 2001 From: Ben Sterling Date: Wed, 4 Jul 2018 16:31:37 +0100 Subject: [PATCH] Add no-scroll to prevent scrolling when menu is open --- dist/MenuChef.js | 2 +- dist/MenuChef.js.map | 2 +- package-lock.json | 5 +++++ package.json | 5 +++-- src/MenuChef.js | 3 +++ 5 files changed, 13 insertions(+), 4 deletions(-) diff --git a/dist/MenuChef.js b/dist/MenuChef.js index 3b3dc31..b26782b 100644 --- a/dist/MenuChef.js +++ b/dist/MenuChef.js @@ -3,5 +3,5 @@ * http://github.com/theus/MenuChef * Released under the MIT License. */ -!function(e){function n(t){if(r[t])return r[t].exports;var a=r[t]={i:t,l:!1,exports:{}};return e[t].call(a.exports,a,a.exports,n),a.l=!0,a.exports}var r={};n.m=e,n.c=r,n.d=function(e,r,t){n.o(e,r)||Object.defineProperty(e,r,{configurable:!1,enumerable:!0,get:t})},n.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(r,"a",r),r},n.o=function(e,n){return Object.prototype.hasOwnProperty.call(e,n)},n.p="",n(n.s=17)}([function(e,n,r){"use strict";function t(e){return null==e?void 0===e?c:s:u&&u in Object(e)?Object(i.a)(e):Object(o.a)(e)}var a=r(9),i=r(22),o=r(23),s="[object Null]",c="[object Undefined]",u=a.a?a.a.toStringTag:void 0;n.a=t},function(e,n,r){"use strict";var t=r(10),a="object"==typeof self&&self&&self.Object===Object&&self,i=t.a||a||Function("return this")();n.a=i},function(e,n,r){"use strict";function t(e){var n=typeof e;return null!=e&&("object"==n||"function"==n)}n.a=t},function(e,n,r){"use strict";function t(e){return null!=e&&Object(i.a)(e.length)&&!Object(a.a)(e)}var a=r(8),i=r(13);n.a=t},function(e,n,r){"use strict";function t(e){return null!=e&&"object"==typeof e}n.a=t},function(e,n,r){"use strict";function t(e,n,r){var t=e[n];s.call(e,n)&&Object(i.a)(t,r)&&(void 0!==r||n in e)||Object(a.a)(e,n,r)}var a=r(6),i=r(11),o=Object.prototype,s=o.hasOwnProperty;n.a=t},function(e,n,r){"use strict";function t(e,n,r){"__proto__"==n&&a.a?Object(a.a)(e,n,{configurable:!0,enumerable:!0,value:r,writable:!0}):e[n]=r}var a=r(7);n.a=t},function(e,n,r){"use strict";var t=r(19),a=function(){try{var e=Object(t.a)(Object,"defineProperty");return e({},"",{}),e}catch(e){}}();n.a=a},function(e,n,r){"use strict";function t(e){if(!Object(i.a)(e))return!1;var n=Object(a.a)(e);return n==s||n==c||n==o||n==u}var a=r(0),i=r(2),o="[object AsyncFunction]",s="[object Function]",c="[object GeneratorFunction]",u="[object Proxy]";n.a=t},function(e,n,r){"use strict";var t=r(1),a=t.a.Symbol;n.a=a},function(e,n,r){"use strict";(function(e){var r="object"==typeof e&&e&&e.Object===Object&&e;n.a=r}).call(n,r(21))},function(e,n,r){"use strict";function t(e,n){return e===n||e!==e&&n!==n}n.a=t},function(e,n,r){"use strict";function t(e){return e}n.a=t},function(e,n,r){"use strict";function t(e){return"number"==typeof e&&e>-1&&e%1==0&&e<=a}var a=9007199254740991;n.a=t},function(e,n,r){"use strict";function t(e,n){var r=typeof e;return!!(n=null==n?a:n)&&("number"==r||"symbol"!=r&&i.test(e))&&e>-1&&e%1==0&&e0&&void 0!==arguments[0]&&arguments[0],n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(a(this,MenuChef),!1===e)throw new Error("MenuChef needs link elements passed as ingredients");if(this._ingredients=document.querySelectorAll(e),0===this._ingredients.length)throw new Error("MenuChef needs link elements passed as ingredients");1===this._ingredients.length&&console.warn('MenuChef don\'t find ingredients. Maybe you passed the menu itself as ingredients. If the class of menu is ".menu", pass ".menu a". The links are the ingredients =)');var r={full:{html:v.default,options:{effectOnOpen:[],pageEffect:[],direction:[]}},side:{html:v.default,options:{effectOnOpen:["smooth"],pageEffect:["blur"],direction:["left","right"]}}},t=["3dx","3dx-r","3dy","3dy-r","arrow","arrow-r","arrowalt","arrowalt-r","boring","collapse","collapse-r","elastic","elastic-r","emphatic","emphatic-r","slider","slider-r","spin","spin-r","spring","spring-r","stand","stand-r","squeeze","vortex","vortex-r"],o=["black","yellow","red","green","blue"],s={parent:"body",theme:{theme:"full",effectOnOpen:"",direction:"",pageEffect:""},scheme:"black",closeOnClick:!0,closeOnClickOutside:!0,button:x.default,classes:{exclude:[],only:[],include:[]},hamburger:"boring",bodyClassOpen:"",kitchenClass:"",kitchenOpenClass:"",onOpen:function(){},onClose:function(){},onClick:function(){},onReady:function(){}};if(this.version=C.version,this._options=(0,c.default)(s,n),this._options.hamburger=(0,b.default)(this._options.hamburger,-1!==t.indexOf(this._options.hamburger),"boring"),this._options.scheme=(0,b.default)(this._options.scheme,-1!==o.indexOf(this._options.scheme),"black"),"string"!=typeof this._options.theme&&"object"!==i(this._options.theme))throw new Error("theme must be a string or a object");if(this._theme="string"==typeof this._options.theme?this._options.theme:this._options.theme.theme,this.$parent=document.querySelector(this._options.parent)?document.querySelector(this._options.parent):document.querySelector(s.parent),this._options.parent===s.parent||this.$parent||console.warning("parent element don't found. body will be used instead."),this._themeOptions="object"===i(this._options.theme)?this._options.theme:{},"function"!=typeof this._options.onOpen)throw new Error("onOpen callback must be a function");if("function"!=typeof this._options.onClose)throw new Error("onClose callback must be a function");if("function"!=typeof this._options.onClick)throw new Error("onClick callback must be a function");if("function"!=typeof this._options.onReady)throw new Error("onReady callback must be a function");r.hasOwnProperty(this._theme)||(console.warn('Theme "'+this._theme+'" passed in options does not exist. Default theme was setted. Themes availables: '+Object.keys(r).join(", ")),this._theme="full");try{this._themeOptions.effectOnOpen=(0,b.default)(this._themeOptions.effectOnOpen,-1!==r[this._theme].options.effectOnOpen.indexOf(this._themeOptions.effectOnOpen))}catch(e){}try{this._themeOptions.direction=(0,b.default)(this._themeOptions.direction,-1!==r[this._theme].options.direction.indexOf(this._themeOptions.direction))}catch(e){}try{this._themeOptions.pageEffect=(0,b.default)(this._themeOptions.pageEffect,-1!==r[this._theme].options.pageEffect.indexOf(this._themeOptions.pageEffect))}catch(e){}this._themeClass="MenuChef--theme-"+this._theme,this._kitchenClass="js-MenuChef",this._kitchenLinksClass="js-MenuChefLinks",this._kitchenLinksClassStyled="MenuChef-links-link",this._dirClass=this._themeOptions.direction?this._themeClass+"--dir--"+this._themeOptions.direction:"",this._themeEffectClass=!!this._themeOptions.effectOnOpen&&this._themeClass+"-effect--"+this._themeOptions.effectOnOpen,this._themeOpenClass=this._themeEffectClass?this._themeEffectClass+"--open":"is-visible",this._classes={init:{body:[this._themeOptions.pageEffect?"has-MenuChef--effect--"+this._themeOptions.pageEffect:""],controlBtn:{open:[this._themeOptions.direction?"MenuChefOpen--dir--"+this._themeOptions.direction:""],close:[]},kitchen:[this._themeClass,this._themeEffectClass,this._dirClass,this._options.kitchenClass]},open:{body:["has-menuChefOpen","has-menuChefOpen--"+this._theme,this._options.bodyClassOpen],controlBtn:{open:[],close:[]},kitchen:[this._themeOpenClass,this._options.kitchenOpenClass]},close:{body:[],controlBtn:{open:[],close:[]},kitchen:[]}},MenuChef.prototype.ISBUTTONDEFAULT=this._options.button===x.default,this.init(),this.inject(r),this.cook()}return o(MenuChef,[{key:"inject",value:function(e){this.ISBUTTONDEFAULT||(this._options.button=''+this._options.button+""),this.$parent.insertAdjacentHTML("afterbegin",(e[this._theme].html+this._options.button).replace(/{{options.hamburger}}/g,this._options.hamburger.toLowerCase())),this.$openButton=document.querySelector(".MenuChefOpen"),this._kitchen=document.querySelector("."+this._kitchenClass),(0,f.default)(document.body,this._classes.init.body),(0,f.default)(this._kitchen,this._classes.init.kitchen),this.ISBUTTONDEFAULT&&(0,f.default)(this.$openButton,this._classes.init.controlBtn.open),this.ISBUTTONDEFAULT&&this.$openButton.setAttribute("data-scheme",this._options.scheme),this._kitchen.setAttribute("data-scheme",this._options.scheme),this._options.onReady()}},{key:"cook",value:function(){var e=this,n=this._kitchen.querySelector("."+this._kitchenLinksClass);(0,g.default)(this._ingredients,function(r,t){var a=t.cloneNode(!0);try{0===e._options.classes.exclude.length||(e._options.classes.exclude.map(function(e){return a.classList.remove(e)}),a.classList.add(e._kitchenLinksClassStyled))}catch(e){}try{if(0===e._options.classes.only.length);else{for(var i=a.classList.length-1;i>=0;i--){var o=a.classList[i];-1===e._options.classes.only.indexOf(o)&&a.classList.remove(o)}a.classList.add(e._kitchenLinksClassStyled)}}catch(e){}try{0!==e._options.classes.include.length&&(e._options.classes.include.map(function(e){return a.classList.add(e)}),a.classList.add(e._kitchenLinksClassStyled))}catch(e){}try{0===e._options.classes.exclude.length&&0===e._options.classes.only.length&&(a.className=e._kitchenLinksClassStyled)}catch(e){}a.onclick=function(){e._options.onClick(),e._options.closeOnClick&&MenuChef.close()},n.appendChild(a)})}},{key:"init",value:function(){var e=this;e._isOpen=null,(0,l.default)(MenuChef,e,"version"),(0,l.default)(MenuChef,e,"isOpen","_isOpen"),MenuChef.open=function(){(0,f.default)(document.body,e._classes.open.body),(0,f.default)(e._kitchen,e._classes.open.kitchen),e._options.closeOnClickOutside&&e.chefObserver("addWatch"),e._options.onOpen(),e.$openButton.classList.add("is-active"),e._isOpen=!0},MenuChef.close=function(){(0,f.default)(document.body,e._classes.open.body,"remove"),(0,f.default)(e._kitchen,e._classes.open.kitchen,"remove"),e._options.closeOnClickOutside&&e.chefObserver("removeWatch"),e._options.onClose(),e.$openButton.classList.remove("is-active"),e._isOpen=!1},MenuChef.toggle=function(){var n=arguments.length>0&&void 0!==arguments[0]&&arguments[0],r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"is-active";e._kitchen.classList.contains(e._themeOpenClass)?(MenuChef.close(),n&&n.classList.remove(r)):(MenuChef.open(),n&&n.classList.add(r))},MenuChef._watcher=function(n){var r=function(n){try{return n.getAttribute("onclick").includes("MenuChef.toggle")}catch(e){}try{return n.classList.contains(e._kitchenLinksClass)||n.classList.contains(e._kitchenClass)}catch(e){}};try{0===n.path.filter(r).length&&MenuChef.close()}catch(n){}},MenuChef.destroy=function(){(0,f.default)(document.body,e._classes.init.body,"remove");var n=document.querySelector("."+e._kitchenClass),r=document.querySelector(".MenuChefOpen");n.parentNode.removeChild(n),r.parentNode.removeChild(r)}}},{key:"chefObserver",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"addWatch";"addWatch"===e&&document.addEventListener("click",MenuChef._watcher,!0),"removeWatch"===e&&document.removeEventListener("click",MenuChef._watcher,!0)}}]),MenuChef}();window.MenuChef=MenuChef},function(e,n,r){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var t=r(5),a=r(28),i=r(29),o=r(3),s=r(15),c=r(38),u=Object.prototype,b=u.hasOwnProperty,h=Object(i.a)(function(e,n){if(Object(s.a)(n)||Object(o.a)(n))return void Object(a.a)(n,Object(c.a)(n),e);for(var r in n)b.call(n,r)&&Object(t.a)(e,r,n[r])});n.default=h},function(e,n,r){"use strict";function t(e,n){var r=Object(i.a)(e,n);return Object(a.a)(r)?r:void 0}var a=r(20),i=r(27);n.a=t},function(e,n,r){"use strict";function t(e){return!(!Object(o.a)(e)||Object(i.a)(e))&&(Object(a.a)(e)?l:u).test(Object(s.a)(e))}var a=r(8),i=r(24),o=r(2),s=r(26),c=/[\\^$.*+?()[\]{}|]/g,u=/^\[object .+?Constructor\]$/,b=Function.prototype,h=Object.prototype,f=b.toString,m=h.hasOwnProperty,l=RegExp("^"+f.call(m).replace(c,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");n.a=t},function(e,n){var r;r=function(){return this}();try{r=r||Function("return this")()||(0,eval)("this")}catch(e){"object"==typeof window&&(r=window)}e.exports=r},function(e,n,r){"use strict";function t(e){var n=o.call(e,c),r=e[c];try{e[c]=void 0;var t=!0}catch(e){}var a=s.call(e);return t&&(n?e[c]=r:delete e[c]),a}var a=r(9),i=Object.prototype,o=i.hasOwnProperty,s=i.toString,c=a.a?a.a.toStringTag:void 0;n.a=t},function(e,n,r){"use strict";function t(e){return i.call(e)}var a=Object.prototype,i=a.toString;n.a=t},function(e,n,r){"use strict";function t(e){return!!i&&i in e}var a=r(25),i=function(){var e=/[^.]+$/.exec(a.a&&a.a.keys&&a.a.keys.IE_PROTO||"");return e?"Symbol(src)_1."+e:""}();n.a=t},function(e,n,r){"use strict";var t=r(1),a=t.a["__core-js_shared__"];n.a=a},function(e,n,r){"use strict";function t(e){if(null!=e){try{return i.call(e)}catch(e){}try{return e+""}catch(e){}}return""}var a=Function.prototype,i=a.toString;n.a=t},function(e,n,r){"use strict";function t(e,n){return null==e?void 0:e[n]}n.a=t},function(e,n,r){"use strict";function t(e,n,r,t){var o=!r;r||(r={});for(var s=-1,c=n.length;++s1?r[a-1]:void 0,s=a>2?r[2]:void 0;for(o=e.length>3&&"function"==typeof o?(a--,o):void 0,s&&Object(i.a)(r[0],r[1],s)&&(o=a<3?void 0:o,a=1),n=Object(n);++t0){if(++n>=a)return arguments[0]}else n=0;return e.apply(void 0,arguments)}}var a=800,i=16,o=Date.now;n.a=t},function(e,n,r){"use strict";function t(e,n,r){if(!Object(s.a)(r))return!1;var t=typeof n;return!!("number"==t?Object(i.a)(r)&&Object(o.a)(n,r.length):"string"==t&&n in r)&&Object(a.a)(r[n],e)}var a=r(11),i=r(3),o=r(14),s=r(2);n.a=t},function(e,n,r){"use strict";function t(e){return Object(o.a)(e)?Object(a.a)(e):Object(i.a)(e)}var a=r(39),i=r(50),o=r(3);n.a=t},function(e,n,r){"use strict";function t(e,n){var r=Object(o.a)(e),t=!r&&Object(i.a)(e),b=!r&&!t&&Object(s.a)(e),f=!r&&!t&&!b&&Object(u.a)(e),m=r||t||b||f,l=m?Object(a.a)(e.length,String):[],p=l.length;for(var g in e)!n&&!h.call(e,g)||m&&("length"==g||b&&("offset"==g||"parent"==g)||f&&("buffer"==g||"byteLength"==g||"byteOffset"==g)||Object(c.a)(g,p))||l.push(g);return l}var a=r(40),i=r(41),o=r(43),s=r(44),c=r(14),u=r(46),b=Object.prototype,h=b.hasOwnProperty;n.a=t},function(e,n,r){"use strict";function t(e,n){for(var r=-1,t=Array(e);++r2&&void 0!==arguments[2]?arguments[2]:"";try{if(n&&e)return e}catch(e){}return r}},function(e,n,r){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.default=function(e,n){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"add";for(var t in n){var a=n[t];if(a)try{e.classList[r](a)}catch(e){console.warn(e)}}}},function(e,n,r){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.default=function(e,n,r){var t=arguments.length>3&&void 0!==arguments[3]?arguments[3]:r;return e.hasOwnProperty(r)&&delete e[r],Object.defineProperty(e,r,{configurable:!0,get:function(){return n[t]},set:function(n){console.warn(e.name+"."+r+" is readonly")}})}},function(e,n,r){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.default=function(e,n,r){for(var t=0;t