@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) • 8.18 kB
JavaScript
!function(t){"function"==typeof define&&define.amd?define(["kendo.core.min","kendo.popup.min","kendo.fx.min","kendo.icons.min"],t):t()}((function(){!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),a=e.isLocalUrl,c="_tb_active",l="aria-describedby",h="show",f="hide",d="error",m="contentLoad",_="requestStart",w="k-content-frame",g=function(o){var n=o.autoHide,i=o.callout,s=o.dir;return'<div role="tooltip" class="k-widget k-tooltip'+(n?"":" k-tooltip-closable")+'"><div class="k-tooltip-content"></div>'+(n?"":'<div class="k-tooltip-button">'+e.ui.icon(t('<a href="#" title="Close"></a>'),{icon:"x"})+"</div>")+(i?'<div class="k-callout k-callout-'+s+'"></div>':"")+"</div>"},v=e.template((function(t){return"<iframe frameborder='0' class='k-content-frame' src='"+t.content.url+"'>This page requires frames in order to show content</iframe>"})),k=".kendoTooltip",b={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"}},y={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&&!S(t);)t=t.parent()}function S(t){var o=t.data(e.ns+"title");if(o)return t.attr("title",o),t.removeData(e.ns+"title"),!0}function H(t){var o=t.attr("title");if(o)return t.data(e.ns+"title",o),t.attr("title",""),!0}function D(t){for(;t.length&&!t.is("body")&&!H(t);)t=t.parent()}var x=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){var 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/)},_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(),a=O[s.flipped?y[e]:e],c=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-"+a).css(i,c)},_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-"+y[t],a=(n||e._outerWidth(i.arrow))/2+o;i.popup.wrapper.css(u,a*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(l)&&i.push(o.attr(l)),n&&(i.push(n+c),o.attr(l,i.join(" ")),t.popup.element.attr("id",n+c))},_removeDescribedBy:function(t){var o,e,n,i=this.popup.element.attr("id"),s=t.attr(l);s&&((o=s.split(" "))&&o.length>0&&(e=o.filter((function(t){return t!==i}))),e&&e.length>0?(n=e.join(" "),t.attr(l,n)):t.removeAttr(l))},_openPopup:function(){this.popup&&(this.popup._hovered=!0,this.popup.open())}});e.ui.plugin(x);var E=x.extend({init:function(t,o){var n,i=this;x.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._isShownOnMouseEnter()&&i.element.on("mouseleave"+k,i.options.filter,i._mouseleave.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,f,m,d,_],_mouseenter:function(o){D(t(o.currentTarget))},_saveTitle:function(t){D(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=!a(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),n.angular("compile",(function(){return{elements:p}}))},_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.trigger(d,{status:n,xhr:t})},success:function(t){e.ui.progress(o.content,!1),o.content.html(t),e._outerHeight(o.popup.element)>e._outerHeight(o.popup.wrapper)&&(o.popup.wrapper.css("height",e._outerHeight(o.popup.element)+"px"),o.popup.position(),o._positionCallout()),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();o.popup||o._initPopup(),e&&e[0]!=t[0]&&(o.popup.close(),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()},_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(f)},copyAnchorStyles:!1,animation:n.animation},b[n.position])),s.css({width:n.width,height:n.height}),o.content=s.find(".k-tooltip-content"),o.arrow=s.find(".k-callout"),n.autoHide&&this._isShownOnMouseEnter()?s.on("mouseleave"+k,o._mouseleave.bind(o)):s.on("click"+k,".k-tooltip-button",o._closeButtonClick.bind(o))},_closeButtonClick:function(t){t.preventDefault(),this.hide()},_mouseleave:function(t){var o=this;clearTimeout(o.timeout),o.timeout=setTimeout((function(){o._closePopup(t.currentTarget)}),o.options.hideAfter)},_blur:function(t){this._closePopup(t.currentTarget)},_closePopup:function(o){this.popup&&!this.popup._hovered?this.popup.close():C(t(o))},destroy:function(){this.element.off(k),u.off("keydown"+k,this._documentKeyDownHandler),x.fn.destroy.call(this)}});e.ui.plugin(E)}(window.kendo.jQuery)}));
//# sourceMappingURL=kendo.tooltip.min.js.map