~ubuntu-branches/ubuntu/trusty/jgrowl/trusty-proposed

« back to all changes in this revision

Viewing changes to jquery.jgrowl.js

  • Committer: Package Import Robot
  • Author(s): Matthias Schmitz
  • Date: 2013-08-15 00:19:41 UTC
  • Revision ID: package-import@ubuntu.com-20130815001941-lubw6p6px4ey6wi4
Tags: upstream-1.2.13+dfsg
ImportĀ upstreamĀ versionĀ 1.2.13+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * jGrowl 1.2.12
 
3
 *
 
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.
 
6
 *
 
7
 * Written by Stan Lemon <stosh1985@gmail.com>
 
8
 * Last updated: 2013.02.14
 
9
 *
 
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).
 
13
 *
 
14
 * To Do:
 
15
 * - Move library settings to containers and allow them to be changed per container
 
16
 *
 
17
 * Changes in 1.2.13
 
18
 * - Fixed clearing interval when the container shuts down
 
19
 *
 
20
 * Changes in 1.2.12
 
21
 * - Added compressed versions using UglifyJS and Sqwish
 
22
 * - Improved README with configuration options explanation
 
23
 * - Added a source map
 
24
 *
 
25
 * Changes in 1.2.11
 
26
 * - Fix artifacts left behind by the shutdown method and text-cleanup
 
27
 *
 
28
 * Changes in 1.2.10
 
29
 * - Fix beforeClose to be called in click event
 
30
 *
 
31
 * Changes in 1.2.9
 
32
 * - Fixed BC break in jQuery 2.0 beta
 
33
 *
 
34
 * Changes in 1.2.8
 
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
 
37
 *
 
38
 * Changes in 1.2.6
 
39
 * - Fixed js error when a notification is opening and closing at the same time
 
40
 *
 
41
 * Changes in 1.2.5
 
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.
 
50
 *
 
51
 * Changes in 1.2.4
 
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
 
56
 *
 
57
 * Changes in 1.2.3
 
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.
 
64
 *
 
65
 * Changes in 1.2.2
 
66
 * - Notification can now be theme rolled for jQuery UI, special thanks to Jeff Chan!
 
67
 *
 
68
 * Changes in 1.2.1
 
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!
 
73
 *
 
74
 * Changes in 1.2.0
 
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.
 
77
 *
 
78
 * Changes in 1.1.2
 
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.
 
82
 *
 
83
 * Changes in 1.1.1
 
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
 
89
 *
 
90
 * Changes in 1.1.0
 
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.
 
97
 *
 
98
 * Changes in 1.0.4
 
99
 * - Various CSS fixes so that jGrowl renders correctly in IE6.
 
100
 *
 
101
 * Changes in 1.0.3
 
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)
 
113
 *
 
114
 * Changes in 1.0.2
 
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.
 
124
 *
 
125
 * Changes in 1.0.1:
 
126
 * - Removed dependency on metadata plugin in favor of .data()
 
127
 * - Namespaced all events
 
128
 */
 
129
(function($) {
 
130
        /** Compatibility holdover for 1.9 to check IE6 **/
 
131
        var $ie6 = (function(){
 
132
                return false === $.support.boxModel && $.support.objectAll && $.support.leadingWhitespace;
 
133
        })();
 
134
 
 
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');
 
140
 
 
141
                // Create a notification on the container.
 
142
                $('#jGrowl').jGrowl(m,o);
 
143
        };
 
144
 
 
145
 
 
146
        /** Raise jGrowl Notification on a jGrowl Container **/
 
147
        $.fn.jGrowl = function( m , o ) {
 
148
                if ( $.isFunction(this.each) ) {
 
149
                        var args = arguments;
 
150
 
 
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 );
 
156
                                }
 
157
 
 
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) );
 
161
                                } else {
 
162
                                        $(this).data('jGrowl.instance').create( m , o );
 
163
                                }
 
164
                        });
 
165
                };
 
166
        };
 
167
 
 
168
        $.extend( $.fn.jGrowl.prototype , {
 
169
 
 
170
                /** Default JGrowl Settings **/
 
171
                defaults: {
 
172
                        pool:                           0,
 
173
                        header:                         '',
 
174
                        group:                          '',
 
175
                        sticky:                         false,
 
176
                        position:                       'top-right',
 
177
                        glue:                           'after',
 
178
                        theme:                          'default',
 
179
                        themeState:                     'highlight',
 
180
                        corners:                        '10px',
 
181
                        check:                          250,
 
182
                        life:                           3000,
 
183
                        closeDuration:          'normal',
 
184
                        openDuration:           'normal',
 
185
                        easing:                         'swing',
 
186
                        closer:                         true,
 
187
                        closeTemplate:          '&times;',
 
188
                        closerTemplate:         '<div>[ close all ]</div>',
 
189
                        log:                            function() {},
 
190
                        beforeOpen:                     function() {},
 
191
                        afterOpen:                      function() {},
 
192
                        open:                           function() {},
 
193
                        beforeClose:            function() {},
 
194
                        close:                          function() {},
 
195
                        animateOpen:            {
 
196
                                opacity:         'show'
 
197
                        },
 
198
                        animateClose:           {
 
199
                                opacity:         'hide'
 
200
                        }
 
201
                },
 
202
 
 
203
                notifications: [],
 
204
 
 
205
                /** jGrowl Container Node **/
 
206
                element:         null,
 
207
 
 
208
                /** Interval Function **/
 
209
                interval:   null,
 
210
 
 
211
                /** Create a Notification **/
 
212
                create:  function( message , o ) {
 
213
                        var o = $.extend({}, this.defaults, o);
 
214
 
 
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;
 
219
                        }
 
220
 
 
221
                        this.notifications.push({ message: message , options: o });
 
222
 
 
223
                        o.log.apply( this.element , [this.element,message,o] );
 
224
                },
 
225
 
 
226
                render:          function( notification ) {
 
227
                        var self = this;
 
228
                        var message = notification.message;
 
229
                        var o = notification.options;
 
230
 
 
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;
 
233
 
 
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');
 
241
                                })
 
242
                                .parent();
 
243
 
 
244
 
 
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');
 
253
                                }
 
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);
 
258
                                        } else {
 
259
                                                $('div.jGrowl-notification:first', self.element).before(notification);
 
260
                                        }
 
261
 
 
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');
 
266
 
 
267
                                                if ( $(this).data("jGrowl") !== null ) // Happens when a notification is closing before it's open.
 
268
                                                        $(this).data("jGrowl").created = new Date();
 
269
 
 
270
                                                $(this).trigger('jGrowl.afterOpen');
 
271
                                        });
 
272
                                }
 
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 )
 
284
                                                        $(this).remove();
 
285
                                        } else {
 
286
                                                $(this).remove();
 
287
                                        }
 
288
                                });
 
289
                        }).trigger('jGrowl.beforeOpen');
 
290
 
 
291
                        /** Optional Corners Plugin **/
 
292
                        if ( o.corners != '' && $.fn.corner != undefined ) $(notification).corner( o.corners );
 
293
 
 
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");
 
301
 
 
302
                                                if ( $.isFunction( self.defaults.closer ) ) {
 
303
                                                        self.defaults.closer.apply( $(this).parent()[0] , [$(this).parent()[0]] );
 
304
                                                }
 
305
                                        });
 
306
                        };
 
307
                },
 
308
 
 
309
                /** Update the jGrowl Container, removing old jGrowl notifications **/
 
310
                update:  function() {
 
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) ) {
 
316
 
 
317
                                        // Pause the notification, lest during the course of animation another close event gets called.
 
318
                                        $(this).trigger('jGrowl.beforeClose');
 
319
                                }
 
320
                        });
 
321
 
 
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() );
 
325
 
 
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() {
 
328
                                        $(this).remove();
 
329
                                });
 
330
                        }
 
331
                },
 
332
 
 
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));
 
339
 
 
340
                        if ($ie6) {
 
341
                                $(this.element).addClass('ie6');
 
342
                        }
 
343
                },
 
344
 
 
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')
 
349
                                .parent().empty()
 
350
 
 
351
                        clearInterval(this.interval);
 
352
                },
 
353
 
 
354
                close:   function() {
 
355
                        $(this.element).find('div.jGrowl-notification').each(function(){
 
356
                                $(this).trigger('jGrowl.beforeClose');
 
357
                        });
 
358
                }
 
359
        });
 
360
 
 
361
        /** Reference the Defaults Object for compatibility with older versions of jGrowl **/
 
362
        $.jGrowl.defaults = $.fn.jGrowl.prototype.defaults;
 
363
 
 
364
})(jQuery);
 
 
b'\\ No newline at end of file'