wishthis/node_modules/fomantic-ui/dist/components/tab.min.js
2022-06-08 12:36:39 +02:00

11 lines
No EOL
13 KiB
JavaScript

/*
* # Fomantic UI - 2.9.0-beta.293+2a71b5e
* https://github.com/fomantic/Fomantic-UI
* http://fomantic-ui.com/
*
* Copyright 2022 Contributors
* Released under the MIT license
* http://opensource.org/licenses/MIT
*
*/
!function(O,j,k,I){"use strict";O.isWindow=O.isWindow||function(e){return null!=e&&e===e.window},O.isFunction=O.isFunction||function(e){return"function"==typeof e&&"number"!=typeof e.nodeType},j=void 0!==j&&j.Math==Math?j:"undefined"!=typeof self&&self.Math==Math?self:Function("return this")(),O.fn.tab=function(c){var l,d=O.isFunction(this)?O(j):O(this),u=d.selector||"",g=(new Date).getTime(),P=[],F=c,w="string"==typeof F,S=[].slice.call(arguments,1),E=!1;return d.each(function(){var b,i,f,h,p,v=O.isPlainObject(c)?O.extend(!0,{},O.fn.tab.settings,c):O.extend({},O.fn.tab.settings),m=v.className,y=v.metadata,t=v.selector,T=v.error,a=v.regExp,e="."+v.namespace,n="module-"+v.namespace,L=O(this),o={},x=!0,r=0,A=this,s=L.data(n),C={initialize:function(){C.debug("Initializing tab menu item",L),C.fix.callbacks(),C.determineTabs(),C.debug("Determining tabs",v.context,i),v.auto&&C.set.auto(),C.bind.events(),v.history&&!E&&(C.initializeHistory(),E=!0);var e,t=C.determine.activeTab();v.autoTabActivation&&s===I&&null==t&&(t=!0===v.autoTabActivation?C.get.initialPath():v.autoTabActivation,C.debug("No active tab detected, setting tab active",t),C.changeTab(t)),null!=t&&v.history&&(e=O.address.autoUpdate(),O.address.autoUpdate(!1),O.address.value(t),O.address.autoUpdate(e)),C.instantiate()},instantiate:function(){C.verbose("Storing instance of module",C),s=C,L.data(n,C)},destroy:function(){C.debug("Destroying tabs",L),L.removeData(n).off(e)},bind:{events:function(){O.isWindow(A)||(C.debug("Attaching tab activation events to element",L),L.on("click"+e,C.event.click))}},determineTabs:function(){var e;"parent"===v.context?(0<L.closest(t.ui).length?(e=L.closest(t.ui),C.verbose("Using closest UI element as parent",e)):e=L,b=e.parent(),C.verbose("Determined parent element for creating context",b)):v.context?(b=[j,k].indexOf(v.context)<0?O(k).find(v.context):O(v.context),C.verbose("Using selector for tab context",v.context,b)):b=O("body"),v.childrenOnly?(i=b.children(t.tabs),C.debug("Searching tab context children for tabs",b,i)):(i=b.find(t.tabs),C.debug("Searching tab context for tabs",b,i))},fix:{callbacks:function(){O.isPlainObject(c)&&(c.onTabLoad||c.onTabInit)&&(c.onTabLoad&&(c.onLoad=c.onTabLoad,delete c.onTabLoad,C.error(T.legacyLoad,c.onLoad)),c.onTabInit&&(c.onFirstLoad=c.onTabInit,delete c.onTabInit,C.error(T.legacyInit,c.onFirstLoad)),v=O.extend(!0,{},O.fn.tab.settings,c))}},initializeHistory:function(){if(C.debug("Initializing page state"),O.address===I)return C.error(T.state),!1;if("state"==v.historyType){if(C.debug("Using HTML5 to manage state"),!1===v.path)return C.error(T.path),!1;O.address.history(!0).state(v.path),O(j).trigger("popstate")}O.address.bind("change",C.event.history.change)},event:{click:function(e){var t=O(this).data(y.tab);t!==I?(v.history?(C.verbose("Updating page state",e),O.address.value(t)):(C.verbose("Changing tab",e),C.changeTab(t)),e.preventDefault()):C.debug("No tab specified")},history:{change:function(e){var t=e.pathNames.join("/")||C.get.initialPath(),a=v.templates.determineTitle(t)||!1;C.performance.display(),C.debug("History change event",t,e),p=e,t!==I&&C.changeTab(t),a&&O.address.title(a)}}},refresh:function(){f&&(C.debug("Refreshing tab",f),C.changeTab(f))},cache:{read:function(e){return e!==I&&o[e]},add:function(e,t){e=e||f,C.debug("Adding cached content for",e),o[e]=t},remove:function(e){e=e||f,C.debug("Removing cached content for",e),delete o[e]}},escape:{string:function(e){return(e=String(e)).replace(a.escape,"\\$&")}},set:{auto:function(){var e="string"==typeof v.path?v.path.replace(/\/$/,"")+"/{$tab}":"/{$tab}";C.verbose("Setting up automatic tab retrieval from server",e),O.isPlainObject(v.apiSettings)?v.apiSettings.url=e:v.apiSettings={url:e}},loading:function(e){var t=C.get.tabElement(e);t.hasClass(m.loading)||(C.verbose("Setting loading state for",t),t.addClass(m.loading).siblings(i).removeClass(m.active+" "+m.loading),0<t.length&&v.onRequest.call(t[0],e))},state:function(e){O.address.value(e)}},changeTab:function(l){var d=j.history&&j.history.pushState&&v.ignoreFirstLoad&&x,u=v.auto||O.isPlainObject(v.apiSettings),g=u&&!d?C.utilities.pathToArray(l):C.get.defaultPathArray(l);l=C.utilities.arrayToPath(g),O.each(g,function(e,t){var a,n,i=g.slice(0,e+1),o=C.utilities.arrayToPath(i),r=C.is.tab(o),s=e+1==g.length,c=C.get.tabElement(o);return C.verbose("Looking for tab",t),r?(C.verbose("Tab was found",t),f=o,h=C.utilities.filterArray(g,i),s?n=!0:(r=g.slice(0,e+2),t=C.utilities.arrayToPath(r),(n=!C.is.tab(t))&&C.verbose("Tab parameters found",r)),!1===v.onBeforeChange.call(A,o)?(C.debug("onBeforeChange returned false, cancelling tab change",c),!1):n&&u?(d?(C.debug("Ignoring remote content on first tab load",o),x=!1,C.cache.add(l,c.html()),C.activate.all(o),v.onFirstLoad.call(c[0],o,h,p),v.onLoad.call(c[0],o,h,p)):(C.activate.navigation(o),C.fetch.content(o,l)),!1):(C.debug("Opened local tab",o),C.activate.all(o),C.cache.read(o)||(C.cache.add(o,!0),C.debug("First time tab loaded calling tab init"),v.onFirstLoad.call(c[0],o,h,p)),void v.onLoad.call(c[0],o,h,p))):-1!=l.search("/")||""===l?(C.error(T.missingTab,L,b,o),!1):(l=C.escape.string(l),o=(a=O("#"+l+', a[name="'+l+'"]')).closest("[data-tab]").data(y.tab),c=C.get.tabElement(o),a&&0<a.length&&o?(C.debug("Anchor link used, opening parent tab",c,a),!1===v.onBeforeChange.call(A,o)?C.debug("onBeforeChange returned false, cancelling tab change",c):(c.hasClass(m.active)||setTimeout(function(){C.scrollTo(a)},0),C.activate.all(o),C.cache.read(o)||(C.cache.add(o,!0),C.debug("First time tab loaded calling tab init"),v.onFirstLoad.call(c[0],o,h,p)),v.onLoad.call(c[0],o,h,p)),!1):void 0)})},scrollTo:function(e){var t=!!(e&&0<e.length)&&e.offset().top;!1!==t&&(C.debug("Forcing scroll to an in-page link in a hidden tab",t,e),O(k).scrollTop(t))},update:{content:function(e,t,a){var n=C.get.tabElement(e),i=n[0];a=a!==I?a:v.evaluateScripts,"string"==typeof v.cacheType&&"dom"==v.cacheType.toLowerCase()&&"string"!=typeof t?n.empty().append(O(t).clone(!0)):a?(C.debug("Updating HTML and evaluating inline scripts",e,t),n.html(t)):(C.debug("Updating HTML",e,t),i.innerHTML=t)}},fetch:{content:function(t,a){var e,n=C.get.tabElement(t),i={dataType:"html",encodeParameters:!1,on:"now",cache:v.alwaysRefresh,headers:{"X-Remote":!0},onSuccess:function(e){"response"==v.cacheType&&C.cache.add(a,e),C.update.content(t,e),t==f?(C.debug("Content loaded",t),C.activate.tab(t)):C.debug("Content loaded in background",t),v.onFirstLoad.call(n[0],t,h,p),v.onLoad.call(n[0],t,h,p),v.loadOnce?C.cache.add(a,!0):"string"==typeof v.cacheType&&"dom"==v.cacheType.toLowerCase()&&0<n.children().length?setTimeout(function(){var e=(e=n.children().clone(!0)).not("script");C.cache.add(a,e)},0):C.cache.add(a,n.html())},urlData:{tab:a}},o=n.api("get request")||!1,o=o&&"pending"===o.state();a=a||t,e=C.cache.read(a),v.cache&&e?(C.activate.tab(t),C.debug("Adding cached content",a),v.loadOnce||("once"==v.evaluateScripts?C.update.content(t,e,!1):C.update.content(t,e)),v.onLoad.call(n[0],t,h,p)):o?(C.set.loading(t),C.debug("Content is already loading",a)):O.api!==I?(e=O.extend(!0,{},v.apiSettings,i),C.debug("Retrieving remote content",a,e),C.set.loading(t),n.api(e)):C.error(T.api)}},activate:{all:function(e){C.activate.tab(e),C.activate.navigation(e)},tab:function(e){var t=C.get.tabElement(e),a="siblings"==v.deactivate?t.siblings(i):i.not(t),n=t.hasClass(m.active);C.verbose("Showing tab content for",t),n||(t.addClass(m.active),a.removeClass(m.active+" "+m.loading),0<t.length&&v.onVisible.call(t[0],e))},navigation:function(e){var t=C.get.navElement(e),a="siblings"==v.deactivate?t.siblings(d):d.not(t),n=t.hasClass(m.active);C.verbose("Activating tab navigation for",t,e),n||(t.addClass(m.active),a.removeClass(m.active+" "+m.loading))}},deactivate:{all:function(){C.deactivate.navigation(),C.deactivate.tabs()},navigation:function(){d.removeClass(m.active)},tabs:function(){i.removeClass(m.active+" "+m.loading)}},is:{tab:function(e){return e!==I&&0<C.get.tabElement(e).length}},get:{initialPath:function(){return d.eq(0).data(y.tab)||i.eq(0).data(y.tab)},path:function(){return O.address.value()},defaultPathArray:function(e){return C.utilities.pathToArray(C.get.defaultPath(e))},defaultPath:function(e){var t=d.filter("[data-"+y.tab+'^="'+C.escape.string(e)+'/"]').eq(0).data(y.tab)||!1;if(t){if(C.debug("Found default tab",t),r<v.maxDepth)return r++,C.get.defaultPath(t);C.error(T.recursion)}else C.debug("No default tabs found for",e,i);return r=0,e},navElement:function(e){return e=e||f,d.filter("[data-"+y.tab+'="'+C.escape.string(e)+'"]')},tabElement:function(e){var t;return e=e||f,t=C.utilities.pathToArray(e),t=C.utilities.last(t),e=i.filter("[data-"+y.tab+'="'+C.escape.string(e)+'"]'),t=i.filter("[data-"+y.tab+'="'+C.escape.string(t)+'"]'),0<e.length?e:t},tab:function(){return f}},determine:{activeTab:function(){var a=null;return i.each(function(e,t){O(t).hasClass(m.active)&&(t=O(this).data(y.tab),d.filter("[data-"+y.tab+'="'+C.escape.string(t)+'"]').hasClass(m.active)&&(a=t))}),a}},utilities:{filterArray:function(e,t){return O.grep(e,function(e){return-1==O.inArray(e,t)})},last:function(e){return!!Array.isArray(e)&&e[e.length-1]},pathToArray:function(e){return"string"==typeof(e=e===I?f:e)?e.split("/"):[e]},arrayToPath:function(e){return!!Array.isArray(e)&&e.join("/")}},setting:function(e,t){if(C.debug("Changing setting",e,t),O.isPlainObject(e))O.extend(!0,v,e);else{if(t===I)return v[e];O.isPlainObject(v[e])?O.extend(!0,v[e],t):v[e]=t}},internal:function(e,t){if(O.isPlainObject(e))O.extend(!0,C,e);else{if(t===I)return C[e];C[e]=t}},debug:function(){!v.silent&&v.debug&&(v.performance?C.performance.log(arguments):(C.debug=Function.prototype.bind.call(console.info,console,v.name+":"),C.debug.apply(console,arguments)))},verbose:function(){!v.silent&&v.verbose&&v.debug&&(v.performance?C.performance.log(arguments):(C.verbose=Function.prototype.bind.call(console.info,console,v.name+":"),C.verbose.apply(console,arguments)))},error:function(){v.silent||(C.error=Function.prototype.bind.call(console.error,console,v.name+":"),C.error.apply(console,arguments))},performance:{log:function(e){var t,a;v.performance&&(a=(t=(new Date).getTime())-(g||t),g=t,P.push({Name:e[0],Arguments:[].slice.call(e,1)||"",Element:A,"Execution Time":a})),clearTimeout(C.performance.timer),C.performance.timer=setTimeout(C.performance.display,500)},display:function(){var e=v.name+":",a=0;g=!1,clearTimeout(C.performance.timer),O.each(P,function(e,t){a+=t["Execution Time"]}),e+=" "+a+"ms",u&&(e+=" '"+u+"'"),(console.group!==I||console.table!==I)&&0<P.length&&(console.groupCollapsed(e),console.table?console.table(P):O.each(P,function(e,t){console.log(t.Name+": "+t["Execution Time"]+"ms")}),console.groupEnd()),P=[]}},invoke:function(n,e,t){var i,o,a,r=s;return e=e||S,t=A||t,"string"==typeof n&&r!==I&&(n=n.split(/[\. ]/),i=n.length-1,O.each(n,function(e,t){var a=e!=i?t+n[e+1].charAt(0).toUpperCase()+n[e+1].slice(1):n;if(O.isPlainObject(r[a])&&e!=i)r=r[a];else{if(r[a]!==I)return o=r[a],!1;{if(!O.isPlainObject(r[t])||e==i)return r[t]!==I?o=r[t]:C.error(T.method,n),!1;r=r[t]}}})),O.isFunction(o)?a=o.apply(t,e):o!==I&&(a=o),Array.isArray(l)?l.push(a):l!==I?l=[l,a]:a!==I&&(l=a),o}};w?(s===I&&C.initialize(),C.invoke(F)):(s!==I&&s.invoke("destroy"),C.initialize())}),l!==I?l:this},O.tab=function(){O(j).tab.apply(this,arguments)},O.fn.tab.settings={name:"Tab",namespace:"tab",silent:!1,debug:!1,verbose:!1,performance:!0,auto:!1,history:!1,historyType:"hash",path:!1,context:!1,childrenOnly:!1,maxDepth:25,deactivate:"siblings",alwaysRefresh:!1,cache:!0,loadOnce:!1,cacheType:"response",ignoreFirstLoad:!1,apiSettings:!1,evaluateScripts:"once",autoTabActivation:!0,onFirstLoad:function(e,t,a){},onLoad:function(e,t,a){},onVisible:function(e,t,a){},onRequest:function(e,t,a){},onBeforeChange:function(e){},templates:{determineTitle:function(e){}},error:{api:"You attempted to load content without API module",method:"The method you called is not defined",missingTab:"Activated tab cannot be found. Tabs are case-sensitive.",noContent:"The tab you specified is missing a content url.",path:"History enabled, but no path was specified",recursion:"Max recursive depth reached",legacyInit:"onTabInit has been renamed to onFirstLoad in 2.0, please adjust your code.",legacyLoad:"onTabLoad has been renamed to onLoad in 2.0. Please adjust your code",state:"History requires Asual's Address library <https://github.com/asual/jquery-address>"},regExp:{escape:/[-[\]{}()*+?.,\\^$|#\s:=@]/g},metadata:{tab:"tab",loaded:"loaded",promise:"promise"},className:{loading:"loading",active:"active"},selector:{tabs:".ui.tab",ui:".ui"}}}(jQuery,window,document);