|
|
!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=!0,n={},o=0,p=this,q=(new Date).getTime(),r=[],s=k.selector||"",t=j.className,u=j.metadata,v=j.namespace,w=j.errors,x=k.data("module"),y=arguments[0],z=x!==d&&"string"==typeof y;return[].slice.call(arguments,1),h={initialize:function(){if(h.debug("Initializing Tabs",k),j.history){if(a.address===d)return h.error(w.state),!1;if(j.path===!1)return h.error(w.path),!1;h.verbose("Address library found adding state change event"),a.address.state(j.path).change(h.event.history.change)}a.isWindow(k.get(0))||k.on("click."+v,h.event.click),k.data("module",h)},destroy:function(){h.debug("Destroying tabs",k),k.off("."+v)},event:{click:function(){h.debug("Navigation clicked");var b=a(this).data(u.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?n[a]:n},add:function(a,b){a=a||e,h.debug("Adding cached content for",a),n[a]=b},remove:function(a){a=a||e,h.debug("Removing cached content for",a),delete n[a]}},change:function(c){var d=h.get.defaultPathArray(c);h.deactivate.all(),a.each(d,function(i,k){var l=d.slice(0,i+1),o=h.utils.arrayToPath(l),p=h.utils.last(d)==o,q=h.is.tab(o),r=!q,s=b.history&&b.history.pushState,t=s&&j.ignoreFirstLoad&&m,u=a.isPlainObject(j.apiSettings),v=h.get.tabElement(o);return h.verbose("Looking for tab",k),r?(h.verbose("Tab is not found, assuming it is a parameter",k),!0):(q&&(h.verbose("Tab was found",k),e=o,f=h.utils.filterArray(d,l),p&&u?t?(h.debug("Ignoring remote content on first tab load",o),m=!1,n[c]=v.html(),h.activate.all(o),a.proxy(j.onTabInit,v)(o,f,g)):(h.activate.navigation(o),h.content.fetch(o,j.onTabLoad)):(h.debug("Opened tab",o),h.activate.all(o),a.proxy(j.onTabLoad,v)(o,f,g))),void 0)})},content:{fetch:function(b){var c=h.get.tabElement(b),i=n[b]||!1,k={dataType:"html",stateContext:c,success:function(d){n[b]=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,c)(b,f,g)},urlData:{tab:b}},l=c.data(u.promise)||!1,m=l&&"pending"===l.state();j.cache&&i?(h.debug("Showing existing content",b),h.activate.tab(b),a.proxy(j.onTabLoad,c)(b,f,g)):m?(h.debug("Content is already loading",b),c.addClass(t.loading)):a.api!==d?(h.debug("Retrieving content",b),a.api(a.extend(!0,{},j.apiSettings,k))):h.error(w.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(t.active)},navigation:function(a){var b=h.get.navElement(a);h.verbose("Activating tab navigation for",b),b.addClass(t.active)}},deactivate:{all:function(){h.deactivate.navigation(),h.deactivate.tabs()},navigation:function(){k.removeClass(t.active)},tabs:function(){l.removeClass(t.active+" "+t.loading)}},is:{tab:function(a){return h.get.tabElement(a).size()>0}},get:{initialPath:function(){return k.eq(0).data(u.tab)||l.eq(0).data(u.tab)},defaultPathArray:function(a){return h.utils.pathToArray(h.get.defaultPath(a))},defaultPath:function(a){var b=k.filter("[data-"+u.tab+'^="'+a+'/"]').eq(0),c=b.data(u.tab)||!1;if(c){if(h.debug("Found default tab",c),o<j.maxDepth)return o++,h.get.defaultPath(c);h.error(w.recursion)}return o=0,a},navElement:function(a){return a=a||e,k.filter("[data-"+u.tab+'="'+a+'"]')},tabElement:function(a){var b,c,d,f;return a=a||e,d=h.utils.pathToArray(a),f=h.utils.last(d),b=l.filter("[data-"+u.tab+'="'+f+'"]'),c=l.filter("[data-"+u.tab+'="'+a+'"]'),b.size()>0?b:c},tab:function(){return e}},utils:{filterArray:function(b,c){return a.grep(b,function(b){return-1==a.inA
|