UNPKG

primevue

Version:

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

2 lines (1 loc) 3.33 kB
import{DomHandler as t,UniqueComponentId as e,ConnectedOverlayScrollHandler as o}from"primevue/utils";function n(t){u(t.currentTarget)}function l(t){d(t.currentTarget)}function i(t){u(t.currentTarget)}function r(t){d(t.currentTarget)}function p(t){d(t.currentTarget)}function u(n){if(!n.$_ptooltipValue)return;let l=function(t){const o=e()+"_tooltip";t.$_ptooltipId=o;let n=document.createElement("div");n.id=o;let l=document.createElement("div");l.className="p-tooltip-arrow",n.appendChild(l);let i=document.createElement("div");return i.className="p-tooltip-text",i.innerHTML=t.$_ptooltipValue,n.appendChild(i),document.body.appendChild(n),n.style.display="inline-block",n}(n);!function(t){const e=t.$_ptooltipModifiers;e.top?(m(t),_(t)&&v(t)):e.left?(g(t),_(t)&&(a(t),_(t)&&(m(t),_(t)&&v(t)))):e.bottom?(v(t),_(t)&&m(t)):(a(t),_(t)&&(g(t),_(t)&&(m(t),_(t)&&v(t))))}(n),t.fadeIn(l,250),l.style.zIndex=++t.zindex,window.addEventListener("resize",(function t(){d(n),this.removeEventListener("resize",t)})),function(t){t.$_ptooltipScrollHandler||(t.$_ptooltipScrollHandler=new o(t,(function(){d(t)}))),t.$_ptooltipScrollHandler.bindScrollListener()}(n)}function d(t){s(t),function(t){t.$_ptooltipScrollHandler&&t.$_ptooltipScrollHandler.unbindScrollListener()}(t)}function c(t){return document.getElementById(t.$_ptooltipId)}function s(t){if(t){let e=c(t);e&&e.parentElement&&document.body.removeChild(e),t.$_ptooltipId=null}}function f(e){let o=e.getBoundingClientRect();return{left:o.left+t.getWindowScrollLeft(),top:o.top+t.getWindowScrollTop()}}function a(e){h(e,"right");let o=c(e),n=f(e),l=n.left+t.getOuterWidth(e),i=n.top+(t.getOuterHeight(e)-t.getOuterHeight(o))/2;o.style.left=l+"px",o.style.top=i+"px"}function g(e){h(e,"left");let o=c(e),n=f(e),l=n.left-t.getOuterWidth(o),i=n.top+(t.getOuterHeight(e)-t.getOuterHeight(o))/2;o.style.left=l+"px",o.style.top=i+"px"}function m(e){h(e,"top");let o=c(e),n=f(e),l=n.left+(t.getOuterWidth(e)-t.getOuterWidth(o))/2,i=n.top-t.getOuterHeight(o);o.style.left=l+"px",o.style.top=i+"px"}function v(e){h(e,"bottom");let o=c(e),n=f(e),l=n.left+(t.getOuterWidth(e)-t.getOuterWidth(o))/2,i=n.top+t.getOuterHeight(e);o.style.left=l+"px",o.style.top=i+"px"}function h(t,e){let o=c(t);o.style.left="-999px",o.style.top="-999px",o.className="p-tooltip p-component p-tooltip-"+e}function _(e){let o=c(e),n=o.getBoundingClientRect(),l=n.top,i=n.left,r=t.getOuterWidth(o),p=t.getOuterHeight(o),u=t.getViewport();return i+r>u.width||i<0||l<0||l+p>u.height}function $(e){return t.hasClass(e,"p-inputwrapper")?t.findSingle(e,"input"):e}const y={beforeMount(t,e){let o=$(t);o.$_ptooltipModifiers=e.modifiers,o.$_ptooltipValue=e.value,function(t){t.$_ptooltipModifiers.focus?(t.addEventListener("focus",i),t.addEventListener("blur",r)):(t.addEventListener("mouseenter",n),t.addEventListener("mouseleave",l),t.addEventListener("click",p))}(o)},unmounted(t){let e=$(t);s(e),function(t){t.$_ptooltipModifiers.focus?(t.removeEventListener("focus",i),t.removeEventListener("blur",r)):(t.removeEventListener("mouseenter",n),t.removeEventListener("mouseleave",l),t.removeEventListener("click",p))}(e),e.$_ptooltipScrollHandler&&(e.$_ptooltipScrollHandler.destroy(),e.$_ptooltipScrollHandler=null)},updated(t,e){let o=$(t);o.$_ptooltipModifiers=e.modifiers,o.$_ptooltipValue=e.value}};export default y;