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.33 kB
import{ObjectUtils as t,DomHandler as e,ZIndexUtils as o,UniqueComponentId as l,ConnectedOverlayScrollHandler as i}from"primevue/utils";function n(t){t.$_ptooltipModifiers.focus?(t.addEventListener("focus",a),t.addEventListener("blur",s)):(t.addEventListener("mouseenter",r),t.addEventListener("mouseleave",u),t.addEventListener("click",d)),t.addEventListener("keydown",c)}function p(t){t.$_ptooltipModifiers.focus?(t.removeEventListener("focus",a),t.removeEventListener("blur",s)):(t.removeEventListener("mouseenter",r),t.removeEventListener("mouseleave",u),t.removeEventListener("click",d)),t.removeEventListener("keydown",c)}function r(t){f(t.currentTarget)}function u(t){v(t.currentTarget)}function a(t){f(t.currentTarget)}function s(t){v(t.currentTarget)}function d(t){v(t.currentTarget)}function c(t){"Escape"===t.code&&v(t.currentTarget)}function f(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?(b(t),C(t)&&(y(t),C(t)&&b(t))):e.left?(h(t),C(t)&&(m(t),C(t)&&(b(t),C(t)&&(y(t),C(t)&&h(t))))):e.bottom?(y(t),C(t)&&(b(t),C(t)&&y(t))):(m(t),C(t)&&(h(t),C(t)&&(b(t),C(t)&&(y(t),C(t)&&m(t)))))}(t),e.fadeIn(n,250),window.addEventListener("resize",(function o(){e.isTouchDevice()||v(t),this.removeEventListener("resize",o)})),function(t){t.$_ptooltipScrollHandler||(t.$_ptooltipScrollHandler=new i(t,(function(){v(t)}))),t.$_ptooltipScrollHandler.bindScrollListener()}(t),o.set("tooltip",n,t.$_ptooltipZIndex)}function v(t){_(t),function(t){t.$_ptooltipScrollHandler&&t.$_ptooltipScrollHandler.unbindScrollListener()}(t)}function $(t){return document.getElementById(t.$_ptooltipId)}function _(t){if(t){let e=$(t);e&&e.parentElement&&(o.clear(e),document.body.removeChild(e)),t.$_ptooltipId=null}}function g(t){let o=t.getBoundingClientRect();return{left:o.left+e.getWindowScrollLeft(),top:o.top+e.getWindowScrollTop()}}function m(t){E(t,"right");let o=$(t),l=g(t),i=l.left+e.getOuterWidth(t),n=l.top+(e.getOuterHeight(t)-e.getOuterHeight(o))/2;o.style.left=i+"px",o.style.top=n+"px"}function h(t){E(t,"left");let o=$(t),l=g(t),i=l.left-e.getOuterWidth(o),n=l.top+(e.getOuterHeight(t)-e.getOuterHeight(o))/2;o.style.left=i+"px",o.style.top=n+"px"}function b(t){E(t,"top");let o=$(t),l=g(t),i=l.left+(e.getOuterWidth(t)-e.getOuterWidth(o))/2,n=l.top-e.getOuterHeight(o);o.style.left=i+"px",o.style.top=n+"px"}function y(t){E(t,"bottom");let o=$(t),l=g(t),i=l.left+(e.getOuterWidth(t)-e.getOuterWidth(o))/2,n=l.top+e.getOuterHeight(t);o.style.left=i+"px",o.style.top=n+"px"}function E(t,e){let o=$(t);o.style.left="-999px",o.style.top="-999px",o.className=`p-tooltip p-component p-tooltip-${e} ${t.$_ptooltipClass||""}`}function C(t){let o=$(t),l=o.getBoundingClientRect(),i=l.top,n=l.left,p=e.getOuterWidth(o),r=e.getOuterHeight(o),u=e.getViewport();return n+p>u.width||n<0||i<0||i+r>u.height}function L(t){return e.hasClass(t,"p-inputwrapper")?e.findSingle(t,"input"):t}function H(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=H(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.$_ptooltipIdAttr="";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.$_ptooltipZIndex=o.instance.$primevue&&o.instance.$primevue.config&&o.instance.$primevue.config.zIndex.tooltip,n(l)}},unmounted(t){let e=L(t);_(e),p(e),e.$_ptooltipScrollHandler&&(e.$_ptooltipScrollHandler.destroy(),e.$_ptooltipScrollHandler=null)},updated(e,o){let l=L(e);if(l.$_ptooltipModifiers=H(o),o.value){if("string"==typeof o.value)l.$_ptooltipValue=o.value,l.$_ptooltipDisabled=!1,l.$_ptooltipEscape=!1,l.$_ptooltipClass=null,l.$_ptooltipIdAttr="",n(l);else if("object"==typeof o.value&&o.value){if(t.isEmpty(o.value.value||""===o.value.value.trim()))return void p(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||"",n(l)}}else p(l)}};export{x as default};