estum / growlyflash

Growl-styled flash messages for Ruby on Rails and Bootstrap
MIT License
58 stars 34 forks source link

Support for triggering client side Flashes via JS #20

Closed mccormjt closed 8 years ago

mccormjt commented 8 years ago

This would be pretty easy to implement as the code is really already there. You just need to expose an interface like this (this code worked for me - btw great gem, super helpful!)

Flash = new function() { var self = this;

self.warning = function(msg) {
    flashMessage(msg, 'alert');
}

self.error = function(msg) {
    flashMessage(msg, 'error');
};

self.notice = function(msg) {
    flashMessage(msg, 'info');
}

self.success = function(msg) {
    flashMessage(msg, 'success');
}

function flashMessage(msg, type) {
    $.growlyflash(new Growlyflash.FlashStruct(msg, type))
}

}

estum commented 8 years ago

@mccormjt Done. I kept the gem's namespace by default to avoid conflicts, so shorthand methods will be available as Growlyflash.warning(msg).