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.
bazarr/static/semantic/components/tab.min.js

1 line
11 KiB

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