Created
December 14, 2011 06:28
-
-
Save c4urself/1475510 to your computer and use it in GitHub Desktop.
jQuery notifications
This file contains hidden or 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($) { | |
| $.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