zmp-core
Version:
Full featured mobile HTML framework for building iOS & Android apps
2 lines (1 loc) • 3.19 kB
JavaScript
(function zmpComponentLoader(e,t){void 0===t&&(t=!0);var r=e.$,i=e.utils,a=(e.getDevice,e.getSupport,e.Class,e.Modal,e.ConstructorMethods,e.ModalMethods,i.extend);function s(e,t){var r=t.css("min-"+e);return"auto"===r||"none"===r?r=0:r.indexOf("px")>=0?r=parseFloat(r):r.indexOf("%")>=0&&(r=t.parent()[0]["height"===e?"offsetHeight":"offsetWidth"]*parseFloat(r)/100),r}function o(e,t){var r=t.css("max-"+e);return"auto"===r||"none"===r?r=null:r.indexOf("px")>=0?r=parseFloat(r):r.indexOf("%")>=0&&(r=t.parent()[0]["height"===e?"offsetHeight":"offsetWidth"]*parseFloat(r)/100),r}var n={init:function(){var e,t,i,a,n,l,g,p,d,h,c,u,f,z,v,m,x,b=this;r(document).on(b.touchEvents.start,".col > .resize-handler, .row > .resize-handler",(function(s){e||t||(n=r(s.target).closest(".resize-handler"),i="touchstart"===s.type?s.targetTouches[0].pageX:s.pageX,a="touchstart"===s.type?s.targetTouches[0].pageY:s.pageY,e=!0,l=void 0,g=void 0,x=void 0)})),b.on("touchmove",(function(r){if(e){var w=1===n.parent(".row").length,y=w?"height":"width",C=w?"offsetHeight":"offsetWidth";t||(!(l=n.parent(w?".row":".col")).length||l.hasClass("resizable")&&!l.hasClass("resizable-fixed")||(l=l.prevAll(".resizable:not(.resizable-fixed)").eq(0)),!(g=l.next(w?".row":".col")).length||g.hasClass("resizable")&&!g.hasClass("resizable-fixed")||(g=g.nextAll(".resizable:not(.resizable-fixed)").eq(0)),l.length&&(p=l[0][C],d=s(y,l),h=o(y,l),z=l.parent()[0][C],v=l.parent().children(w?".row":'[class*="col-"], .col').length,m=parseFloat(l.css(w?"--zmp-grid-row-gap":"--zmp-grid-gap"))),g.length&&(c=g[0][C],u=s(y,g),f=o(y,g),l.length||(z=g.parent()[0][C],v=g.parent().children(w?".row":'[class*="col-"], .col').length,m=parseFloat(g.css(w?"--zmp-grid-row-gap":"--zmp-grid-gap"))))),t=!0;var M="touchmove"===r.type?r.targetTouches[0].pageX:r.pageX,F="touchmove"===r.type?r.targetTouches[0].pageY:r.pageY;if(void 0!==x||w||(x=!!(x||Math.abs(F-a)>Math.abs(M-i))),x)return e=!1,void(t=!1);var O=l.hasClass("resizable-absolute")||g.hasClass("resizable-absolute"),R=!w||w&&!O;if(R&&!g.length||!l.length)return e=!1,void(t=!1);r.preventDefault();var T,X,Y=w?F-a:M-i;if(l.length&&((T=p+Y)<d&&(Y=(T=d)-p),h&&T>h&&(Y=(T=h)-p)),g.length&&R&&((X=c-Y)<u&&(T=p+(Y=c-(X=u))),f&&X>f&&(T=p+(Y=c-(X=f)))),O)return l[0].style[y]=T+"px",R&&(g[0].style[y]=X+"px"),l.trigger("grid:resize"),g.trigger("grid:resize"),b.emit("gridResize",l[0]),void b.emit("gridResize",g[0]);var H=(v-1)*m/v,W=w?v-1+" * var(--zmp-grid-row-gap) / "+v:"(var(--zmp-cols-per-row) - 1) * var(--zmp-grid-gap) / var(--zmp-cols-per-row)",q=T+H,A=X+H;l[0].style[y]="calc("+q/z*100+"% - "+W+")",g[0].style[y]="calc("+A/z*100+"% - "+W+")",l.trigger("grid:resize"),g.trigger("grid:resize"),b.emit("gridResize",l[0]),b.emit("gridResize",g[0])}})),b.on("touchend",(function(){e&&(t||(e=!1),e=!1,t=!1)}))}},l={name:"grid",create:function(){a(this,{grid:{init:n.init.bind(this)}})},on:{init:function(){this.grid.init()}}};if(t){if(e.prototype.modules&&e.prototype.modules[l.name])return;e.use(l),e.instance&&(e.instance.useModuleParams(l,e.instance.params),e.instance.useModule(l))}return l}(ZMP, typeof ZMPAutoInstallComponent === 'undefined' ? undefined : ZMPAutoInstallComponent))