app/assets/javascripts/voltron-flash.js in voltron-flash-0.1.5 vs app/assets/javascripts/voltron-flash.js in voltron-flash-0.1.6

- old
+ new

@@ -36,30 +36,32 @@ this.afterConfigChange(); return this; }, addListener: function(){ + var self = this; $(document).ajaxComplete(function(event, request){ - if(_defaults.autoAdd){ - var flashes = request.getResponseHeader(Voltron.getConfig('flash/header', 'X-Flash')); - var flash = $.parseJSON(flashes); - if(flash){ - Voltron('Flash/new', flash); - } + var flashes = request.getResponseHeader(Voltron.getConfig('flash/header', 'X-Flash')); + var flash = $.parseJSON(flashes); + Voltron.dispatch('flash:received', { event: event, request: request, flash: self, flashes: flash }); + if(_defaults.autoAdd && flash){ + Voltron('Flash/new', flash); } }); }, new: function(flashes, options){ options = $.extend(_defaults, options); var flash; - this.getContainer(options).addClass(options.class); + this.getContainer(options).addClass(options.containerClass); $.each(flashes, $.proxy(function(type, messages){ flash = this.addFlash(type, messages, options); + flash.addClass(options.class); + if(flash.find('.flash-message').length == 1){ // If this is the first flash message, reveal the whole container flash.find('.flash-message').show(); flash[options.revealMethod](options.revealTime); }else{ @@ -76,11 +78,11 @@ return this; }, addFlash: function(type, messages, options){ - var flash = this.getFlash(type); + var flash = this.getFlash(type, options); flash.append($.map($.makeArray(messages), function(message){ return $('<p />', { class: 'flash-message' }).html(message).hide(); })); @@ -94,11 +96,11 @@ this.getContainer(options).append(flash); return flash; }, - getFlash: function(type){ + getFlash: function(type, options){ if(Voltron.getConfig('flash/group') && $('.flash.' + type).length){ return $('.flash.' + type).first(); } return $('<div />', { class: ['flash', type].join(' ') }).hide(); }, @@ -133,10 +135,10 @@ if($('#' + o.options.id).find('.flash').length == 0){ $('#' + o.options.id).remove(); } }); }else{ - // .clear() was called preumably with no arguments, + // .clear() was called presumably with no arguments, // in which case hide and remove the entire flashes container element options = $.extend(_defaults, options); $('#' + options.id)[options.concealMethod](options.concealTime, function(){ $(this).remove(); });