4
* Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
5
* and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
7
* Written by Stan Lemon <stosh1985@gmail.com>
8
* Last updated: 2013.02.14
10
* jGrowl is a jQuery plugin implementing unobtrusive userland notifications. These
11
* notifications function similarly to the Growl Framework available for
12
* Mac OS X (http://growl.info).
15
* - Move library settings to containers and allow them to be changed per container
18
* - Fixed clearing interval when the container shuts down
21
* - Added compressed versions using UglifyJS and Sqwish
22
* - Improved README with configuration options explanation
23
* - Added a source map
26
* - Fix artifacts left behind by the shutdown method and text-cleanup
29
* - Fix beforeClose to be called in click event
32
* - Fixed BC break in jQuery 2.0 beta
35
* - Fixes for jQuery 1.9 and the MSIE6 check, note that with jQuery 2.0 support
36
* jGrowl intends to drop support for IE6 altogether
39
* - Fixed js error when a notification is opening and closing at the same time
42
* - Changed wrapper jGrowl's options usage to "o" instead of $.jGrowl.defaults
43
* - Added themeState option to control 'highlight' or 'error' for jQuery UI
44
* - Ammended some CSS to provide default positioning for nested usage.
45
* - Changed some CSS to be prefixed with jGrowl- to prevent namespacing issues
46
* - Added two new options - openDuration and closeDuration to allow
47
* better control of notification open and close speeds, respectively
48
* Patch contributed by Jesse Vincet.
49
* - Added afterOpen callback. Patch contributed by Russel Branca.
52
* - Fixed IE bug with the close-all button
53
* - Fixed IE bug with the filter CSS attribute (special thanks to gotwic)
54
* - Update IE opacity CSS
55
* - Changed font sizes to use "em", and only set the base style
58
* - The callbacks no longer use the container as context, instead they use the actual notification
59
* - The callbacks now receive the container as a parameter after the options parameter
60
* - beforeOpen and beforeClose now check the return value, if it's false - the notification does
61
* not continue. The open callback will also halt execution if it returns false.
62
* - Fixed bug where containers would get confused
63
* - Expanded the pause functionality to pause an entire container.
66
* - Notification can now be theme rolled for jQuery UI, special thanks to Jeff Chan!
69
* - Fixed instance where the interval would fire the close method multiple times.
70
* - Added CSS to hide from print media
71
* - Fixed issue with closer button when div { position: relative } is set
72
* - Fixed leaking issue with multiple containers. Special thanks to Matthew Hanlon!
75
* - Added message pooling to limit the number of messages appearing at a given time.
76
* - Closing a notification is now bound to the notification object and triggered by the close button.
79
* - Added iPhone styled example
80
* - Fixed possible IE7 bug when determining if the ie6 class shoudl be applied.
81
* - Added template for the close button, so that it's content could be customized.
84
* - Fixed CSS styling bug for ie6 caused by a mispelling
85
* - Changes height restriction on default notifications to min-height
86
* - Added skinned examples using a variety of images
87
* - Added the ability to customize the content of the [close all] box
88
* - Added jTweet, an example of using jGrowl + Twitter
91
* - Multiple container and instances.
92
* - Standard $.jGrowl() now wraps $.fn.jGrowl() by first establishing a generic jGrowl container.
93
* - Instance methods of a jGrowl container can be called by $.fn.jGrowl(methodName)
94
* - Added glue preferenced, which allows notifications to be inserted before or after nodes in the container
95
* - Added new log callback which is called before anything is done for the notification
96
* - Corner's attribute are now applied on an individual notification basis.
99
* - Various CSS fixes so that jGrowl renders correctly in IE6.
102
* - Fixed bug with options persisting across notifications
103
* - Fixed theme application bug
104
* - Simplified some selectors and manipulations.
105
* - Added beforeOpen and beforeClose callbacks
106
* - Reorganized some lines of code to be more readable
107
* - Removed unnecessary this.defaults context
108
* - If corners plugin is present, it's now customizable.
109
* - Customizable open animation.
110
* - Customizable close animation.
111
* - Customizable animation easing.
112
* - Added customizable positioning (top-left, top-right, bottom-left, bottom-right, center)
115
* - All CSS styling is now external.
116
* - Added a theme parameter which specifies a secondary class for styling, such
117
* that notifications can be customized in appearance on a per message basis.
118
* - Notification life span is now customizable on a per message basis.
119
* - Added the ability to disable the global closer, enabled by default.
120
* - Added callbacks for when a notification is opened or closed.
121
* - Added callback for the global closer.
122
* - Customizable animation speed.
123
* - jGrowl now set itself up and tears itself down.
126
* - Removed dependency on metadata plugin in favor of .data()
127
* - Namespaced all events
130
/** Compatibility holdover for 1.9 to check IE6 **/
131
var $ie6 = (function(){
132
return false === $.support.boxModel && $.support.objectAll && $.support.leadingWhitespace;
135
/** jGrowl Wrapper - Establish a base jGrowl Container for compatibility with older releases. **/
136
$.jGrowl = function( m , o ) {
137
// To maintain compatibility with older version that only supported one instance we'll create the base container.
138
if ( $('#jGrowl').size() == 0 )
139
$('<div id="jGrowl"></div>').addClass( (o && o.position) ? o.position : $.jGrowl.defaults.position ).appendTo('body');
141
// Create a notification on the container.
142
$('#jGrowl').jGrowl(m,o);
146
/** Raise jGrowl Notification on a jGrowl Container **/
147
$.fn.jGrowl = function( m , o ) {
148
if ( $.isFunction(this.each) ) {
149
var args = arguments;
151
return this.each(function() {
152
/** Create a jGrowl Instance on the Container if it does not exist **/
153
if ( $(this).data('jGrowl.instance') == undefined ) {
154
$(this).data('jGrowl.instance', $.extend( new $.fn.jGrowl(), { notifications: [], element: null, interval: null } ));
155
$(this).data('jGrowl.instance').startup( this );
158
/** Optionally call jGrowl instance methods, or just raise a normal notification **/
159
if ( $.isFunction($(this).data('jGrowl.instance')[m]) ) {
160
$(this).data('jGrowl.instance')[m].apply( $(this).data('jGrowl.instance') , $.makeArray(args).slice(1) );
162
$(this).data('jGrowl.instance').create( m , o );
168
$.extend( $.fn.jGrowl.prototype , {
170
/** Default JGrowl Settings **/
176
position: 'top-right',
179
themeState: 'highlight',
183
closeDuration: 'normal',
184
openDuration: 'normal',
187
closeTemplate: '×',
188
closerTemplate: '<div>[ close all ]</div>',
190
beforeOpen: function() {},
191
afterOpen: function() {},
193
beforeClose: function() {},
194
close: function() {},
205
/** jGrowl Container Node **/
208
/** Interval Function **/
211
/** Create a Notification **/
212
create: function( message , o ) {
213
var o = $.extend({}, this.defaults, o);
215
/* To keep backward compatibility with 1.24 and earlier, honor 'speed' if the user has set it */
216
if (typeof o.speed !== 'undefined') {
217
o.openDuration = o.speed;
218
o.closeDuration = o.speed;
221
this.notifications.push({ message: message , options: o });
223
o.log.apply( this.element , [this.element,message,o] );
226
render: function( notification ) {
228
var message = notification.message;
229
var o = notification.options;
231
// Support for jQuery theme-states, if this is not used it displays a widget header
232
o.themeState = (o.themeState == '') ? '' : 'ui-state-' + o.themeState;
234
var notification = $('<div/>')
235
.addClass('jGrowl-notification ' + o.themeState + ' ui-corner-all' + ((o.group != undefined && o.group != '') ? ' ' + o.group : ''))
236
.append($('<div/>').addClass('jGrowl-close').html(o.closeTemplate))
237
.append($('<div/>').addClass('jGrowl-header').html(o.header))
238
.append($('<div/>').addClass('jGrowl-message').html(message))
239
.data("jGrowl", o).addClass(o.theme).children('div.jGrowl-close').bind("click.jGrowl", function() {
240
$(this).parent().trigger('jGrowl.beforeClose');
245
/** Notification Actions **/
246
$(notification).bind("mouseover.jGrowl", function() {
247
$('div.jGrowl-notification', self.element).data("jGrowl.pause", true);
248
}).bind("mouseout.jGrowl", function() {
249
$('div.jGrowl-notification', self.element).data("jGrowl.pause", false);
250
}).bind('jGrowl.beforeOpen', function() {
251
if ( o.beforeOpen.apply( notification , [notification,message,o,self.element] ) !== false ) {
252
$(this).trigger('jGrowl.open');
254
}).bind('jGrowl.open', function() {
255
if ( o.open.apply( notification , [notification,message,o,self.element] ) !== false ) {
256
if ( o.glue == 'after' ) {
257
$('div.jGrowl-notification:last', self.element).after(notification);
259
$('div.jGrowl-notification:first', self.element).before(notification);
262
$(this).animate(o.animateOpen, o.openDuration, o.easing, function() {
263
// Fixes some anti-aliasing issues with IE filters.
264
if ($.support.opacity === false)
265
this.style.removeAttribute('filter');
267
if ( $(this).data("jGrowl") !== null ) // Happens when a notification is closing before it's open.
268
$(this).data("jGrowl").created = new Date();
270
$(this).trigger('jGrowl.afterOpen');
273
}).bind('jGrowl.afterOpen', function() {
274
o.afterOpen.apply( notification , [notification,message,o,self.element] );
275
}).bind('jGrowl.beforeClose', function() {
276
if ( o.beforeClose.apply( notification , [notification,message,o,self.element] ) !== false )
277
$(this).trigger('jGrowl.close');
278
}).bind('jGrowl.close', function() {
279
// Pause the notification, lest during the course of animation another close event gets called.
280
$(this).data('jGrowl.pause', true);
281
$(this).animate(o.animateClose, o.closeDuration, o.easing, function() {
282
if ( $.isFunction(o.close) ) {
283
if ( o.close.apply( notification , [notification,message,o,self.element] ) !== false )
289
}).trigger('jGrowl.beforeOpen');
291
/** Optional Corners Plugin **/
292
if ( o.corners != '' && $.fn.corner != undefined ) $(notification).corner( o.corners );
294
/** Add a Global Closer if more than one notification exists **/
295
if ( $('div.jGrowl-notification:parent', self.element).size() > 1 &&
296
$('div.jGrowl-closer', self.element).size() == 0 && this.defaults.closer !== false ) {
297
$(this.defaults.closerTemplate).addClass('jGrowl-closer ' + this.defaults.themeState + ' ui-corner-all').addClass(this.defaults.theme)
298
.appendTo(self.element).animate(this.defaults.animateOpen, this.defaults.speed, this.defaults.easing)
299
.bind("click.jGrowl", function() {
300
$(this).siblings().trigger("jGrowl.beforeClose");
302
if ( $.isFunction( self.defaults.closer ) ) {
303
self.defaults.closer.apply( $(this).parent()[0] , [$(this).parent()[0]] );
309
/** Update the jGrowl Container, removing old jGrowl notifications **/
311
$(this.element).find('div.jGrowl-notification:parent').each( function() {
312
if ( $(this).data("jGrowl") != undefined && $(this).data("jGrowl").created !== undefined &&
313
($(this).data("jGrowl").created.getTime() + parseInt($(this).data("jGrowl").life)) < (new Date()).getTime() &&
314
$(this).data("jGrowl").sticky !== true &&
315
($(this).data("jGrowl.pause") == undefined || $(this).data("jGrowl.pause") !== true) ) {
317
// Pause the notification, lest during the course of animation another close event gets called.
318
$(this).trigger('jGrowl.beforeClose');
322
if ( this.notifications.length > 0 &&
323
(this.defaults.pool == 0 || $(this.element).find('div.jGrowl-notification:parent').size() < this.defaults.pool) )
324
this.render( this.notifications.shift() );
326
if ( $(this.element).find('div.jGrowl-notification:parent').size() < 2 ) {
327
$(this.element).find('div.jGrowl-closer').animate(this.defaults.animateClose, this.defaults.speed, this.defaults.easing, function() {
333
/** Setup the jGrowl Notification Container **/
334
startup: function(e) {
335
this.element = $(e).addClass('jGrowl').append('<div class="jGrowl-notification"></div>');
336
this.interval = setInterval( function() {
337
$(e).data('jGrowl.instance').update();
338
}, parseInt(this.defaults.check));
341
$(this.element).addClass('ie6');
345
/** Shutdown jGrowl, removing it and clearing the interval **/
346
shutdown: function() {
347
$(this.element).removeClass('jGrowl')
348
.find('div.jGrowl-notification').trigger('jGrowl.close')
351
clearInterval(this.interval);
355
$(this.element).find('div.jGrowl-notification').each(function(){
356
$(this).trigger('jGrowl.beforeClose');
361
/** Reference the Defaults Object for compatibility with older versions of jGrowl **/
362
$.jGrowl.defaults = $.fn.jGrowl.prototype.defaults;
b'\\ No newline at end of file'