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,S=[].slice.call(arguments,1),E=!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,T=v.error,a=v.regExp,e="."+v.namespace,n="module-"+v.namespace,L=j(this),o={},A=!0,r=0,s=this,c=L.data(n),x={initialize:function(){x.debug("Initializing tab menu item",L),x.fix.callbacks(),x.determineTabs(),x.debug("Determining tabs",v.context,i),v.auto&&x.set.auto(),x.bind.events(),v.history&&!E&&(x.initializeHistory(),E=!0),v.autoTabActivation&&c===I&&null==x.determine.activeTab()&&(x.debug("No active tab detected, setting first tab active",x.get.initialPath()),x.changeTab(!0===v.autoTabActivation?x.get.initialPath():v.autoTabActivation)),x.instantiate()},instantiate:function(){x.verbose("Storing instance of module",x),c=x,L.data(n,x)},destroy:function(){x.debug("Destroying tabs",L),L.removeData(n).off(e)},bind:{events:function(){j.isWindow(s)||(x.debug("Attaching tab activation events to element",L),L.on("click"+e,x.event.click))}},determineTabs:function(){var e;"parent"===v.context?(0<L.closest(t.ui).length?(e=L.closest(t.ui),x.verbose("Using closest UI element as parent",e)):e=L,g=e.parent(),x.verbose("Determined parent element for creating context",g)):v.context?(g=j(v.context),x.verbose("Using selector for tab context",v.context,g)):g=j("body"),v.childrenOnly?(i=g.children(t.tabs),x.debug("Searching tab context children for tabs",g,i)):(i=g.find(t.tabs),x.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,x.error(T.legacyLoad,l.onLoad)),l.onTabInit&&(l.onFirstLoad=l.onTabInit,delete l.onTabInit,x.error(T.legacyInit,l.onFirstLoad)),v=j.extend(!0,{},j.fn.tab.settings,l))}},initializeHistory:function(){if(x.debug("Initializing page state"),j.address===I)return x.error(T.state),!1;if("state"==v.historyType){if(x.debug("Using HTML5 to manage state"),!1===v.path)return x.error(T.path),!1;j.address.history(!0).state(v.path)}j.address.bind("change",x.event.history.change)},event:{click:function(e){var t=j(this).data(y.tab);t!==I?(v.history?(x.verbose("Updating page state",e),j.address.value(t)):(x.verbose("Changing tab",e),x.changeTab(t)),e.preventDefault()):x.debug("No tab specified")},history:{change:function(e){var t=e.pathNames.join("/")||x.get.initialPath(),a=v.templates.determineTitle(t)||!1;x.performance.display(),x.debug("History change event",t,e),p=e,t!==I&&x.changeTab(t),a&&j.address.title(a)}}},refresh:function(){f&&(x.debug("Refreshing tab",f),x.changeTab(f))},cache:{read:function(e){return e!==I&&o[e]},add:function(e,t){e=e||f,x.debug("Adding cached content for",e),o[e]=t},remove:function(e){e=e||f,x.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}";x.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=x.get.tabElement(e);t.hasClass(m.loading)||(x.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&&A,u=v.auto||j.isPlainObject(v.apiSettings),b=u&&!d?x.utilities.pathToArray(l):x.get.defaultPathArray(l);l=x.utilities.arrayToPath(b),j.each(b,function(e,t){var a,n,i=b.slice(0,e+1),o=x.utilities.arrayToPath(i),r=x.is.tab(o),s=e+1==b.length,c=x.get.tabElement(o);return x.verbose("Looking for tab",t),r?(x.verbose("Tab was found",t),f=o,h=x.utilities.filterArray(b,i),s?n=!0:(s=b.slice(0,e+2),e=x.utilities.arrayToPath(s),(n=!x.is.tab(e))&&x.verbose("Tab parameters found",s)),n&&u?(d?(x.debug("Ignoring remote content on first tab load",o),A=!1,x.cache.add(l,c.html()),x.activate.all(o),v.onFirstLoad.call(c[0],o,h,p),v.onLoad.call(c[0],o,h,p)):(x.activate.navigation(o),x.fetch.content(o,l)),!1):(x.debug("Opened local tab",o),x.activate.all(o),x.cache.read(o)||(x.cache.add(o,!0),x.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?(x.error(T.missingTab,L,g,o),!1):(l=x.escape.string(l),o=(a=j("#"+l+', a[name="'+l+'"]')).closest("[data-tab]").data(y.tab),c=x.get.tabElement(o),a&&0<a.length&&o?(x.debug("Anchor link used, opening parent tab",c,a),c.hasClass(m.active)||setTimeout(function(){x.scrollTo(a)},0),x.activate.all(o),x.cache.read(o)||(x.cache.add(o,!0),x.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&&(x.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=x.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?(x.debug("Updating HTML and evaluating inline scripts",e,t),n.html(t)):(x.debug("Updating HTML",e,t),i.innerHTML=t)}},fetch:{content:function(t,a){var n=x.get.tabElement(t),e={dataType:"html",encodeParameters:!1,on:"now",cache:v.alwaysRefresh,headers:{"X-Remote":!0},onSuccess:function(e){"response"==v.cacheType&&x.cache.add(a,e),x.update.content(t,e),t==f?(x.debug("Content loaded",t),x.activate.tab(t)):x.debug("Content loaded in background",t),v.onFirstLoad.call(n[0],t,h,p),v.onLoad.call(n[0],t,h,p),v.loadOnce?x.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");x.cache.add(a,e)},0):x.cache.add(a,n.html())},urlData:{tab:a}},i=n.api("get request")||!1,o=i&&"pending"===i.state();a=a||t,i=x.cache.read(a),v.cache&&i?(x.activate.tab(t),x.debug("Adding cached content",a),v.loadOnce||("once"==v.evaluateScripts?x.update.content(t,i,!1):x.update.content(t,i)),v.onLoad.call(n[0],t,h,p)):o?(x.set.loading(t),x.debug("Content is already loading",a)):j.api!==I?(e=j.extend(!0,{},v.apiSettings,e),x.debug("Retrieving remote content",a,e),x.set.loading(t),n.api(e)):x.error(T.api)}},activate:{all:function(e){x.activate.tab(e),x.activate.navigation(e)},tab:function(e){var t=x.get.tabElement(e),a="siblings"==v.deactivate?t.siblings(i):i.not(t),n=t.hasClass(m.active);x.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=x.get.navElement(e),a="siblings"==v.deactivate?t.siblings(u):u.not(t),n=t.hasClass(m.active);x.verbose("Activating tab navigation for",t,e),n||(t.addClass(m.active),a.removeClass(m.active+" "+m.loading))}},deactivate:{all:function(){x.deactivate.navigation(),x.deactivate.tabs()},navigation:function(){u.removeClass(m.active)},tabs:function(){i.removeClass(m.active+" "+m.loading)}},is:{tab:function(e){return e!==I&&0<x.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 x.utilities.pathToArray(x.get.defaultPath(e))},defaultPath:function(e){var t=u.filter("[data-"+y.tab+'^="'+x.escape.string(e)+'/"]').eq(0).data(y.tab)||!1;if(t){if(x.debug("Found default tab",t),r<v.maxDepth)return r++,x.get.defaultPath(t);x.error(T.recursion)}else x.debug("No default tabs found for",e,i);return r=0,e},navElement:function(e){return e=e||f,u.filter("[data-"+y.tab+'="'+x.escape.string(e)+'"]')},tabElement:function(e){var t;return e=e||f,t=x.utilities.pathToArray(e),t=x.utilities.last(t),e=i.filter("[data-"+y.tab+'="'+x.escape.string(e)+'"]'),t=i.filter("[data-"+y.tab+'="'+x.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+'="'+x.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(x.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,x,e);else{if(t===I)return x[e];x[e]=t}},debug:function(){!v.silent&&v.debug&&(v.performance?x.performance.log(arguments):(x.debug=Function.prototype.bind.call(console.info,console,v.name+":"),x.debug.apply(console,arguments)))},verbose:function(){!v.silent&&v.verbose&&v.debug&&(v.performance?x.performance.log(arguments):(x.verbose=Function.prototype.bind.call(console.info,console,v.name+":"),x.verbose.apply(console,arguments)))},error:function(){v.silent||(x.error=Function.prototype.bind.call(console.error,console,v.name+":"),x.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(x.performance.timer),x.performance.timer=setTimeout(x.performance.display,500)},display:function(){var e=v.name+":",a=0;P=!1,clearTimeout(x.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||S,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]:x.error(T.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&&x.initialize(),x.invoke(F)):(c!==I&&c.invoke("destroy"),x.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); |