11 lines
No EOL
15 KiB
JavaScript
11 lines
No EOL
15 KiB
JavaScript
/*
|
|
* # Fomantic UI - 2.9.3
|
|
* 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,D,R){"use strict";function I(e){return"function"==typeof e&&"number"!=typeof e.nodeType}D=void 0!==D&&D.Math===Math?D:globalThis,j.fn.sidebar=function(T){var k,e=j(this),w=j(D),A=j(R),F=j("body"),E=(j("html"),j("head")),O=Date.now(),P=[],H=T,M="string"==typeof H,B=[].slice.call(arguments,1),L=function(e,i){var n;return 0<=[D,R].indexOf(e)?n=F:0===(n=j(i.document).find(e)).length&&(n=i.frameElement?L(e,i.parent):F),n};return e.each(function(){var o,r,e,s,a=j.isPlainObject(T)?j.extend(!0,{},j.fn.sidebar.settings,T):j.extend({},j.fn.sidebar.settings),i=a.selector,l=a.className,n=a.namespace,t=a.regExp,c=a.error,d="."+n,u="module-"+n,f=j(this),h=L(a.context,D),b=h[0]===F[0],g=f.children(i.sidebar),m=(h.children(i.fixed),h.children(i.pusher)),v=this,p=f.data(u),y="",S="",x=!1,C={initialize:function(){C.debug("Initializing sidebar",T),C.create.id(),a.delaySetup?requestAnimationFrame(C.setup.layout):C.setup.layout(),requestAnimationFrame(function(){C.setup.cache()}),C.instantiate()},instantiate:function(){C.verbose("Storing instance of module",C),p=C,f.data(u,C)},create:{id:function(){e=(Math.random().toString(16)+"000000000").slice(2,10),r="."+e,C.verbose("Creating unique id for element",e)}},destroy:function(){C.verbose("Destroying previous module for",f),f.off(d).removeData(u),h.off(r),w.off(r),A.off(r)},event:{clickaway:function(e){var i;a.closable&&(i=0<m.find(e.target).length||m.is(e.target),e=h.is(e.target),i&&(C.verbose("User clicked on dimmed page"),C.hide()),e&&(C.verbose("User clicked on dimmable context (scaled out page)"),C.hide()))},touch:function(e){},containScroll:function(e){v.scrollTop<=0&&(v.scrollTop=1),v.scrollTop+v.offsetHeight>=v.scrollHeight&&(v.scrollTop=v.scrollHeight-v.offsetHeight-1)},scroll:function(e){0===j(e.target).closest(i.sidebar).length&&e.preventDefault()}},bind:{clickaway:function(){C.verbose("Adding clickaway events to context",h),h.on("click"+r,C.event.clickaway).on("touchend"+r,C.event.clickaway)},scrollLock:function(){a.scrollLock&&(C.debug("Disabling page scroll"),(x=C.has.scrollbar())&&(C.save.bodyMargin(),C.set.bodyMargin()),h.addClass(l.locked)),C.verbose("Adding events to contain sidebar scroll"),A.on("touchmove"+r,C.event.touch),f.on("scroll"+d,C.event.containScroll)}},unbind:{clickaway:function(){C.verbose("Removing clickaway events from context",h),h.off(r)},scrollLock:function(){C.verbose("Removing scroll lock from page"),x&&C.restore.bodyMargin(),h.removeClass(l.locked),A.off(r),f.off("scroll"+d)}},add:{inlineCSS:function(){var e=C.cache.width||f.outerWidth(),i=C.cache.height||f.outerHeight(),n=C.is.rtl(),t=C.get.direction(),i={left:e,right:-e,top:i,bottom:-i};n&&(C.verbose("RTL detected, flipping widths"),i.left=-e,i.right=e),n="<style>","left"===t||"right"===t?(C.debug("Adding CSS rules for animation distance",e),n+=" .ui.visible."+t+".sidebar ~ .fixed, .ui.visible."+t+".sidebar ~ .pusher { transform: translate3d("+i[t]+"px, 0, 0); }"):"top"!==t&&"bottom"!==t||(n+=" .ui.visible."+t+".sidebar ~ .fixed, .ui.visible."+t+".sidebar ~ .pusher { transform: translate3d(0, "+i[t]+"px, 0); }"),C.is.ie()&&("left"===t||"right"===t?(C.debug("Adding CSS rules for animation distance",e),n+=" body.pushable > .ui.visible."+t+".sidebar ~ .pusher::after { transform: translate3d("+i[t]+"px, 0, 0); }"):"top"!==t&&"bottom"!==t||(n+=" body.pushable > .ui.visible."+t+".sidebar ~ .pusher::after { transform: translate3d(0, "+i[t]+"px, 0); }"),n+=" body.pushable > .ui.visible.left.sidebar ~ .ui.visible.right.sidebar ~ .pusher::after, body.pushable > .ui.visible.right.sidebar ~ .ui.visible.left.sidebar ~ .pusher::after { transform: translate3d(0, 0, 0); }"),o=j(n+="</style>").appendTo(E),C.debug("Adding sizing css to head",o)}},refresh:function(){C.verbose("Refreshing selector cache"),h=L(a.context,D),C.refreshSidebars(),m=h.children(i.pusher),h.children(i.fixed),C.clear.cache()},refreshSidebars:function(){C.verbose("Refreshing other sidebars"),g=h.children(i.sidebar)},repaint:function(){C.verbose("Forcing repaint event"),v.style.display="none";v.offsetHeight;v.scrollTop=v.scrollTop,v.style.display=""},setup:{cache:function(){C.cache={width:f.outerWidth(),height:f.outerHeight()}},layout:function(){0===h.children(i.pusher).length&&(C.debug("Adding wrapper element for sidebar"),C.error(c.pusher),m=j('<div class="pusher" />'),h.children().not(i.omitted).not(g).wrapAll(m),C.refresh()),0!==f.nextAll(i.pusher).length&&f.nextAll(i.pusher)[0]===m[0]||(C.debug("Moved sidebar to correct parent element"),C.error(c.movedSidebar,v),f.detach().prependTo(h),C.refresh()),C.clear.cache(),C.set.pushable(),C.set.direction()}},attachEvents:function(e,i){var n=j(e);i=I(C[i])?C[i]:C.toggle,0<n.length?(C.debug("Attaching sidebar events to element",e,i),n.on("click"+d,i)):C.error(c.notFound,e)},can:{leftBodyScrollbar:function(){return void 0===C.cache.leftBodyScrollbar&&(C.cache.leftBodyScrollbar=C.is.rtl()&&(C.is.iframe&&!C.is.firefox()||C.is.safari()||C.is.edge()||C.is.ie())),C.cache.leftBodyScrollbar}},save:{bodyMargin:function(){y=h.css((b?"margin-":"padding-")+(C.can.leftBodyScrollbar()?"left":"right"));var e=parseInt(y.replace(/[^\d.]/g,""),10),i=b?D.innerWidth-R.documentElement.clientWidth:h[0].offsetWidth-h[0].clientWidth;S=e+i}},show:function(e){if(e=I(e)?e:function(){},C.is.hidden())if(!1===a.onShow.call(v))C.verbose("Show callback returned false cancelling show");else{if(a.overlay&&(C.error(c.overlay),a.transition="overlay"),C.refresh(),C.othersActive())if(C.debug("Other sidebars currently visible"),a.exclusive){if("overlay"!==a.transition)return void C.hideOthers(C.show);C.hideOthers()}else a.transition="overlay";C.set.dimmerStyles(),C.pushPage(function(){e.call(v),a.onVisible.call(v)}),a.onChange.call(v)}else C.debug("Sidebar is already visible")},hide:function(e){e=I(e)?e:function(){},(C.is.visible()||C.is.animating())&&!1!==a.onHide.call(v)&&(C.debug("Hiding sidebar",e),C.refreshSidebars(),C.pullPage(function(){e.call(v),a.onHidden.call(v)}),a.onChange.call(v))},othersAnimating:function(){return 0<g.not(f).filter("."+l.animating).length},othersVisible:function(){return 0<g.not(f).filter("."+l.visible).length},othersActive:function(){return C.othersVisible()||C.othersAnimating()},hideOthers:function(e){var i=g.not(f).filter("."+l.visible),n=i.length,t=0;e=e||function(){},i.sidebar("hide",function(){++t===n&&e()})},toggle:function(){C.verbose("Determining toggled direction"),C.is.hidden()?C.show():C.hide()},pushPage:function(i){var e,n,t=C.get.transition(),o="overlay"===t||C.othersActive()?f:m;i=I(i)?i:function(){},a.returnScroll&&(s=(b?w:h).scrollTop()),"scale down"===a.transition&&C.scrollToTop(),C.bind.scrollLock(),C.set.transition(t),C.repaint(),t=function(){C.bind.clickaway(),C.add.inlineCSS(),C.set.animating(),C.set.visible()},e=function(){C.set.dimmed()},n=function(e){e.target===o[0]&&(o.off("transitionend"+r,n),C.remove.animating(),i.call(v))},o.off("transitionend"+r),o.on("transitionend"+r,n),requestAnimationFrame(t),a.dimPage&&!C.othersVisible()&&requestAnimationFrame(e)},pullPage:function(i){var e,n,t=C.get.transition(),o="overlay"===t||C.othersActive()?f:m;i=I(i)?i:function(){},C.verbose("Removing context push state",C.get.direction()),C.unbind.clickaway(),C.unbind.scrollLock(),e=function(){C.set.transition(t),C.set.animating(),a.dimPage&&!C.othersVisible()&&C.set.closing(),C.remove.visible()},n=function(e){e.target===o[0]&&(o.off("transitionend"+r,n),C.remove.animating(),C.remove.closing(),C.remove.transition(),C.remove.inlineCSS(),"scale down"!==t&&!a.returnScroll||C.scrollBack(),a.dimPage&&!C.othersVisible()&&m.removeClass(l.dimmed),i.call(v))},o.off("transitionend"+r),o.on("transitionend"+r,n),requestAnimationFrame(e)},scrollToTop:function(){C.verbose("Scrolling to top of page to avoid animation issues"),f.scrollTop(0),(b?w:h)[0].scrollTo(0,0)},scrollBack:function(){C.verbose("Scrolling back to original page position"),(b?w:h)[0].scrollTo(0,s)},clear:{cache:function(){C.verbose("Clearing cached dimensions"),C.cache={}}},set:{bodyMargin:function(){var n=C.can.leftBodyScrollbar()?"left":"right";h.css((b?"margin-":"padding-")+n,S+"px"),h.find(i.bodyFixed.replace("right",n)).each(function(){var e=j(this),i="fixed"===e.css("position")?"padding-"+n:n;e.css(i,"calc("+e.css(i)+" + "+S+"px)")})},dimmerStyles:function(){a.blurring?m.addClass(l.blurring):m.removeClass(l.blurring)},pushed:function(){h.addClass(l.pushed)},pushable:function(){h.addClass(l.pushable)},dimmed:function(){m.addClass(l.dimmed)},active:function(){f.addClass(l.active)},animating:function(){f.addClass(l.animating)},closing:function(){m.addClass(l.closing)},transition:function(e){e=e||C.get.transition(),f.addClass(e)},direction:function(e){e=e||C.get.direction(),f.addClass(l[e])},visible:function(){f.addClass(l.visible)},overlay:function(){f.addClass(l.overlay)}},remove:{inlineCSS:function(){C.debug("Removing inline css styles",o),o&&0<o.length&&o.remove()},pushed:function(){h.removeClass(l.pushed)},pushable:function(){h.removeClass(l.pushable)},active:function(){f.removeClass(l.active)},animating:function(){f.removeClass(l.animating)},closing:function(){m.removeClass(l.closing)},transition:function(e){e=e||C.get.transition(),f.removeClass(e)},direction:function(e){e=e||C.get.direction(),f.removeClass(l[e])},visible:function(){f.removeClass(l.visible)},overlay:function(){f.removeClass(l.overlay)}},restore:{bodyMargin:function(){var n=C.can.leftBodyScrollbar()?"left":"right";h.css((b?"margin-":"padding-")+n,y),h.find(i.bodyFixed.replace("right",n)).each(function(){var e=j(this),i="fixed"===e.css("position")?"padding-"+n:n;e.css(i,"")})}},get:{direction:function(){return f.hasClass(l.top)?l.top:f.hasClass(l.right)?l.right:f.hasClass(l.bottom)?l.bottom:l.left},transition:function(){var e=C.get.direction(),e=C.is.mobile()?"auto"===a.mobileTransition?a.defaultTransition.mobile[e]:a.mobileTransition:"auto"===a.transition?a.defaultTransition.computer[e]:a.transition;return C.verbose("Determined transition",e),e}},has:{scrollbar:function(){return b||"hidden"!==h.css("overflow-y")}},is:{safari:function(){return void 0===C.cache.isSafari&&(C.cache.isSafari=/constructor/i.test(D.HTMLElement)||!!D.ApplePaySession),C.cache.isSafari},edge:function(){return void 0===C.cache.isEdge&&(C.cache.isEdge=!!D.setImmediate&&!C.is.ie()),C.cache.isEdge},firefox:function(){return void 0===C.cache.isFirefox&&(C.cache.isFirefox=!!D.InstallTrigger),C.cache.isFirefox},iframe:function(){return!(self===top)},ie:function(){var e,i;return void 0===C.cache.isIE&&(e=!D.ActiveXObject&&"ActiveXObject"in D,i="ActiveXObject"in D,C.cache.isIE=e||i),C.cache.isIE},mobile:function(){var e=navigator.userAgent;return e.match(t.mobile)?(C.verbose("Browser was found to be mobile",e),!0):(C.verbose("Browser is not mobile, using regular transition",e),!1)},hidden:function(){return!C.is.visible()},visible:function(){return f.hasClass(l.visible)},open:function(){return C.is.visible()},closed:function(){return C.is.hidden()},vertical:function(){return f.hasClass(l.top)},animating:function(){return h.hasClass(l.animating)},rtl:function(){return void 0===C.cache.isRTL&&(C.cache.isRTL="rtl"===f.attr("dir")||"rtl"===f.css("direction")||"rtl"===F.attr("dir")||"rtl"===F.css("direction")||"rtl"===h.attr("dir")||"rtl"===h.css("direction")),C.cache.isRTL}},setting:function(e,i){if(C.debug("Changing setting",e,i),j.isPlainObject(e))j.extend(!0,a,e);else{if(void 0===i)return a[e];j.isPlainObject(a[e])?j.extend(!0,a[e],i):a[e]=i}},internal:function(e,i){if(j.isPlainObject(e))j.extend(!0,C,e);else{if(void 0===i)return C[e];C[e]=i}},debug:function(){!a.silent&&a.debug&&(a.performance?C.performance.log(arguments):(C.debug=Function.prototype.bind.call(console.info,console,a.name+":"),C.debug.apply(console,arguments)))},verbose:function(){!a.silent&&a.verbose&&a.debug&&(a.performance?C.performance.log(arguments):(C.verbose=Function.prototype.bind.call(console.info,console,a.name+":"),C.verbose.apply(console,arguments)))},error:function(){a.silent||(C.error=Function.prototype.bind.call(console.error,console,a.name+":"),C.error.apply(console,arguments))},performance:{log:function(e){var i,n;a.performance&&(n=(i=Date.now())-(O||i),O=i,P.push({Name:e[0],Arguments:[].slice.call(e,1)||"",Element:v,"Execution Time":n})),clearTimeout(C.performance.timer),C.performance.timer=setTimeout(function(){C.performance.display()},500)},display:function(){var e=a.name+":",n=0;O=!1,clearTimeout(C.performance.timer),j.each(P,function(e,i){n+=i["Execution Time"]}),e+=" "+n+"ms",0<P.length&&(console.groupCollapsed(e),console.table?console.table(P):j.each(P,function(e,i){console.log(i.Name+": "+i["Execution Time"]+"ms")}),console.groupEnd()),P=[]}},invoke:function(t,e,i){var o,r,n,s=p;return e=e||B,i=i||v,"string"==typeof t&&void 0!==s&&(t=t.split(/[ .]/),o=t.length-1,j.each(t,function(e,i){var n=e!==o?i+t[e+1].charAt(0).toUpperCase()+t[e+1].slice(1):t;if(j.isPlainObject(s[n])&&e!==o)s=s[n];else{if(void 0!==s[n])return r=s[n],!1;{if(!j.isPlainObject(s[i])||e===o)return void 0!==s[i]?r=s[i]:C.error(c.method,t),!1;s=s[i]}}})),I(r)?n=r.apply(i,e):void 0!==r&&(n=r),Array.isArray(k)?k.push(n):void 0!==k?k=[k,n]:void 0!==n&&(k=n),r}};M?(void 0===p&&C.initialize(),C.invoke(H)):(void 0!==p&&C.invoke("destroy"),C.initialize())}),void 0!==k?k:this},j.fn.sidebar.settings={name:"Sidebar",namespace:"sidebar",silent:!1,debug:!1,verbose:!1,performance:!0,transition:"auto",mobileTransition:"auto",defaultTransition:{computer:{left:"uncover",right:"uncover",top:"overlay",bottom:"overlay"},mobile:{left:"uncover",right:"uncover",top:"overlay",bottom:"overlay"}},context:"body",exclusive:!1,closable:!0,dimPage:!0,scrollLock:!1,returnScroll:!1,delaySetup:!1,onChange:function(){},onShow:function(){},onHide:function(){},onHidden:function(){},onVisible:function(){},className:{active:"active",animating:"animating",blurring:"blurring",closing:"closing",dimmed:"dimmed",locked:"locked",pushable:"pushable",pushed:"pushed",right:"right",top:"top",left:"left",bottom:"bottom",visible:"visible"},selector:{bodyFixed:"> .ui.fixed.menu, > .ui.right.toast-container, > .ui.right.sidebar, > .ui.fixed.nag, > .ui.fixed.nag > .close",fixed:".fixed",omitted:"script, link, style, .ui.modal, .ui.dimmer, .ui.nag, .ui.fixed",pusher:".pusher",sidebar:".ui.sidebar"},regExp:{mobile:/Mobile|iP(hone|od|ad)|Android|BlackBerry|IEMobile|Kindle|NetFront|Silk-Accelerated|(hpw|web)OS|Fennec|Minimo|Opera M(obi|ini)|Blazer|Dolfin|Dolphin|Skyfire|Zune/g},error:{method:"The method you called is not defined.",pusher:"Had to add pusher element. For optimal performance make sure body content is inside a pusher element",movedSidebar:"Had to move sidebar. For optimal performance make sure sidebar and pusher are direct children of your body tag",overlay:"The overlay setting is no longer supported, use animation: overlay",notFound:"There were no elements that matched the specified selector"}}}(jQuery,window,document); |