-
-
Save adamwdraper/2370133 to your computer and use it in GitHub Desktop.
Javascript AMD Display Notification Module
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div id="notify"> | |
<p></p> | |
<a class="close" href="#">x</a> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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