framework7
Version:
Full featured mobile HTML framework for building iOS & Android apps
2 lines (1 loc) • 4.08 kB
JavaScript
(function framework7ComponentLoader(t,a){void 0===a&&(a=!0);var e=t.$,n=t.utils,i=(t.getDevice,t.getSupport,t.Class,t.Modal,t.ConstructorMethods,t.ModalMethods,t.$jsx,n.extend);const s={show(){const t=this;let a,n,i,s,r;for(var l=arguments.length,o=new Array(l),b=0;b<l;b++)o[b]=arguments[b];1===o.length&&o[0]&&o[0].constructor===Object?(a=o[0].tabEl,n=o[0].tabLinkEl,i=o[0].animate,s=o[0].tabRoute,r=o[0].animatedInit):([a,n,i,s]=o,"boolean"==typeof o[1]&&([a,i,n,s]=o,o.length>2&&n.constructor===Object&&([a,i,s,n]=o))),void 0===i&&(i=!0);const h=e(a);if(s&&h[0]&&(h[0].f7TabRoute=s),!r&&(0===h.length||h.hasClass("tab-active")))return{$newTabEl:h,newTabEl:h[0]};let d;n&&(d=e(n));const g=h.parent(".tabs");if(0===g.length)return{$newTabEl:h,newTabEl:h[0]};t.swipeout&&(t.swipeout.allowOpen=!0);const c=[];function p(){c.forEach((t=>{t()}))}let f,u=!1;if(g.parent().hasClass("tabs-animated-wrap")){g.parent()[i?"removeClass":"addClass"]("not-animated");const a=parseFloat(g.css("transition-duration").replace(",","."));i&&a&&(g.transitionEnd(p),u=!0);const e=100*(t.rtl?h.index():-h.index());g.transform(`translate3d(${e}%,0,0)`)}g.parent().hasClass("tabs-swipeable-wrap")&&t.swiper&&(f=g.parent()[0].swiper,f&&f.activeIndex!==h.index()?(u=!0,f.once("slideChangeTransitionEnd",(()=>{p()})).slideTo(h.index(),i?void 0:0)):f&&f.animating&&(u=!0,f.once("slideChangeTransitionEnd",(()=>{p()}))));const m=g.children(".tab-active");if(m.removeClass("tab-active"),!r&&(!f||f&&!f.animating||f&&s)&&(m.hasClass("view")&&m.children(".page").length&&m.children(".page").each((a=>{e(a).trigger("page:tabhide"),t.emit("pageTabHide",a)})),m.trigger("tab:hide"),t.emit("tabHide",m[0])),h.addClass("tab-active"),!r&&(!f||f&&!f.animating||f&&s)&&(h.hasClass("view")&&h.children(".page").length&&h.children(".page").each((a=>{e(a).trigger("page:tabshow"),t.emit("pageTabShow",a)})),h.trigger("tab:show"),t.emit("tabShow",h[0])),!d&&(d=e("string"==typeof a?`.tab-link[href="${a}"]`:`.tab-link[href="#${h.attr("id")}"]`),(!d||d&&0===d.length)&&e("[data-tab]").each((t=>{h.is(e(t).attr("data-tab"))&&(d=e(t))})),s&&(!d||d&&0===d.length)&&(d=e(`[data-route-tab-id="${s.route.tab.id}"]`),0===d.length&&(d=e(`.tab-link[href="${s.url}"]`))),d.length>1&&h.parents(".page").length&&(d=d.filter((t=>e(t).parents(".page")[0]===h.parents(".page")[0])),"ios"===t.theme&&0===d.length&&s))){const a=h.parents(".page"),n=e(t.navbar.getElByPage(a));d=n.find(`[data-route-tab-id="${s.route.tab.id}"]`),0===d.length&&(d=n.find(`.tab-link[href="${s.url}"]`))}if(d.length>0){let a;if(m&&m.length>0){const t=m.attr("id");t&&(a=e(`.tab-link[href="#${t}"]`),(!a||a&&0===a.length)&&(a=e(`.tab-link[data-route-tab-id="${t}"]`))),(!a||a&&0===a.length)&&e("[data-tab]").each((t=>{m.is(e(t).attr("data-tab"))&&(a=e(t))})),(!a||a&&0===a.length)&&(a=d.siblings(".tab-link-active"))}else s&&(a=d.siblings(".tab-link-active"));if(a&&a.length>1&&m&&m.parents(".page").length&&(a=a.filter((t=>e(t).parents(".page")[0]===m.parents(".page")[0]))),a&&a.length>0&&a.removeClass("tab-link-active"),d&&d.length>0){d.addClass("tab-link-active");const a=d.parents(".tabbar, .tabbar-labels");t.toolbar&&a.length>0&&(a.hasClass("tabbar-highlight")||"ios"!==t.theme)&&t.toolbar.setHighlight(a)}}return{$newTabEl:h,newTabEl:h[0],$oldTabEl:m,oldTabEl:m[0],onTabsChanged:function(t){c.push(t)},animated:u}}};var r={name:"tabs",create(){i(this,{tab:{show:s.show.bind(this)}})},on:{"pageInit tabMounted":function(t){const a=e(t.el||t).find(".tabs-animated-wrap > .tabs > .tab-active")[0];if(!a)return;this.tab.show({tabEl:a,animatedInit:!0,animate:!1})}},clicks:{".tab-link":function(t,a){if(void 0===a&&(a={}),t.attr("href")&&0===t.attr("href").indexOf("#")||t.attr("data-tab")){this.tab.show({tabEl:a.tab||t.attr("href"),tabLinkEl:t,animate:a.animate})}}}};if(a){if(t.prototype.modules&&t.prototype.modules[r.name])return;t.use(r),t.instance&&(t.instance.useModuleParams(r,t.instance.params),t.instance.useModule(r))}return r}(Framework7, typeof Framework7AutoInstallComponent === 'undefined' ? undefined : Framework7AutoInstallComponent))