Skip to content

Instantly share code, notes, and snippets.

@c4urself
Created December 14, 2011 06:28
Show Gist options
  • Select an option

  • Save c4urself/1475510 to your computer and use it in GitHub Desktop.

Select an option

Save c4urself/1475510 to your computer and use it in GitHub Desktop.
jQuery notifications
define([ 'jquery' ], function($) {
$.fn.notification = function(msg_type, msg, options) {
var container = this;
var defaults = {
autoHide: true,
hideSpeed: 3000,
fadeInSpeed: 'fast',
hideOthers: true
};
var settings = $.extend({}, defaults, options);
if(settings.hideOthers) {
$('div.notification', container).remove();
}
this.each(function() {
var element = $('<div class="notification"></div>'),
close = $('<div class="close"></div>');
$(close).bind('click dblclick', function() {$(this).parent().remove();});
element.addClass(msg_type)
.append(msg)
.append(close)
.prependTo(container)
.hide()
.fadeIn(settings.fadeInSpeed);
if(settings.autoHide) {
setTimeout(function(){
element.slideUp(function() {
element.remove();
});
}, settings.hideSpeed);
}
});
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment