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.
1 lines
6.6 KiB
1 lines
6.6 KiB
(function(e,t,n,o){e.fn.tabNavigation=function(n){var i,a,r,s,c,l=e.extend(!0,{},e.fn.tabNavigation.settings,n),u=e(this),d=e(l.context).find(l.selector.tabs),m=!0,f={},g=0,p=this,h=(new Date).getTime(),v=[],b=u.selector||"",y=l.className,x=l.metadata,w=l.namespace,C=l.errors,k=u.data("module"),T=arguments[0],N=k!==o&&"string"==typeof T;return[].slice.call(arguments,1),s={initialize:function(){if(s.debug("Initializing Tabs",u),l.history){if(e.address===o)return s.error(C.state),!1;if(l.path===!1)return s.error(C.path),!1;s.verbose("Address library found adding state change event"),e.address.state(l.path).change(s.event.history.change)}e.isWindow(u.get(0))||u.on("click."+w,s.event.click),u.data("module",s)},destroy:function(){s.debug("Destroying tabs",u),u.off("."+w)},event:{click:function(){s.debug("Navigation clicked");var t=e(this).data(x.tab);t!==o?t!==i&&(l.history?e.address.value(t):s.change(t)):s.debug("No tab specified")},history:{change:function(t){var n=t.pathNames.join("/")||s.get.initialPath(),i=l.templates.determineTitle(n)||!1;s.debug("History change event",n,t),r=t,n!==o&&s.change(n),i&&e.address.title(i)}}},refresh:function(){i&&(s.debug("Refreshing tab",i),s.change(i))},cache:{read:function(e){return e!==o?f[e]:f},add:function(e,t){e=e||i,s.debug("Adding cached content for",e),f[e]=t},remove:function(e){e=e||i,s.debug("Removing cached content for",e),delete f[e]}},change:function(n){var c=s.get.defaultPathArray(n);s.deactivate.all(),e.each(c,function(u,d){var g=c.slice(0,u+1),p=s.utils.arrayToPath(g),h=s.utils.last(c)==p,v=s.is.tab(p),b=!v,y=t.history&&t.history.pushState,x=y&&l.ignoreFirstLoad&&m,w=e.isPlainObject(l.apiSettings),C=s.get.tabElement(p);return s.verbose("Looking for tab",d),b?(s.verbose("Tab is not found, assuming it is a parameter",d),!0):(v&&(s.verbose("Tab was found",d),i=p,a=s.utils.filterArray(c,g),h&&w?x?(s.debug("Ignoring remote content on first tab load",p),m=!1,f[n]=C.html(),s.activate.all(p),e.proxy(l.onTabInit,C)(p,a,r)):(s.activate.navigation(p),s.content.fetch(p,l.onTabLoad)):(s.debug("Opened tab",p),s.activate.all(p),e.proxy(l.onTabLoad,C)(p,a,r))),o)})},content:{fetch:function(t){var n=s.get.tabElement(t),c=f[t]||!1,u={dataType:"html",stateContext:n,success:function(o){f[t]=o,s.content.update(t,o),t==i?(s.debug("Content loaded",t),s.activate.tab(t)):s.debug("Content loaded in background",t),e.proxy(l.onTabInit,n)(t,a,r)},urlData:{tab:t}},d=n.data(x.promise)||!1,m=d&&"pending"===d.state();l.cache&&c?(s.debug("Showing existing content",t),s.activate.tab(t),e.proxy(l.onTabLoad,n)(t,a,r)):m?(s.debug("Content is already loading",t),n.addClass(y.loading)):e.api!==o?(s.debug("Retrieving content",t),e.api(e.extend(!0,{},l.apiSettings,u))):s.error(C.api)},update:function(e,t){s.debug("Updating html for",e);var n=s.get.tabElement(e);n.html(t)}},activate:{all:function(e){s.activate.tab(e),s.activate.navigation(e)},tab:function(e){var t=s.get.tabElement(e);s.verbose("Showing tab content for",t),t.addClass(y.active)},navigation:function(e){var t=s.get.navElement(e);s.verbose("Activating tab navigation for",t),t.addClass(y.active)}},deactivate:{all:function(){s.deactivate.navigation(),s.deactivate.tabs()},navigation:function(){u.removeClass(y.active)},tabs:function(){d.removeClass(y.active+" "+y.loading)}},is:{tab:function(e){return s.get.tabElement(e).size()>0}},get:{initialPath:function(){return u.eq(0).data(x.tab)||d.eq(0).data(x.tab)},defaultPathArray:function(e){return s.utils.pathToArray(s.get.defaultPath(e))},defaultPath:function(e){var t=u.filter("[data-"+x.tab+'^="'+e+'/"]').eq(0),n=t.data(x.tab)||!1;if(n){if(s.debug("Found default tab",n),l.maxDepth>g)return g++,s.get.defaultPath(n);s.error(C.recursion)}return g=0,e},navElement:function(e){return e=e||i,u.filter("[data-"+x.tab+'="'+e+'"]')},tabElement:function(e){var t,n,o,a;return e=e||i,o=s.utils.pathToArray(e),a=s.utils.last(o),t=d.filter("[data-"+x.tab+'="'+a+'"]'),n=d.filter("[data-"+x.tab+'="'+e+'"]'),t.size()>0?t:n},tab:function(){return i}},utils:{filterArray:function(t,n){return e.grep(t,function(t){return-1==e.inArray(t,n)})},last:function(t){return e.isArray(t)?t[t.length-1]:!1},pathToArray:function(e){return e===o&&(e=i),"string"==typeof e?e.split("/"):[e]},arrayToPath:function(t){return e.isArray(t)?t.join("/"):!1}},setting:function(t,n){return s.debug("Changing setting",t,n),n===o?l[t]:(e.isPlainObject(t)?e.extend(!0,l,t):l[t]=n,o)},internal:function(t,n){return s.debug("Changing internal",t,n),n===o?s[t]:(e.isPlainObject(t)?e.extend(!0,s,t):s[t]=n,o)},verbose:function(){l.verbose&&l.debug&&(s.performance.log(arguments[0]),s.verbose=Function.prototype.bind.call(console.info,console,l.moduleName+":"))},debug:function(){l.debug&&(s.performance.log(arguments[0]),s.debug=Function.prototype.bind.call(console.info,console,l.moduleName+":"))},error:function(){console.log!==o&&(s.error=Function.prototype.bind.call(console.error,console,l.moduleName+":"))},performance:{log:function(e){var t,n,o;l.performance&&(t=(new Date).getTime(),o=h||t,n=t-o,h=t,v.push({Element:p,Name:e[0],Arguments:e[1]||"","Execution Time":n})),clearTimeout(s.performance.timer),s.performance.timer=setTimeout(s.performance.display,100)},display:function(){var t=l.moduleName+":",n=0;h=!1,e.each(v,function(e,t){n+=t["Execution Time"]}),t+=" "+n+"ms",b&&(t+=" '"+b+"'"),(console.group!==o||console.table!==o)&&v.length>0&&(console.groupCollapsed(t),console.table?console.table(v):e.each(v,function(e,t){console.log(t.Name+": "+t["Execution Time"]+"ms")}),console.groupEnd()),v=[]}},invoke:function(t,n,i){var a,r;return i=i||[].slice.call(arguments,2),"string"==typeof t&&k!==o&&(t=t.split("."),a=t.length-1,e.each(t,function(t,n){return e.isPlainObject(k[n])&&t!=a?(k=k[n],!0):k[n]!==o?(r=k[n],!0):(s.error(l.errors.method),!1)})),e.isFunction(r)?r.apply(n,i):r}},N?(k===o&&s.initialize(),c=s.invoke(T)):(k!==o&&s.destroy(),s.initialize()),c!==o?c:this},e.tabNavigation=function(n){e(t).tabNavigation(n)},e.fn.tabNavigation.settings={moduleName:"Tab Module",verbose:!1,debug:!0,namespace:"tab",onTabInit:function(){},onTabLoad:function(){},templates:{determineTitle:function(){}},history:!1,path:!1,context:"body",maxDepth:25,ignoreFirstLoad:!0,alwaysRefresh:!1,cache:!0,apiSettings:!1,errors:{api:"You attempted to load content without API module",noContent:"The tab you specified is missing a content url.",method:"The method you called is not defined",state:"The state library has not been initialized",missingTab:"Missing tab: ",path:"History enabled, but no path was specified",recursion:"Max recursive depth reached"},metadata:{tab:"tab",loaded:"loaded",promise:"promise"},className:{loading:"loading",active:"active"},selector:{tabs:".tab"}}})(jQuery,window,document);
|