Skip to content

Instantly share code, notes, and snippets.

@adamwdraper
Created April 12, 2012 19:02
Show Gist options
  • Save adamwdraper/2370133 to your computer and use it in GitHub Desktop.
Save adamwdraper/2370133 to your computer and use it in GitHub Desktop.
Javascript AMD Display Notification Module
<div id="notify">
<p></p>
<a class="close" href="#">x</a>
</div>
define([
'jQuery',
], function ($) {
var Notify = function() {};
Notify.prototype.show = function(element, message, time) {
var self = this;
$(element + ' p').html(message);
$(element).fadeIn('fast');
if(time === undefined) {
time = 3000;
}
if(time > 0) {
setTimeout(function() {
self.hide(element);
}, time);
}
$(element + ' .close').on('click', function(e) {
self.hide(element);
e.preventDefault();
return false;
});
}
Notify.prototype.hide = function(element, clear) {
if($(element).is(':visible')) {
$(element).fadeOut('slow');
}
if(clear) {
$(element + ' p').html('');
}
}
return new Notify;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment