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.

10 lines
10 KiB

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