11 lines
No EOL
12 KiB
JavaScript
11 lines
No EOL
12 KiB
JavaScript
/*
|
|
* # Fomantic UI - 2.9.2
|
|
* https://github.com/fomantic/Fomantic-UI
|
|
* https://fomantic-ui.com/
|
|
*
|
|
* Copyright 2023 Contributors
|
|
* Released under the MIT license
|
|
* https://opensource.org/licenses/MIT
|
|
*
|
|
*/
|
|
!function(j,U,k){"use strict";function D(e){return"function"==typeof e&&"number"!=typeof e.nodeType}U=void 0!==U&&U.Math===Math?U:globalThis,j.fn.tab=function(c){var l,d=D(this)?j(U):j(this),u=j(k),g=d.selector||"",L=Date.now(),S=[],E=c,w="string"==typeof E,O=[].slice.call(arguments,1),F=!1;return d.each(function(){var b,i,f,h,p,v=j.isPlainObject(c)?j.extend(!0,{},j.fn.tab.settings,c):j.extend({},j.fn.tab.settings),m=v.className,y=v.metadata,t=v.selector,T=v.error,a=v.regExp,n="."+v.namespace,e="module-"+v.namespace,A=j(this),o={},C=!0,r=0,x=this,s=A.data(e),P={initialize:function(){P.debug("Initializing tab menu item",A),P.determineTabs(),P.debug("Determining tabs",v.context,i),v.auto&&P.set.auto(),P.bind.events(),v.history&&!F&&(P.initializeHistory(),F=!0);var e,t=P.determine.activeTab();v.autoTabActivation&&void 0===s&&null===t&&(t=!0===v.autoTabActivation?P.get.initialPath():v.autoTabActivation,P.debug("No active tab detected, setting tab active",t),P.changeTab(t)),null!==t&&v.history&&(e=j.address.autoUpdate(),j.address.autoUpdate(!1),j.address.value(t),j.address.autoUpdate(e)),P.instantiate()},instantiate:function(){P.verbose("Storing instance of module",P),s=P,A.data(e,P)},destroy:function(){P.debug("Destroying tabs",A),A.removeData(e).off(n)},bind:{events:function(){var e;null!==(e=x)&&e===e.window||(P.debug("Attaching tab activation events to element",A),A.on("click"+n,P.event.click))}},determineTabs:function(){var e;"parent"===v.context?(0<A.closest(t.ui).length?(e=A.closest(t.ui),P.verbose("Using closest UI element as parent",e)):e=A,b=e.parent(),P.verbose("Determined parent element for creating context",b)):v.context?(b=[U,k].indexOf(v.context)<0?u.find(v.context):j(v.context),P.verbose("Using selector for tab context",v.context,b)):b=j("body"),v.childrenOnly?(i=b.children(t.tabs),P.debug("Searching tab context children for tabs",b,i)):(i=b.find(t.tabs),P.debug("Searching tab context for tabs",b,i))},initializeHistory:function(){if(P.debug("Initializing page state"),void 0===j.address)return P.error(T.state),!1;if("state"===v.historyType){if(P.debug("Using HTML5 to manage state"),!1===v.path)return P.error(T.path),!1;j.address.history(!0).state(v.path),j(U).trigger("popstate")}j.address.bind("change",P.event.history.change)},event:{click:function(e){var t=j(this).data(y.tab);void 0!==t?(v.history?(P.verbose("Updating page state",e),j.address.value(t)):(P.verbose("Changing tab",e),P.changeTab(t)),e.preventDefault()):P.debug("No tab specified")},history:{change:function(e){var t=e.pathNames.join("/")||P.get.initialPath(),a=v.templates.determineTitle(t)||!1;P.performance.display(),P.debug("History change event",t,e),p=e,void 0!==t&&P.changeTab(t),a&&j.address.title(a)}}},refresh:function(){f&&(P.debug("Refreshing tab",f),P.changeTab(f))},cache:{read:function(e){return void 0!==e&&o[e]},add:function(e,t){e=e||f,P.debug("Adding cached content for",e),o[e]=t},remove:function(e){e=e||f,P.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}";P.verbose("Setting up automatic tab retrieval from server",e),j.isPlainObject(v.apiSettings)?v.apiSettings.url=e:v.apiSettings={url:e}},loading:function(e){var t=P.get.tabElement(e);t.hasClass(m.loading)||(P.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){j.address.value(e)}},changeTab:function(l){var d=U.history&&U.history.pushState&&v.ignoreFirstLoad&&C,u=v.auto||j.isPlainObject(v.apiSettings),g=u&&!d?P.utilities.pathToArray(l):P.get.defaultPathArray(l);l=P.utilities.arrayToPath(g),j.each(g,function(e,t){var a,n,i=g.slice(0,e+1),o=P.utilities.arrayToPath(i),r=P.is.tab(o),s=e+1===g.length,c=P.get.tabElement(o);return P.verbose("Looking for tab",t),r?(P.verbose("Tab was found",t),f=o,h=P.utilities.filterArray(g,i),s?n=!0:(r=g.slice(0,e+2),t=P.utilities.arrayToPath(r),(n=!P.is.tab(t))&&P.verbose("Tab parameters found",r)),!1===v.onBeforeChange.call(x,o)?(P.debug("onBeforeChange returned false, cancelling tab change",c),!1):n&&u?(d?(P.debug("Ignoring remote content on first tab load",o),C=!1,P.cache.add(l,c.html()),P.activate.all(o),v.onFirstLoad.call(c[0],o,h,p),v.onLoad.call(c[0],o,h,p)):(P.activate.navigation(o),P.fetch.content(o,l)),!1):(P.debug("Opened local tab",o),P.activate.all(o),P.cache.read(o)||(P.cache.add(o,!0),P.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?(P.error(T.missingTab,A,b,o),!1):(l=P.escape.string(l),o=(a=j("#"+l+', a[name="'+l+'"]')).closest("[data-tab]").data(y.tab),c=P.get.tabElement(o),a&&0<a.length&&o?(P.debug("Anchor link used, opening parent tab",c,a),!1===v.onBeforeChange.call(x,o)?P.debug("onBeforeChange returned false, cancelling tab change",c):(c.hasClass(m.active)||setTimeout(function(){P.scrollTo(a)},0),P.activate.all(o),P.cache.read(o)||(P.cache.add(o,!0),P.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&&(P.debug("Forcing scroll to an in-page link in a hidden tab",t,e),u.scrollTop(t))},update:{content:function(e,t,a){var n=P.get.tabElement(e),i=n[0];a=void 0!==a?a:v.evaluateScripts,"string"==typeof v.cacheType&&"dom"===v.cacheType.toLowerCase()&&"string"!=typeof t?n.empty().append(j(t).clone(!0)):a?(P.debug("Updating HTML and evaluating inline scripts",e,t),n.html(t)):(P.debug("Updating HTML",e,t),i.innerHTML=t)}},fetch:{content:function(t,a){var e,n=P.get.tabElement(t),i={dataType:"html",encodeParameters:!1,on:"now",cache:v.alwaysRefresh,headers:{"X-Remote":!0},onSuccess:function(e){"response"===v.cacheType&&P.cache.add(a,e),P.update.content(t,e),t==f?(P.debug("Content loaded",t),P.activate.tab(t)):P.debug("Content loaded in background",t),v.onFirstLoad.call(n[0],t,h,p),v.onLoad.call(n[0],t,h,p),v.loadOnce?P.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");P.cache.add(a,e)},0):P.cache.add(a,n.html())},urlData:{tab:a}},o=n.api("get request")||!1,o=o&&"pending"===o.state();a=a||t,e=P.cache.read(a),v.cache&&e?(P.activate.tab(t),P.debug("Adding cached content",a),v.loadOnce||("once"===v.evaluateScripts?P.update.content(t,e,!1):P.update.content(t,e)),v.onLoad.call(n[0],t,h,p)):o?(P.set.loading(t),P.debug("Content is already loading",a)):void 0!==j.api?(e=j.extend(!0,{},v.apiSettings,i),P.debug("Retrieving remote content",a,e),P.set.loading(t),n.api(e)):P.error(T.api)}},activate:{all:function(e){P.activate.tab(e),P.activate.navigation(e)},tab:function(e){var t=P.get.tabElement(e),a="siblings"===v.deactivate?t.siblings(i):i.not(t),n=t.hasClass(m.active);P.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=P.get.navElement(e),a="siblings"===v.deactivate?t.siblings(d):d.not(t),n=t.hasClass(m.active);P.verbose("Activating tab navigation for",t,e),n||(t.addClass(m.active),a.removeClass(m.active+" "+m.loading))}},deactivate:{all:function(){P.deactivate.navigation(),P.deactivate.tabs()},navigation:function(){d.removeClass(m.active)},tabs:function(){i.removeClass(m.active+" "+m.loading)}},is:{tab:function(e){return void 0!==e&&0<P.get.tabElement(e).length}},get:{initialPath:function(){return d.eq(0).data(y.tab)||i.eq(0).data(y.tab)},path:function(){return j.address.value()},defaultPathArray:function(e){return P.utilities.pathToArray(P.get.defaultPath(e))},defaultPath:function(e){var t=d.filter("[data-"+y.tab+'^="'+P.escape.string(e)+'/"]').eq(0).data(y.tab)||!1;if(t){if(P.debug("Found default tab",t),r<v.maxDepth)return r++,P.get.defaultPath(t);P.error(T.recursion)}else P.debug("No default tabs found for",e,i);return r=0,e},navElement:function(e){return e=e||f,d.filter("[data-"+y.tab+'="'+P.escape.string(e)+'"]')},tabElement:function(e){var t;return e=e||f,t=P.utilities.pathToArray(e),t=P.utilities.last(t),e=i.filter("[data-"+y.tab+'="'+P.escape.string(e)+'"]'),t=i.filter("[data-"+y.tab+'="'+P.escape.string(t)+'"]'),0<e.length?e:t},tab:function(){return f}},determine:{activeTab:function(){var a=null;return i.each(function(e,t){j(t).hasClass(m.active)&&(t=j(this).data(y.tab),d.filter("[data-"+y.tab+'="'+P.escape.string(t)+'"]').hasClass(m.active))&&(a=t)}),a}},utilities:{filterArray:function(e,t){return j.grep(e,function(e){return-1===j.inArray(e,t)})},last:function(e){return!!Array.isArray(e)&&e[e.length-1]},pathToArray:function(e){return"string"==typeof(e=void 0===e?f:e)?e.split("/"):[e]},arrayToPath:function(e){return!!Array.isArray(e)&&e.join("/")}},setting:function(e,t){if(P.debug("Changing setting",e,t),j.isPlainObject(e))j.extend(!0,v,e);else{if(void 0===t)return v[e];j.isPlainObject(v[e])?j.extend(!0,v[e],t):v[e]=t}},internal:function(e,t){if(j.isPlainObject(e))j.extend(!0,P,e);else{if(void 0===t)return P[e];P[e]=t}},debug:function(){!v.silent&&v.debug&&(v.performance?P.performance.log(arguments):(P.debug=Function.prototype.bind.call(console.info,console,v.name+":"),P.debug.apply(console,arguments)))},verbose:function(){!v.silent&&v.verbose&&v.debug&&(v.performance?P.performance.log(arguments):(P.verbose=Function.prototype.bind.call(console.info,console,v.name+":"),P.verbose.apply(console,arguments)))},error:function(){v.silent||(P.error=Function.prototype.bind.call(console.error,console,v.name+":"),P.error.apply(console,arguments))},performance:{log:function(e){var t,a;v.performance&&(a=(t=Date.now())-(L||t),L=t,S.push({Name:e[0],Arguments:[].slice.call(e,1)||"",Element:x,"Execution Time":a})),clearTimeout(P.performance.timer),P.performance.timer=setTimeout(P.performance.display,500)},display:function(){var e=v.name+":",a=0;L=!1,clearTimeout(P.performance.timer),j.each(S,function(e,t){a+=t["Execution Time"]}),e+=" "+a+"ms",g&&(e+=" '"+g+"'"),0<S.length&&(console.groupCollapsed(e),console.table?console.table(S):j.each(S,function(e,t){console.log(t.Name+": "+t["Execution Time"]+"ms")}),console.groupEnd()),S=[]}},invoke:function(n,e,t){var i,o,a,r=s;return e=e||O,t=t||x,"string"==typeof n&&void 0!==r&&(n=n.split(/[ .]/),i=n.length-1,j.each(n,function(e,t){var a=e!==i?t+n[e+1].charAt(0).toUpperCase()+n[e+1].slice(1):n;if(j.isPlainObject(r[a])&&e!==i)r=r[a];else{if(void 0!==r[a])return o=r[a],!1;{if(!j.isPlainObject(r[t])||e===i)return void 0!==r[t]?o=r[t]:P.error(T.method,n),!1;r=r[t]}}})),D(o)?a=o.apply(t,e):void 0!==o&&(a=o),Array.isArray(l)?l.push(a):void 0!==l?l=[l,a]:void 0!==a&&(l=a),o}};w?(void 0===s&&P.initialize(),P.invoke(E)):(void 0!==s&&s.invoke("destroy"),P.initialize())}),void 0!==l?l:this},j.tab=function(){j(U).tab.apply(this,arguments)},j.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",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); |