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