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