|
135 | 135 | /** jGrowl Wrapper - Establish a base jGrowl Container for compatibility with older releases. **/ |
136 | 136 | $.jGrowl = function( m , o ) { |
137 | 137 | // To maintain compatibility with older version that only supported one instance we'll create the base container. |
138 | | - if ( $('#jGrowl').size() == 0 ) |
| 138 | + if ( $('#jGrowl').size() === 0 ) |
139 | 139 | $('<div id="jGrowl"></div>').addClass( (o && o.position) ? o.position : $.jGrowl.defaults.position ).appendTo('body'); |
140 | 140 |
|
141 | 141 | // Create a notification on the container. |
|
150 | 150 |
|
151 | 151 | return this.each(function() { |
152 | 152 | /** Create a jGrowl Instance on the Container if it does not exist **/ |
153 | | - if ( $(this).data('jGrowl.instance') == undefined ) { |
| 153 | + if ( $(this).data('jGrowl.instance') === undefined ) { |
154 | 154 | $(this).data('jGrowl.instance', $.extend( new $.fn.jGrowl(), { notifications: [], element: null, interval: null } )); |
155 | 155 | $(this).data('jGrowl.instance').startup( this ); |
156 | 156 | } |
|
162 | 162 | $(this).data('jGrowl.instance').create( m , o ); |
163 | 163 | } |
164 | 164 | }); |
165 | | - }; |
| 165 | + } |
166 | 166 | }; |
167 | 167 |
|
168 | 168 | $.extend( $.fn.jGrowl.prototype , { |
|
173 | 173 | header: '', |
174 | 174 | group: '', |
175 | 175 | sticky: false, |
176 | | - position: 'top-right', |
| 176 | + position: 'top-right', |
177 | 177 | glue: 'after', |
178 | 178 | theme: 'default', |
179 | 179 | themeState: 'highlight', |
180 | 180 | corners: '10px', |
181 | 181 | check: 250, |
182 | 182 | life: 3000, |
183 | | - closeDuration: 'normal', |
184 | | - openDuration: 'normal', |
185 | | - easing: 'swing', |
186 | | - closer: true, |
187 | | - closeTemplate: '×', |
188 | | - closerTemplate: '<div>[ close all ]</div>', |
| 183 | + closeDuration: 'normal', |
| 184 | + openDuration: 'normal', |
| 185 | + easing: 'swing', |
| 186 | + closer: true, |
| 187 | + closeTemplate: '×', |
| 188 | + closerTemplate: '<div>[ close all ]</div>', |
189 | 189 | log: function() {}, |
190 | 190 | beforeOpen: function() {}, |
191 | 191 | afterOpen: function() {}, |
192 | 192 | open: function() {}, |
193 | | - beforeClose: function() {}, |
| 193 | + beforeClose: function() {}, |
194 | 194 | close: function() {}, |
195 | | - animateOpen: { |
196 | | - opacity: 'show' |
| 195 | + animateOpen: { |
| 196 | + opacity: 'show' |
197 | 197 | }, |
198 | | - animateClose: { |
199 | | - opacity: 'hide' |
| 198 | + animateClose: { |
| 199 | + opacity: 'hide' |
200 | 200 | } |
201 | 201 | }, |
202 | 202 |
|
203 | 203 | notifications: [], |
204 | 204 |
|
205 | 205 | /** jGrowl Container Node **/ |
206 | | - element: null, |
| 206 | + element: null, |
207 | 207 |
|
208 | 208 | /** Interval Function **/ |
209 | | - interval: null, |
| 209 | + interval: null, |
210 | 210 |
|
211 | 211 | /** Create a Notification **/ |
212 | | - create: function( message , o ) { |
213 | | - var o = $.extend({}, this.defaults, o); |
| 212 | + create: function( message , options ) { |
| 213 | + var o = $.extend({}, this.defaults, options); |
214 | 214 |
|
215 | 215 | /* To keep backward compatibility with 1.24 and earlier, honor 'speed' if the user has set it */ |
216 | 216 | if (typeof o.speed !== 'undefined') { |
|
223 | 223 | o.log.apply( this.element , [this.element,message,o] ); |
224 | 224 | }, |
225 | 225 |
|
226 | | - render: function( notification ) { |
| 226 | + render: function( n ) { |
227 | 227 | var self = this; |
228 | | - var message = notification.message; |
229 | | - var o = notification.options; |
| 228 | + var message = n.message; |
| 229 | + var o = n.options; |
230 | 230 |
|
231 | 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; |
| 232 | + o.themeState = (o.themeState === '') ? '' : 'ui-state-' + o.themeState; |
233 | 233 |
|
234 | 234 | var notification = $('<div/>') |
235 | | - .addClass('jGrowl-notification ' + o.themeState + ' ui-corner-all' + ((o.group != undefined && o.group != '') ? ' ' + o.group : '')) |
| 235 | + .addClass('jGrowl-notification ' + o.themeState + ' ui-corner-all' + ((o.group !== undefined && o.group !== '') ? ' ' + o.group : '')) |
236 | 236 | .append($('<div/>').addClass('jGrowl-close').html(o.closeTemplate)) |
237 | 237 | .append($('<div/>').addClass('jGrowl-header').html(o.header)) |
238 | 238 | .append($('<div/>').addClass('jGrowl-message').html(message)) |
|
289 | 289 | }).trigger('jGrowl.beforeOpen'); |
290 | 290 |
|
291 | 291 | /** Optional Corners Plugin **/ |
292 | | - if ( o.corners != '' && $.fn.corner != undefined ) $(notification).corner( o.corners ); |
| 292 | + if ( o.corners !== '' && $.fn.corner !== undefined ) $(notification).corner( o.corners ); |
293 | 293 |
|
294 | 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 ) { |
| 295 | + if ($('div.jGrowl-notification:parent', self.element).size() > 1 && |
| 296 | + $('div.jGrowl-closer', self.element).size() === 0 && this.defaults.closer !== false ) { |
297 | 297 | $(this.defaults.closerTemplate).addClass('jGrowl-closer ' + this.defaults.themeState + ' ui-corner-all').addClass(this.defaults.theme) |
298 | 298 | .appendTo(self.element).animate(this.defaults.animateOpen, this.defaults.speed, this.defaults.easing) |
299 | 299 | .bind("click.jGrowl", function() { |
|
303 | 303 | self.defaults.closer.apply( $(this).parent()[0] , [$(this).parent()[0]] ); |
304 | 304 | } |
305 | 305 | }); |
306 | | - }; |
| 306 | + } |
307 | 307 | }, |
308 | 308 |
|
309 | 309 | /** Update the jGrowl Container, removing old jGrowl notifications **/ |
310 | | - update: function() { |
| 310 | + update: function() { |
311 | 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) ) { |
| 312 | + if ($(this).data("jGrowl") !== undefined && $(this).data("jGrowl").created !== undefined && |
| 313 | + ($(this).data("jGrowl").created.getTime() + parseInt($(this).data("jGrowl").life, 10)) < (new Date()).getTime() && |
| 314 | + $(this).data("jGrowl").sticky !== true && |
| 315 | + ($(this).data("jGrowl.pause") === undefined || $(this).data("jGrowl.pause") !== true) ) { |
316 | 316 |
|
317 | 317 | // Pause the notification, lest during the course of animation another close event gets called. |
318 | 318 | $(this).trigger('jGrowl.beforeClose'); |
319 | 319 | } |
320 | 320 | }); |
321 | 321 |
|
322 | | - if ( this.notifications.length > 0 && |
323 | | - (this.defaults.pool == 0 || $(this.element).find('div.jGrowl-notification:parent').size() < this.defaults.pool) ) |
| 322 | + if (this.notifications.length > 0 && |
| 323 | + (this.defaults.pool === 0 || $(this.element).find('div.jGrowl-notification:parent').size() < this.defaults.pool) ) |
324 | 324 | this.render( this.notifications.shift() ); |
325 | 325 |
|
326 | | - if ( $(this.element).find('div.jGrowl-notification:parent').size() < 2 ) { |
| 326 | + if ($(this.element).find('div.jGrowl-notification:parent').size() < 2 ) { |
327 | 327 | $(this.element).find('div.jGrowl-closer').animate(this.defaults.animateClose, this.defaults.speed, this.defaults.easing, function() { |
328 | 328 | $(this).remove(); |
329 | 329 | }); |
330 | 330 | } |
331 | 331 | }, |
332 | 332 |
|
333 | 333 | /** Setup the jGrowl Notification Container **/ |
334 | | - startup: function(e) { |
| 334 | + startup: function(e) { |
335 | 335 | this.element = $(e).addClass('jGrowl').append('<div class="jGrowl-notification"></div>'); |
336 | 336 | this.interval = setInterval( function() { |
337 | 337 | $(e).data('jGrowl.instance').update(); |
338 | | - }, parseInt(this.defaults.check)); |
| 338 | + }, parseInt(this.defaults.check, 10)); |
339 | 339 |
|
340 | 340 | if ($ie6) { |
341 | 341 | $(this.element).addClass('ie6'); |
342 | 342 | } |
343 | 343 | }, |
344 | 344 |
|
345 | 345 | /** Shutdown jGrowl, removing it and clearing the interval **/ |
346 | | - shutdown: function() { |
| 346 | + shutdown: function() { |
347 | 347 | $(this.element).removeClass('jGrowl') |
348 | 348 | .find('div.jGrowl-notification').trigger('jGrowl.close') |
349 | 349 | .parent().empty() |
| 350 | + ; |
350 | 351 |
|
351 | 352 | clearInterval(this.interval); |
352 | 353 | }, |
353 | 354 |
|
354 | | - close: function() { |
| 355 | + close: function() { |
355 | 356 | $(this.element).find('div.jGrowl-notification').each(function(){ |
356 | 357 | $(this).trigger('jGrowl.beforeClose'); |
357 | 358 | }); |
|
0 commit comments