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,l,c=e.extend(!0,{},e.fn.tabNavigation.settings,n),u=e(this),d=e(c.context).find(c.selector.tabs),f=!0,p={},g=0,m=c.className,h=c.metadata,v=c.namespace,b=c.errors,y=u.data("module"),x=arguments[0],C=y!==o&&"string"==typeof x,w=[].slice.call(arguments,1);return r={initialize:function(){r.debug("Initializing Tabs",u),c.history&&c.path!==!1&&(e.address!==o?(r.verbose("Address library found adding state change event"),e.address.state(c.path).change(r.event.history.change)):r.error(b.state)),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&&(c.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=c.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?p[e]:p},add:function(e,t){e=e||i,r.debug("Adding cached content for",e),p[e]=t},remove:function(e){e=e||i,r.debug("Removing cached content for",e),delete p[e]}},change:function(n){var l=r.get.defaultPathArray(n);r.deactivate.all(),e.each(l,function(u,d){var g=l.slice(0,u+1),m=r.utils.arrayToPath(g),h=r.utils.last(l)==m,v=r.is.tab(m),b=!v,y=t.history&&t.history.pushState,x=y&&c.ignoreFirstLoad&&f,C=e.isPlainObject(c.apiSettings),w=r.get.tabElement(m);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=m,a=r.utils.filterArray(l,g),h&&C?x?(r.debug("Ignoring remote content on first tab load",m),f=!1,p[n]=w.html(),r.activate.all(m),e.proxy(c.onTabInit,w)(m,a,s)):(r.activate.navigation(m),r.content.fetch(m,c.onTabLoad)):(r.debug("Opened tab",m),r.activate.all(m),e.proxy(c.onTabLoad,w)(m,a,s))),o)})},content:{fetch:function(t){var n=r.get.tabElement(t),l=p[t]||!1,u={dataType:"html",stateContext:n,success:function(o){p[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(c.onTabInit,n)(t,a,s)},urlData:{tab:t}},d=n.data(h.promise)||!1,f=d&&"pending"===d.state();c.cache&&l?(r.debug("Showing existing content",t),r.activate.tab(t),e.proxy(c.onTabLoad,n)(t,a,s)):f?(r.debug("Content is already loading",t),n.addClass(m.loading)):e.api!==o?(r.debug("Retrieving content",t),e.api(e.extend(!0,{},c.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(m.active)},navigation:function(e){var t=r.get.navElement(e);r.verbose("Activating tab navigation for",t),t.addClass(m.active)}},deactivate:{all:function(){r.deactivate.navigation(),r.deactivate.tabs()},navigation:function(){u.removeClass(m.active)},tabs:function(){d.removeClass(m.active+" "+m.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),c.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?c[e]:(c[e]=t,o)},verbose:function(){c.verbose&&r.debug.apply(this,arguments)},debug:function(){var e=[],t=c.moduleName+": "+arguments[0],n=[].slice.call(arguments,1),o=console.info||console.log||function(){};o=Function.prototype.bind.call(o,console),c.debug&&(e.push(t),o.apply(console,e.concat(n)))},error:function(){var e=[],t=c.moduleName+": "+arguments[0],n=[].slice.call(arguments,1),o=console.warn||console.log||function(){};o=Function.prototype.bind.call(o,console),c.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(c.errors.method),!1)})),e.isFunction(s)?s.apply(n,i):s}},C?l=r.invoke(x,this,w):r.initialize(),l!==o?l: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: ",recursion:"Max recursive depth reached"},metadata:{tab:"tab",loaded:"loaded",promise:"promise"},className:{loading:"loading",active:"active"},selector:{tabs:".tab"}}})(jQuery,window,document);
|