wishthis/node_modules/fomantic-ui/dist/components/popup.min.js
2023-08-17 11:47:40 +02:00

11 lines
No EOL
19 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(V,W,M){"use strict";function z(t){return"function"==typeof t&&"number"!=typeof t.nodeType}W=void 0!==W&&W.Math===Math?W:globalThis,V.fn.popup=function(T){var E,t=V(this),k=V(M),S=V(W),O=V("body"),A=t.selector||"",D="ontouchstart"in M.documentElement?"touchstart":"click",j=Date.now(),F=[],R=T,H="string"==typeof R,N=[].slice.call(arguments,1);return t.each(function(){var p,s,t,e,o,u=V.isPlainObject(T)?V.extend(!0,{},V.fn.popup.settings,T):V.extend({},V.fn.popup.settings),n=u.selector,c=u.className,d=u.error,f=u.metadata,i=u.namespace,r="."+u.namespace,a="module-"+i,h=V(this),l=[W,M].indexOf(u.context)<0?k.find(u.context):V(u.context),g=[W,M].indexOf(u.scrollContext)<0?k.find(u.scrollContext):V(u.scrollContext),v=[W,M].indexOf(u.boundary)<0?k.find(u.boundary):V(u.boundary),m=u.target?[W,M].indexOf(u.target)<0?k.find(u.target):V(u.target):h,b=0,w=!1,y=!1,P=this,C=h.data(a),x={initialize:function(){x.debug("Initializing",h),x.createID(),x.bind.events(),!x.exists()&&u.preserve&&x.create(),u.observeChanges&&x.observeChanges(),x.instantiate()},instantiate:function(){x.verbose("Storing instance",x),C=x,h.data(a,C)},observeChanges:function(){"MutationObserver"in W&&((t=new MutationObserver(x.event.documentChanged)).observe(M,{childList:!0,subtree:!0}),x.debug("Setting up mutation observer",t))},refresh:function(){u.popup?p=k.find(u.popup).eq(0):u.inline&&(p=m.nextAll(n.popup).eq(0),u.popup=p),u.popup?(x.set.invisible(),s=x.get.offsetParent(),x.remove.invisible(),u.movePopup&&x.has.popup()&&x.get.offsetParent(p)[0]!==s[0]&&(x.debug("Moving popup to the same offset parent as target"),p.detach().appendTo(s))):s=u.inline?x.get.offsetParent(m):x.has.popup()?x.get.offsetParent(p):O,s.is("html")&&s[0]!==O[0]&&(x.debug("Setting page as offset parent"),s=O),x.get.variation()&&x.set.variation()},reposition:function(){x.refresh(),x.set.position()},destroy:function(){x.debug("Destroying previous module"),t&&t.disconnect(),p&&!u.preserve&&x.removePopup(),clearTimeout(x.hideTimer),clearTimeout(x.showTimer),x.unbind.close(),x.unbind.events(),h.removeData(a)},event:{start:function(t){var e=V.isPlainObject(u.delay)?u.delay.show:u.delay;clearTimeout(x.hideTimer),y&&!u.addTouchEvents||(x.showTimer=setTimeout(x.show,e))},end:function(){var t=V.isPlainObject(u.delay)?u.delay.hide:u.delay;clearTimeout(x.showTimer),x.hideTimer=setTimeout(x.hide,t)},touchstart:function(t){y=!0,u.addTouchEvents&&x.show()},resize:function(){x.is.visible()&&x.set.position()},documentChanged:function(t){[].forEach.call(t,function(t){t.removedNodes&&[].forEach.call(t.removedNodes,function(t){(t===P||0<V(t).find(P).length)&&(x.debug("Element removed from DOM, tearing down events"),x.destroy())})})},hideGracefully:function(t){var e=V(t.target),o=V.contains(M.documentElement,t.target),e=0<e.closest(n.popup).length;t&&!e&&o?(x.debug("Click occurred outside popup hiding popup"),x.hide()):x.debug("Click was inside popup, keeping popup open")}},create:function(){var t=x.get.html(),e=x.get.title(),o=x.get.content();t||o||e?(x.debug("Creating pop-up html"),t=t||u.templates.popup({title:e,content:o}),p=V("<div/>").addClass(c.popup).data(f.activator,h).html(t),u.inline?(x.verbose("Inserting popup element inline",p),p.insertAfter(h)):(x.verbose("Appending popup element to body",p),p.appendTo(l)),x.refresh(),x.set.variation(),u.hoverable&&x.bind.popup(),u.onCreate.call(p,P)):u.popup?(k.find(u.popup).data(f.activator,h),x.verbose("Used popup specified in settings"),x.refresh(),u.hoverable&&x.bind.popup()):0<m.next(n.popup).length?(x.verbose("Pre-existing popup found"),u.inline=!0,u.popup=m.next(n.popup).data(f.activator,h),x.refresh(),u.hoverable&&x.bind.popup()):x.debug("No content specified skipping display",P)},createID:function(){o=(Math.random().toString(16)+"000000000").slice(2,10),e="."+o,x.verbose("Creating unique id for element",o)},toggle:function(){x.debug("Toggling pop-up"),x.is.hidden()?(x.debug("Popup is hidden, showing pop-up"),x.unbind.close(),x.show()):(x.debug("Popup is visible, hiding pop-up"),x.hide())},show:function(t){t=t||function(){},x.debug("Showing pop-up",u.transition),!x.is.hidden()||x.is.active()&&x.is.dropdown()||(x.exists()||x.create(),!1===u.onShow.call(p,P)?x.debug("onShow callback returned false, cancelling popup animation"):(u.preserve||u.popup||x.refresh(),p&&x.set.position()&&(x.save.conditions(),u.exclusive&&x.hideAll(),x.animate.show(t))))},hide:function(t){t=t||function(){},(x.is.visible()||x.is.animating())&&(!1===u.onHide.call(p,P)?x.debug("onHide callback returned false, cancelling popup animation"):(x.remove.visible(),x.unbind.close(),x.restore.conditions(),x.animate.hide(t)))},hideAll:function(){k.find(n.popup).filter("."+c.popupVisible).each(function(){V(this).data(f.activator).popup("hide")})},exists:function(){return!!p&&(u.inline||u.popup?x.has.popup():0<p.closest(l).length)},removePopup:function(){x.has.popup()&&!u.popup&&(x.debug("Removing popup",p),p.remove(),p=void 0,u.onRemove.call(p,P))},save:{conditions:function(){x.cache={title:h.attr("title")},x.cache.title&&h.removeAttr("title"),x.verbose("Saving original attributes",x.cache.title)}},restore:{conditions:function(){return x.cache&&x.cache.title&&(h.attr("title",x.cache.title),x.verbose("Restoring original attributes",x.cache.title)),!0}},supports:{svg:function(){return"undefined"!=typeof SVGGraphicsElement}},animate:{show:function(t){t=z(t)?t:function(){},u.transition&&x.can.useElement("transition")&&(x.set.visible(),p.transition({animation:(u.transition.showMethod||u.transition)+" in",queue:!1,debug:u.debug,verbose:u.verbose,silent:u.silent,duration:u.transition.showDuration||u.duration,onComplete:function(){x.bind.close(),t.call(p,P),u.onVisible.call(p,P)}}))},hide:function(t){t=z(t)?t:function(){},x.debug("Hiding pop-up"),u.transition&&void 0!==V.fn.transition?p.transition({animation:(u.transition.hideMethod||u.transition)+" out",queue:!1,duration:u.transition.hideDuration||u.duration,debug:u.debug,verbose:u.verbose,silent:u.silent,onComplete:function(){x.reset(),t.call(p,P),u.onHidden.call(p,P)}}):x.error(d.noTransition)}},change:{content:function(t){p.html(t)}},get:{html:function(){return h.removeData(f.html),h.data(f.html)||u.html},title:function(){return h.removeData(f.title),h.data(f.title)||u.title},content:function(){return h.removeData(f.content),h.data(f.content)||u.content||h.attr("title")},variation:function(){return h.removeData(f.variation),h.data(f.variation)||u.variation},popup:function(){return p},popupOffset:function(){return p.offset()},calculations:function(){var t=x.get.offsetParent(p),e=m[0],o=v[0]===W,n=m.offset(),i=u.inline||u.popup&&u.movePopup?m.offsetParent().offset():{top:0,left:0},r=o?{top:0,left:0}:v.offset(),a={},o=o?{top:S.scrollTop(),left:S.scrollLeft()}:{top:0,left:0},a={target:{element:m[0],width:m.outerWidth(),height:m.outerHeight(),top:n.top-i.top,left:n.left-i.left,margin:{}},popup:{width:p.outerWidth(),height:p.outerHeight()},parent:{width:s.outerWidth(),height:s.outerHeight()},screen:{top:r.top,left:r.left,scroll:{top:o.top,left:o.left},width:v.width(),height:v.height()}};return t[0]!==s[0]&&(n=t.offset(),a.target.top-=n.top,a.target.left-=n.left,a.parent.width=t.outerWidth(),a.parent.height=t.outerHeight()),u.setFluidWidth&&x.is.fluid()&&(a.container={width:p.parent().outerWidth()},a.popup.width=a.container.width),a.target.margin.top=u.inline?parseInt(W.getComputedStyle(e).getPropertyValue("margin-top"),10):0,a.target.margin.left=u.inline?x.is.rtl()?parseInt(W.getComputedStyle(e).getPropertyValue("margin-right"),10):parseInt(W.getComputedStyle(e).getPropertyValue("margin-left"),10):0,i=a.screen,a.boundary={top:i.top+i.scroll.top,bottom:i.top+i.scroll.top+i.height,left:i.left+i.scroll.left,right:i.left+i.scroll.left+i.width},a},id:function(){return o},startEvent:function(){return"hover"===u.on?"mouseenter":"focus"===u.on&&"focus"},scrollEvent:function(){return"scroll"},endEvent:function(){return"hover"===u.on?"mouseleave":"focus"===u.on&&"blur"},distanceFromBoundary:function(t,e){var o={},n=(e=e||x.get.calculations()).popup,e=e.boundary;return t&&(o={top:t.top-e.top,left:t.left-e.left,right:e.right-(t.left+n.width),bottom:e.bottom-(t.top+n.height)},x.verbose("Distance from boundaries determined",t,o)),o},offsetParent:function(t){var e=(void 0!==t?t:m)[0].parentNode,o=V(e);if(e)for(var n="none"===o.css("transform"),i="static"===o.css("position"),r=o.is("body");e&&!r&&i&&n;)e=e.parentNode,n="none"===(o=V(e)).css("transform"),i="static"===o.css("position"),r=o.is("body");return o&&0<o.length?o:V()},positions:function(){return{"top left":!1,"top center":!1,"top right":!1,"bottom left":!1,"bottom center":!1,"bottom right":!1,"left center":!1,"right center":!1}},nextPosition:function(t){var e=t.split(" "),o=e[0],e=e[1],n="top"===o||"bottom"===o,i=!1,r=!1,a=!1;return w||(x.verbose("All available positions available"),w=x.get.positions()),x.debug("Recording last position tried",t),w[t]=!0,"opposite"===u.prefer&&(a=(a=[{top:"bottom",bottom:"top",left:"right",right:"left"}[o],e]).join(" "),i=!0===w[a],x.debug("Trying opposite strategy",a)),"adjacent"===u.prefer&&n&&(a=(a=[o,{left:"center",center:"right",right:"left"}[e]]).join(" "),r=!0===w[a],x.debug("Trying adjacent strategy",a)),(r||i)&&(x.debug("Using backup position",a),a={"top left":"top center","top center":"top right","top right":"right center","right center":"bottom right","bottom right":"bottom center","bottom center":"bottom left","bottom left":"left center","left center":"top left"}[t]),a}},set:{position:function(t,e){if(0!==m.length&&0!==p.length){var o,n,i,r,a,s,l;if(e=e||x.get.calculations(),t=t||h.data(f.position)||u.position,o=h.data(f.offset)||u.offset,n=u.distanceAway,i=e.target,r=e.popup,a=e.parent,x.should.centerArrow(e)&&(x.verbose("Adjusting offset to center arrow on small target element"),"top left"!==t&&"bottom left"!==t||(o=(o+=i.width/2)-u.arrowPixelsFromEdge),"top right"!==t&&"bottom right"!==t||(o=(o-=i.width/2)+u.arrowPixelsFromEdge)),0===i.width&&0===i.height&&!x.is.svg(i.element))return x.debug("Popup target is hidden, no action taken"),!1;switch(u.inline&&(x.debug("Adding margin to calculation",i.margin),"left center"===t||"right center"===t?(o+=i.margin.top,n+=-i.margin.left):"top left"===t||"top center"===t||"top right"===t?(o+=i.margin.left,n-=i.margin.top):(o+=i.margin.left,n+=i.margin.top)),x.debug("Determining popup position from calculations",t,e),x.is.rtl()&&(t=t.replace(/left|right/g,function(t){return"left"===t?"right":"left"}),x.debug("RTL: Popup position updated",t)),t=b===u.maxSearchDepth&&"string"==typeof u.lastResort?u.lastResort:t){case"top left":s={top:"auto",bottom:a.height-i.top+n,left:i.left+o,right:"auto"};break;case"top center":s={bottom:a.height-i.top+n,left:i.left+i.width/2-r.width/2+o,top:"auto",right:"auto"};break;case"top right":s={bottom:a.height-i.top+n,right:a.width-i.left-i.width-o,top:"auto",left:"auto"};break;case"left center":s={top:i.top+i.height/2-r.height/2+o,right:a.width-i.left+n,left:"auto",bottom:"auto"};break;case"right center":s={top:i.top+i.height/2-r.height/2+o,left:i.left+i.width+n,bottom:"auto",right:"auto"};break;case"bottom left":s={top:i.top+i.height+n,left:i.left+o,bottom:"auto",right:"auto"};break;case"bottom center":s={top:i.top+i.height+n,left:i.left+i.width/2-r.width/2+o,bottom:"auto",right:"auto"};break;case"bottom right":s={top:i.top+i.height+n,right:a.width-i.left-i.width-o,left:"auto",bottom:"auto"}}if(void 0===s&&x.error(d.invalidPosition,t),x.debug("Calculated popup positioning values",s),p.css(s).removeClass(c.position).addClass(t),x.set.invisible(),l=x.get.popupOffset(),l=x.get.distanceFromBoundary(l,e),!u.forcePosition&&x.is.offstage(l,t)){if(x.debug("Position is outside viewport",t),b<u.maxSearchDepth)return b++,t=x.get.nextPosition(t),x.debug("Trying new position",t),!!p&&x.set.position(t,e);if(!u.lastResort)return x.debug("Popup could not find a position to display",p),x.error(d.cannotPlace,P),x.remove.attempts(),x.remove.invisible(),x.reset(),u.onUnplaceable.call(p,P),!1;x.debug("No position found, showing with last position")}return x.debug("Position is on stage",t),x.remove.attempts(),x.remove.invisible(),u.setFluidWidth&&x.is.fluid()&&x.set.fluidWidth(e),!0}x.error(d.notFound)},fluidWidth:function(t){t=t||x.get.calculations(),x.debug("Automatically setting element width to parent width",t.parent.width),p.css("width",t.container.width)},loading:function(){p.addClass(c.loading)},invisible:function(){p.addClass(c.invisible)},variation:function(t){(t=t||x.get.variation())&&x.has.popup()&&(x.verbose("Adding variation to popup",t),p.addClass(t))},visible:function(){h.addClass(c.visible)}},remove:{loading:function(){p.removeClass(c.loading)},invisible:function(){p.removeClass(c.invisible)},variation:function(t){(t=t||x.get.variation())&&(x.verbose("Removing variation",t),p.removeClass(t))},visible:function(){h.removeClass(c.visible)},attempts:function(){x.verbose("Resetting all searched positions"),b=0,w=!1}},bind:{events:function(){x.debug("Binding popup events to module"),"click"===u.on&&h.on(D+r,x.toggle),"hover"===u.on&&h.on("touchstart"+r,x.event.touchstart),x.get.startEvent()&&h.on(x.get.startEvent()+r,x.event.start).on(x.get.endEvent()+r,x.event.end),u.target&&x.debug("Target set to element",m),S.on("resize"+e,x.event.resize)},popup:function(){x.verbose("Allowing hover events on popup to prevent closing"),p&&x.has.popup()&&p.on("mouseenter"+r,x.event.start).on("mouseleave"+r,x.event.end)},close:function(){(!0===u.hideOnScroll||"auto"===u.hideOnScroll&&"click"!==u.on)&&x.bind.closeOnScroll(),x.is.closable()?x.bind.clickaway():"hover"===u.on&&y&&x.bind.touchClose()},closeOnScroll:function(){x.verbose("Binding scroll close event to document"),g.one(x.get.scrollEvent()+e,x.event.hideGracefully)},touchClose:function(){x.verbose("Binding popup touchclose event to document"),k.on("touchstart"+e,function(t){x.verbose("Touched away from popup"),x.event.hideGracefully.call(P,t)})},clickaway:function(){x.verbose("Binding popup close event to document"),k.on(D+e,function(t){x.verbose("Clicked away from popup"),x.event.hideGracefully.call(P,t)})}},unbind:{events:function(){S.off(e),h.off(r)},close:function(){k.off(e),g.off(e)}},can:{useElement:function(t){return void 0!==V.fn[t]||(x.error(d.noElement.replace("{element}",t)),!1)}},has:{popup:function(){return p&&0<p.length}},should:{centerArrow:function(t){return!x.is.basic()&&t.target.width<=2*u.arrowPixelsFromEdge}},is:{closable:function(){return"auto"===u.closable?"hover"!==u.on:u.closable},offstage:function(t,o){var n=[];return V.each(t,function(t,e){e<-u.jitter&&(x.debug("Position exceeds allowable distance from edge",t,e,o),n.push(t))}),0<n.length},svg:function(t){return x.supports.svg()&&t instanceof SVGGraphicsElement},basic:function(){return h.hasClass(c.basic)},active:function(){return h.hasClass(c.active)},animating:function(){return void 0!==p&&p.hasClass(c.animating)},fluid:function(){return void 0!==p&&p.hasClass(c.fluid)},visible:function(){return void 0!==p&&p.hasClass(c.popupVisible)},dropdown:function(){return h.hasClass(c.dropdown)},hidden:function(){return!x.is.visible()},rtl:function(){return"rtl"===h.attr("dir")||"rtl"===h.css("direction")||"rtl"===O.attr("dir")||"rtl"===O.css("direction")||"rtl"===l.attr("dir")||"rtl"===l.css("direction")}},reset:function(){x.remove.visible(),u.preserve?void 0!==V.fn.transition&&p.transition("remove transition"):x.removePopup()},setting:function(t,e){if(V.isPlainObject(t))V.extend(!0,u,t);else{if(void 0===e)return u[t];u[t]=e}},internal:function(t,e){if(V.isPlainObject(t))V.extend(!0,x,t);else{if(void 0===e)return x[t];x[t]=e}},debug:function(){!u.silent&&u.debug&&(u.performance?x.performance.log(arguments):(x.debug=Function.prototype.bind.call(console.info,console,u.name+":"),x.debug.apply(console,arguments)))},verbose:function(){!u.silent&&u.verbose&&u.debug&&(u.performance?x.performance.log(arguments):(x.verbose=Function.prototype.bind.call(console.info,console,u.name+":"),x.verbose.apply(console,arguments)))},error:function(){u.silent||(x.error=Function.prototype.bind.call(console.error,console,u.name+":"),x.error.apply(console,arguments))},performance:{log:function(t){var e,o;u.performance&&(o=(e=Date.now())-(j||e),j=e,F.push({Name:t[0],Arguments:[].slice.call(t,1)||"",Element:P,"Execution Time":o})),clearTimeout(x.performance.timer),x.performance.timer=setTimeout(x.performance.display,500)},display:function(){var t=u.name+":",o=0;j=!1,clearTimeout(x.performance.timer),V.each(F,function(t,e){o+=e["Execution Time"]}),t+=" "+o+"ms",A&&(t+=" '"+A+"'"),0<F.length&&(console.groupCollapsed(t),console.table?console.table(F):V.each(F,function(t,e){console.log(e.Name+": "+e["Execution Time"]+"ms")}),console.groupEnd()),F=[]}},invoke:function(n,t,e){var i,r,o,a=C;return t=t||N,e=e||P,"string"==typeof n&&void 0!==a&&(n=n.split(/[ .]/),i=n.length-1,V.each(n,function(t,e){var o=t!==i?e+n[t+1].charAt(0).toUpperCase()+n[t+1].slice(1):n;if(V.isPlainObject(a[o])&&t!==i)a=a[o];else{if(void 0!==a[o])return r=a[o],!1;{if(!V.isPlainObject(a[e])||t===i)return void 0!==a[e]?r=a[e]:x.error(d.method,n),!1;a=a[e]}}})),z(r)?o=r.apply(e,t):void 0!==r&&(o=r),Array.isArray(E)?E.push(o):void 0!==E?E=[E,o]:void 0!==o&&(E=o),r}};H?(void 0===C&&x.initialize(),x.invoke(R)):(void 0!==C&&C.invoke("destroy"),x.initialize())}),void 0!==E?E:this},V.fn.popup.settings={name:"Popup",silent:!1,debug:!1,verbose:!1,performance:!0,namespace:"popup",observeChanges:!0,onCreate:function(){},onRemove:function(){},onShow:function(){},onVisible:function(){},onHide:function(){},onUnplaceable:function(){},onHidden:function(){},on:"hover",boundary:W,addTouchEvents:!0,position:"top left",forcePosition:!1,variation:"",movePopup:!0,target:!1,popup:!1,inline:!1,preserve:!1,hoverable:!1,content:!1,html:!1,title:!1,closable:!0,hideOnScroll:"auto",exclusive:!1,context:"body",scrollContext:W,prefer:"opposite",lastResort:!1,arrowPixelsFromEdge:20,delay:{show:50,hide:70},setFluidWidth:!0,duration:200,transition:"scale",distanceAway:0,jitter:2,offset:0,maxSearchDepth:15,error:{invalidPosition:"The position you specified is not a valid position",cannotPlace:"Popup does not fit within the boundaries of the viewport",method:"The method you called is not defined.",noElement:"This module requires ui {element}",notFound:"The target or popup you specified does not exist on the page"},metadata:{activator:"activator",content:"content",html:"html",offset:"offset",position:"position",title:"title",variation:"variation"},className:{active:"active",basic:"basic",animating:"animating",dropdown:"dropdown",invisible:"invisible",fluid:"fluid",loading:"loading",popup:"ui popup",position:"top left center bottom right",visible:"visible",popupVisible:"visible"},selector:{popup:".ui.popup"},templates:{escape:function(t){var e={"<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#x27;","`":"&#x60;"};return/["&'<>`]/.test(t)?(t=t.replace(/&(?![\d#a-z]{1,12};)/gi,"&amp;")).replace(/["'<>`]/g,function(t){return e[t]}):t},popup:function(t){var e="",o=V.fn.popup.settings.templates.escape;return void 0!==t&&(t.title&&(t.title=o(t.title),e+='<div class="header">'+t.title+"</div>"),t.content&&(t.content=o(t.content),e+='<div class="content">'+t.content+"</div>")),e}}}}(jQuery,window,document);