framework7
Version:
Full featured mobile HTML framework for building iOS & Android apps
2 lines (1 loc) • 4.24 kB
JavaScript
(function framework7ComponentLoader(t,e){void 0===e&&(e=!0);var a=t.$,s=t.utils,o=(t.getDevice,t.getSupport),r=(t.Class,t.Modal,t.ConstructorMethods,t.ModalMethods,s.bindMethods),i={init:function(){var t,e,s,r,i,l,n,d,p,v,u,b,f,g,c,h,m,x,w,C,M,I=this;function T(o,r){e=!1,t=!0,M=!1,s="touchstart"===o.type?o.targetTouches[0].pageY:o.pageY,i=a(o.target).closest("li").eq(0),f=i.index(),n=i.parents(".sortable");var d=i.parents(".list-group");d.length&&d.parents(n).length&&(n=d),l=n.children("ul").children("li:not(.disallow-sorting):not(.no-sorting)"),I.panel&&(I.panel.allowOpen=!1),I.swipeout&&(I.swipeout.allow=!1),r&&(i.addClass("sorting"),n.addClass("sortable-sorting"),M=!0)}var L=!!o().passiveListener&&{passive:!1,capture:!1};a(document).on(I.touchEvents.start,".list.sortable .sortable-handler",T,L),I.on("touchmove:active",(function(o){if(t&&i){var f="touchmove"===o.type?o.targetTouches[0].pageY:o.pageY;if(!e){g=i.parents(".page"),c=i.parents(".page-content");var M=parseInt(c.css("padding-top"),10),I=parseInt(c.css("padding-bottom"),10);C=c[0].scrollTop,m=g.offset().top+M,h=g.height()-M-I,i.addClass("sorting"),n.addClass("sortable-sorting"),x=i[0].offsetTop,p=i[0].offsetTop,v=i.parent().height()-x-i.height(),d=i[0].offsetHeight,w=i.offset().top}e=!0,o.preventDefault(),o.f7PreventSwipePanel=!0,r=f-s;var T=c[0].scrollTop-C,L=Math.min(Math.max(r+T,-p),v);i.transform("translate3d(0,"+L+"px,0)");var E,y=44,V=!0;r+T+y<-p&&(V=!1),r+T-y>v&&(V=!1),b=void 0,u=void 0,V&&(w+r+d+y>m+h&&(E=w+r+d+y-(m+h)),w+r<m+y&&(E=w+r-m-y),E&&(c[0].scrollTop+=E)),l.each((function(t){var e=a(t);if(e[0]!==i[0]){var s=e[0].offsetTop,o=e.height(),r=x+L;r>=s-o/2&&i.index()<e.index()?(e.transform("translate3d(0, "+-d+"px,0)"),u=e,b=void 0):r<=s+o/2&&i.index()>e.index()?(e.transform("translate3d(0, "+d+"px,0)"),u=void 0,b||(b=e)):e.transform("translate3d(0, 0%,0)")}}))}})),I.on("touchend:passive",(function(){if(!t||!e)return t&&!e&&(I.panel&&(I.panel.allowOpen=!0),I.swipeout&&(I.swipeout.allow=!0),M&&(i.removeClass("sorting"),n.removeClass("sortable-sorting"))),t=!1,void(e=!1);var a;I.panel&&(I.panel.allowOpen=!0),I.swipeout&&(I.swipeout.allow=!0),l.transform(""),i.removeClass("sorting"),n.removeClass("sortable-sorting"),u?a=u.index():b&&(a=b.index());var s=n.dataset().sortableMoveElements;if(void 0===s&&(s=I.params.sortable.moveElements),s&&(u&&i.insertAfter(u),b&&i.insertBefore(b)),(u||b)&&n.hasClass("virtual-list")){void 0===(f=i[0].f7VirtualListIndex)&&(f=i.attr("data-virtual-list-index")),b?void 0===(a=b[0].f7VirtualListIndex)&&(a=b.attr("data-virtual-list-index")):void 0===(a=u[0].f7VirtualListIndex)&&(a=u.attr("data-virtual-list-index")),a=null!==a?parseInt(a,10):void 0;var o=n[0].f7VirtualList;f&&(f=parseInt(f,10)),a&&(a=parseInt(a,10)),o&&o.moveItem(f,a)}void 0===a||Number.isNaN(a)||a===f||(i.trigger("sortable:sort",{from:f,to:a}),I.emit("sortableSort",i[0],{from:f,to:a,el:i[0]},n[0])),b=void 0,u=void 0,t=!1,e=!1})),a(document).on("taphold",".sortable-tap-hold",(function(t,e){T(e,!0)}))},enable:function(t){void 0===t&&(t=".list.sortable");var e=a(t);0!==e.length&&(e.addClass("sortable-enabled"),e.trigger("sortable:enable"),this.emit("sortableEnable",e[0]))},disable:function(t){void 0===t&&(t=".list.sortable");var e=a(t);0!==e.length&&(e.removeClass("sortable-enabled"),e.trigger("sortable:disable"),this.emit("sortableDisable",e[0]))},toggle:function(t){void 0===t&&(t=".list.sortable");var e=a(t);0!==e.length&&(e.hasClass("sortable-enabled")?this.sortable.disable(e):this.sortable.enable(e))}},l={name:"sortable",params:{sortable:{moveElements:!0}},create:function(){r(this,{sortable:i})},on:{init:function(){this.params.sortable&&this.sortable.init()}},clicks:{".sortable-enable":function(t,e){void 0===e&&(e={});this.sortable.enable(e.sortable)},".sortable-disable":function(t,e){void 0===e&&(e={});this.sortable.disable(e.sortable)},".sortable-toggle":function(t,e){void 0===e&&(e={});this.sortable.toggle(e.sortable)}}};if(e){if(t.prototype.modules&&t.prototype.modules[l.name])return;t.use(l),t.instance&&(t.instance.useModuleParams(l,t.instance.params),t.instance.useModule(l))}return l}(Framework7, typeof Framework7AutoInstallComponent === 'undefined' ? undefined : Framework7AutoInstallComponent))