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
5.8 KiB
1 lines
5.8 KiB
(function(e,t,n,o){e.fn.tabNavigation=function(n){var i,a,s,r,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=l.className,h=l.metadata,v=l.namespace,b=l.errors,y=u.data("module"),x=arguments[0],w=y!==o&&"string"==typeof x,C=[].slice.call(arguments,1);return r={initialize:function(){if(r.debug("Initializing Tabs",u),l.history){if(e.address===o)return r.error(b.state),!1;if(l.path===!1)return r.error(b.path),!1;r.verbose("Address library found adding state change event"),e.address.state(l.path).change(r.event.history.change)}e.isWindow(u.get(0))||u.on("click."+v,r.event.click),u.data("module",r)},destroy:function(){r.debug("Destroying tabs",u),u.off("."+v)},event:{click:function(){r.debug("Navigation clicked");var t=e(this).data(h.tab);t!==o?t!==i&&(l.history?e.address.value(t):r.change(t)):r.debug("No tab specified")},history:{change:function(t){var n=t.pathNames.join("/")||r.get.initialPath(),i=l.templates.determineTitle(n)||!1;r.debug("History change event",n,t),s=t,n!==o&&r.change(n),i&&e.address.title(i)}}},refresh:function(){i&&(r.debug("Refreshing tab",i),r.change(i))},cache:{read:function(e){return e!==o?f[e]:f},add:function(e,t){e=e||i,r.debug("Adding cached content for",e),f[e]=t},remove:function(e){e=e||i,r.debug("Removing cached content for",e),delete f[e]}},change:function(n){var c=r.get.defaultPathArray(n);r.deactivate.all(),e.each(c,function(u,d){var g=c.slice(0,u+1),p=r.utils.arrayToPath(g),h=r.utils.last(c)==p,v=r.is.tab(p),b=!v,y=t.history&&t.history.pushState,x=y&&l.ignoreFirstLoad&&m,w=e.isPlainObject(l.apiSettings),C=r.get.tabElement(p);return r.verbose("Looking for tab",d),b?(r.verbose("Tab is not found, assuming it is a parameter",d),!0):(v&&(r.verbose("Tab was found",d),i=p,a=r.utils.filterArray(c,g),h&&w?x?(r.debug("Ignoring remote content on first tab load",p),m=!1,f[n]=C.html(),r.activate.all(p),e.proxy(l.onTabInit,C)(p,a,s)):(r.activate.navigation(p),r.content.fetch(p,l.onTabLoad)):(r.debug("Opened tab",p),r.activate.all(p),e.proxy(l.onTabLoad,C)(p,a,s))),o)})},content:{fetch:function(t){var n=r.get.tabElement(t),c=f[t]||!1,u={dataType:"html",stateContext:n,success:function(o){f[t]=o,r.content.update(t,o),t==i?(r.debug("Content loaded",t),r.activate.tab(t)):r.debug("Content loaded in background",t),e.proxy(l.onTabInit,n)(t,a,s)},urlData:{tab:t}},d=n.data(h.promise)||!1,m=d&&"pending"===d.state();l.cache&&c?(r.debug("Showing existing content",t),r.activate.tab(t),e.proxy(l.onTabLoad,n)(t,a,s)):m?(r.debug("Content is already loading",t),n.addClass(p.loading)):e.api!==o?(r.debug("Retrieving content",t),e.api(e.extend(!0,{},l.apiSettings,u))):r.error(b.api)},update:function(e,t){r.debug("Updating html for",e);var n=r.get.tabElement(e);n.html(t)}},activate:{all:function(e){r.activate.tab(e),r.activate.navigation(e)},tab:function(e){var t=r.get.tabElement(e);r.verbose("Showing tab content for",t),t.addClass(p.active)},navigation:function(e){var t=r.get.navElement(e);r.verbose("Activating tab navigation for",t),t.addClass(p.active)}},deactivate:{all:function(){r.deactivate.navigation(),r.deactivate.tabs()},navigation:function(){u.removeClass(p.active)},tabs:function(){d.removeClass(p.active+" "+p.loading)}},is:{tab:function(e){return r.get.tabElement(e).size()>0}},get:{initialPath:function(){return u.eq(0).data(h.tab)||d.eq(0).data(h.tab)},defaultPathArray:function(e){return r.utils.pathToArray(r.get.defaultPath(e))},defaultPath:function(e){var t=u.filter("[data-"+h.tab+'^="'+e+'/"]').eq(0),n=t.data(h.tab)||!1;if(n){if(r.debug("Found default tab",n),l.maxDepth>g)return g++,r.get.defaultPath(n);r.error(b.recursion)}return g=0,e},navElement:function(e){return e=e||i,u.filter("[data-"+h.tab+'="'+e+'"]')},tabElement:function(e){var t,n,o,a;return e=e||i,o=r.utils.pathToArray(e),a=r.utils.last(o),t=d.filter("[data-"+h.tab+'="'+a+'"]'),n=d.filter("[data-"+h.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(e,t){return t===o?l[e]:(l[e]=t,o)},verbose:function(){l.verbose&&r.debug.apply(this,arguments)},debug:function(){var e=[],t=l.moduleName+": "+arguments[0],n=[].slice.call(arguments,1),o=console.info||console.log||function(){};o=Function.prototype.bind.call(o,console),l.debug&&(e.push(t),o.apply(console,e.concat(n)))},error:function(){var e=[],t=l.moduleName+": "+arguments[0],n=[].slice.call(arguments,1),o=console.warn||console.log||function(){};o=Function.prototype.bind.call(o,console),l.debug&&(e.push(t),e.concat(n),o.apply(console,e.concat(n)))},invoke:function(t,n,i){var a,s;return i=i||[].slice.call(arguments,2),"string"==typeof t&&y!==o&&(t=t.split("."),a=t.length-1,e.each(t,function(t,n){return e.isPlainObject(y[n])&&t!=a?(y=y[n],!0):y[n]!==o?(s=y[n],!0):(r.error(l.errors.method),!1)})),e.isFunction(s)?s.apply(n,i):s}},w?c=r.invoke(x,this,C):r.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);
|