vendor/assets/javascripts/uikit/components/notify.js in uikit-sass-rails-1.3.0 vs vendor/assets/javascripts/uikit/components/notify.js in uikit-sass-rails-1.4.0

- old
+ new

@@ -1,61 +1,68 @@ -/*! UIkit 2.11.1 | http://www.getuikit.com | (c) 2014 YOOtheme | MIT License */ +/*! UIkit 2.20.3 | http://www.getuikit.com | (c) 2014 YOOtheme | MIT License */ (function(addon) { var component; - if (jQuery && jQuery.UIkit) { - component = addon(jQuery, jQuery.UIkit); + if (window.UIkit) { + component = addon(UIkit); } if (typeof define == "function" && define.amd) { define("uikit-notify", ["uikit"], function(){ - return component || addon(jQuery, jQuery.UIkit); + return component || addon(UIkit); }); } -})(function($, UI){ +})(function(UI){ + "use strict"; + var containers = {}, messages = {}, notify = function(options){ - if ($.type(options) == 'string') { + if (UI.$.type(options) == 'string') { options = { message: options }; } if (arguments[1]) { - options = $.extend(options, $.type(arguments[1]) == 'string' ? {status:arguments[1]} : arguments[1]); + options = UI.$.extend(options, UI.$.type(arguments[1]) == 'string' ? {status:arguments[1]} : arguments[1]); } return (new Message(options)).show(); }, closeAll = function(group, instantly){ - if(group) { - for(var id in messages) { if(group===messages[id].group) messages[id].close(instantly); } + + var id; + + if (group) { + for(id in messages) { if(group===messages[id].group) messages[id].close(instantly); } } else { - for(var id in messages) { messages[id].close(instantly); } + for(id in messages) { messages[id].close(instantly); } } }; var Message = function(options){ var $this = this; - this.options = $.extend({}, Message.defaults, options); + this.options = UI.$.extend({}, Message.defaults, options); - this.uuid = "ID"+(new Date().getTime())+"RAND"+(Math.ceil(Math.random() * 100000)); - this.element = $([ + this.uuid = UI.Utils.uid("notifymsg"); + this.element = UI.$([ '<div class="uk-notify-message">', '<a class="uk-close"></a>', - '<div>'+this.options.message+'</div>', + '<div></div>', '</div>' ].join('')).data("notifyMessage", this); + this.content(this.options.message); + // status if (this.options.status) { this.element.addClass('uk-notify-message-'+this.options.status); this.currentstatus = this.options.status; } @@ -63,18 +70,22 @@ this.group = this.options.group; messages[this.uuid] = this; if(!containers[this.options.pos]) { - containers[this.options.pos] = $('<div class="uk-notify uk-notify-'+this.options.pos+'"></div>').appendTo('body').on("click", ".uk-notify-message", function(){ - $(this).data("notifyMessage").close(); + containers[this.options.pos] = UI.$('<div class="uk-notify uk-notify-'+this.options.pos+'"></div>').appendTo('body').on("click", ".uk-notify-message", function(){ + + var message = UI.$(this).data("notifyMessage"); + + message.element.trigger('manualclose.uk.notify', [message]); + message.close(); }); } }; - $.extend(Message.prototype, { + UI.$.extend(Message.prototype, { uuid: false, element: false, timout: false, currentstatus: "", @@ -113,22 +124,23 @@ var $this = this, finalize = function(){ $this.element.remove(); - if(!containers[$this.options.pos].children().length) { + if (!containers[$this.options.pos].children().length) { containers[$this.options.pos].hide(); } $this.options.onClose.apply($this, []); + $this.element.trigger('close.uk.notify', [$this]); delete messages[$this.uuid]; }; - if(this.timeout) clearTimeout(this.timeout); + if (this.timeout) clearTimeout(this.timeout); - if(instantly) { + if (instantly) { finalize(); } else { this.element.animate({"opacity":0, "margin-top": -1* this.element.outerHeight(), "margin-bottom":0}, function(){ finalize(); }); @@ -148,11 +160,11 @@ return this; }, status: function(status) { - if(!status) { + if (!status) { return this.currentstatus; } this.element.removeClass('uk-notify-message-'+this.currentstatus).addClass('uk-notify-message-'+status); @@ -174,6 +186,6 @@ UI.notify = notify; UI.notify.message = Message; UI.notify.closeAll = closeAll; return notify; -}); \ No newline at end of file +});