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.3 KiB

10 years ago
  1. /*
  2. * # Semantic UI - 1.6.2
  3. * https://github.com/Semantic-Org/Semantic-UI
  4. * http://www.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.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,h,p,m,v=s.className,y=s.metadata,T=s.selector,x=s.error,A="."+s.namespace,P="module-"+s.namespace,C=e(this),E={},S=!0,w=0,j=this,D=C.data(P);i={initialize:function(){i.debug("Initializing tab menu item",C),i.determineTabs(),i.debug("Determining tabs",s.context,f),s.auto&&(i.verbose("Setting up automatic tab retrieval from server"),s.apiSettings={url:s.path+"/{$tab}"}),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(T.ui).length>0?(t=C.closest(T.ui),i.verbose("Using closest UI element for determining parent",t)):t=C,a=t.parent(),i.verbose("Determined parent element for creating context",a)):s.context?(a=e(s.context),i.verbose("Using selector for tab context",s.context,a)):a=e("body"),s.childrenOnly?(f=a.children(T.tabs),i.debug("Searching tab context children for tabs",a,f)):(f=a.find(T.tabs),i.debug("Searching tab context for tabs",a,f))},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),D=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(y.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),m=t,a!==n&&i.changeTab(a),o&&e.address.title(o)}}},refresh:function(){h&&(i.debug("Refreshing tab",h),i.changeTab(h))},cache:{read:function(e){return e!==n?E[e]:!1},add:function(e,t){e=e||h,i.debug("Adding cached content for",e),E[e]=t},remove:function(e){e=e||h,i.debug("Removing cached content for",e),delete E[e]}},set:{state:function(t){e.address.value(t)}},changeTab:function(n){var o=t.history&&t.history.pushState,r=o&&s.ignoreFirstLoad&&S,c=s.auto||e.isPlainObject(s.apiSettings),l=c&&!r?i.utilities.pathToArray(n):i.get.defaultPathArray(n);n=i.utilities.arrayToPath(l),e.each(l,function(t,o){var u,d,b,g,f=l.slice(0,t+1),v=i.utilities.arrayToPath(f),y=i.is.tab(v),T=t+1==l.length,A=i.get.tabElement(v);if(i.verbose("Looking for tab",o),y){if(i.verbose("Tab was found",o),h=v,p=i.utilities.filterArray(l,f),T?g=!0:(d=l.slice(0,t+2),b=i.utilities.arrayToPath(d),g=!i.is.tab(b),g&&i.verbose("Tab parameters found",d)),g&&c)return r?(i.debug("Ignoring remote content on first tab load",v),S=!1,i.cache.add(n,A.html()),i.activate.all(v),e.proxy(s.onTabInit,A)(v,p,m),e.proxy(s.onTabLoad,A)(v,p,m)):(i.activate.navigation(v),i.content.fetch(v,n)),!1;i.debug("Opened local tab",v),i.activate.all(v),i.cache.read(v)||(i.cache.add(v,!0),i.debug("First time tab loaded calling tab init"),e.proxy(s.onTabInit,A)(v,p,m)),e.proxy(s.onTabLoad,A)(v,p,m)}else{if(-1!=n.search("/")||""===n)return i.error(x.missingTab,C,a,v),!1;if(u=e("#"+n+', a[name="'+n+'"]'),v=u.closest("[data-tab]").data("tab"),A=i.get.tabElement(v),u&&u.length>0&&v)return i.debug("No tab found, but deep anchor link present, opening parent tab"),i.activate.all(v),i.cache.read(v)||(i.cache.add(v,!0),i.debug("First time tab loaded calling tab init"),e.proxy(s.onTabInit,A)(v,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==h?(i.debug("Con