UNPKG

kendo-ui-core

Version:
3 lines (2 loc) 9.02 kB
!function(t,o){"object"==typeof exports&&"undefined"!=typeof module?module.exports=o(require("kendo.core.js"),require("kendo.popup.js"),require("kendo.fx.js"),require("kendo.icons.js")):"function"==typeof define&&define.amd?define(["kendo.core.min","kendo.popup.min","kendo.fx.min","kendo.icons.min"],o):((t="undefined"!=typeof globalThis?globalThis:t||self).kendotooltip=t.kendotooltip||{},t.kendotooltip.js=o())}(this,(function(){return function(t,o){var e=window.kendo,n=e.ui.Widget,i=e.ui.Popup,s=e.isFunction,r=t.isPlainObject,p=t.extend,u=t(document),l=e.isLocalUrl,a="_tb_active",c="aria-describedby",h="show",d="hide",f="error",m="contentLoad",_="requestStart",w="k-content-frame",g=({autoHide:o,callout:n,dir:i})=>`<div role="tooltip" class="k-tooltip${o?"":" k-tooltip-closable"}"><div class="k-tooltip-content"></div>`+(o?"":`<div class="k-tooltip-button">${e.ui.icon(t('<span title="Close"></span>'),{icon:"x"})}</div>`)+(n?`<div class="k-callout k-callout-${i}"></div>`:"")+"</div>",v=e.template((({content:t})=>`<iframe frameborder='0' class='${w}' src='${t.url}'>This page requires frames in order to show content</iframe>`)),k=".kendoTooltip",y={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"},O={bottom:"n",top:"s",left:"e",right:"w",center:"n"},T={horizontal:{offset:"top",size:"outerHeight"},vertical:{offset:"left",size:"outerWidth"}};function C(t){for(;t.length&&!D(t);)t=t.parent()}function D(t){var o=t.data(e.ns+"title");if(o)return t.attr("title",o),t.removeData(e.ns+"title"),!0}function S(t){var o=t.attr("title");if(o)return t.data(e.ns+"title",o),t.attr("title",""),!0}function x(t){for(;t.length&&!t.is("body")&&!S(t);)t=t.parent()}var j=n.extend({init:function(t,o){var i,s=this;n.fn.init.call(s,t,o),i=s.options.position.match(/left|right/)?"horizontal":"vertical",s.dimensions=T[i],e.support.touch&&this._isShownOnMouseEnter()&&s.element.on(e.support.mousedown+k,s.options.filter,s._showOn.bind(s)),s.element.on(s.options.showOn+k,s.options.filter,s._showOn.bind(s)),"click"===s.options.showOn&&s.element.on("keydown"+k,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(k),t.destroy()),clearTimeout(this.timeout),n.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(o){var n=t(o.currentTarget);o.keyCode==e.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",e._outerHeight(t.popup.element)+"px"),t.popup.wrapper.css("width",e._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=O[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,o,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||e._outerWidth(i.arrow))/2+o;i.popup.wrapper.css(u,l*p+"px")},_addDescribedBy:function(){var t=this,o=t.popup.options.anchor,n=o[0].id||t.element[0].id||e.guid(),i=[];o.attr(c)&&i.push(o.attr(c)),n&&(i.push(n+a),o.attr(c,i.join(" ")),t.popup.element.attr("id",n+a))},_removeDescribedBy:function(t){var o,e,n,i=this.popup.element.attr("id"),s=t.attr(c);s&&((o=s.split(" "))&&o.length>0&&(e=o.filter((function(t){return t!==i}))),e&&e.length>0?(n=e.join(" "),t.attr(c,n)):t.removeAttr(c))},_openPopup:function(){this.popup&&(this.popup.visible()||(this.popup._hovered=!0),this.popup._shouldCorrectWidth=!1,this.popup.open())}});e.ui.plugin(j);var H=j.extend({init:function(t,o){var n,i=this;j.fn.init.call(i,t,o),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"+k,i.options.filter,i._mouseenter.bind(i)),this.options.autoHide&&this._isShownOnFocus()&&i.element.on("blur"+k,i.options.filter,i._blur.bind(i)),e.support.touch&&i.element.on(e.support.mousedown+k,i.options.filter,i._mouseenter.bind(i))},options:{name:"Tooltip",filter:"",content:function(t){return t.target.data(e.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:[h,d,m,f,_],_mouseenter:function(o){x(t(o.currentTarget))},_saveTitle:function(t){x(t)},_appendContent:function(t){var o,n=this,i=n.options.content,p=n.content,u=n.options.iframe;r(i)&&i.url?("iframe"in n.options||(u=!l(i.url)),n.trigger(_,{options:i,target:t}),u?(p.hide(),(o=p.find("."+w)[0])?o.src=i.url||o.src:p.html(v({content:i})),p.find("."+w).off("load"+k).on("load"+k,(function(){n.trigger(m),p.show()}))):(p.empty(),e.ui.progress(p,!0),n._ajaxRequest(i))):i&&s(i)?(i=i({sender:this,target:t}),p.html(i||"")):p.html(i)},_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 o=this;jQuery.ajax(p({type:"GET",dataType:"html",cache:!1,error:function(t,n){e.ui.progress(o.content,!1),o._recalculatePopupDimensions(),o.trigger(f,{status:n,xhr:t})},success:function(t){e.ui.progress(o.content,!1),o.content.html(t),o._verifyContentLoaded(),o.trigger(m)}.bind(o)},t))},_documentKeyDown:function(t){t.keyCode===e.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(){C(t),o._removeDescribedBy(t),this.element.removeAttr("id").attr("aria-hidden",!0),u.off("keydown"+k,o._documentKeyDownHandler)})),o._openPopup(),this.options.autoHide&&this._isShownOnMouseEnter()&&(t.on("mouseleave"+k,o._mouseleave.bind(o)),o._target=t),n&&(o.options.autoHide&&this._isShownOnMouseEnter()?o.popup.wrapper.on("mouseleave"+k,o._mouseleave.bind(o)):o.popup.element.on("click"+k,".k-tooltip-button",o._closeButtonClick.bind(o)),n=!1)},_initPopup:function(){var o=this,n=o.options,s=t(e.template(g)({callout:n.callout&&"center"!==n.position,dir:O[n.position],autoHide:n.autoHide}));o.popup=new i(s,p({autosize:!0,activate:function(){o._addDescribedBy(),n.callout?o._positionCallout():o._offset(o.options.position,o.options.offset),this.element.removeAttr("aria-hidden"),u.on("keydown"+k,o._documentKeyDownHandler),o.trigger(h),o.popup._hovered=undefined},close:function(){o.trigger(d)},copyAnchorStyles:!1,animation:n.animation},y[n.position])),s.css({width:n.width,height:n.height}),o.content=s.find(".k-tooltip-content"),o.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(),t(this._target).off("mouseleave"+k)):C(t(o))},destroy:function(){this.element.off(k),u.off("keydown"+k,this._documentKeyDownHandler),j.fn.destroy.call(this)}});e.ui.plugin(H)}(window.kendo.jQuery),kendo})); //# sourceMappingURL=kendo.tooltip.min.js.map