Skip to content

Instantly share code, notes, and snippets.

@bendytree
Created October 14, 2014 22:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bendytree/dc873de0adc9200c29f8 to your computer and use it in GitHub Desktop.
Save bendytree/dc873de0adc9200c29f8 to your computer and use it in GitHub Desktop.
$(function(){
var $container = $("<div class='notify-container'></div>").appendTo($("body"));
var hide = function ($note){
$note.slideUp(function(){
$note.remove();
});
};
var show = function(data) {
var html = "<div class='notify-note'><table><tr><td class='notify-icon'></td><td class='notify-text'></td></tr></table></div>";
var $note = $(html);
$container.append($note);
//class
$note.addClass(data.cssclass);
//text
$note.find(".notify-text").text(data.msg);
//icon
if (data.icon)
$note.find(".notify-icon").html("<i class='fa "+data.icon+"'></i>");
setTimeout(function (){
hide($note);
}, 3000);
};
$container.on("click", ".notify-note", function(e){
var $note = $(e.target).closest('.notify-note');
hide($note);
});
$.notify = {
success: function(msg){
show({
msg: msg,
icon: "fa-check-circle",
cssclass: "success"
});
},
info: function(msg){
show({
msg: msg,
icon: "fa-exclamation-circle",
cssclass: "info"
});
},
warning: function(msg){
show({
msg: msg,
icon: "fa-warning",
cssclass: "warning"
});
},
danger: function(msg){
show({
msg: msg,
icon: "fa-warning",
cssclass: "danger"
});
}
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment