"use strict";Object.defineProperty(exports,"__esModule",{value:true});var _utils=require("$:/plugins/felixhayashi/tiddlymap/js/utils");var _utils2=_interopRequireDefault(_utils);function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}function Popup(e,t){t=t||{};this._parentDomNode=e;this._domNode=document.createElement("div");this._domNode.style.display="none";this._domNode.className="tmap-popup";this._parentDomNode.appendChild(this._domNode);$tw.utils.addClass(this._domNode,t.className);this._isEnabled=true;this._isPreventShowOrHide=false;this._isHideOnClick=!!t.hideOnClick;this._timeoutShow=null;this._timeoutHide=null;this._isDisplayNoneAfterAnimation=true;var i=parseInt(t.leavingDelay);this._hideDelayLeavingPopup=_utils2.default.isInteger(i)?i:200;i=parseInt(t.hideDelay);this._hideDelay=_utils2.default.isInteger(i)?i:200;i=parseInt(t.showDelay);this._showDelay=_utils2.default.isInteger(i)?i:200;_utils2.default.bindTo(this,["_show","_hide","_handleEnter","_handleLeave","_handleAnimationEnd","_handleClick"]);this._listeners={mouseenter:this._handleEnter,mouseleave:this._handleLeave,click:[this._handleClick,true]};var s=this._handleAnimationEnd;this._listeners[$tw.utils.convertEventName("animationEnd")]=s;this._listeners[$tw.utils.convertEventName("transitionEnd")]=s;_utils2.default.setDomListeners("add",this._domNode,this._listeners,false)}
/* @preserve TW-Guard */
/*\

title: $:/plugins/felixhayashi/tiddlymap/js/Popup
type: application/javascript
module-type: library

@preserve

\*/
/* @preserve TW-Guard */Popup.prototype._handleEnter=function(e){this._isPreventShowOrHide=true};Popup.prototype._handleLeave=function(e){this._isPreventShowOrHide=false;this.hide(this._hideDelayLeavingPopup)};Popup.prototype._handleClick=function(e){if(this._isHideOnClick){this._hide(true)}};Popup.prototype._handleAnimationEnd=function(){if(this._isDisplayNoneAfterAnimation){this._domNode.style.display="none"}};Popup.prototype._hide=function(e){if(!e&&this._isPreventShowOrHide)return;this._isDisplayNoneAfterAnimation=true;this._isPreventShowOrHide=false;$tw.utils.removeClass(this._domNode,"tmap-popup-active")};Popup.prototype._show=function(e,t){if(this._isPreventShowOrHide||$tm.mouse.ctrlKey||!this._isEnabled){return}this._domNode.style.display="none";$tw.utils.removeClass(this._domNode,"tmap-popup-active");this._domNode.removeAttribute("style");_utils2.default.removeDOMChildNodes(this._domNode);var i=this._domNode.appendChild(document.createElement("div"));if(typeof t==="function"){t(e,i)}else{i.innerHTML=t}if(!i.childNodes.length)return;var s=this._parentDomNode.getBoundingClientRect();var o=$tm.mouse.clientX;var n=$tm.mouse.clientY;this._domNode.style.display="block";var d=this._domNode.getBoundingClientRect();var l=s.right-(o+d.width);var h=o-d.width-s.left;var a=l>h;var u=s.bottom-(n+d.height);var r=n-d.height-s.top;var p=u>r;var _=a?-15:d.width+15;var m=p?-15:d.height+15;this._domNode.style.left=o-s.left-_+"px";this._domNode.style.top=n-s.top-m+"px";this._isDisplayNoneAfterAnimation=false;$tw.utils.addClass(this._domNode,"tmap-popup-active")};Popup.prototype.show=function(e,t,i){this._clearTimeouts();i=_utils2.default.isInteger(i)?i:this._showDelay;this._timeoutShow=setTimeout(this._show,i,e,t)};Popup.prototype.hide=function(e,t){this._clearTimeouts();e=_utils2.default.isInteger(e)?e:this._hideDelay;if(t||e===0){this._hide(t)}else{this._timeoutHide=setTimeout(this._hide,e,t)}};Popup.prototype.setEnabled=function(e){this._isEnabled=e};Popup.prototype.isShown=function(){return this._domNode.style.display==="block"};Popup.prototype._clearTimeouts=function(){clearTimeout(this._timeoutShow);clearTimeout(this._timeoutHide);this._timeoutShow=undefined;this._timeoutHide=undefined};exports.default=Popup;
//# sourceMappingURL=./maps/felixhayashi/tiddlymap/js/lib/Popup.js.map
