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

10 years ago
10 years ago
  1. /*
  2. * # Semantic UI
  3. * https://github.com/Semantic-Org/Semantic-UI
  4. * http://beta.semantic-ui.com/
  5. *
  6. * Copyright 2014 Contributors
  7. * Released under the MIT license
  8. * http://opensource.org/licenses/MIT
  9. *
  10. */
  11. !function(e,t,a,n){"use strict";e.tab=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(),u=[],d=arguments[0],b="string"==typeof d,g=[].slice.call(arguments,1);return r.each(function(){var a,f,p,h,m=s.className,v=s.metadata,y=s.selector,T=s.error,x="."+s.namespace,A="module-"+s.namespace,P=e(this),C=e(y.tabs),E={},z=!0,S=0,w=this,F=P.data(A);i={initialize:function(){i.debug("Initializing tab menu item",P),s.context&&(i.determineTabs(),i.debug("Using only tabs inside context",s.context,C)),s.auto&&(i.verbose("Setting up automatic tab retrieval from server"),s.apiSettings={url:s.path+"/{$tab}"}),e.isWindow(w)||(i.debug("Attaching tab activation events to element",P),P.on("click"+x,i.event.click)),i.instantiate()},determineTabs:function(){var t;"parent"===s.context?(P.closest("."+m.ui).size()>0?(t=P.closest("."+m.ui),i.verbose("Using closest UI element for determining parent",t)):t=P,a=t.parent(),i.verbose("Determining parent element for creating context",a)):(a=e(s.context),i.verbose("Using selector for tab context",s.context,a)),s.childrenOnly?(C=a.children(y.tabs),i.debug("Searching tab context children for tabs",a,C)):(C=a.find(y.tabs),i.debug("Searching tab context for tabs",a,C))},initializeHistory:function(){if(s.history){if(i.debug("Initializing page state"),e.address===n)return i.error(T.state),!1;if("state"==s.historyType){if(i.debug("Using HTML5 to manage state"),s.path===!1)return i.error(T.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),P.data(A,i)},destroy:function(){i.debug("Destroying tabs",P),P.removeData(A).off(x)},event:{click:function(t){var a=e(this).data(v.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),h=t,a!==n&&i.changeTab(a),o&&e.address.title(o)}}},refresh:function(){f&&(i.debug("Refreshing tab",f),i.changeTab(f))},cache:{read:function(e){return e!==n?E[e]:!1},add:function(e,t){e=e||f,i.debug("Adding cached content for",e),E[e]=t},remove:function(e){e=e||f,i.debug("Removing cached content for",e),delete E[e]}},set:{state:function(t){e.address.value(t)}},changeTab:function(a){var n=t.history&&t.history.pushState,o=n&&s.ignoreFirstLoad&&z,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,u,d,b,g=c.slice(0,t+1),m=i.utilities.arrayToPath(g),v=i.is.tab(m),y=t+1==c.length,x=i.get.tabElement(m);return i.verbose("Looking for tab",n),v?(i.verbose("Tab was found",n),f=m,p=i.utilities.filterArray(c,g),y?b=!0:(u=c.slice(0,t+2),d=i.utilities.arrayToPath(u),b=!i.is.tab(d),b&&i.verbose("Tab parameters found",u)),b&&r?(o?(i.debug("Ignoring remote content on first tab load",m),z=!1,i.cache.add(a,x.html()),i.activate.all(m),e.proxy(s.onTabInit,x)(m,p,h),e.proxy(s.onTabLoad,x)(m,p,h)):(i.activate.navigation(m),i.content.fetch(m,a)),!1):(i.debug("Opened local tab",m),i.activate.all(m),i.cache.read(m)||(i.cache.add(m,!0),i.debug("First time tab loaded calling tab init"),e.proxy(s.onTabInit,x)(m,p,h)),e.proxy(s.onTabLoad,x)(m,p,h),void 0)):(l=e("#"+a+', a[name="'+a+'"]'),m=l.closest("[data-tab]").data("tab"),x=i.get.tabElement(m),l.size()>0&&m?(i.debug("No tab found, but deep anchor link present, opening parent tab"),i.activate.all(m),i.cache.read(m)||(i.cache.add(m,!0),i.debug("First time tab loaded calling tab init"),e.proxy(s.onTabInit,x)(m,p,h))):i.error(T.missingTab,P,m),!1)})},content:{fetch:function(t,a){var o,r,c=i.get.tabElement(t),l={dataType:"html",stateContext:c,onSuccess:function(n){i.cache.add(a,n),i.content.update(t,n),t==f?(i.debug("Content loaded",t),i.activa