@progress/kendo-ui
Version:
This package is part of the [Kendo UI for jQuery](http://www.telerik.com/kendo-ui) suite.
3 lines • 7.59 kB
JavaScript
/* @license */
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`kendo.core.min.js`),require(`kendo.popup.min.js`),require(`kendo.icons.min.js`)):typeof define==`function`&&define.amd?define([`exports`,`kendo.core.min`,`kendo.popup.min`,`kendo.icons.min`],t):(e=typeof globalThis<`u`?globalThis:e||self,t((e.kendo=e.kendo||{},e.kendo._globals=e.kendo._globals||{},e.kendo._globals.Notification={}),e.kendo._globals.Core,e.kendo._globals.Popup,e.kendo._globals.Icons))})(this,function(e,t,n,r){Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});let i={id:`notification`,name:`Notification`,category:`web`,description:`The Notification widget displays user alerts.`,depends:[`core`,`popup`,`icons`],features:[{id:`notification-fx`,name:`Animation`,description:`Support for animation`,depends:[`fx`]}]};(function(e,t){var n=window.kendo,r=n.ui.Widget,i=e.extend,a=n.htmlEncode,o=window.setTimeout,s=`click`,c=`show`,l=`hide`,u=`k-notification`,d=`.k-notification-actions .k-icon`,f=`k-hiding`,p=`info`,m=`base`,h=`success`,g=`warning`,_=`error`,v={[m]:``,[p]:`info-circle`,[_]:`x-outline`,[g]:`exclamation-circle`,[h]:`check-outline`},y=`top`,b=`left`,x=`bottom`,S=`right`,C=`up`,w=`.kendoNotification`,T=`<div role="alert" aria-live="polite" class="k-notification"></div>`,E=t=>({typeIcon:r,content:i,closeButton:o})=>(r&&(v[a(r)]||a(r))?n.ui.icon(e(`<span class="k-notification-status" title="${a(r)}"></span>`),{icon:v[a(r)]||a(r)}):``)+`<div class="k-notification-content">${t?a(i):i}</div>`,D=E(!1),O=E(!0),k={close:{template:n.ui.icon(e(`<span aria-hidden="true" title="Hide"></span>`),{icon:`x`})}},A=r.extend({init:function(t,i){let a=this;r.fn.init.call(a,t,i),i&&i.button&&!i.position&&a.options.position&&(a.options.position.right=40),i=a.options,(!i.appendTo||!e(i.appendTo).is(t))&&a.element.hide(),a._compileTemplates(i.templates),a._guid=`_`+n.guid(),a._isRtl=n.support.isRtl(t),a._compileStacking(i.stacking,i.position.top,i.position.left),n.notify(a)},events:[c,l],options:{name:`Notification`,position:{pinned:!0,top:null,left:null,bottom:20,right:20},stacking:`default`,hideOnClick:!0,button:!1,allowHideAfter:0,autoHideAfter:5e3,appendTo:null,width:null,height:null,templates:[],title:null,animation:{open:{effects:`fade:in`,duration:300},close:{effects:`fade:out`,duration:600,hide:!0}}},_compileTemplates:function(t){var r=this,i=n.template;r._compiled={},e.each(t,function(t,n){r._compiled[n.type]=i(n.template||e(`#`+n.templateId).html())}),r._defaultCompiled=i(D),r._safeCompiled=i(O)},_getCompiled:function(e,t){var n=t?this._safeCompiled:this._defaultCompiled;return e&&this._compiled[e]||n},_compileStacking:function(e,t,n){var r=this,i={paddingTop:0,paddingRight:0,paddingBottom:0,paddingLeft:0},a=n===null?S:b,o,s;switch(e){case`down`:o=x+` `+a,s=y+` `+a,delete i.paddingBottom;break;case S:o=y+` `+S,s=y+` `+b,delete i.paddingRight;break;case b:o=y+` `+b,s=y+` `+S,delete i.paddingLeft;break;case C:o=y+` `+a,s=x+` `+a,delete i.paddingTop;break;default:t===null?(o=y+` `+a,s=x+` `+a,delete i.paddingTop):(o=x+` `+a,s=y+` `+a,delete i.paddingBottom);break}r._popupOrigin=o,r._popupPosition=s,r._popupPaddings=i},_attachPopupEvents:function(e,t){var n=this,r=e.allowHideAfter,i=!isNaN(r)&&r>0,a;function c(e){e.on(s+w,function(){n._hidePopup(t)})}e.hideOnClick?t.bind(`activate`,function(){i?o(function(){c(t.element)},r):c(t.element)}):e.button&&(a=t.element.find(d),i?o(function(){c(a)},r):c(a))},_showPopup:function(t,r,a){var s=this,c=r.autoHideAfter,l=r.position.left,u=r.position.top,p,m,h=r.position.right;a&&h===20?h=40:!a&&h===40&&r.button&&(h=20),m=e(`.`+s._guid+`:not(.`+f+`)`).last(),p=new n.ui.Popup(t,{anchor:m[0]?m:document.body,origin:s._popupOrigin,position:s._popupPosition,_resizeOnWrap:!0,animation:r.animation,copyAnchorStyles:!1,autosize:!0,modal:!0,collision:``,isRtl:s._isRtl,close:function(){s._triggerHide(this.element)},deactivate:function(e){e.sender.element.off(w),e.sender.element.find(d).off(w),e.sender.destroy()}}),s._attachPopupEvents(r,p),t.removeClass(`k-group k-reset k-popup`),m[0]?p.open():(l===null&&(l=e(window).width()-t.outerWidth()-h),u===null&&(u=e(window).height()-t.outerHeight()-r.position.bottom),p.open(l,u)),t.removeClass(`k-popup`),p.wrapper.addClass(s._guid).css(i({margin:0,zIndex:12e3},s._popupPaddings)),r.position.pinned?(p.wrapper.css(`position`,`fixed`),m[0]&&s._togglePin(p.wrapper,!0)):m[0]||s._togglePin(p.wrapper,!1),c>0&&o(function(){s._hidePopup(p)},c)},_hidePopup:function(e){e.wrapper.addClass(f),e.close()},_togglePin:function(t,n){var r=e(window),i=n?-1:1;t.css({top:parseInt(t.css(y),10)+i*r.scrollTop(),left:parseInt(t.css(b),10)+i*r.scrollLeft()})},_attachStaticEvents:function(e,t){var n=this,r=e.allowHideAfter,i=!isNaN(r)&&r>0;function a(e){e.on(s+w,n._hideStatic.bind(n,t))}e.hideOnClick?i?o(function(){a(t)},r):a(t):e.button&&(i?o(function(){a(t.find(d))},r):a(t.find(d)))},_showStatic:function(t,r){var i=this,a=r.autoHideAfter,s=r.animation,c=r.stacking==C||r.stacking==b?`prependTo`:`appendTo`,l;i._hideTimeouts||=[],t.removeClass(`k-popup`).addClass(i._guid)[c](r.appendTo).hide().kendoAnimate(s.open||!1),t.css(`display`,``),l=i.getNotifications(),l.each(function(t,s){i._attachStaticEvents(r,e(s)),a>0&&!e(s).attr(n.attr(`has-hidetimeout`))&&(e(s).attr(n.attr(`has-hidetimeout`),!0),i._hideTimeouts.push(o(function(){i._hideStatic(e(s))},a)))})},_hideStatic:function(e){e.kendoAnimate(i(this.options.animation.close||!1,{complete:function(){e.off(w).find(d).off(w),e.remove()}})),this._triggerHide(e)},_triggerHide:function(e){this.trigger(l,{element:e})},show:function(r,a,o){let s=this,l=s.options,d=e(T),f=n.guid(),p=u+`-`+a,h=a||``,g,_;return a||(a=m,p=``),d.attr(`aria-label`,a),r!==null&&r!==t&&r!==``&&(n.isFunction(r)&&(r=r()),_={typeIcon:h,content:``,closeButton:l.button},g=e.isPlainObject(r)?i(_,r):i(_,{content:r}),d.addClass(p).toggleClass(u+`-closable`,g.closeButton).attr({"data-role":`alert`,title:l.title}).css({width:l.width,height:l.height}).append(s._getCompiled(a,o)(g)),g.closeButton&&d.append(s.addActions(`close`)),d.find(`.k-notification-content`).attr(`id`,f),d.attr(`aria-describedby`,f),e(l.appendTo)[0]?s._showStatic(d,l):s._showPopup(d,l,g.closeButton),s.trigger(c,{element:d})),s},showText:function(e,t){this.show(e,t,!0)},info:function(e){return this.show(e,p)},success:function(e){return this.show(e,h)},warning:function(e){return this.show(e,g)},error:function(e){return this.show(e,_)},hide:function(){var t=this,n=t.getNotifications();return t.options.appendTo?(t._hideTimeouts&&t._hideTimeouts.forEach(clearTimeout),t._hideTimeouts=[],n.each(function(n,r){t._hideStatic(e(r))})):n.each(function(n,r){var i=e(r).data(`kendoPopup`);i&&t._hidePopup(i)}),t},getNotifications:function(){var t=this,n=e(`.`+t._guid+`:not(.`+f+`)`);return t.options.appendTo?n:n.find(`>.k-child-animation-container >.`+u)},setOptions:function(e){var n=this,i;r.fn.setOptions.call(n,e),i=n.options,e.templates!==t&&n._compileTemplates(i.templates),(e.stacking!==t||e.position!==t)&&n._compileStacking(i.stacking,i.position.top,i.position.left)},destroy:function(){r.fn.destroy.call(this),this.getNotifications().off(w).find(d).off(w)},addActions:function(t){var n=e(`<span class="k-notification-actions"/>`);return Array.isArray(t)||(t=[t]),t.forEach(function(t){e(k[t].template).wrap(`<span class="k-notification-action k-notification-${t}-action">`).parent().appendTo(n)}),n}});n.ui.plugin(A)})(window.kendo.jQuery);var a=kendo;e.__meta__=i,e.default=a});
//# sourceMappingURL=kendo.notification.min.js.map