UNPKG

@progress/kendo-ui

Version:

This package is part of the [Kendo UI for jQuery](http://www.telerik.com/kendo-ui) suite.

3 lines (2 loc) 9.35 kB
!function(t,o){"object"==typeof exports&&"undefined"!=typeof module?o(exports,require("kendo.core.js"),require("kendo.popup.js"),require("kendo.fx.js"),require("kendo.icons.js")):"function"==typeof define&&define.amd?define(["exports","kendo.core.min","kendo.popup","kendo.fx","kendo.icons"],o):o(((t="undefined"!=typeof globalThis?globalThis:t||self).kendo=t.kendo||{},t.kendo._globals=t.kendo._globals||{},t.kendo._globals.Tooltip={}))}(this,(function(t){!function(t){var o=window.kendo,e=o.ui.Widget,n=o.ui.Popup,i=o.isFunction,s=t.isPlainObject,r=t.extend,p=t(document),u=o.isLocalUrl,l="_tb_active",a="aria-describedby",c="show",d="hide",h="error",f="contentLoad",m="requestStart",_="k-content-frame",w=({autoHide:e,callout:n,dir:i})=>`<div role="tooltip" class="k-tooltip${e?"":" k-tooltip-closable"}"><div class="k-tooltip-content"></div>`+(e?"":`<div class="k-tooltip-button">${o.ui.icon(t('<span title="Close"></span>'),{icon:"x"})}</div>`)+(n?`<div class="k-callout k-callout-${i}"></div>`:"")+"</div>",g=o.template((({content:t})=>`<iframe frameborder='0' class='${_}' src='${t.url}'>This page requires frames in order to show content</iframe>`)),v=".kendoTooltip",k={bottom:{origin:"bottom center",position:"top center"},top:{origin:"top center",position:"bottom center"},left:{origin:"center left",position:"center right",collision:"fit flip"},right:{origin:"center right",position:"center left",collision:"fit flip"},center:{position:"center center",origin:"center center"}},b={top:"bottom",bottom:"top",left:"right",right:"left",center:"center"},y={bottom:"n",top:"s",left:"e",right:"w",center:"n"},T={horizontal:{offset:"top",size:"outerHeight"},vertical:{offset:"left",size:"outerWidth"}};function O(t){for(;t.length&&!C(t);)t=t.parent()}function C(t){var e=t.data(o.ns+"title");if(e)return t.attr("title",e),t.removeData(o.ns+"title"),!0}function x(t){var e=t.attr("title");if(e)return t.data(o.ns+"title",e),t.attr("title",""),!0}function S(t){for(;t.length&&!t.is("body")&&!x(t);)t=t.parent()}var D=e.extend({init:function(t,n){var i,s=this;e.fn.init.call(s,t,n),i=s.options.position.match(/left|right/)?"horizontal":"vertical",s.dimensions=T[i],o.support.touch&&this._isShownOnMouseEnter()&&s.element.on(o.support.mousedown+v,s.options.filter,s._showOn.bind(s)),s.element.on(s.options.showOn+v,s.options.filter,s._showOn.bind(s)),"click"===s.options.showOn&&s.element.on("keydown"+v,s.options.filter,s._keydown.bind(s))},options:{name:"TooltipBase",filter:"",offset:0,showAfter:100,hideAfter:100,callout:!0,position:"bottom",showOn:"mouseenter",animation:{open:{effects:"fade:in",duration:0},close:{duration:40,hide:!0}}},destroy:function(){var t=this.popup;t&&(t.element.off(v),t.destroy()),clearTimeout(this.timeout),e.fn.destroy.call(this)},hide:function(){this.popup&&this.popup.close()},show:function(t){t=t||this.element,this._saveTitle(t),this._show(t)},target:function(){return this.popup?this.popup.options.anchor:null},_keydown:function(e){var n=t(e.currentTarget);e.keyCode==o.keys.ENTER&&this._show(n)},_showOn:function(o){const e=this,n=t(o.currentTarget);e._isShownOnClick()&&!e._isShownOnMouseEnter()?e._show(n):e._isShownOnFocus()?(e._saveTitle(n),e._show(n)):(clearTimeout(e.timeout),e.timeout=setTimeout((function(){e._show(n)}),e.options.showAfter))},_isShownOnFocus:function(){return this.options.showOn&&this.options.showOn.match(/focus/)},_isShownOnMouseEnter:function(){return this.options.showOn&&this.options.showOn.match(/mouseenter/)},_isShownOnClick:function(){return this.options.showOn&&this.options.showOn.match(/click/)},_recalculatePopupDimensions:function(){var t=this;t.popup.wrapper.css("height",o._outerHeight(t.popup.element)+"px"),t.popup.wrapper.css("width",o._outerWidth(t.popup.element)+"px"),t.popup.position(),t._positionCallout()},_positionCallout:function(){var o=this,e=o.options.position,n=o.dimensions,i=n.offset,s=o.popup,r=s.options.anchor,p=t(r).offset(),u=t(s.element).offset(),l=y[s.flipped?b[e]:e],a=p[i]-u[i]+t(r)[n.size]()/2;o._offset(e,o.options.offset),o.arrow.removeClass("k-callout-n k-callout-s k-callout-w k-callout-e").addClass("k-callout-"+l).css(i,a)},_offset:function(t,e,n){var i=this,s="top"==t||"left"==t,r=i.popup.flipped,p=s&&r||!s&&!r?1:-1,u=s?"margin-"+t:"margin-"+b[t],l=(n||o._outerWidth(i.arrow))/2+e;i.popup.wrapper.css(u,l*p+"px")},_addDescribedBy:function(){var t=this,e=t.popup.options.anchor,n=e[0].id||t.element[0].id||o.guid(),i=[];e.attr(a)&&i.push(e.attr(a)),n&&(i.push(n+l),e.attr(a,i.join(" ")),t.popup.element.attr("id",n+l))},_removeDescribedBy:function(t){var o,e,n,i=this.popup.element.attr("id"),s=t.attr(a);s&&((o=s.split(" "))&&o.length>0&&(e=o.filter((function(t){return t!==i}))),e&&e.length>0?(n=e.join(" "),t.attr(a,n)):t.removeAttr(a))},_openPopup:function(){this.popup&&(this.popup.visible()||(this.popup._hovered=!0),this.popup._shouldCorrectWidth=!1,this.popup.open())}});o.ui.plugin(D);var j=D.extend({init:function(t,e){var n,i=this;D.fn.init.call(i,t,e),n=i.options.position.match(/left|right/)?"horizontal":"vertical",i.dimensions=T[n],i._documentKeyDownHandler=i._documentKeyDown.bind(i),(this._isShownOnMouseEnter()||this._isShownOnClick())&&i.element.on("mouseenter"+v,i.options.filter,i._mouseenter.bind(i)),this.options.autoHide&&this._isShownOnMouseEnter()&&i.element.on("mouseleave"+v,i.options.filter,i._mouseleave.bind(i)),this.options.autoHide&&this._isShownOnFocus()&&i.element.on("blur"+v,i.options.filter,i._blur.bind(i)),o.support.touch&&i.element.on(o.support.mousedown+v,i.options.filter,i._mouseenter.bind(i))},options:{name:"Tooltip",filter:"",content:function(t){return t.target.data(o.ns+"title")},showAfter:100,callout:!0,offset:0,position:"bottom",showOn:"mouseenter",autoHide:!0,width:null,height:null,animation:{open:{effects:"fade:in",duration:0},close:{duration:40,hide:!0}}},events:[c,d,f,h,m],_mouseenter:function(o){S(t(o.currentTarget))},_saveTitle:function(t){S(t)},_appendContent:function(t){var e,n=this,r=n.options.content,p=n.content,l=n.options.iframe;s(r)&&r.url?("iframe"in n.options||(l=!u(r.url)),n.trigger(m,{options:r,target:t}),l?(p.hide(),(e=p.find("."+_)[0])?e.src=r.url||e.src:p.html(g({content:r})),p.find("."+_).off("load"+v).on("load"+v,(function(){n.trigger(f),p.show()}))):(p.empty(),o.ui.progress(p,!0),n._ajaxRequest(r))):r&&i(r)?(r=r({sender:this,target:t}),p.html(r||"")):p.html(r)},_verifyContentLoaded(){var t=this,o=t.content.find("[src]"),e=o.length,n=0;0!==e?o.on("load",(function(){n++,e===n&&t._recalculatePopupDimensions()})):t._recalculatePopupDimensions()},_ajaxRequest:function(t){var e=this;jQuery.ajax(r({type:"GET",dataType:"html",cache:!1,error:function(t,n){o.ui.progress(e.content,!1),e._recalculatePopupDimensions(),e.trigger(h,{status:n,xhr:t})},success:function(t){o.ui.progress(e.content,!1),e.content.html(t),e._verifyContentLoaded(),e.trigger(f)}.bind(e)},t))},_documentKeyDown:function(t){t.keyCode===o.keys.ESC&&this.hide()},refresh:function(){var t=this.popup;t&&t.options.anchor&&this._appendContent(t.options.anchor)},_show:function(t){var o=this,e=o.target();let n=!1;o.popup||(o._initPopup(),n=!0),e&&e[0]!=t[0]&&(o.popup.close(!0),o.popup.element.kendoStop(!0,!0)),e&&e[0]==t[0]||(o._appendContent(t),o.popup.options.anchor=t),o.popup.one("deactivate",(function(){O(t),o._removeDescribedBy(t),this.element.removeAttr("id").attr("aria-hidden",!0),p.off("keydown"+v,o._documentKeyDownHandler)})),o._openPopup(),n&&(o.options.autoHide&&this._isShownOnMouseEnter()?o.popup.wrapper.on("mouseleave"+v,o._mouseleave.bind(o)):o.popup.element.on("click"+v,".k-tooltip-button",o._closeButtonClick.bind(o)),n=!1)},_initPopup:function(){var e=this,i=e.options,s=t(o.template(w)({callout:i.callout&&"center"!==i.position,dir:y[i.position],autoHide:i.autoHide}));e.popup=new n(s,r({autosize:!0,activate:function(){e._addDescribedBy(),i.callout?e._positionCallout():e._offset(e.options.position,e.options.offset),this.element.removeAttr("aria-hidden"),p.on("keydown"+v,e._documentKeyDownHandler),e.trigger(c),e.popup._hovered=undefined},close:function(){e.trigger(d)},copyAnchorStyles:!1,animation:i.animation},k[i.position])),s.css({width:i.width,height:i.height}),e.content=s.find(".k-tooltip-content"),e.arrow=s.find(".k-callout")},_closeButtonClick:function(t){t.preventDefault(),this.hide()},_mouseleave:function(o){const e=this,n=t(o.relatedTarget).closest(".k-animation-container").length>0;let i=!t(o.relatedTarget).is(e.element);e.options.filter&&(i=i?!e.element.find(o.relatedTarget).length>0:!i);const s="center"!==e.options.position||i&&!n;clearTimeout(e.timeout),s&&(e.timeout=setTimeout((function(){e._closePopup(o.currentTarget)}),e.options.hideAfter))},_blur:function(t){this._closePopup(t.currentTarget)},_closePopup:function(o){this.popup&&!this.popup._hovered?this.popup.close():O(t(o))},destroy:function(){this.element.off(v),p.off("keydown"+v,this._documentKeyDownHandler),D.fn.destroy.call(this)}});o.ui.plugin(j)}(window.kendo.jQuery);var o=kendo;t.__meta__={id:"tooltip",name:"Tooltip",category:"web",description:"The Tooltip widget displays a popup hint for a given html element.",depends:["core","popup","icons"],features:[{id:"tooltip-fx",name:"Animation",description:"Support for animation",depends:["fx"]}]},t.default=o,Object.defineProperty(t,"__esModule",{value:!0})})); //# sourceMappingURL=kendo.tooltip.min.js.map