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) 5.88 kB
import{ObjectUtils as t,ZIndexUtils as e,DomHandler as o,UniqueComponentId as l,ConnectedOverlayScrollHandler as i}from"primevue/utils";let n;function p(t){t.$_ptooltipModifiers.focus?(t.addEventListener("focus",d),t.addEventListener("blur",s)):(t.addEventListener("mouseenter",u),t.addEventListener("mouseleave",r),t.addEventListener("click",c)),t.addEventListener("keydown",f)}function a(t){t.$_ptooltipModifiers.focus?(t.removeEventListener("focus",d),t.removeEventListener("blur",s)):(t.removeEventListener("mouseenter",u),t.removeEventListener("mouseleave",r),t.removeEventListener("click",c)),t.removeEventListener("keydown",f)}function u(t){const e=t.currentTarget;$(e,e.$_ptooltipShowDelay)}function r(t){const e=t.currentTarget;m(e,e.$_ptooltipHideDelay)}function d(t){const e=t.currentTarget;$(e,e.$_ptooltipShowDelay)}function s(t){const e=t.currentTarget;m(e,e.$_ptooltipHideDelay)}function c(t){const e=t.currentTarget;m(e,e.$_ptooltipHideDelay)}function f(t){"Escape"===t.code&&m(t.currentTarget,hideDelay)}function v(t){if(t.$_ptooltipDisabled)return;let n=function(t){const e=""!==t.$_ptooltipIdAttr?t.$_ptooltipIdAttr:l()+"_tooltip";t.$_ptooltipId=e;let o=document.createElement("div");o.id=e;let i=document.createElement("div");i.className="p-tooltip-arrow",o.appendChild(i);let n=document.createElement("div");n.className="p-tooltip-text",t.$_ptooltipEscape?n.innerHTML=t.$_ptooltipValue:(n.innerHTML="",n.appendChild(document.createTextNode(t.$_ptooltipValue)));o.setAttribute("role","tooltip"),o.appendChild(n),document.body.appendChild(o),o.style.display="inline-block",t.$_ptooltipFitContent&&(o.style.width="fit-content");return o}(t);!function(t){const e=t.$_ptooltipModifiers;e.top?(D(t),w(t)&&(H(t),w(t)&&D(t))):e.left?(E(t),w(t)&&(b(t),w(t)&&(D(t),w(t)&&(H(t),w(t)&&E(t))))):e.bottom?(H(t),w(t)&&(D(t),w(t)&&H(t))):(b(t),w(t)&&(E(t),w(t)&&(D(t),w(t)&&(H(t),w(t)&&b(t)))))}(t),o.fadeIn(n,250),window.addEventListener("resize",(function e(){o.isTouchDevice()||m(t),this.removeEventListener("resize",e)})),function(t){t.$_ptooltipScrollHandler||(t.$_ptooltipScrollHandler=new i(t,(function(){m(t)}))),t.$_ptooltipScrollHandler.bindScrollListener()}(t),e.set("tooltip",n,t.$_ptooltipZIndex)}function $(t,e){void 0!==e?n=setTimeout((()=>v(t)),e):v(t)}function _(t){y(t),function(t){t.$_ptooltipScrollHandler&&t.$_ptooltipScrollHandler.unbindScrollListener()}(t)}function m(t,e){clearTimeout(n),void 0!==e?setTimeout((()=>_(t)),e):_(t)}function g(t){return document.getElementById(t.$_ptooltipId)}function y(t){if(t){let o=g(t);o&&o.parentElement&&(e.clear(o),document.body.removeChild(o)),t.$_ptooltipId=null}}function h(t){let e=t.getBoundingClientRect();return{left:e.left+o.getWindowScrollLeft(),top:e.top+o.getWindowScrollTop()}}function b(t){C(t,"right");let e=g(t),l=h(t),i=l.left+o.getOuterWidth(t),n=l.top+(o.getOuterHeight(t)-o.getOuterHeight(e))/2;e.style.left=i+"px",e.style.top=n+"px"}function E(t){C(t,"left");let e=g(t),l=h(t),i=l.left-o.getOuterWidth(e),n=l.top+(o.getOuterHeight(t)-o.getOuterHeight(e))/2;e.style.left=i+"px",e.style.top=n+"px"}function D(t){C(t,"top");let e=g(t),l=h(t),i=l.left+(o.getOuterWidth(t)-o.getOuterWidth(e))/2,n=l.top-o.getOuterHeight(e);e.style.left=i+"px",e.style.top=n+"px"}function H(t){C(t,"bottom");let e=g(t),l=h(t),i=l.left+(o.getOuterWidth(t)-o.getOuterWidth(e))/2,n=l.top+o.getOuterHeight(t);e.style.left=i+"px",e.style.top=n+"px"}function C(t,e){let o=g(t);o.style.left="-999px",o.style.top="-999px",o.className=`p-tooltip p-component p-tooltip-${e} ${t.$_ptooltipClass||""}`}function w(t){let e=g(t),l=e.getBoundingClientRect(),i=l.top,n=l.left,p=o.getOuterWidth(e),a=o.getOuterHeight(e),u=o.getViewport();return n+p>u.width||n<0||i<0||i+a>u.height}function L(t){return o.hasClass(t,"p-inputwrapper")?o.findSingle(t,"input"):t}function S(t){return t.modifiers&&Object.keys(t.modifiers).length?t.modifiers:t.arg&&"object"==typeof t.arg?Object.entries(t.arg).reduce(((t,[e,o])=>("event"!==e&&"position"!==e||(t[o]=!0),t)),{}):{}}const x={beforeMount(e,o){let l=L(e);if(l.$_ptooltipModifiers=S(o),o.value){if("string"==typeof o.value)l.$_ptooltipValue=o.value,l.$_ptooltipDisabled=!1,l.$_ptooltipEscape=!1,l.$_ptooltipClass=null,l.$_ptooltipFitContent=!0,l.$_ptooltipShowDelay=0,l.$_ptooltipHideDelay=0;else if("object"==typeof o.value&&o.value){if(t.isEmpty(o.value.value)||""===o.value.value.trim())return;l.$_ptooltipValue=o.value.value,l.$_ptooltipDisabled=!!o.value.disabled===o.value.disabled&&o.value.disabled,l.$_ptooltipEscape=!!o.value.escape===o.value.escape&&o.value.escape,l.$_ptooltipClass=o.value.class,l.$_ptooltipFitContent=!!o.value.fitContent!==o.value.fitContent||o.value.fitContent,l.$_ptooltipIdAttr=o.value.id||"",l.$_ptooltipShowDelay=o.value.showDelay||0,l.$_ptooltipHideDelay=o.value.hideDelay||0}l.$_ptooltipZIndex=o.instance.$primevue&&o.instance.$primevue.config&&o.instance.$primevue.config.zIndex.tooltip,p(l)}},unmounted(t){let e=L(t);y(e),a(e),e.$_ptooltipScrollHandler&&(e.$_ptooltipScrollHandler.destroy(),e.$_ptooltipScrollHandler=null)},updated(e,o){let l=L(e);if(l.$_ptooltipModifiers=S(o),o.value){if("string"==typeof o.value)l.$_ptooltipValue=o.value,l.$_ptooltipDisabled=!1,l.$_ptooltipEscape=!1,l.$_ptooltipClass=null,l.$_ptooltipIdAttr="",l.$_ptooltipShowDelay=0,l.$_ptooltipHideDelay=0,p(l);else if("object"==typeof o.value&&o.value){if(t.isEmpty(o.value.value)||""===o.value.value.trim())return void a(l);l.$_ptooltipValue=o.value.value,l.$_ptooltipDisabled=!!o.value.disabled===o.value.disabled&&o.value.disabled,l.$_ptooltipEscape=!!o.value.escape===o.value.escape&&o.value.escape,l.$_ptooltipClass=o.value.class,l.$_ptooltipFitContent=!!o.value.fitContent!==o.value.fitContent||o.value.fitContent,l.$_ptooltipIdAttr=o.value.id||"",l.$_ptooltipShowDelay=o.value.showDelay||0,l.$_ptooltipHideDelay=o.value.hideDelay||0,p(l)}}else a(l)}};export{x as default};