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) [![Discord Chat](https://img.shields.io/discord/55794023

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