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
7.5 KiB

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