From fcaaff7d9782318110cd5879389a865f2db1f2f0 Mon Sep 17 00:00:00 2001 From: Torben Date: Mon, 8 May 2023 13:16:38 +0200 Subject: [PATCH 1/2] Attach main function explicitly to window object --- src/js/touch-menu-la.js | 4 ++-- src/js/touch-menu-la.min.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/js/touch-menu-la.js b/src/js/touch-menu-la.js index 1999e63..43d3325 100644 --- a/src/js/touch-menu-la.js +++ b/src/js/touch-menu-la.js @@ -1,4 +1,4 @@ -var TouchMenuLA = function (options) { +window.TouchMenuLA = function (options) { var self, defaults, menuClassName = '', @@ -224,4 +224,4 @@ var TouchMenuLA = function (options) { }; return new TouchMenuLA(); -}; \ No newline at end of file +}; diff --git a/src/js/touch-menu-la.min.js b/src/js/touch-menu-la.min.js index 4cdca79..7d867bd 100644 --- a/src/js/touch-menu-la.min.js +++ b/src/js/touch-menu-la.min.js @@ -1,2 +1,2 @@ -var TouchMenuLA=function(n){var t,s,e="",r,f,h,c,u=0,o=0,v=0,l=0,a=0,i=function(){t=this;s={width:280,zIndex:99999,disableSlide:!1,handleSize:20,disableMask:!1,maxMaskOpacity:.5};this.isVisible=!1;this.initialize()};return i.prototype.setDefaultsOptions=function(){for(var t in s)n[t]||(n[t]=s[t])},i.prototype.initElements=function(){n.target.style.zIndex=n.zIndex;n.target.style.width=n.width+"px";n.target.style.left=-n.width+"px";f=document.createElement("div");f.className="tmla-handle";f.style.width=n.handleSize+"px";f.style.right=-n.handleSize+"px";n.target.appendChild(f);n.disableMask||(r=document.createElement("div"),r.className="tmla-mask",document.body.appendChild(r),c=new Hammer(r,null))},i.prototype.touchStartMenu=function(){h.on("panstart panmove",function(n){u=o+n.deltaX;t.changeMenuPos();a=Math.abs(n.velocity)})},i.prototype.changeMenuPos=function(){u<=n.width&&(n.target.className=e+" tmla-menu",n.target.style.transform="translate3d("+u+"px, 0, 0)",n.target.style.WebkitTransform="translate3d("+u+"px, 0, 0)",n.target.style.MozTransform="translate3d("+u+"px, 0, 0)",n.disableMask||this.setMaskOpacity(u))},i.prototype.setMaskOpacity=function(t){var i=parseFloat(t/n.width*n.maxMaskOpacity);r.style.opacity=i;r.style.zIndex=i===0?-1:n.zIndex-1},i.prototype.touchEndMenu=function(){h.on("panend pancancel",function(n){o=n.deltaX;t.checkMenuState(n.deltaX)})},i.prototype.eventStartMask=function(){c.on("panstart panmove",function(i){i.center.x<=n.width&&t.isVisible&&(l++,l==1&&(v=i.deltaX),i.deltaX<0&&(u=i.deltaX-v+n.width,t.changeMenuPos(),a=Math.abs(i.velocity)))})},i.prototype.eventEndMask=function(){c.on("panend pancancel",function(n){t.checkMenuState(n.deltaX);l=0})},i.prototype.clickMaskClose=function(){r.addEventListener("click",function(){t.close()})},i.prototype.checkMenuState=function(n){a>=1?n>=0?t.open():t.close():u>=100?t.open():t.close()},i.prototype.open=function(){n.target.className=e+" tmla-menu opened";n.target.style.transform="translate3d("+n.width+"px, 0, 0)";n.target.style.WebkitTransform="translate3d("+n.width+"px, 0, 0)";n.target.style.MozTransform="translate3d("+n.width+"px, 0, 0)";o=n.width;this.isVisible=!0;t.showMask();t.invoke(n.onOpen)},i.prototype.close=function(){n.target.className=e+" tmla-menu closed";o=0;t.isVisible=!1;t.hideMask();t.invoke(n.onClose)},i.prototype.toggle=function(){t.isVisible?t.close():t.open()},i.prototype.showMask=function(){r.className="tmla-mask transition";r.style.opacity=n.maxMaskOpacity;r.style.zIndex=n.zIndex-1},i.prototype.hideMask=function(){r.className="tmla-mask transition";r.style.opacity=0;r.style.zIndex=-1},i.prototype.setMenuClassName=function(){e=n.target.className},i.prototype.invoke=function(n){n&&n.apply(t)},i.prototype.initialize=function(){n.target?(h=Hammer(n.target,null),t.setDefaultsOptions(),t.setMenuClassName(),t.initElements(),n.disableSlide||(t.touchStartMenu(),t.touchEndMenu(),t.eventStartMask(),t.eventEndMask()),n.disableMask||t.clickMaskClose()):console.error("TouchMenuLA: The option 'target' is required.")},new i}; +window.TouchMenuLA=function(n){var t,s,e="",r,f,h,c,u=0,o=0,v=0,l=0,a=0,i=function(){t=this;s={width:280,zIndex:99999,disableSlide:!1,handleSize:20,disableMask:!1,maxMaskOpacity:.5};this.isVisible=!1;this.initialize()};return i.prototype.setDefaultsOptions=function(){for(var t in s)n[t]||(n[t]=s[t])},i.prototype.initElements=function(){n.target.style.zIndex=n.zIndex;n.target.style.width=n.width+"px";n.target.style.left=-n.width+"px";f=document.createElement("div");f.className="tmla-handle";f.style.width=n.handleSize+"px";f.style.right=-n.handleSize+"px";n.target.appendChild(f);n.disableMask||(r=document.createElement("div"),r.className="tmla-mask",document.body.appendChild(r),c=new Hammer(r,null))},i.prototype.touchStartMenu=function(){h.on("panstart panmove",function(n){u=o+n.deltaX;t.changeMenuPos();a=Math.abs(n.velocity)})},i.prototype.changeMenuPos=function(){u<=n.width&&(n.target.className=e+" tmla-menu",n.target.style.transform="translate3d("+u+"px, 0, 0)",n.target.style.WebkitTransform="translate3d("+u+"px, 0, 0)",n.target.style.MozTransform="translate3d("+u+"px, 0, 0)",n.disableMask||this.setMaskOpacity(u))},i.prototype.setMaskOpacity=function(t){var i=parseFloat(t/n.width*n.maxMaskOpacity);r.style.opacity=i;r.style.zIndex=i===0?-1:n.zIndex-1},i.prototype.touchEndMenu=function(){h.on("panend pancancel",function(n){o=n.deltaX;t.checkMenuState(n.deltaX)})},i.prototype.eventStartMask=function(){c.on("panstart panmove",function(i){i.center.x<=n.width&&t.isVisible&&(l++,l==1&&(v=i.deltaX),i.deltaX<0&&(u=i.deltaX-v+n.width,t.changeMenuPos(),a=Math.abs(i.velocity)))})},i.prototype.eventEndMask=function(){c.on("panend pancancel",function(n){t.checkMenuState(n.deltaX);l=0})},i.prototype.clickMaskClose=function(){r.addEventListener("click",function(){t.close()})},i.prototype.checkMenuState=function(n){a>=1?n>=0?t.open():t.close():u>=100?t.open():t.close()},i.prototype.open=function(){n.target.className=e+" tmla-menu opened";n.target.style.transform="translate3d("+n.width+"px, 0, 0)";n.target.style.WebkitTransform="translate3d("+n.width+"px, 0, 0)";n.target.style.MozTransform="translate3d("+n.width+"px, 0, 0)";o=n.width;this.isVisible=!0;t.showMask();t.invoke(n.onOpen)},i.prototype.close=function(){n.target.className=e+" tmla-menu closed";o=0;t.isVisible=!1;t.hideMask();t.invoke(n.onClose)},i.prototype.toggle=function(){t.isVisible?t.close():t.open()},i.prototype.showMask=function(){r.className="tmla-mask transition";r.style.opacity=n.maxMaskOpacity;r.style.zIndex=n.zIndex-1},i.prototype.hideMask=function(){r.className="tmla-mask transition";r.style.opacity=0;r.style.zIndex=-1},i.prototype.setMenuClassName=function(){e=n.target.className},i.prototype.invoke=function(n){n&&n.apply(t)},i.prototype.initialize=function(){n.target?(h=Hammer(n.target,null),t.setDefaultsOptions(),t.setMenuClassName(),t.initElements(),n.disableSlide||(t.touchStartMenu(),t.touchEndMenu(),t.eventStartMask(),t.eventEndMask()),n.disableMask||t.clickMaskClose()):console.error("TouchMenuLA: The option 'target' is required.")},new i}; //# sourceMappingURL=touch-menu-la.min.js.map From 8b679220fa5d374dfcd9ce849d1844a14eedb831 Mon Sep 17 00:00:00 2001 From: Torben Date: Mon, 8 May 2023 14:09:03 +0200 Subject: [PATCH 2/2] Set proper package main file --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 9bdd821..ec7441e 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "touch-menu-la", "version": "0.5.0", "description": "A touch menu like Navigation Drawer of Android.", - "main": "sample.hmtl", + "main": "src/js/touch-menu-la.min.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" },