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.7 KiB
1 lines
8.7 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,r=a.isPlainObject(c)?a.extend(!0,{},a.fn.tab.settings,c):a.extend({},a.fn.tab.settings),s=r.className,t=r.metadata,u=r.selector,v=r.error,w="."+r.namespace,x="module-"+r.namespace,y=a(this),z=a(u.tabs),A={},B=!0,C=0,D=this,E=y.data(x);q={initialize:function(){q.debug("Initializing tab menu item",y),r.context&&(q.determineTabs(),q.debug("Using only tabs inside context",r.context,z)),r.auto&&(q.verbose("Setting up automatic tab retrieval from server"),r.apiSettings={url:r.path+"/{$tab}"}),a.isWindow(D)||(q.debug("Attaching tab activation events to element",y),y.on("click"+w,q.event.click)),q.initializeHistory(),q.instantiate()},determineTabs:function(){var b;"parent"===r.context?(y.closest("."+s.ui).size()>0?(b=y.closest("."+s.ui),q.verbose("Using closest UI element for determining parent",b)):b=y,m=b.parent(),q.verbose("Determining parent element for creating context",m)):(m=a(r.context),q.verbose("Using selector for tab context",r.context,m)),r.childrenOnly?(z=m.children(u.tabs),q.debug("Searching tab context children for tabs",m,z)):(z=m.find(u.tabs),q.debug("Searching tab context for tabs",m,z))},initializeHistory:function(){if(r.history){if(q.debug("Initializing page state"),a.address===d)return q.error(v.state),!1;if("state"==r.historyType){if(q.debug("Using HTML5 to manage state"),r.path===!1)return q.error(v.path),!1;a.address.history(!0).state(r.path)}a.address.unbind("change").bind("change",q.event.history.change)}},instantiate:function(){q.verbose("Storing instance of module",q),y.data(x,q)},destroy:function(){q.debug("Destroying tabs",y),y.removeData(x).off(w)},event:{click:function(b){var c=a(this).data(t.tab);c!==d?(r.history?(q.verbose("Updating page state",b),a.address.value(c)):(q.verbose("Changing tab",b),q.changeTab(c)),b.preventDefault()):q.debug("No tab specified")},history:{change:function(b){var c=b.pathNames.join("/")||q.get.initialPath(),e=r.templates.determineTitle(c)||!1;q.performance.display(),q.debug("History change event",c,b),p=b,c!==d&&q.changeTab(c),e&&a.address.title(e)}}},refresh:function(){n&&(q.debug("Refreshing tab",n),q.changeTab(n))},cache:{read:function(a){return a!==d?A[a]:!1},add:function(a,b){a=a||n,q.debug("Adding cached content for",a),A[a]=b},remove:function(a){a=a||n,q.debug("Removing cached content for",a),delete A[a]}},set:{state:function(b){a.address.value(b)}},changeTab:function(c){var d=b.history&&b.history.pushState,e=d&&r.ignoreFirstLoad&&B,f=r.auto||a.isPlainObject(r.apiSettings),g=f&&!e?q.utilities.pathToArray(c):q.get.defaultPathArray(c);c=q.utilities.arrayToPath(g),a.each(g,function(b,d){var h,i,j,k=g.slice(0,b+1),l=q.utilities.arrayToPath(k),m=q.is.tab(l),s=b+1==g.length,t=q.get.tabElement(l);return q.verbose("Looking for tab",d),m?(q.verbose("Tab was found",d),n=l,o=q.utilities.filterArray(g,k),s?j=!0:(h=g.slice(0,b+2),i=q.utilities.arrayToPath(h),j=!q.is.tab(i),j&&q.verbose("Tab parameters found",h)),j&&f?(e?(q.debug("Ignoring remote content on first tab load",l),B=!1,q.cache.add(c,t.html()),q.activate.all(l),a.proxy(r.onTabInit,t)(l,o,p),a.proxy(r.onTabLoad,t)(l,o,p)):(q.activate.navigation(l),q.content.fetch(l,c)),!1):(q.debug("Opened local tab",l),q.activate.all(l),q.cache.read(l)||(q.cache.add(l,!0),q.debug("First time tab loaded calling tab init"),a.proxy(r.onTabInit,t)(l,o,p)),a.proxy(r.onTabLoad,t)(l,o,p),void 0)):(q.error(v.missingTab,d),!1)})},content:{fetch:function(b,c){var e,f,g=q.get.tabElement(b),h={dataType:"html",stateContext:g,success:function(d){q.cache.add(c,d),q.content.update(b,d),b==n?(q.debug("Content loaded",b),q.activate.tab(b)):q.debug("Content loaded in background",b),a.proxy(r.onTabInit,g)(b,o,p),a.proxy(r.onTabLoad,g)(b,o,p)},urlData:{tab:c}},i=g.data(t.promise)||!1,j=i&&"pending"===i.state();c=c||b,f=q.cache.read(c),r.cache&&f?(q.debug("Showing existing content",c),q.content.update(b,f),q.activate.tab(b),a.proxy(r.onTabLoad,g)(b,o,p)):j?(q.debug("Content is already loading",c),g.addClass(s.loading)):a.api!==d?(e=a.extend(!0,{headers:{"X-Remote":!0}},r.apiSettings,h),q.debug("Retrieving remote content",c,e),a.api(e)):q.error(v.api)},update:function(a,b){q.debug("Updating html for",a);var c=q.get.tabElement(a);c.html(b)}},activate:{all:function(a){q.activate.tab(a),q.activate.navigation(a)},tab:function(a){var b=q.get.tabElement(a);q.verbose("Showing tab content for",b),b.addClass(s.active).siblings(z).removeClass(s.active+" "+s.loading)},navigation:function(a){var b=q.get.navElement(a);q.verbose("Activating tab navigation for",b,a),b.addClass(s.active).siblings(f).removeClass(s.active+" "+s.loading)}},deactivate:{all:function(){q.deactivate.navigation(),q.deactivate.tabs()},navigation:function(){f.removeClass(s.active)},tabs:function(){z.removeClass(s.active+" "+s.loading)}},is:{tab:function(a){return a!==d?q.get.tabElement(a).size()>0:!1}},get:{initialPath:function(){return f.eq(0).data(t.tab)||z.eq(0).data(t.tab)},path:function(){return a.address.value()},defaultPathArray:function(a){return q.utilities.pathToArray(q.get.defaultPath(a))},defaultPath:function(a){var b=f.filter("[data-"+t.tab+'^="'+a+'/"]').eq(0),c=b.data(t.tab)||!1;if(c){if(q.debug("Found default tab",c),C<r.maxDepth)return C++,q.get.defaultPath(c);q.error(v.recursion)}else q.debug("No default tabs found for",a,z);return C=0,a},navElement:function(a){return a=a||n,f.filter("[data-"+t.tab+'="'+a+'"]')},tabElement:function(a){var b,c,d,e;return a=a||n,d=q.utilities.pathToArray(a),e=q.utilities.last(d),b=z.filter("[data-"+t.tab+'="'+e+'"]'),c=z.filter("[data-"+t.tab+'="'+a+'"]'),b.size()>0?b:c},tab:function(){return n}},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=n),"string"==typeof a?a.split("/"):[a]},arrayToPath:function(b){return a.isArray(b)?b.join("/"):!1}},setting:function(b,c){if(q.debug("Changing setting",b,c),a.isPlainObject(b))a.extend(!0,r,b);else{if(c===d)return r[b];r[b]=c}},internal:function(b,c){if(a.isPlainObject(b))a.extend(!0,q,b);else{if(c===d)return q[b];q[b]=c}},debug:function(){r.debug&&(r.performance?q.performance.log(arguments):(q.debug=Function.prototype.bind.call(console.info,console,r.name+":"),q.debug.apply(console,arguments)))},verbose:function(){r.verbose&&r.debug&&(r.performance?q.performance.log(arguments):(q.verbose=Function.prototype.bind.call(console.info,console,r.name+":"),q.verbose.apply(console,arguments)))},error:function(){q.error=Function.prototype.bind.call(console.error,console,r.name+":"),q.error.apply(console,arguments)},performance:{log:function(a){var b,c,d;r.performance&&(b=(new Date).getTime(),d=h||b,c=b-d,h=b,i.push({Element:D,Name:a[0],Arguments:[].slice.call(a,1)||"","Execution Time":c})),clearTimeout(q.performance.timer),q.performance.timer=setTimeout(q.performance.display,100)},display:function(){var b=r.name+":",c=0;h=!1,clearTimeout(q.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=E;return c=c||l,f=D||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):(q.error(v.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?(E===d&&q.initialize(),q.invoke(j)):(E!==d&&q.destroy(),q.initialize())}),e!==d?e:this},a.tab=function(c){a(b).tab(c)},a.fn.tab.settings={name:"Tab",namespace:"tab",debug:!0,verbose:!0,performance:!0,onTabInit:function(){},onTabLoad:function(){},templates:{determineTitle:function(){}},auto:!1,history:!1,historyType:"hash",path:!1,context:!1,childrenOnly:!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",ui:"ui"},selector:{tabs:".ui.tab"}}}(jQuery,window,document);
|