Skip to content

Instantly share code, notes, and snippets.

@rmax
Created March 16, 2011 22:20
Show Gist options
  • Save rmax/873447 to your computer and use it in GitHub Desktop.
Save rmax/873447 to your computer and use it in GitHub Desktop.
(function($) {
window.FlashMessages = {
init: function() {
this.container = $("#flash-messages")
.find("a.message-close")
.fadeIn("slow")
.live("click", function() {
$(this).parent()
.fadeOut("slow", function() {
$(this).remove();
});
return false;
})
.end()
;
},
success: f("success"),
info: f("info"),
warning: f("warning"),
error: f("error")
};
function f(tag) {
return function(message) {
return li(tag, message).hide()
.prependTo(this.container).end()
.fadeIn("slow", function() {
$(this).children("a.message-close").fadeIn("slow");
})
;
};
}
function li(tag, message) {
return $("<li/>")
.addClass(tag)
.html(message)
.prepend(close())
;
}
function close() {
return $("<a/>")
.attr("href", "#")
.attr("title", "Dismiss this message")
.addClass("message-close")
.text("X")
;
}
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment