UNPKG

primeng

Version:

[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![npm version](https://badge.fury.io/js/primeng.svg)](https://badge.fury.io/js/primeng) [![Discord](https://img.shields.io/discord/557940238991753

2 lines 9.35 kB
!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="undefined"!=typeof globalThis?globalThis:t||self).primeng=t.primeng||{},t.primeng.tooltip={}),t.ng.core,t.ng.common,t.primeng.dom)}(this,(function(t,e,i,n){"use strict";var o=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:!1,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:!1,configurable:!0}),t.prototype.create=function(){this.container&&(this.clearHideTimeout(),this.remove()),this.container=document.createElement("div");var t=document.createElement("div");t.className="p-tooltip-arrow",this.container.appendChild(t),this.tooltipText=document.createElement("div"),this.tooltipText.className="p-tooltip-text",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?n.DomHandler.appendChild(this.container,this.el.nativeElement):n.DomHandler.appendChild(this.container,this.appendTo),this.container.style.display="inline-block"},t.prototype.show=function(){this.text&&!this.disabled&&(this.create(),this.align(),n.DomHandler.fadeIn(this.container,250),"auto"===this.tooltipZIndex?this.container.style.zIndex=++n.DomHandler.zindex:this.container.style.zIndex=this.tooltipZIndex,this.bindDocumentResizeListener(),this.bindScrollListener())},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+n.DomHandler.getWindowScrollLeft(),top:t.top+n.DomHandler.getWindowScrollTop()}}return{left:0,top:0}},t.prototype.alignRight=function(){this.preAlign("right");var t=this.getHostOffset(),e=t.left+n.DomHandler.getOuterWidth(this.el.nativeElement),i=t.top+(n.DomHandler.getOuterHeight(this.el.nativeElement)-n.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-n.DomHandler.getOuterWidth(this.container),i=t.top+(n.DomHandler.getOuterHeight(this.el.nativeElement)-n.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+(n.DomHandler.getOuterWidth(this.el.nativeElement)-n.DomHandler.getOuterWidth(this.container))/2,i=t.top-n.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+(n.DomHandler.getOuterWidth(this.el.nativeElement)-n.DomHandler.getOuterWidth(this.container))/2,i=t.top+n.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="p-tooltip p-component p-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,o=n.DomHandler.getOuterWidth(this.container),s=n.DomHandler.getOuterHeight(this.container),r=n.DomHandler.getViewport();return i+o>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.bindScrollListener=function(){var t=this;this.scrollHandler||(this.scrollHandler=new n.ConnectedOverlayScrollHandler(this.el.nativeElement,(function(){t.container&&t.hide()}))),this.scrollHandler.bindScrollListener()},t.prototype.unbindScrollListener=function(){this.scrollHandler&&this.scrollHandler.unbindScrollListener()},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):n.DomHandler.removeChild(this.container,this.appendTo)),this.unbindDocumentResizeListener(),this.unbindScrollListener(),this.clearTimeouts(),this.container=null,this.scrollHandler=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(),this.scrollHandler&&(this.scrollHandler.destroy(),this.scrollHandler=null)},t}();o.decorators=[{type:e.Directive,args:[{selector:"[pTooltip]"}]}],o.ctorParameters=function(){return[{type:e.ElementRef},{type:e.NgZone}]},o.propDecorators={tooltipPosition:[{type:e.Input}],tooltipEvent:[{type:e.Input}],appendTo:[{type:e.Input}],positionStyle:[{type:e.Input}],tooltipStyleClass:[{type:e.Input}],tooltipZIndex:[{type:e.Input}],escape:[{type:e.Input}],showDelay:[{type:e.Input}],hideDelay:[{type:e.Input}],life:[{type:e.Input}],disabled:[{type:e.Input,args:["tooltipDisabled"]}],text:[{type:e.Input,args:["pTooltip"]}]};var s=function(){};s.decorators=[{type:e.NgModule,args:[{imports:[i.CommonModule],exports:[o],declarations:[o]}]}],t.Tooltip=o,t.TooltipModule=s,Object.defineProperty(t,"__esModule",{value:!0})})); //# sourceMappingURL=primeng-tooltip.umd.min.js.map