primevue
Version:
PrimeVue is an open source UI library for Vue featuring a rich set of 80+ components, a theme designer, various theme alternatives such as Material, Bootstrap, Tailwind, premium templates and professional support. In addition, it integrates with PrimeBloc
2 lines (1 loc) • 11.3 kB
JavaScript
this.primevue=this.primevue||{},this.primevue.tooltip=function(t,e,o){"use strict";function i(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}function n(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function l(t,e){if(t){if("string"==typeof t)return r(t,e);var o=Object.prototype.toString.call(t).slice(8,-1);return"Object"===o&&t.constructor&&(o=t.constructor.name),"Map"===o||"Set"===o?Array.from(t):"Arguments"===o||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(o)?r(t,e):void 0}}function r(t,e){(null==e||e>t.length)&&(e=t.length);for(var o=0,i=new Array(e);o<e;o++)i[o]=t[o];return i}function s(t,e){var o=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=o){var i,n,l,r,s=[],a=!0,u=!1;try{if(l=(o=o.call(t)).next,0===e){if(Object(o)!==o)return;a=!1}else for(;!(a=(i=l.call(o)).done)&&(s.push(i.value),s.length!==e);a=!0);}catch(t){u=!0,n=t}finally{try{if(!a&&null!=o.return&&(r=o.return(),Object(r)!==r))return}finally{if(u)throw n}}return s}}function a(t){if(Array.isArray(t))return t}function u(t){return u="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},u(t)}return i(e).default.extend({style:i(o).default}).extend("tooltip",{beforeMount:function(e,o){var i,n=this.getTarget(e);if(n.$_ptooltipModifiers=this.getModifiers(o),o.value){if("string"==typeof o.value)n.$_ptooltipValue=o.value,n.$_ptooltipDisabled=!1,n.$_ptooltipEscape=!0,n.$_ptooltipClass=null,n.$_ptooltipFitContent=!0,n.$_ptooltipIdAttr=t.UniqueComponentId()+"_tooltip",n.$_ptooltipShowDelay=0,n.$_ptooltipHideDelay=0,n.$_ptooltipAutoHide=!0;else if("object"===u(o.value)&&o.value){if(t.ObjectUtils.isEmpty(o.value.value)||""===o.value.value.trim())return;n.$_ptooltipValue=o.value.value,n.$_ptooltipDisabled=!!o.value.disabled===o.value.disabled&&o.value.disabled,n.$_ptooltipEscape=!!o.value.escape!==o.value.escape||o.value.escape,n.$_ptooltipClass=o.value.class||"",n.$_ptooltipFitContent=!!o.value.fitContent!==o.value.fitContent||o.value.fitContent,n.$_ptooltipIdAttr=o.value.id||t.UniqueComponentId()+"_tooltip",n.$_ptooltipShowDelay=o.value.showDelay||0,n.$_ptooltipHideDelay=o.value.hideDelay||0,n.$_ptooltipAutoHide=!!o.value.autoHide!==o.value.autoHide||o.value.autoHide}n.$_ptooltipZIndex=null===(i=o.instance.$primevue)||void 0===i||null===(i=i.config)||void 0===i||null===(i=i.zIndex)||void 0===i?void 0:i.tooltip,this.bindEvents(n,o),e.setAttribute("data-pd-tooltip",!0)}},updated:function(e,o){var i=this.getTarget(e);if(i.$_ptooltipModifiers=this.getModifiers(o),this.unbindEvents(i),o.value)if("string"==typeof o.value)i.$_ptooltipValue=o.value,i.$_ptooltipDisabled=!1,i.$_ptooltipEscape=!0,i.$_ptooltipClass=null,i.$_ptooltipIdAttr=i.$_ptooltipIdAttr||t.UniqueComponentId()+"_tooltip",i.$_ptooltipShowDelay=0,i.$_ptooltipHideDelay=0,i.$_ptooltipAutoHide=!0,this.bindEvents(i,o);else if("object"===u(o.value)&&o.value){if(t.ObjectUtils.isEmpty(o.value.value)||""===o.value.value.trim())return void this.unbindEvents(i,o);i.$_ptooltipValue=o.value.value,i.$_ptooltipDisabled=!!o.value.disabled===o.value.disabled&&o.value.disabled,i.$_ptooltipEscape=!!o.value.escape!==o.value.escape||o.value.escape,i.$_ptooltipClass=o.value.class||"",i.$_ptooltipFitContent=!!o.value.fitContent!==o.value.fitContent||o.value.fitContent,i.$_ptooltipIdAttr=o.value.id||i.$_ptooltipIdAttr||t.UniqueComponentId()+"_tooltip",i.$_ptooltipShowDelay=o.value.showDelay||0,i.$_ptooltipHideDelay=o.value.hideDelay||0,i.$_ptooltipAutoHide=!!o.value.autoHide!==o.value.autoHide||o.value.autoHide,this.bindEvents(i,o)}},unmounted:function(t,e){var o=this.getTarget(t);this.remove(o),this.unbindEvents(o,e),o.$_ptooltipScrollHandler&&(o.$_ptooltipScrollHandler.destroy(),o.$_ptooltipScrollHandler=null)},timer:void 0,methods:{bindEvents:function(t,e){var o=this;t.$_ptooltipModifiers.focus?(t.$_focusevent=function(t){return o.onFocus(t,e)},t.addEventListener("focus",t.$_focusevent),t.addEventListener("blur",this.onBlur.bind(this))):(t.$_mouseenterevent=function(t){return o.onMouseEnter(t,e)},t.addEventListener("mouseenter",t.$_mouseenterevent),t.addEventListener("mouseleave",this.onMouseLeave.bind(this)),t.addEventListener("click",this.onClick.bind(this))),t.addEventListener("keydown",this.onKeydown.bind(this))},unbindEvents:function(t){t.$_ptooltipModifiers.focus?(t.removeEventListener("focus",t.$_focusevent),t.$_focusevent=null,t.removeEventListener("blur",this.onBlur.bind(this))):(t.removeEventListener("mouseenter",t.$_mouseenterevent),t.$_mouseenterevent=null,t.removeEventListener("mouseleave",this.onMouseLeave.bind(this)),t.removeEventListener("click",this.onClick.bind(this))),t.removeEventListener("keydown",this.onKeydown.bind(this))},bindScrollListener:function(e){var o=this;e.$_ptooltipScrollHandler||(e.$_ptooltipScrollHandler=new t.ConnectedOverlayScrollHandler(e,(function(){o.hide(e)}))),e.$_ptooltipScrollHandler.bindScrollListener()},unbindScrollListener:function(t){t.$_ptooltipScrollHandler&&t.$_ptooltipScrollHandler.unbindScrollListener()},onMouseEnter:function(t,e){var o=t.currentTarget;this.show(o,e,o.$_ptooltipShowDelay)},onMouseLeave:function(e){var o=e.currentTarget,i=o.$_ptooltipHideDelay;o.$_ptooltipAutoHide?this.hide(o,i):!("tooltip"===t.DomHandler.getAttribute(e.target,"data-pc-name")||"arrow"===t.DomHandler.getAttribute(e.target,"data-pc-section")||"text"===t.DomHandler.getAttribute(e.target,"data-pc-section")||"tooltip"===t.DomHandler.getAttribute(e.relatedTarget,"data-pc-name")||"arrow"===t.DomHandler.getAttribute(e.relatedTarget,"data-pc-section")||"text"===t.DomHandler.getAttribute(e.relatedTarget,"data-pc-section"))&&this.hide(o,i)},onFocus:function(t,e){var o=t.currentTarget;this.show(o,e,o.$_ptooltipShowDelay)},onBlur:function(t){var e=t.currentTarget;this.hide(e,e.$_ptooltipHideDelay)},onClick:function(t){var e=t.currentTarget;this.hide(e,e.$_ptooltipHideDelay)},onKeydown:function(t){"Escape"===t.code&&this.hide(t.currentTarget,t.currentTarget.$_ptooltipHideDelay)},tooltipActions:function(e,o){if(!e.$_ptooltipDisabled&&t.DomHandler.isExist(e)){var i=this.create(e,o);this.align(e),!this.isUnstyled()&&t.DomHandler.fadeIn(i,250);var n=this;window.addEventListener("resize",(function o(){t.DomHandler.isTouchDevice()||n.hide(e),window.removeEventListener("resize",o)})),i.addEventListener("mouseleave",(function t(){n.hide(e),i.removeEventListener("mouseleave",t)})),this.bindScrollListener(e),t.ZIndexUtils.set("tooltip",i,e.$_ptooltipZIndex)}},show:function(t,e,o){var i=this;void 0!==o?this.timer=setTimeout((function(){return i.tooltipActions(t,e)}),o):this.tooltipActions(t,e)},tooltipRemoval:function(t){this.remove(t),this.unbindScrollListener(t)},hide:function(t,e){var o=this;clearTimeout(this.timer),void 0!==e?setTimeout((function(){return o.tooltipRemoval(t)}),e):this.tooltipRemoval(t)},getTooltipElement:function(t){return document.getElementById(t.$_ptooltipId)},create:function(e,o){var i=e.$_ptooltipModifiers,n=t.DomHandler.createElement("div",{class:!this.isUnstyled()&&this.cx("arrow"),style:{top:null!=i&&i.bottom?"0":!(null!=i&&i.right||null!=i&&i.left)&&(null!=i&&i.right||null!=i&&i.left||null!=i&&i.top||null!=i&&i.bottom)?null:"50%",bottom:null!=i&&i.top?"0":null,left:(null==i||!i.right)&&(null!=i&&i.right||null!=i&&i.left||null!=i&&i.top||null!=i&&i.bottom)?null!=i&&i.top||null!=i&&i.bottom?"50%":null:"0",right:null!=i&&i.left?"0":null},"p-bind":this.ptm("arrow",{context:i})}),l=t.DomHandler.createElement("div",{class:!this.isUnstyled()&&this.cx("text"),"p-bind":this.ptm("text",{context:i})});e.$_ptooltipEscape?(l.innerHTML="",l.appendChild(document.createTextNode(e.$_ptooltipValue))):l.innerHTML=e.$_ptooltipValue;var r=t.DomHandler.createElement("div",{id:e.$_ptooltipIdAttr,role:"tooltip",style:{display:"inline-block",width:e.$_ptooltipFitContent?"fit-content":void 0,pointerEvents:!this.isUnstyled()&&e.$_ptooltipAutoHide&&"none"},class:[!this.isUnstyled()&&this.cx("root"),e.$_ptooltipClass],"p-bind":this.ptm("root",{context:i})},n,l);return document.body.appendChild(r),e.$_ptooltipId=r.id,this.$el=r,r},remove:function(e){if(e){var o=this.getTooltipElement(e);o&&o.parentElement&&(t.ZIndexUtils.clear(o),document.body.removeChild(o)),e.$_ptooltipId=null}},align:function(t){var e=t.$_ptooltipModifiers;e.top?(this.alignTop(t),this.isOutOfBounds(t)&&(this.alignBottom(t),this.isOutOfBounds(t)&&this.alignTop(t))):e.left?(this.alignLeft(t),this.isOutOfBounds(t)&&(this.alignRight(t),this.isOutOfBounds(t)&&(this.alignTop(t),this.isOutOfBounds(t)&&(this.alignBottom(t),this.isOutOfBounds(t)&&this.alignLeft(t))))):e.bottom?(this.alignBottom(t),this.isOutOfBounds(t)&&(this.alignTop(t),this.isOutOfBounds(t)&&this.alignBottom(t))):(this.alignRight(t),this.isOutOfBounds(t)&&(this.alignLeft(t),this.isOutOfBounds(t)&&(this.alignTop(t),this.isOutOfBounds(t)&&(this.alignBottom(t),this.isOutOfBounds(t)&&this.alignRight(t)))))},getHostOffset:function(e){var o=e.getBoundingClientRect();return{left:o.left+t.DomHandler.getWindowScrollLeft(),top:o.top+t.DomHandler.getWindowScrollTop()}},alignRight:function(e){this.preAlign(e,"right");var o=this.getTooltipElement(e),i=this.getHostOffset(e),n=i.left+t.DomHandler.getOuterWidth(e),l=i.top+(t.DomHandler.getOuterHeight(e)-t.DomHandler.getOuterHeight(o))/2;o.style.left=n+"px",o.style.top=l+"px"},alignLeft:function(e){this.preAlign(e,"left");var o=this.getTooltipElement(e),i=this.getHostOffset(e),n=i.left-t.DomHandler.getOuterWidth(o),l=i.top+(t.DomHandler.getOuterHeight(e)-t.DomHandler.getOuterHeight(o))/2;o.style.left=n+"px",o.style.top=l+"px"},alignTop:function(e){this.preAlign(e,"top");var o=this.getTooltipElement(e),i=this.getHostOffset(e),n=i.left+(t.DomHandler.getOuterWidth(e)-t.DomHandler.getOuterWidth(o))/2,l=i.top-t.DomHandler.getOuterHeight(o);o.style.left=n+"px",o.style.top=l+"px"},alignBottom:function(e){this.preAlign(e,"bottom");var o=this.getTooltipElement(e),i=this.getHostOffset(e),n=i.left+(t.DomHandler.getOuterWidth(e)-t.DomHandler.getOuterWidth(o))/2,l=i.top+t.DomHandler.getOuterHeight(e);o.style.left=n+"px",o.style.top=l+"px"},preAlign:function(e,o){var i=this.getTooltipElement(e);i.style.left="-999px",i.style.top="-999px",t.DomHandler.removeClass(i,"p-tooltip-".concat(i.$_ptooltipPosition)),!this.isUnstyled()&&t.DomHandler.addClass(i,"p-tooltip-".concat(o)),i.$_ptooltipPosition=o,i.setAttribute("data-p-position",o)},isOutOfBounds:function(e){var o=this.getTooltipElement(e),i=o.getBoundingClientRect(),n=i.top,l=i.left,r=t.DomHandler.getOuterWidth(o),s=t.DomHandler.getOuterHeight(o),a=t.DomHandler.getViewport();return l+r>a.width||l<0||n<0||n+s>a.height},getTarget:function(e){return t.DomHandler.hasClass(e,"p-inputwrapper")?t.DomHandler.findSingle(e,"input"):e},getModifiers:function(t){return t.modifiers&&Object.keys(t.modifiers).length?t.modifiers:t.arg&&"object"===u(t.arg)?Object.entries(t.arg).reduce((function(t,e){var o,i,r=(i=2,a(o=e)||s(o,i)||l(o,i)||n()),u=r[0];return"event"!==u&&"position"!==u||(t[r[1]]=!0),t}),{}):{}}}})}(primevue.utils,primevue.basedirective,primevue.tooltip.style);