|
|
/*! * # Semantic UI 2.0.0 - Tab * http://github.com/semantic-org/semantic-ui/
* * * Copyright 2015 Contributors * Released under the MIT license * http://opensource.org/licenses/MIT
* */ !function(e,t,a,n){"use strict";e.fn.tab=function(i){var o,r,s=e(e.isFunction(this)?t:this),c=e.isPlainObject(i)?e.extend(!0,{},e.fn.tab.settings,i):e.extend({},e.fn.tab.settings),l=s.selector||"",d=(new Date).getTime(),u=[],b=arguments[0],g="string"==typeof b,f=[].slice.call(arguments,1);return s.each(function(){var h,p,m,v,y,T=c.className,L=c.metadata,x=c.selector,A=c.error,C="."+c.namespace,P="module-"+c.namespace,F=e(this),S={},E=!0,j=0,k=this,w=F.data(P);o={initialize:function(){o.debug("Initializing tab menu item",F),o.fix.callbacks(),o.determineTabs(),o.debug("Determining tabs",c.context,p),c.auto&&o.set.auto(),e.isWindow(k)||(o.debug("Attaching tab activation events to element",F),F.on("click"+C,o.event.click)),o.instantiate()},determineTabs:function(){var t;"parent"===c.context?(F.closest(x.ui).length>0?(t=F.closest(x.ui),o.verbose("Using closest UI element for determining parent",t)):t=F,h=t.parent(),o.verbose("Determined parent element for creating context",h)):c.context?(h=e(c.context),o.verbose("Using selector for tab context",c.context,h)):h=e("body"),c.childrenOnly?(p=h.children(x.tabs),o.debug("Searching tab context children for tabs",h,p)):(p=h.find(x.tabs),o.debug("Searching tab context for tabs",h,p))},fix:{callbacks:function(){e.isPlainObject(i)&&(i.onTabLoad||i.onTabInit)&&(i.onTabLoad&&(i.onLoad=i.onTabLoad,delete i.onTabLoad,o.error(A.legacyLoad,i.onLoad)),i.onTabInit&&(i.onFirstLoad=i.onTabInit,delete i.onTabInit,o.error(A.legacyInit,i.onFirstLoad)),c=e.extend(!0,{},e.fn.tab.settings,i))}},initializeHistory:function(){if(c.history){if(o.debug("Initializing page state"),e.address===n)return o.error(A.state),!1;if("state"==c.historyType){if(o.debug("Using HTML5 to manage state"),c.path===!1)return o.error(A.path),!1;e.address.history(!0).state(c.path)}e.address.bind("change",o.event.history.change)}},instantiate:function(){o.verbose("Storing instance of module",o),w=o,F.data(P,o)},destroy:function(){o.debug("Destroying tabs",F),F.removeData(P).off(C)},event:{click:function(t){var a=e(this).data(L.tab);a!==n?(c.history?(o.verbose("Updating page state",t),e.address.value(a)):(o.verbose("Changing tab",t),o.changeTab(a)),t.preventDefault()):o.debug("No tab specified")},history:{change:function(t){var a=t.pathNames.join("/")||o.get.initialPath(),i=c.templates.determineTitle(a)||!1;o.performance.display(),o.debug("History change event",a,t),y=t,a!==n&&o.changeTab(a),i&&e.address.title(i)}}},refresh:function(){m&&(o.debug("Refreshing tab",m),o.changeTab(m))},cache:{read:function(e){return e!==n?S[e]:!1},add:function(e,t){e=e||m,o.debug("Adding cached content for",e),S[e]=t},remove:function(e){e=e||m,o.debug("Removing cached content for",e),delete S[e]}},set:{auto:function(){var t="string"==typeof c.path?c.path.replace(/\/$/,"")+"/{$tab}":"/{$tab}";o.verbose("Setting up automatic tab retrieval from server",t),e.isPlainObject(c.apiSettings)?c.apiSettings.url=t:c.apiSettings={url:t}},loading:function(e){var t=o.get.tabElement(e),a=t.hasClass(T.loading);a||(o.verbose("Setting loading state for",t),t.addClass(T.loading).siblings(p).removeClass(T.active+" "+T.loading),t.length>0&&c.onRequest.call(t[0],e))},state:function(t){e.address.value(t)}},changeTab:function(a){var a="string"==typeof a?a.toLowerCase():a,n=t.history&&t.history.pushState,i=n&&c.ignoreFirstLoad&&E,r=c.auto||e.isPlainObject(c.apiSettings),s=r&&!i?o.utilities.pathToArray(a):o.get.defaultPathArray(a);a=o.utilities.arrayToPath(s),e.each(s,function(t,n){var l,d,u,b,g=s.slice(0,t+1),f=o.utilities.arrayToPath(g),p=o.is.tab(f),L=t+1==s.length,x=o.get.tabElement(f);if(o.verbose("Looking for tab",n),p){if(o.verbose("Tab was found",n),m=f,v=o.utilities.filterArray(s,g),L?b=!0:(d=s.slice(0,t+2),u=o.utilities.arrayToPath(d),b=!o.is.tab(u),b&&o.verbose("Tab parameters found",d)),b&&r)return i?(o.debug("Ignoring remote content on first tab load",f),E=!1,o.cache.add(a,x.html()),o.activate.all(f),c.onFirstLoad.call(x[0],f,v,y),c.onLoad.call(x[0],f,v,y)):(o.activate.navigation(f),o.fetch.content(f,a)),!1;o.debug("Opened local tab",f),o.activate.all(f),o.cache.
|