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) 6.77 kB
!function(t,o){"object"==typeof exports&&"undefined"!=typeof module?o(exports,require("kendo.tooltip.js"),require("kendo.html.button.js")):"function"==typeof define&&define.amd?define(["exports","kendo.tooltip","kendo.html.button"],o):o(((t="undefined"!=typeof globalThis?globalThis:t||self).kendo=t.kendo||{},t.kendo._globals=t.kendo._globals||{},t.kendo._globals.Popover={}))}(this,(function(t){!function(t){var o=window.kendo,e=o.ui.Popup,n=o.ui.TooltipBase,i=t.extend,r=t(document),s=".kendoPopover",a=({index:t,text:e})=>o.html.renderButton(`<button ${t}>${e}</button>`,{fillMode:"flat",themeColor:"primary"}),p=({index:t,text:e,icon:n,iconClass:i})=>o.html.renderButton(`<button ${t}>${e}</button>`,{icon:n,iconClass:"k-button-icon"+(i?` ${i}`:"")}),l=({index:t,icon:e,iconClass:n})=>o.html.renderButton(`<button ${t}></button>`,{icon:e,iconClass:"k-button-icon"+(n?` ${n}`:"")}),c=({callout:t,dir:o})=>'<div role="tooltip" class="k-popover">'+(t?'<div class="k-popover-callout k-callout-'+o+'"></div><div class="k-popover-inner"></div>':"")+"</div>",d="show",u="hide",f={top:"bottom",bottom:"top",left:"right",right:"left",center:"center"},h={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"}},m={bottom:"n",top:"s",left:"e",right:"w",center:"n"},v={mouseenter:"mouseleave",focus:"blur",focusin:"focusout"},_={horizontal:{offset:"top",size:"outerHeight"},vertical:{offset:"left",size:"outerWidth"}},g=n.extend({init:function(e,i){var r,a=this;n.fn.init.call(a,e,i),r=a.options.position.match(/left|right/)?"horizontal":"vertical",a.dimensions=_[r],a._saveTitle=t.noop,a._documentKeyDownHandler=a._documentKeyDown.bind(a),a._actionsHandler=a._actionsClick.bind(a),a.options.toggleOnClick&&a._isShownOnClick()&&a.element.on((o.support.touch?o.support.mousedown:a.options.showOn)+s,a.options.filter,a._showAction.bind(a)),a._isShownOnClick()||a.element.on(v[a.options.showOn],a.options.filter,a._dismissAction.bind(a))},options:{name:"Popover",filter:"",actions:[],actionsLayout:"center",position:"bottom",showOn:"mouseenter",toggleOnClick:!1,width:null,height:null,animation:{open:{effects:"fade:in",duration:0},close:{duration:40,hide:!0}}},events:[d,u],_addAria:function(){var t,e=this,n=e.options;e._isShownOnClick()&&e.wrapper.find("a,input,select,textarea,button").length?(e.wrapper.attr("role","dialog"),e._isDialog=!0,n.header&&(t=o.guid(),e.wrapper.attr("aria-labelledby",t).find(".k-popover-header").attr("id",t)),n.body&&(t=o.guid(),e.wrapper.attr("aria-describedby",t).find(".k-popover-body").attr("id",t))):e.wrapper.attr("role","tooltip")},_appendContent:function(t){var e=this,n=e.options,i=e.wrapper.find(".k-popover-inner"),r=e.options.template,s=()=>"";i.length?i.children().remove():e.wrapper.children(":not(.k-popover-callout)").remove(),i=i.length?i:e.wrapper,r?i.append(o.template(r)({target:t})):i.append((({header:t,actions:o,body:e,positioning:n})=>(t?'<div class="k-popover-header">'+t+"</div>":"")+`<div class="k-popover-body">${e}</div>`+(o?'<div class="k-popover-actions k-actions k-actions-horizontal k-justify-content-'+n+'">'+o+"</div>":""))({header:o.template(n.header||s)({target:t}),body:o.template(n.body||s)({target:t}),actions:e._buildActions(n.actions),positioning:n.actionsLayout}))},_actionsClick:function(e){var n=this,i=n.options.actions,r=t(e.currentTarget),s=i[parseInt(r.attr(o.attr("index")),10)];s.click&&s.click.call(n,{sender:n,target:r})},_attachActions:function(){this.wrapper.on("click"+s,".k-popover-actions .k-button",this._actionsHandler)},_dettachActions:function(){var t=this;t.wrapper&&t.wrapper.off("click"+s,t._actionsHandler)},_buildActions:function(t){if(t.length){for(var e,n="",i=0;i<t.length;i++)(e=t[i]).text&&(e.icon||e.iconClass)?n+=o.template(p)({text:e.text,index:o.attr("index")+"="+i,icon:e.icon,iconClass:e.iconClass}):!e.icon&&!e.iconClass||e.text?n+=o.template(a)({text:e.text,index:o.attr("index")+"="+i}):n+=o.template(l)({index:o.attr("index")+"="+i,icon:e.icon,iconClass:e.iconClass});return n}},_documentKeyDown:function(t){if(t.keyCode===o.keys.ESC&&(this._shown=!1,this._dismissAction()),t.keyCode===o.keys.TAB){var e=this.wrapper.find(":kendoFocusable"),n=e.first(),i=e.last();t.shiftKey?document.activeElement===n[0]&&(i.trigger("focus"),t.preventDefault()):document.activeElement===i[0]&&(n.trigger("focus"),t.preventDefault())}},_initPopup:function(){var n=this,a=n.options,p=t(o.template(c)({callout:a.callout&&"center"!==a.position,dir:m[a.position]}));n.wrapper=p,n.popup=new e(p,i({activate:function(){n._offset(n.options.position,n.options.offset,28),n._positionCallout(),n._attachActions(),r.on("keydown"+s,n._documentKeyDownHandler),n._isDialog?n.wrapper.find(":kendoFocusable").first().trigger("focus"):n._addDescribedBy(),n.trigger(d),n.popup._hovered=undefined},close:function(t){n.options.toggleOnClick&&n._shown?t.preventDefault():n.trigger(u)},copyAnchorStyles:!1,animation:a.animation},h[a.position])),p.css({width:a.width,height:a.height}),n._isShownOnMouseEnter()&&p.on("mouseleave"+s,n._dismissAction.bind(n)),n.arrow=p.find(".k-popover-callout")},_dismissAction:function(){var t=this;clearTimeout(t.timeout),t.timeout=setTimeout((function(){t.popup&&!t.popup._hovered&&t.popup.close()}),t.options.hideAfter)},_showAction:function(){var t=this;t._shown=!t._shown,t._shown||t.popup.close()},_show:function(t){var o=this,e=o.target();o.popup||o._initPopup(),e&&e[0]!=t[0]&&(o.popup.close(),o.popup.element.parent().kendoStop(!0,!0)),e&&e[0]==t[0]||(o._appendContent(t),o._addAria(),o.popup.options.anchor=t),o.popup.one("deactivate",(function(){r.off("keydown"+s,o._documentKeyDownHandler),o._isDialog||(o._removeDescribedBy(o.target()),this.element.removeAttr("id")),o._dettachActions()})),o._openPopup()},_positionCallout:function(){var t=this,o=t.options.position,e=t.popup,n=m[e.flipped?f[o]:o];t.arrow.removeClass("k-callout-s k-callout-w k-callout-e k-callout-n").addClass("k-callout-"+n)},destroy:function(){this.element.off(s),this._dettachActions(),clearTimeout(this.timeout),r.off("keydown"+s,this._documentKeyDownHandler),n.fn.destroy.call(this)}});o.ui.plugin(g)}(window.kendo.jQuery);var o=kendo;t.__meta__={id:"popover",name:"Popover",category:"web",description:"The Popover widget displays a popup with additional information for an element.",depends:["tooltip","html.button"],features:[{id:"popover-fx",name:"Animation",description:"Support for animation",depends:["fx"]}]},t.default=o,Object.defineProperty(t,"__esModule",{value:!0})})); //# sourceMappingURL=kendo.popover.min.js.map