@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.9 kB
JavaScript
!function(t){"function"==typeof define&&define.amd?define(["kendo.core.min","kendo.popup.min","kendo.icons.min"],t):t()}((function(){var t,i,n,o,e,a,s,p,c,d,l,r,u,f,h,m,g,_,k,w,v,T,b,C,P,y,A,S;t=window.kendo.jQuery,o=window.kendo,e=o.ui.Widget,a=t.extend,s=o.htmlEncode,p=window.setTimeout,c="click",d="show",l="hide",r="k-close-icon",u=".k-notification-actions .k-close-icon",f="k-hiding",h="info",m="success",g="warning",_="error",(n={}).info="info-circle",n.error="x-outline",n.warning="exclamation-circle",n.success="check-outline",k=n,w="top",v="left",T="right",b=".kendoNotification",P=(C=function(i){return function(n){var e=n.typeIcon,a=n.content;return n.closeButton,o.ui.icon(t('<span title="'+s(e)+'"></span>'),{icon:k[s(e)]||s(e)})+'<div class="k-notification-content">'+(i?s(a):a)+"</div>"}})(!1),y=C(!0),A={close:{template:o.ui.icon(t('<span aria-hidden="true" title="Hide"></span>'),{icon:"x",iconClass:r})}},S=e.extend({init:function(i,n){var a=this;e.fn.init.call(a,i,n),(n=a.options).appendTo&&t(n.appendTo).is(i)||a.element.hide(),a._compileTemplates(n.templates),a._guid="_"+o.guid(),a._isRtl=o.support.isRtl(i),a._compileStacking(n.stacking,n.position.top,n.position.left),o.notify(a)},events:[d,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(i){var n=this,e=o.template;n._compiled={},t.each(i,(function(i,o){n._compiled[o.type]=e(o.template||t("#"+o.templateId).html())})),n._defaultCompiled=e(P),n._safeCompiled=e(y)},_getCompiled:function(t,i){var n=i?this._safeCompiled:this._defaultCompiled;return t&&this._compiled[t]||n},_compileStacking:function(t,i,n){var o,e,a=this,s={paddingTop:0,paddingRight:0,paddingBottom:0,paddingLeft:0},p=null!==n?v:T;switch(t){case"down":o="bottom "+p,e="top "+p,delete s.paddingBottom;break;case T:o="top right",e="top left",delete s.paddingRight;break;case v:o="top left",e="top right",delete s.paddingLeft;break;case"up":o="top "+p,e="bottom "+p,delete s.paddingTop;break;default:null!==i?(o="bottom "+p,e="top "+p,delete s.paddingBottom):(o="top "+p,e="bottom "+p,delete s.paddingTop)}a._popupOrigin=o,a._popupPosition=e,a._popupPaddings=s},_attachPopupEvents:function(t,i){var n,o=this,e=t.allowHideAfter,a=!isNaN(e)&&e>0;function s(t){t.on(c+b,(function(){o._hidePopup(i)}))}t.hideOnClick?i.bind("activate",(function(){a?p((function(){s(i.element)}),e):s(i.element)})):t.button&&(n=i.element.find(u),a?p((function(){s(n)}),e):s(n))},_showPopup:function(i,n){var e,s,c=this,d=n.autoHideAfter,l=n.position.left,r=n.position.top;s=t("."+c._guid+":not(.k-hiding)").last(),e=new o.ui.Popup(i,{anchor:s[0]?s:document.body,origin:c._popupOrigin,position:c._popupPosition,animation:n.animation,copyAnchorStyles:!1,modal:!0,collision:"",isRtl:c._isRtl,close:function(){c._triggerHide(this.element)},deactivate:function(t){t.sender.element.off(b),t.sender.element.find(u).off(b),t.sender.destroy()}}),c._attachPopupEvents(n,e),i.removeClass("k-group k-reset"),s[0]?e.open():(null===l&&(l=t(window).width()-i.outerWidth()-n.position.right),null===r&&(r=t(window).height()-i.outerHeight()-n.position.bottom),e.open(l,r)),i.removeClass("k-popup"),e.wrapper.addClass(c._guid).css(a({margin:0,zIndex:10050},c._popupPaddings)),n.position.pinned?(e.wrapper.css("position","fixed"),s[0]&&c._togglePin(e.wrapper,!0)):s[0]||c._togglePin(e.wrapper,!1),d>0&&p((function(){c._hidePopup(e)}),d)},_hidePopup:function(t){t.wrapper.addClass(f),t.close()},_togglePin:function(i,n){var o=t(window),e=n?-1:1;i.css({top:parseInt(i.css(w),10)+e*o.scrollTop(),left:parseInt(i.css(v),10)+e*o.scrollLeft()})},_attachStaticEvents:function(t,i){var n=this,o=t.allowHideAfter,e=!isNaN(o)&&o>0;function a(t){t.on(c+b,n._hideStatic.bind(n,i))}t.hideOnClick?e?p((function(){a(i)}),o):a(i):t.button&&(e?p((function(){a(i.find(u))}),o):a(i.find(u)))},_showStatic:function(i,n){var e=this,a=n.autoHideAfter,s=n.animation,c="up"==n.stacking||n.stacking==v?"prependTo":"appendTo";e._hideTimeouts||(e._hideTimeouts=[]),i.removeClass("k-popup").addClass(e._guid)[c](n.appendTo).hide().kendoAnimate(s.open||!1),i.css("display",""),e.getNotifications().each((function(i,s){e._attachStaticEvents(n,t(s)),a>0&&!t(s).attr(o.attr("has-hidetimeout"))&&(t(s).attr(o.attr("has-hidetimeout"),!0),e._hideTimeouts.push(p((function(){e._hideStatic(t(s))}),a)))}))},_hideStatic:function(t){t.kendoAnimate(a(this.options.animation.close||!1,{complete:function(){t.off(b).find(u).off(b),t.remove()}})),this._triggerHide(t)},_triggerHide:function(t){this.trigger(l,{element:t}),this.angular("cleanup",(function(){return{elements:t}}))},show:function(n,e,s){var p,c,l=this,r=l.options,u=t('<div role="alert" aria-live="polite" class="k-notification"></div>'),f=o.guid();return e||(e=h),u.attr("aria-label",e),null!==n&&n!==i&&""!==n&&(o.isFunction(n)&&(n=n()),c={typeIcon:e,content:"",closeButton:r.button},p=t.isPlainObject(n)?a(c,n):a(c,{content:n}),u.addClass("k-notification-"+e).toggleClass("k-notification-closable",r.button).attr({"data-role":"alert",title:r.title}).css({width:r.width,height:r.height}).append(l._getCompiled(e,s)(p)),l.options.button&&u.append(l.addActions("close")),u.find(".k-notification-content").attr("id",f),u.attr("aria-describedby",f),l.angular("compile",(function(){return{elements:u,data:[{dataItem:p}]}})),t(r.appendTo)[0]?l._showStatic(u,r):l._showPopup(u,r),l.trigger(d,{element:u})),l},showText:function(t,i){this.show(t,i,!0)},info:function(t){return this.show(t,h)},success:function(t){return this.show(t,m)},warning:function(t){return this.show(t,g)},error:function(t){return this.show(t,_)},hide:function(){var i=this,n=i.getNotifications();return i.options.appendTo?(i._hideTimeouts&&i._hideTimeouts.forEach(clearTimeout),i._hideTimeouts=[],n.each((function(n,o){i._hideStatic(t(o))}))):n.each((function(n,o){var e=t(o).data("kendoPopup");e&&i._hidePopup(e)})),i},getNotifications:function(){var i=t("."+this._guid+":not(.k-hiding)");return this.options.appendTo?i:i.find(">.k-child-animation-container >.k-notification")},setOptions:function(t){var n,o=this;e.fn.setOptions.call(o,t),n=o.options,t.templates!==i&&o._compileTemplates(n.templates),t.stacking===i&&t.position===i||o._compileStacking(n.stacking,n.position.top,n.position.left)},destroy:function(){e.fn.destroy.call(this),this.getNotifications().off(b).find(u).off(b)},addActions:function(i){var n=t('<span class="k-notification-actions"/>');return Array.isArray(i)||(i=[i]),i.forEach((function(i){t(A[i].template).wrap('<span class="k-notification-action k-notification-'+i+'-action">').parent().appendTo(n)})),n}}),o.ui.plugin(S)}));
//# sourceMappingURL=kendo.notification.min.js.map