primevue
Version:
[](https://opensource.org/licenses/MIT) [](https://badge.fury.io/js/primevue) [ • 5.03 kB
JavaScript
import{ObjectUtils as t,ZIndexUtils as e,DomHandler 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",u),t.addEventListener("mouseleave",r),t.addEventListener("click",c))}function p(t){t.$_ptooltipModifiers.focus?(t.removeEventListener("focus",a),t.removeEventListener("blur",s)):(t.removeEventListener("mouseenter",u),t.removeEventListener("mouseleave",r),t.removeEventListener("click",c))}function u(t){d(t.currentTarget)}function r(t){f(t.currentTarget)}function a(t){d(t.currentTarget)}function s(t){f(t.currentTarget)}function c(t){f(t.currentTarget)}function d(t){if(t.$_ptooltipDisabled)return;let n=function(t){const e=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.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?(h(t),E(t)&&(b(t),E(t)&&h(t))):e.left?(m(t),E(t)&&(_(t),E(t)&&(h(t),E(t)&&(b(t),E(t)&&m(t))))):e.bottom?(b(t),E(t)&&(h(t),E(t)&&b(t))):(_(t),E(t)&&(m(t),E(t)&&(h(t),E(t)&&(b(t),E(t)&&_(t)))))}(t),o.fadeIn(n,250),window.addEventListener("resize",(function e(){o.isTouchDevice()||f(t),this.removeEventListener("resize",e)})),function(t){t.$_ptooltipScrollHandler||(t.$_ptooltipScrollHandler=new i(t,(function(){f(t)}))),t.$_ptooltipScrollHandler.bindScrollListener()}(t),e.set("tooltip",n,t.$_ptooltipZIndex)}function f(t){$(t),function(t){t.$_ptooltipScrollHandler&&t.$_ptooltipScrollHandler.unbindScrollListener()}(t)}function v(t){return document.getElementById(t.$_ptooltipId)}function $(t){if(t){let o=v(t);o&&o.parentElement&&(e.clear(o),document.body.removeChild(o)),t.$_ptooltipId=null}}function g(t){let e=t.getBoundingClientRect();return{left:e.left+o.getWindowScrollLeft(),top:e.top+o.getWindowScrollTop()}}function _(t){y(t,"right");let e=v(t),l=g(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 m(t){y(t,"left");let e=v(t),l=g(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 h(t){y(t,"top");let e=v(t),l=g(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 b(t){y(t,"bottom");let e=v(t),l=g(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 y(t,e){let o=v(t);o.style.left="-999px",o.style.top="-999px",o.className=`p-tooltip p-component p-tooltip-${e} ${t.$_ptooltipClass||""}`}function E(t){let e=v(t),l=e.getBoundingClientRect(),i=l.top,n=l.left,p=o.getOuterWidth(e),u=o.getOuterHeight(e),r=o.getViewport();return n+p>r.width||n<0||i<0||i+u>r.height}function C(t){return o.hasClass(t,"p-inputwrapper")?o.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 L={beforeMount(e,o){let l=C(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;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.$_ptooltipZIndex=o.instance.$primevue&&o.instance.$primevue.config&&o.instance.$primevue.config.zIndex.tooltip,n(l)}},unmounted(t){let o=C(t);$(o),p(o),o.$_ptooltipScrollHandler&&(o.$_ptooltipScrollHandler.destroy(),o.$_ptooltipScrollHandler=null),e.clear(t)},updated(e,o){let l=C(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,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,n(l)}}else p(l)}};export{L as default};