Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Display a notification. If the page is not yet ready, delay the notification until it is ready.
- * @var string message a text or html message to display
- * @var object options an object with any options for the message - optional
- * - closeButton: true to add a close button to the message (default: true)
- * - autoClose: true to close message after (closeDelay) ms (default: true)
- * - closeDelay: delay before message close (default: 8000)
- */
- var notify = function(message, options)
- {
- var block = jQuery('#notifications');
- // If ready
- if (block.length > 0)
- {
- var settings = jQuery.extend({}, notify.defaults, options);
- // Style
- var styles = [];
- if ( settings.background ) { styles.push( 'background: '+settings.background ); }
- if ( settings.color ) { styles.push( 'color: '+settings.color ); }
- var styleString = styles.length ? ' style="'+styles.join(';')+'"' : '';
- // Append message
- var closeButton = settings.closeButton ? '<span class="close-bt"></span>' : '';
- var element = jQuery('#notifications').append('<li'+styleString+'>'+message+closeButton+'</li>').children(':last-child');
- // Effect
- element.expand();
- // If closing
- if (settings.autoClose)
- {
- // Timer
- var timeoutId = setTimeout(function() { element.fadeAndRemove(); }, settings.closeDelay);
- // Prevent closing when hover
- element.hover(function()
- {
- clearTimeout(timeoutId);
- }, function()
- {
- timeoutId = setTimeout(function() { element.fadeAndRemove(); }, settings.closeDelay);
- });
- }
- }
- else
- {
- // Not ready, delay action
- setTimeout(function() { notify(message, options); }, 40);
- }
- };
- // Defaults values for the notify method
- notify.defaults = {
- closeButton: true, // Add a close button to the message
- autoClose: true, // Message will close after (closeDelay) ms
- closeDelay: 8000, // Delay before message closes
- background: null, // Background for notification
- color: null // Text color
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement