You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

0 lines
7.0 KiB

  1. !function(a,b,c,d){a.fn.tabNavigation=function(c){var e,f,g,h,i,j=a.extend(!0,{},a.fn.tabNavigation.settings,c),k=a(this),l=a(j.context).find(j.selector.tabs),m={},n=!0,o=0,p=this,q=(new Date).getTime(),r=[],s=k.selector||"",t="."+j.namespace,u=j.namespace+"-module",v=j.className,w=j.metadata,x=j.namespace,y=j.errors,z=k.data(u),A=arguments[0],B=z!==d&&"string"==typeof A,C=[].slice.call(arguments,1);return h={initialize:function(){if(h.debug("Initializing Tabs",k),j.history){if(a.address===d)return h.error(y.state),!1;if(j.path===!1)return h.error(y.path),!1;j.auto&&(j.apiSettings={url:j.path+"/{$tab}"}),h.verbose("Address library found adding state change event"),a.address.state(j.path).unbind("change").bind("change",h.event.history.change)}a.isWindow(p)||k.on("click."+t,h.event.click),k.data(u,h)},destroy:function(){h.debug("Destroying tabs",k),k.off("."+x)},event:{click:function(){h.debug("Navigation clicked");var b=a(this).data(w.tab);b!==d?b!==e&&(j.history?a.address.value(b):h.change(b)):h.debug("No tab specified")},history:{change:function(b){var c=b.pathNames.join("/")||h.get.initialPath(),e=j.templates.determineTitle(c)||!1;h.debug("History change event",c,b),g=b,c!==d&&h.change(c),e&&a.address.title(e)}}},refresh:function(){e&&(h.debug("Refreshing tab",e),h.change(e))},cache:{read:function(a){return a!==d?m[a]:!1},add:function(a,b){a=a||e,h.debug("Adding cached content for",a),m[a]=b},remove:function(a){a=a||e,h.debug("Removing cached content for",a),delete m[a]}},change:function(c){var d=b.history&&b.history.pushState,i=d&&j.ignoreFirstLoad&&n,k=a.isPlainObject(j.apiSettings),l=k&&!i?h.utils.pathToArray(c):h.get.defaultPathArray(c),c=h.utils.arrayToPath(l);h.deactivate.all(),a.each(l,function(b,d){var m,o,p,q=l.slice(0,b+1),r=h.utils.arrayToPath(q),s=h.is.tab(r),t=b+1==l.length,u=h.get.tabElement(r);return h.verbose("Looking for tab",d),s?(h.verbose("Tab was found",d),e=r,f=h.utils.filterArray(l,q),t?p=!0:(m=l.slice(0,b+2),o=h.utils.arrayToPath(m),p=!h.is.tab(o),p&&h.verbose("Tab parameters found",m)),p&&k?(i?(h.debug("Ignoring remote content on first tab load",r),n=!1,h.cache.add(c,u.html()),h.activate.all(r),a.proxy(j.onTabInit,u)(r,f,g),a.proxy(j.onTabLoad,u)(r,f,g)):(h.activate.navigation(r),h.content.fetch(r,c)),!1):(h.debug("Opened local tab",r),h.activate.all(r),a.proxy(j.onTabLoad,u)(r,f,g),void 0)):(h.error(y.missingTab,d),!1)})},content:{fetch:function(b,c){var i=h.get.tabElement(b),c=c||b,k=h.cache.read(c),l={dataType:"html",stateContext:i,success:function(d){h.cache.add(c,d),h.content.update(b,d),b==e?(h.debug("Content loaded",b),h.activate.tab(b)):h.debug("Content loaded in background",b),a.proxy(j.onTabInit,i)(b,f,g),a.proxy(j.onTabLoad,i)(b,f,g)},urlData:{tab:c}},m=i.data(w.promise)||!1,n=m&&"pending"===m.state();j.cache&&k?(h.debug("Showing existing content",c),h.content.update(b,k),h.activate.tab(b),a.proxy(j.onTabLoad,i)(b,f,g)):n?(h.debug("Content is already loading",c),i.addClass(v.loading)):a.api!==d?(h.debug("Retrieving remote content",c),a.api(a.extend(!0,{headers:{"X-Remote":!0}},j.apiSettings,l))):h.error(y.api)},update:function(a,b){h.debug("Updating html for",a);var c=h.get.tabElement(a);c.html(b)}},activate:{all:function(a){h.activate.tab(a),h.activate.navigation(a)},tab:function(a){var b=h.get.tabElement(a);h.verbose("Showing tab content for",b),b.addClass(v.active)},navigation:function(a){var b=h.get.navElement(a);h.verbose("Activating tab navigation for",b,a),b.addClass(v.active)}},deactivate:{all:function(){h.deactivate.navigation(),h.deactivate.tabs()},navigation:function(){k.removeClass(v.active)},tabs:function(){l.removeClass(v.active+" "+v.loading)}},is:{tab:function(a){return a!==d?h.get.tabElement(a).size()>0:!1}},get:{initialPath:function(){return k.eq(0).data(w.tab)||l.eq(0).data(w.tab)},path:function(){return a.address.value()},defaultPathArray:function(a){return h.utils.pathToArray(h.get.defaultPath(a))},defaultPath:function(a){var b=k.filter("[data-"+w.tab+'^="'+a+'/"]').eq(0),c=b.data(w.tab)||!1;if(c){if(h.debug("Found default tab",c),o<j.maxDepth)return o++,h.get.d