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
8.0 KiB
1 lines
8.0 KiB
!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=p.get.navElement(a);p.verbose("Activating tab navigation for",b,a),b.addClass(r.active)}},deactivate:{all:function(){p.deactivate.navigation(),p.deactivate.tabs()},navigation:function(){f.removeClass(r.active)},tabs:function(){y.removeClass(r.active+" "+r.loading)}},is:{tab:function(a){return a!==d?p.get.tabElement(a).size()>0:!1}},get:{initialPath:function(){return f.eq(0).data(s.tab)||y.eq(0).data(s.tab)},path:function(){return a.address.value()},defaultPathArray:function(a){return p.utilities.pathToArray(p.get.defaultPath(a))},defaultPath:function(a){var b=f.filter("[data-"+s.tab+'^="'+a+'/"]').eq(0),c=b.data(s.tab)||!1;if(c){if(p.debug("Found default tab",c),B<q.maxDepth)return B++,p.get.defaultPath(c);p.error(u.recursion)}else p.debug("No default tabs found for",a,y);return B=0,a},navElement:function(a){return a=a||m,f.filter("[data-"+s.tab+'="'+a+'"]')},tabElement:function(a){var b,c,d,e;return a=a||m,d=p.utilities.pathToArray(a),e=p.utilities.last(d),b=y.filter("[data-"+s.tab+'="'+e+'"]'),c=y.filter("[data-"+s.tab+'="'+a+'"]'),b.size()>0?b:c},tab:function(){return m}},utilities:{filterArray:function(b,c){return a.grep(b,function(b){return-1==a.inArray(b,c)})},last:function(b){return a.isArray(b)?b[b.length-1]:!1},pathToArray:function(a){return a===d&&(a=m),"string"==typeof a?a.split("/"):[a]},arrayToPath:function(b){return a.isArray(b)?b.join("/"):!1}},setting:function(b,c){if(p.debug("Changing setting",b,c),a.isPlainObject(b))a.extend(!0,q,b);else{if(c===d)return q[b];q[b]=c}},internal:function(b,c){if(a.isPlainObject(b))a.extend(!0,p,b);else{if(c===d)return p[b];p[b]=c}},debug:function(){q.debug&&(q.performance?p.performance.log(arguments):(p.debug=Function.prototype.bind.call(console.info,console,q.name+":"),p.debug.apply(console,arguments)))},verbose:function(){q.verbose&&q.debug&&(q.performance?p.performance.log(arguments):(p.verbose=Function.prototype.bind.call(console.info,console,q.name+":"),p.verbose.apply(console,arguments)))},error:function(){p.error=Function.prototype.bind.call(console.error,console,q.name+":"),p.error.apply(console,arguments)},performance:{log:function(a){var b,c,d;q.performance&&(b=(new Date).getTime(),d=h||b,c=b-d,h=b,i.push({Element:C,Name:a[0],Arguments:[].slice.call(a,1)||"","Execution Time":c})),clearTimeout(p.performance.timer),p.performance.timer=setTimeout(p.performance.display,100)},display:function(){var b=q.name+":",c=0;h=!1,clearTimeout(p.performance.timer),a.each(i,function(a,b){c+=b["Execution Time"]}),b+=" "+c+"ms",g&&(b+=" '"+g+"'"),(console.group!==d||console.table!==d)&&i.length>0&&(console.groupCollapsed(b),console.table?console.table(i):a.each(i,function(a,b){console.log(b.Name+": "+b["Execution Time"]+"ms")}),console.groupEnd()),i=[]}},invoke:function(b,c,f){var g,h,i,j=D;return c=c||l,f=C||f,"string"==typeof b&&j!==d&&(b=b.split(/[\. ]/),g=b.length-1,a.each(b,function(c,e){var f=c!=g?e+b[c+1].charAt(0).toUpperCase()+b[c+1].slice(1):b;if(a.isPlainObject(j[f])&&c!=g)j=j[f];else{if(j[f]!==d)return h=j[f],!1;if(!a.isPlainObject(j[e])||c==g)return j[e]!==d?(h=j[e],!1):(p.error(u.method,b),!1);j=j[e]}})),a.isFunction(h)?i=h.apply(f,c):h!==d&&(i=h),a.isArray(e)?e.push(i):e!==d?e=[e,i]:i!==d&&(e=i),h}},k?(D===d&&p.initialize(),p.invoke(j)):(D!==d&&p.destroy(),p.initialize())}),e!==d?e:this},a.tab=function(c){a(b).tab(c)},a.fn.tab.settings={name:"Tab",namespace:"tab",verbose:!0,debug:!1,performance:!0,onTabInit:function(){},onTabLoad:function(){},templates:{determineTitle:function(){}},auto:!1,history:!0,historyType:"hash",path:!1,context:!1,maxDepth:25,ignoreFirstLoad:!1,alwaysRefresh:!1,cache:!0,apiSettings:!1,error:{api:"You attempted to load content without API module",method:"The method you called is not defined",missingTab:"Tab cannot be found",noContent:"The tab you specified is missing a content url.",path:"History enabled, but no path was specified",recursion:"Max recursive depth reached",state:"The state library has not been initialized"},metadata:{tab:"tab",loaded:"loaded",promise:"promise"},className:{loading:"loading",active:"active"},selector:{tabs:".ui.tab"}}}(jQuery,window,document);
|