|
|
!function(a,b,c,d){a.tab=a.fn.tab=function(c){var e,f=a(a.isFunction(this)?b:this),g=f.selector||"",h=(new Date).getTime(),i=[],j=arguments[0],k="string"==typeof j,l=[].slice.call(arguments,1);return f.each(function(){var m,n,o,p,q=a.extend(!0,{},a.fn.tab.settings,c),r=q.className,s=q.metadata,t=q.selector,u=q.error,v="."+q.namespace,w="module-"+q.namespace,x=a(this),y=a(t.tabs),z={},A=!0,B=0,C=this,D=x.data(w);p={initialize:function(){p.debug("Initializing tab menu item",x),q.context&&(y=a(q.context).children(t.tabs),p.debug("Using only tabs inside context",q.context,y)),q.auto&&(p.verbose("Setting up automatic tab retrieval from server"),q.apiSettings={url:q.path+"/{$tab}"}),a.isWindow(C)||(p.debug("Attaching tab activation events to element",x),x.on("click"+v,p.event.click)),p.initializeHistory(),p.instantiate()},initializeHistory:function(){if(q.history){if(p.debug("Initializing page state"),a.address===d)return p.error(u.state),!1;if("state"==q.historyType){if(p.debug("Using HTML5 to manage state"),q.path===!1)return p.error(u.path),!1;a.address.history(!0).state(q.path)}a.address.unbind("change").bind("change",p.event.history.change)}},instantiate:function(){p.verbose("Storing instance of module",p),x.data(w,p)},destroy:function(){p.debug("Destroying tabs",x),x.removeData(w).off(v)},event:{click:function(b){var c=a(this).data(s.tab);c!==d?(q.history?(p.verbose("Updating page state",b),a.address.value(c)):(p.verbose("Changing tab",b),p.changeTab(c)),b.preventDefault()):p.debug("No tab specified")},history:{change:function(b){var c=b.pathNames.join("/")||p.get.initialPath(),e=q.templates.determineTitle(c)||!1;p.debug("History change event",c,b),o=b,c!==d&&p.changeTab(c),e&&a.address.title(e)}}},refresh:function(){m&&(p.debug("Refreshing tab",m),p.changeTab(m))},cache:{read:function(a){return a!==d?z[a]:!1},add:function(a,b){a=a||m,p.debug("Adding cached content for",a),z[a]=b},remove:function(a){a=a||m,p.debug("Removing cached content for",a),delete z[a]}},set:{state:function(b){a.address.value(b)}},changeTab:function(c){var d=b.history&&b.history.pushState,e=d&&q.ignoreFirstLoad&&A,f=q.auto||a.isPlainObject(q.apiSettings),g=f&&!e?p.utilities.pathToArray(c):p.get.defaultPathArray(c);c=p.utilities.arrayToPath(g),p.deactivate.all(),a.each(g,function(b,d){var h,i,j,k=g.slice(0,b+1),l=p.utilities.arrayToPath(k),r=p.is.tab(l),s=b+1==g.length,t=p.get.tabElement(l);return p.verbose("Looking for tab",d),r?(p.verbose("Tab was found",d),m=l,n=p.utilities.filterArray(g,k),s?j=!0:(h=g.slice(0,b+2),i=p.utilities.arrayToPath(h),j=!p.is.tab(i),j&&p.verbose("Tab parameters found",h)),j&&f?(e?(p.debug("Ignoring remote content on first tab load",l),A=!1,p.cache.add(c,t.html()),p.activate.all(l),a.proxy(q.onTabInit,t)(l,n,o),a.proxy(q.onTabLoad,t)(l,n,o)):(p.activate.navigation(l),p.content.fetch(l,c)),!1):(p.debug("Opened local tab",l),p.activate.all(l),p.cache.read(l)||(p.cache.add(l,!0),p.debug("First time tab loaded calling tab init"),a.proxy(q.onTabInit,t)(l,n,o)),a.proxy(q.onTabLoad,t)(l,n,o),void 0)):(p.error(u.missingTab,d),!1)})},content:{fetch:function(b,c){var e,f,g=p.get.tabElement(b),h={dataType:"html",stateContext:g,success:function(d){p.cache.add(c,d),p.content.update(b,d),b==m?(p.debug("Content loaded",b),p.activate.tab(b)):p.debug("Content loaded in background",b),a.proxy(q.onTabInit,g)(b,n,o),a.proxy(q.onTabLoad,g)(b,n,o)},urlData:{tab:c}},i=g.data(s.promise)||!1,j=i&&"pending"===i.state();c=c||b,f=p.cache.read(c),q.cache&&f?(p.debug("Showing existing content",c),p.content.update(b,f),p.activate.tab(b),a.proxy(q.onTabLoad,g)(b,n,o)):j?(p.debug("Content is already loading",c),g.addClass(r.loading)):a.api!==d?(e=a.extend(!0,{headers:{"X-Remote":!0}},q.apiSettings,h),p.debug("Retrieving remote content",c,e),a.api(e)):p.error(u.api)},update:function(a,b){p.debug("Updating html for",a);var c=p.get.tabElement(a);c.html(b)}},activate:{all:function(a){p.activate.tab(a),p.activate.navigation(a)},tab:function(a){var b=p.get.tabElement(a);p.verbose("Showing tab content for",b),b.addClass(r.active)},navigation:function(a){var b=
|