framework7
Version:
Full featured mobile HTML framework for building iOS & Android apps
2 lines (1 loc) • 7.65 kB
JavaScript
(function framework7ComponentLoader(e,t){void 0===t&&(t=!0);var n=e.$,i=e.utils,r=(e.getDevice,e.getSupport),a=e.Class,o=(e.Modal,e.ConstructorMethods),s=(e.ModalMethods,i.extend),l=i.deleteProps;function c(e){this.wrapped=e}function d(e){var t,n;function i(t,n){try{var a=e[t](n),o=a.value,s=o instanceof c;Promise.resolve(s?o.wrapped:o).then((function(e){s?i("return"===t?"return":"next",e):r(a.done?"return":"normal",e)}),(function(e){i("throw",e)}))}catch(e){r("throw",e)}}function r(e,r){switch(e){case"return":t.resolve({value:r,done:!0});break;case"throw":t.reject(r);break;default:t.resolve({value:r,done:!1})}(t=t.next)?i(t.key,t.arg):n=null}this._invoke=function(e,r){return new Promise((function(a,o){var s={key:e,arg:r,resolve:a,reject:o,next:null};n?n=n.next=s:(t=n=s,i(e,r))}))},"function"!=typeof e.return&&(this.return=void 0)}function u(e,t){return(u=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function p(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}d.prototype["function"==typeof Symbol&&Symbol.asyncIterator||"@@asyncIterator"]=function(){return this},d.prototype.next=function(e){return this._invoke("next",e)},d.prototype.throw=function(e){return this._invoke("throw",e)},d.prototype.return=function(e){return this._invoke("return",e)};var f=function(e){var t,i;function a(t,i){var a;void 0===i&&(i={});var o,l,c,d,u=p(a=e.call(this,i,[t])||this),f={el:null,listEl:null,indexes:"auto",iosItemHeight:14,mdItemHeight:14,auroraItemHeight:14,scrollList:!0,label:!1,renderItem:function(e,t){return("\n <li>"+e+"</li>\n ").trim()},renderSkipPlaceholder:function(){return'<li class="list-index-skip-placeholder"></li>'},on:{}};if(u.useModulesParams(f),u.params=s(f,i),!u.params.el)return u||p(a);if((o=n(u.params.el))[0].f7ListIndex)return o[0].f7ListIndex||p(a);if(0===(d=o.find("ul")).length&&(d=n("<ul></ul>"),o.append(d)),u.params.listEl&&(l=n(u.params.listEl)),"auto"===u.params.indexes&&!l)return u||p(a);function h(){var e={index:u};u.calcSize(),e!==u.height&&u.render()}function v(e){var t=n(e.target).closest("li");if(t.length){var i=t.index();if(u.skipRate>0){var r=i/(t.siblings("li").length-1);i=Math.round((u.indexes.length-1)*r)}var a=u.indexes[i];u.$el.trigger("listindex:click",{content:a,index:i}),u.emit("local::click listIndexClick",u,a,i),u.$el.trigger("listindex:select",{content:a,index:i}),u.emit("local::select listIndexSelect",u,a,i),u.$listEl&&u.params.scrollList&&u.scrollListToIndex(a,i)}}l?c=l.parents(".page-content").eq(0):0===(c=o.siblings(".page-content").eq(0)).length&&(c=o.parents(".page").eq(0).find(".page-content").eq(0)),o[0].f7ListIndex=u,s(u,{app:t,$el:o,el:o&&o[0],$ul:d,ul:d&&d[0],$listEl:l,listEl:l&&l[0],$pageContentEl:c,pageContentEl:c&&c[0],indexes:i.indexes,height:0,skipRate:0}),u.useModules();var g,x,m,I,y,b={},k=null;function L(e){var t=d.children();t.length&&(m=t[0].getBoundingClientRect().top,I=t[t.length-1].getBoundingClientRect().top+t[0].offsetHeight,b.x="touchstart"===e.type?e.targetTouches[0].pageX:e.pageX,b.y="touchstart"===e.type?e.targetTouches[0].pageY:e.pageY,g=!0,x=!1,k=null)}function E(e){if(g){!x&&u.params.label&&(y=n('<span class="list-index-label"></span>'),o.append(y)),x=!0;var t="touchmove"===e.type?e.targetTouches[0].pageY:e.pageY;e.preventDefault();var i=(t-m)/(I-m);i=Math.min(Math.max(i,0),1);var r=Math.round((u.indexes.length-1)*i),a=u.indexes[r],s=I-m,l=(u.height-s)/2+(1-i)*s;r!==k&&(u.params.label&&y.html(a).transform("translateY(-"+l+"px)"),u.$listEl&&u.params.scrollList&&u.scrollListToIndex(a,r)),k=r,u.$el.trigger("listindex:select"),u.emit("local::select listIndexSelect",u,a,r)}}function $(){g&&(g=!1,x=!1,u.params.label&&(y&&y.remove(),y=void 0))}var w=!!r().passiveListener&&{passive:!0};return u.attachEvents=function(){o.parents(".tab").on("tab:show",h),o.parents(".page").on("page:reinit",h),o.parents(".panel").on("panel:open",h),o.parents(".sheet-modal, .actions-modal, .popup, .popover, .login-screen, .dialog, .toast").on("modal:open",h),t.on("resize",h),o.on("click",v),o.on(t.touchEvents.start,L,w),t.on("touchmove:active",E),t.on("touchend:passive",$)},u.detachEvents=function(){o.parents(".tab").off("tab:show",h),o.parents(".page").off("page:reinit",h),o.parents(".panel").off("panel:open",h),o.parents(".sheet-modal, .actions-modal, .popup, .popover, .login-screen, .dialog, .toast").off("modal:open",h),t.off("resize",h),o.off("click",v),o.off(t.touchEvents.start,L,w),t.off("touchmove:active",E),t.off("touchend:passive",$)},u.init(),u||p(a)}i=e,(t=a).prototype=Object.create(i.prototype),t.prototype.constructor=t,u(t,i);var o=a.prototype;return o.scrollListToIndex=function(e,t){var i,r=this,a=r.$listEl,o=r.$pageContentEl,s=r.app;if(!a||!o||0===o.length)return r;if(a.find(".list-group-title, .item-divider").each((function(t){if(!i){var r=n(t);r.text()===e&&(i=r)}})),!i||0===i.length)return r;var l=i.parent().offset().top,c=parseInt(o.css("padding-top"),10),d=o[0].scrollTop,u=i.offset().top;if(o.parents(".page-with-navbar-large").length){var p=s.navbar.getElByPage(o.parents(".page-with-navbar-large").eq(0)),f=n(p).find(".title-large");f.length&&(c-=f[0].offsetHeight||0)}return l<=c?o.scrollTop(l+d-c):o.scrollTop(u+d-c),r},o.renderSkipPlaceholder=function(){return this.params.renderSkipPlaceholder.call(this)},o.renderItem=function(e,t){return this.params.renderItem.call(this,e,t)},o.render=function(){var e,t=this,n=t.$ul,i=t.indexes,r=t.skipRate,a=i.map((function(n,i){if(i%r!=0&&r>0)return e=!0,"";var a=t.renderItem(n,i);return e&&(a=t.renderSkipPlaceholder()+a),e=!1,a})).join("");return n.html(a),t},o.calcSize=function(){var e=this,t=e.app,n=e.params,i=e.el,r=e.indexes,a=i.offsetHeight,o=n[t.theme+"ItemHeight"],s=Math.floor(a/o),l=r.length,c=0;return l>s&&(c=Math.ceil((2*l-1)/s)),e.height=a,e.skipRate=c,e},o.calcIndexes=function(){var e=this;return"auto"===e.params.indexes?(e.indexes=[],e.$listEl.find(".list-group-title, .item-divider").each((function(t){var i=n(t).text();e.indexes.indexOf(i)<0&&e.indexes.push(i)}))):e.indexes=e.params.indexes,e},o.update=function(){var e=this;return e.calcIndexes(),e.calcSize(),e.render(),e},o.init=function(){var e=this;e.calcIndexes(),e.calcSize(),e.render(),e.attachEvents()},o.destroy=function(){var e=this;e.$el.trigger("listindex:beforedestroy",e),e.emit("local::beforeDestroy listIndexBeforeDestroy"),e.detachEvents(),e.$el[0]&&(e.$el[0].f7ListIndex=null,delete e.$el[0].f7ListIndex),l(e),e=null},a}(a),h={name:"listIndex",static:{ListIndex:f},create:function(){this.listIndex=o({defaultSelector:".list-index",constructor:f,app:this,domProp:"f7ListIndex"})},on:{tabMounted:function(e){var t=this;n(e).find(".list-index-init").each((function(e){var i=s(n(e).dataset(),{el:e});t.listIndex.create(i)}))},tabBeforeRemove:function(e){n(e).find(".list-index-init").each((function(e){e.f7ListIndex&&e.f7ListIndex.destroy()}))},pageInit:function(e){var t=this;e.$el.find(".list-index-init").each((function(e){var i=s(n(e).dataset(),{el:e});t.listIndex.create(i)}))},pageBeforeRemove:function(e){e.$el.find(".list-index-init").each((function(e){e.f7ListIndex&&e.f7ListIndex.destroy()}))}},vnode:{"list-index-init":{insert:function(e){var t=e.elm,i=s(n(t).dataset(),{el:t});this.listIndex.create(i)},destroy:function(e){var t=e.elm;t.f7ListIndex&&t.f7ListIndex.destroy()}}}};if(t){if(e.prototype.modules&&e.prototype.modules[h.name])return;e.use(h),e.instance&&(e.instance.useModuleParams(h,e.instance.params),e.instance.useModule(h))}return h}(Framework7, typeof Framework7AutoInstallComponent === 'undefined' ? undefined : Framework7AutoInstallComponent))