wishthis/semantic/dist/components/popup.min.js
2022-02-23 22:46:34 +01:00

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