/** * jGrowl 1.0.1 * by Stan Lemon * Last updated: 2008.03.20 * * jGrowl is a jQuery plugin implementing basic userland notifications. These * notifications appear in a manner similar to the Growl plugin available for * the Mac OS X operating system (http://growl.info). * * Changes in 1.0.1: * - Removed dependency on metadata plugin in favor of .data() * - Namespaced all events * * @todo Fix IE6 position: fixed problem * @todo Make animations customizable * @todo Add callbacks for jGrowl events, ie. a notification is opened or close, * the close all button is triggered, etc. * @todo Sort by header and then by creation. * @todo Option to disable javascript CSS styling. */ (function($) { /** Raise jGrowl Notifications **/ $.jGrowl = function( message , options ) { var options = $.extend({ sticky: false, css: {} }, options || {}); options.css = $.extend({ backgroundColor: '#000', color: '#fff', opacity: '.85', width: '235px', minHeight: '40px', padding: '10px', margin: '5px', fontFamily: 'Tahoma, Arial, Helvetica, sans-serif', fontSize: '12px', textAlign: 'left' }, options.css || {}); var closer = $('
×
').css({ styleFloat : 'right' , fontWeight : 'bold' , fontSize : '12px' , cursor : 'pointer' }).bind("click.jGrowl", function() { $(this).unbind('click.jGrowl').parent().fadeOut('normal', function() { $(this).remove(); }); }); var now = new Date(); var notification = $('
' + message + '
').css({ display: 'none' }).prepend( closer ).data("jGrowl", { created: now.getTime(), sticky: options.sticky }); if ( options.header != undefined ) var header = $('' + options.header + '').css({ fontSize : '10px' }).append('
').insertAfter( notification.children() ); if ($('div#jGrowl').children('div.jGrowl').size() == 0) { $('div#jGrowl').append( notification ); } else { $('div#jGrowl div.jGrowl:last').after( notification ); }; $('div#jGrowl div.jGrowl:last').css( options.css ).fadeIn('slow').bind("mouseover.jGrowl", function() { $(this).data("jGrowl").pause = true; }).bind("mouseout.jGrowl", function() { $(this).data("jGrowl").pause = false; }); // If the jQuery Corner's plugin is loaded, use it! if ( $.fn.corner != undefined ) $('div#jGrowl').children().corner('10px'); if ($('div#jGrowl div.jGrowl').size() > 1 && $('div#jGrowl div.closer').size() == 0) { var closeAll = $("
[ close all ]
").css( options.css ).css({ minHeight: '10px', paddingTop: '4px', paddingBottom: '4px', cursor: 'pointer', display: 'none' , fontSize: '11px', fontWeight: 'bold', textAlign: 'center' }).fadeIn('slow').bind("click.jGrowl", function() { $(this).siblings().andSelf().fadeOut('slow', function() { $(this).children('div.close').trigger("click.jGrowl"); });; }); $('div#jGrowl div.jGrowl:last').after(closeAll); }; }; /** Default JGrowl Settings **/ $.jGrowl.defaults = { autostart: true, check: 3000, life: 1000 }; /** Store the Interval Method Here **/ $.jGrowl.interval = null; /** Update the jGrowl Container, removing old jGrowl notifications **/ $.jGrowl.update = function() { // No message being raised, we're just updating the jGrowl container. if ( $('div#jGrowl div.jGrowl').size() != 0 ) { var now = new Date(); $.each( $('div#jGrowl').children() , function( key , value) { if ( $(value).data("jGrowl") != undefined && ($(value).data("jGrowl").created + $.jGrowl.defaults.life) < now.getTime() && $(value).data("jGrowl").sticky != true && ($(value).data("jGrowl").pause == undefined || $(value).data("jGrowl").pause != true) ) { $(value).fadeOut('slow', function() { $(this).children('div.close').click(); }); } }); }; if ( $('div#jGrowl div.jGrowl').size() < 2 && $('div#jGrowl div.closer').size() > 0) { $('div#jGrowl div.closer').fadeOut('slow', function() { $(this).remove(); }); }; }; /** Setup the jGrowl Notification Container **/ $.jGrowl.setup = function() { // Create the jGrowl Container Node $('body').append('
'); // Set basic style information for the jGrowl Container $('div#jGrowl').css({ padding: '10px', zIndex: '999', right: '0px', top: '0px' }); // If you're running in IE: // Add the following to a stylesheet on your page: // // div#jGrowl { // _position: absolute; // _top: expression(eval(document.body.scrollTop)); // } // // Also... make sure you trick the browser into quirks mode! Before IE7 this can be accomplished by // moving the before // the doctype and that will work for both IE6 and IE7. In strict mode the above hack will not work. // if ( !$.browser.msie ) $('div#jGrowl').css('position', 'fixed'); $.jGrowl.interval = setInterval( "jQuery.jGrowl.update()" , $.jGrowl.defaults.check ); }; /** Automatically Start jGrowl **/ if ( $.jGrowl.defaults.autostart == true ) { $(document).ready( $.jGrowl.setup ); }; })(jQuery);