jquery.noty.min.js
9.99 KB
/*!
@package noty - jQuery Notification Plugin
@version version: 2.3.4
@contributors https://github.com/needim/noty/graphs/contributors
@documentation Examples and Documentation - http://needim.github.com/noty/
@license Licensed under the MIT licenses: http://www.opensource.org/licenses/mit-license.php
*/
if(typeof Object.create!=="function"){Object.create=function(e){function t(){}t.prototype=e;return new t}}var NotyObject={init:function(e){this.options=$.extend({},$.noty.defaults,e);this.options.layout=this.options.custom?$.noty.layouts["inline"]:$.noty.layouts[this.options.layout];if($.noty.themes[this.options.theme])this.options.theme=$.noty.themes[this.options.theme];else e.themeClassName=this.options.theme;delete e.layout;delete e.theme;this.options=$.extend({},this.options,this.options.layout.options);this.options.id="noty_"+(new Date).getTime()*Math.floor(Math.random()*1e6);this.options=$.extend({},this.options,e);this._build();return this},_build:function(){var e=$('<div class="noty_bar noty_type_'+this.options.type+'"></div>').attr("id",this.options.id);e.append(this.options.template).find(".noty_text").html(this.options.text);this.$bar=this.options.layout.parent.object!==null?$(this.options.layout.parent.object).css(this.options.layout.parent.css).append(e):e;if(this.options.themeClassName)this.$bar.addClass(this.options.themeClassName).addClass("noty_container_type_"+this.options.type);if(this.options.buttons){this.options.closeWith=[];this.options.timeout=false;var t=$("<div/>").addClass("noty_buttons");this.options.layout.parent.object!==null?this.$bar.find(".noty_bar").append(t):this.$bar.append(t);var n=this;$.each(this.options.buttons,function(e,t){var r=$("<button/>").addClass(t.addClass?t.addClass:"gray").html(t.text).attr("id",t.id?t.id:"button-"+e).appendTo(n.$bar.find(".noty_buttons")).on("click",function(e){if($.isFunction(t.onClick)){t.onClick.call(r,n,e)}})})}this.$message=this.$bar.find(".noty_message");this.$closeButton=this.$bar.find(".noty_close");this.$buttons=this.$bar.find(".noty_buttons");$.noty.store[this.options.id]=this},show:function(){var e=this;e.options.custom?e.options.custom.find(e.options.layout.container.selector).append(e.$bar):$(e.options.layout.container.selector).append(e.$bar);if(e.options.theme&&e.options.theme.style)e.options.theme.style.apply(e);$.type(e.options.layout.css)==="function"?this.options.layout.css.apply(e.$bar):e.$bar.css(this.options.layout.css||{});e.$bar.addClass(e.options.layout.addClass);e.options.layout.container.style.apply($(e.options.layout.container.selector));e.showing=true;if(e.options.theme&&e.options.theme.style)e.options.theme.callback.onShow.apply(this);if($.inArray("click",e.options.closeWith)>-1)e.$bar.css("cursor","pointer").one("click",function(t){e.stopPropagation(t);if(e.options.callback.onCloseClick){e.options.callback.onCloseClick.apply(e)}e.close()});if($.inArray("hover",e.options.closeWith)>-1)e.$bar.one("mouseenter",function(){e.close()});if($.inArray("button",e.options.closeWith)>-1)e.$closeButton.one("click",function(t){e.stopPropagation(t);e.close()});if($.inArray("button",e.options.closeWith)==-1)e.$closeButton.remove();if(e.options.callback.onShow)e.options.callback.onShow.apply(e);if(typeof e.options.animation.open=="string"){e.$bar.css("height",e.$bar.innerHeight());e.$bar.show().addClass(e.options.animation.open).one("webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend",function(){if(e.options.callback.afterShow)e.options.callback.afterShow.apply(e);e.showing=false;e.shown=true})}else{e.$bar.animate(e.options.animation.open,e.options.animation.speed,e.options.animation.easing,function(){if(e.options.callback.afterShow)e.options.callback.afterShow.apply(e);e.showing=false;e.shown=true})}if(e.options.timeout)e.$bar.delay(e.options.timeout).promise().done(function(){e.close()});return this},close:function(){if(this.closed)return;if(this.$bar&&this.$bar.hasClass("i-am-closing-now"))return;var e=this;if(this.showing){e.$bar.queue(function(){e.close.apply(e)});return}if(!this.shown&&!this.showing){var t=[];$.each($.noty.queue,function(n,r){if(r.options.id!=e.options.id){t.push(r)}});$.noty.queue=t;return}e.$bar.addClass("i-am-closing-now");if(e.options.callback.onClose){e.options.callback.onClose.apply(e)}if(typeof e.options.animation.close=="string"){e.$bar.addClass(e.options.animation.close).one("webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend",function(){if(e.options.callback.afterClose)e.options.callback.afterClose.apply(e);e.closeCleanUp()})}else{e.$bar.clearQueue().stop().animate(e.options.animation.close,e.options.animation.speed,e.options.animation.easing,function(){if(e.options.callback.afterClose)e.options.callback.afterClose.apply(e)}).promise().done(function(){e.closeCleanUp()})}},closeCleanUp:function(){var e=this;if(e.options.modal){$.notyRenderer.setModalCount(-1);if($.notyRenderer.getModalCount()==0)$(".noty_modal").fadeOut("fast",function(){$(this).remove()})}$.notyRenderer.setLayoutCountFor(e,-1);if($.notyRenderer.getLayoutCountFor(e)==0)$(e.options.layout.container.selector).remove();if(typeof e.$bar!=="undefined"&&e.$bar!==null){if(typeof e.options.animation.close=="string"){e.$bar.css("transition","all 100ms ease").css("border",0).css("margin",0).height(0);e.$bar.one("transitionend webkitTransitionEnd oTransitionEnd MSTransitionEnd",function(){e.$bar.remove();e.$bar=null;e.closed=true;if(e.options.theme.callback&&e.options.theme.callback.onClose){e.options.theme.callback.onClose.apply(e)}})}else{e.$bar.remove();e.$bar=null;e.closed=true}}delete $.noty.store[e.options.id];if(e.options.theme.callback&&e.options.theme.callback.onClose){e.options.theme.callback.onClose.apply(e)}if(!e.options.dismissQueue){$.noty.ontap=true;$.notyRenderer.render()}if(e.options.maxVisible>0&&e.options.dismissQueue){$.notyRenderer.render()}},setText:function(e){if(!this.closed){this.options.text=e;this.$bar.find(".noty_text").html(e)}return this},setType:function(e){if(!this.closed){this.options.type=e;this.options.theme.style.apply(this);this.options.theme.callback.onShow.apply(this)}return this},setTimeout:function(e){if(!this.closed){var t=this;this.options.timeout=e;t.$bar.delay(t.options.timeout).promise().done(function(){t.close()})}return this},stopPropagation:function(e){e=e||window.event;if(typeof e.stopPropagation!=="undefined"){e.stopPropagation()}else{e.cancelBubble=true}},closed:false,showing:false,shown:false};$.notyRenderer={};$.notyRenderer.init=function(e){var t=Object.create(NotyObject).init(e);if(t.options.killer)$.noty.closeAll();t.options.force?$.noty.queue.unshift(t):$.noty.queue.push(t);$.notyRenderer.render();return $.noty.returns=="object"?t:t.options.id};$.notyRenderer.render=function(){var e=$.noty.queue[0];if($.type(e)==="object"){if(e.options.dismissQueue){if(e.options.maxVisible>0){if($(e.options.layout.container.selector+" li").length<e.options.maxVisible){$.notyRenderer.show($.noty.queue.shift())}else{}}else{$.notyRenderer.show($.noty.queue.shift())}}else{if($.noty.ontap){$.notyRenderer.show($.noty.queue.shift());$.noty.ontap=false}}}else{$.noty.ontap=true}};$.notyRenderer.show=function(e){if(e.options.modal){$.notyRenderer.createModalFor(e);$.notyRenderer.setModalCount(+1)}if(e.options.custom){if(e.options.custom.find(e.options.layout.container.selector).length==0){e.options.custom.append($(e.options.layout.container.object).addClass("i-am-new"))}else{e.options.custom.find(e.options.layout.container.selector).removeClass("i-am-new")}}else{if($(e.options.layout.container.selector).length==0){$("body").append($(e.options.layout.container.object).addClass("i-am-new"))}else{$(e.options.layout.container.selector).removeClass("i-am-new")}}$.notyRenderer.setLayoutCountFor(e,+1);e.show()};$.notyRenderer.createModalFor=function(e){if($(".noty_modal").length==0){var t=$("<div/>").addClass("noty_modal").addClass(e.options.theme).data("noty_modal_count",0);if(e.options.theme.modal&&e.options.theme.modal.css)t.css(e.options.theme.modal.css);t.prependTo($("body")).fadeIn("fast");if($.inArray("backdrop",e.options.closeWith)>-1)t.on("click",function(e){$.noty.closeAll()})}};$.notyRenderer.getLayoutCountFor=function(e){return $(e.options.layout.container.selector).data("noty_layout_count")||0};$.notyRenderer.setLayoutCountFor=function(e,t){return $(e.options.layout.container.selector).data("noty_layout_count",$.notyRenderer.getLayoutCountFor(e)+t)};$.notyRenderer.getModalCount=function(){return $(".noty_modal").data("noty_modal_count")||0};$.notyRenderer.setModalCount=function(e){return $(".noty_modal").data("noty_modal_count",$.notyRenderer.getModalCount()+e)};$.fn.noty=function(e){e.custom=$(this);return $.notyRenderer.init(e)};$.noty={};$.noty.queue=[];$.noty.ontap=true;$.noty.layouts={};$.noty.themes={};$.noty.returns="object";$.noty.store={};$.noty.get=function(e){return $.noty.store.hasOwnProperty(e)?$.noty.store[e]:false};$.noty.close=function(e){return $.noty.get(e)?$.noty.get(e).close():false};$.noty.setText=function(e,t){return $.noty.get(e)?$.noty.get(e).setText(t):false};$.noty.setType=function(e,t){return $.noty.get(e)?$.noty.get(e).setType(t):false};$.noty.clearQueue=function(){$.noty.queue=[]};$.noty.closeAll=function(){$.noty.clearQueue();$.each($.noty.store,function(e,t){t.close()})};var windowAlert=window.alert;$.noty.consumeAlert=function(e){window.alert=function(t){if(e)e.text=t;else e={text:t};$.notyRenderer.init(e)}};$.noty.stopConsumeAlert=function(){window.alert=windowAlert};$.noty.defaults={layout:"top",theme:"defaultTheme",type:"alert",text:"",dismissQueue:true,template:'<div class="noty_message"><span class="noty_text"></span><div class="noty_close"></div></div>',animation:{open:{height:"toggle"},close:{height:"toggle"},easing:"swing",speed:500},timeout:false,force:false,modal:false,maxVisible:5,killer:false,closeWith:["click"],callback:{onShow:function(){},afterShow:function(){},onClose:function(){},afterClose:function(){},onCloseClick:function(){}},buttons:false};$(window).on("resize",function(){$.each($.noty.layouts,function(e,t){t.container.style.apply($(t.container.selector))})});window.noty=function(t){return jQuery.notyRenderer.init(t)}