UNPKG

9.36 kBJavaScriptView Raw
1!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@angular/core"),require("@angular/common"),require("primeng/dom")):"function"==typeof define&&define.amd?define("primeng/tooltip",["exports","@angular/core","@angular/common","primeng/dom"],e):e(((t=t||self).primeng=t.primeng||{},t.primeng.tooltip={}),t.ng.core,t.ng.common,t.primeng.dom)}(this,(function(t,e,i,o){"use strict";var n=this&&this.__decorate||function(t,e,i,o){var n,s=arguments.length,r=s<3?e:null===o?o=Object.getOwnPropertyDescriptor(e,i):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(t,e,i,o);else for(var l=t.length-1;l>=0;l--)(n=t[l])&&(r=(s<3?n(r):s>3?n(e,i,r):n(e,i))||r);return s>3&&r&&Object.defineProperty(e,i,r),r},s=function(){function t(t,e){this.el=t,this.zone=e,this.tooltipPosition="right",this.tooltipEvent="hover",this.appendTo="body",this.tooltipZIndex="auto",this.escape=!0}return Object.defineProperty(t.prototype,"disabled",{get:function(){return this._disabled},set:function(t){this._disabled=t,this.deactivate()},enumerable:!0,configurable:!0}),t.prototype.ngAfterViewInit=function(){var t=this;this.zone.runOutsideAngular((function(){"hover"===t.tooltipEvent?(t.mouseEnterListener=t.onMouseEnter.bind(t),t.mouseLeaveListener=t.onMouseLeave.bind(t),t.clickListener=t.onClick.bind(t),t.el.nativeElement.addEventListener("mouseenter",t.mouseEnterListener),t.el.nativeElement.addEventListener("mouseleave",t.mouseLeaveListener),t.el.nativeElement.addEventListener("click",t.clickListener)):"focus"===t.tooltipEvent&&(t.focusListener=t.onFocus.bind(t),t.blurListener=t.onBlur.bind(t),t.el.nativeElement.addEventListener("focus",t.focusListener),t.el.nativeElement.addEventListener("blur",t.blurListener))}))},t.prototype.onMouseEnter=function(t){this.container||this.showTimeout||this.activate()},t.prototype.onMouseLeave=function(t){this.deactivate()},t.prototype.onFocus=function(t){this.activate()},t.prototype.onBlur=function(t){this.deactivate()},t.prototype.onClick=function(t){this.deactivate()},t.prototype.activate=function(){var t=this;if(this.active=!0,this.clearHideTimeout(),this.showDelay?this.showTimeout=setTimeout((function(){t.show()}),this.showDelay):this.show(),this.life){var e=this.showDelay?this.life+this.showDelay:this.life;this.hideTimeout=setTimeout((function(){t.hide()}),e)}},t.prototype.deactivate=function(){var t=this;this.active=!1,this.clearShowTimeout(),this.hideDelay?(this.clearHideTimeout(),this.hideTimeout=setTimeout((function(){t.hide()}),this.hideDelay)):this.hide()},Object.defineProperty(t.prototype,"text",{get:function(){return this._text},set:function(t){this._text=t,this.active&&(this._text?this.container&&this.container.offsetParent?(this.updateText(),this.align()):this.show():this.hide())},enumerable:!0,configurable:!0}),t.prototype.create=function(){this.container&&(this.clearHideTimeout(),this.remove()),this.container=document.createElement("div");var t=document.createElement("div");t.className="ui-tooltip-arrow",this.container.appendChild(t),this.tooltipText=document.createElement("div"),this.tooltipText.className="ui-tooltip-text ui-shadow ui-corner-all",this.updateText(),this.positionStyle&&(this.container.style.position=this.positionStyle),this.container.appendChild(this.tooltipText),"body"===this.appendTo?document.body.appendChild(this.container):"target"===this.appendTo?o.DomHandler.appendChild(this.container,this.el.nativeElement):o.DomHandler.appendChild(this.container,this.appendTo),this.container.style.display="inline-block"},t.prototype.show=function(){this.text&&!this.disabled&&(this.create(),this.align(),o.DomHandler.fadeIn(this.container,250),"auto"===this.tooltipZIndex?this.container.style.zIndex=++o.DomHandler.zindex:this.container.style.zIndex=this.tooltipZIndex,this.bindDocumentResizeListener())},t.prototype.hide=function(){this.remove()},t.prototype.updateText=function(){this.escape?(this.tooltipText.innerHTML="",this.tooltipText.appendChild(document.createTextNode(this._text))):this.tooltipText.innerHTML=this._text},t.prototype.align=function(){switch(this.tooltipPosition){case"top":this.alignTop(),this.isOutOfBounds()&&(this.alignBottom(),this.isOutOfBounds()&&(this.alignRight(),this.isOutOfBounds()&&this.alignLeft()));break;case"bottom":this.alignBottom(),this.isOutOfBounds()&&(this.alignTop(),this.isOutOfBounds()&&(this.alignRight(),this.isOutOfBounds()&&this.alignLeft()));break;case"left":this.alignLeft(),this.isOutOfBounds()&&(this.alignRight(),this.isOutOfBounds()&&(this.alignTop(),this.isOutOfBounds()&&this.alignBottom()));break;case"right":this.alignRight(),this.isOutOfBounds()&&(this.alignLeft(),this.isOutOfBounds()&&(this.alignTop(),this.isOutOfBounds()&&this.alignBottom()))}},t.prototype.getHostOffset=function(){if("body"===this.appendTo||"target"===this.appendTo){var t=this.el.nativeElement.getBoundingClientRect();return{left:t.left+o.DomHandler.getWindowScrollLeft(),top:t.top+o.DomHandler.getWindowScrollTop()}}return{left:0,top:0}},t.prototype.alignRight=function(){this.preAlign("right");var t=this.getHostOffset(),e=t.left+o.DomHandler.getOuterWidth(this.el.nativeElement),i=t.top+(o.DomHandler.getOuterHeight(this.el.nativeElement)-o.DomHandler.getOuterHeight(this.container))/2;this.container.style.left=e+"px",this.container.style.top=i+"px"},t.prototype.alignLeft=function(){this.preAlign("left");var t=this.getHostOffset(),e=t.left-o.DomHandler.getOuterWidth(this.container),i=t.top+(o.DomHandler.getOuterHeight(this.el.nativeElement)-o.DomHandler.getOuterHeight(this.container))/2;this.container.style.left=e+"px",this.container.style.top=i+"px"},t.prototype.alignTop=function(){this.preAlign("top");var t=this.getHostOffset(),e=t.left+(o.DomHandler.getOuterWidth(this.el.nativeElement)-o.DomHandler.getOuterWidth(this.container))/2,i=t.top-o.DomHandler.getOuterHeight(this.container);this.container.style.left=e+"px",this.container.style.top=i+"px"},t.prototype.alignBottom=function(){this.preAlign("bottom");var t=this.getHostOffset(),e=t.left+(o.DomHandler.getOuterWidth(this.el.nativeElement)-o.DomHandler.getOuterWidth(this.container))/2,i=t.top+o.DomHandler.getOuterHeight(this.el.nativeElement);this.container.style.left=e+"px",this.container.style.top=i+"px"},t.prototype.preAlign=function(t){this.container.style.left="-999px",this.container.style.top="-999px";var e="ui-tooltip ui-widget ui-tooltip-"+t;this.container.className=this.tooltipStyleClass?e+" "+this.tooltipStyleClass:e},t.prototype.isOutOfBounds=function(){var t=this.container.getBoundingClientRect(),e=t.top,i=t.left,n=o.DomHandler.getOuterWidth(this.container),s=o.DomHandler.getOuterHeight(this.container),r=o.DomHandler.getViewport();return i+n>r.width||i<0||e<0||e+s>r.height},t.prototype.onWindowResize=function(t){this.hide()},t.prototype.bindDocumentResizeListener=function(){var t=this;this.zone.runOutsideAngular((function(){t.resizeListener=t.onWindowResize.bind(t),window.addEventListener("resize",t.resizeListener)}))},t.prototype.unbindDocumentResizeListener=function(){this.resizeListener&&(window.removeEventListener("resize",this.resizeListener),this.resizeListener=null)},t.prototype.unbindEvents=function(){"hover"===this.tooltipEvent?(this.el.nativeElement.removeEventListener("mouseenter",this.mouseEnterListener),this.el.nativeElement.removeEventListener("mouseleave",this.mouseLeaveListener),this.el.nativeElement.removeEventListener("click",this.clickListener)):"focus"===this.tooltipEvent&&(this.el.nativeElement.removeEventListener("focus",this.focusListener),this.el.nativeElement.removeEventListener("blur",this.blurListener)),this.unbindDocumentResizeListener()},t.prototype.remove=function(){this.container&&this.container.parentElement&&("body"===this.appendTo?document.body.removeChild(this.container):"target"===this.appendTo?this.el.nativeElement.removeChild(this.container):o.DomHandler.removeChild(this.container,this.appendTo)),this.unbindDocumentResizeListener(),this.clearTimeouts(),this.container=null},t.prototype.clearShowTimeout=function(){this.showTimeout&&(clearTimeout(this.showTimeout),this.showTimeout=null)},t.prototype.clearHideTimeout=function(){this.hideTimeout&&(clearTimeout(this.hideTimeout),this.hideTimeout=null)},t.prototype.clearTimeouts=function(){this.clearShowTimeout(),this.clearHideTimeout()},t.prototype.ngOnDestroy=function(){this.unbindEvents(),this.remove()},t.ctorParameters=function(){return[{type:e.ElementRef},{type:e.NgZone}]},n([e.Input()],t.prototype,"tooltipPosition",void 0),n([e.Input()],t.prototype,"tooltipEvent",void 0),n([e.Input()],t.prototype,"appendTo",void 0),n([e.Input()],t.prototype,"positionStyle",void 0),n([e.Input()],t.prototype,"tooltipStyleClass",void 0),n([e.Input()],t.prototype,"tooltipZIndex",void 0),n([e.Input()],t.prototype,"escape",void 0),n([e.Input()],t.prototype,"showDelay",void 0),n([e.Input()],t.prototype,"hideDelay",void 0),n([e.Input()],t.prototype,"life",void 0),n([e.Input("tooltipDisabled")],t.prototype,"disabled",null),n([e.Input("pTooltip")],t.prototype,"text",null),t=n([e.Directive({selector:"[pTooltip]"})],t)}(),r=function(){function t(){}return t=n([e.NgModule({imports:[i.CommonModule],exports:[s],declarations:[s]})],t)}();t.Tooltip=s,t.TooltipModule=r,Object.defineProperty(t,"__esModule",{value:!0})}));
2//# sourceMappingURL=primeng-tooltip.umd.min.js.map
\No newline at end of file