forked from sciactive/pnotify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpnotify.core.js
789 lines (744 loc) · 25.2 KB
/
pnotify.core.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
/*
PNotify 2.0.1 sciactive.com/pnotify/
(C) 2014 Hunter Perrin
license GPL/LGPL/MPL
*/
/*
* ====== PNotify ======
*
* http://sciactive.com/pnotify/
*
* Copyright 2009-2014 Hunter Perrin
*
* Triple licensed under the GPL, LGPL, and MPL.
* http://gnu.org/licenses/gpl.html
* http://gnu.org/licenses/lgpl.html
* http://mozilla.org/MPL/MPL-1.1.html
*/
// Uses AMD or browser globals for jQuery.
(function (factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as a module.
define('pnotify', ['jquery'], factory);
} else {
// Browser globals
factory(jQuery);
}
}(function($){
var default_stack = {
dir1: "down",
dir2: "left",
push: "bottom",
spacing1: 25,
spacing2: 25,
context: $("body")
};
var timer, // Position all timer.
body,
jwindow = $(window);
// Set global variables.
var do_when_ready = function(){
body = $("body");
PNotify.prototype.options.stack.context = body;
jwindow = $(window);
// Reposition the notices when the window resizes.
jwindow.bind('resize', function(){
if (timer)
clearTimeout(timer);
timer = setTimeout(function(){ PNotify.positionAll(true) }, 10);
});
};
PNotify = function(options){
this.parseOptions(options);
this.init();
};
$.extend(PNotify.prototype, {
// The current version of PNotify.
version: "2.0.1",
// === Options ===
// Options defaults.
options: {
// The notice's title.
title: false,
// Whether to escape the content of the title. (Not allow HTML.)
title_escape: false,
// The notice's text.
text: false,
// Whether to escape the content of the text. (Not allow HTML.)
text_escape: false,
// What styling classes to use. (Can be either jqueryui or bootstrap.)
styling: "bootstrap3",
// Additional classes to be added to the notice. (For custom styling.)
addclass: "",
// Class to be added to the notice for corner styling.
cornerclass: "",
// Display the notice when it is created.
auto_display: true,
// Width of the notice.
width: "300px",
// Minimum height of the notice. It will expand to fit content.
min_height: "16px",
// Type of the notice. "notice", "info", "success", or "error".
type: "notice",
// Set icon to true to use the default icon for the selected
// style/type, false for no icon, or a string for your own icon class.
icon: true,
// Opacity of the notice.
opacity: 1,
// The animation to use when displaying and hiding the notice. "none",
// "show", "fade", and "slide" are built in to jQuery. Others require jQuery
// UI. Use an object with effect_in and effect_out to use different effects.
animation: "fade",
// Speed at which the notice animates in and out. "slow", "def" or "normal",
// "fast" or number of milliseconds.
animate_speed: "slow",
// Specify a specific duration of position animation
position_animate_speed: 500,
// Display a drop shadow.
shadow: true,
// After a delay, remove the notice.
hide: true,
// Delay in milliseconds before the notice is removed.
delay: 8000,
// Reset the hide timer if the mouse moves over the notice.
mouse_reset: true,
// Remove the notice's elements from the DOM after it is removed.
remove: true,
// Change new lines to br tags.
insert_brs: true,
// Whether to remove notices from the global array.
destroy: true,
// The stack on which the notices will be placed. Also controls the
// direction the notices stack.
stack: default_stack
},
// === Modules ===
// This object holds all the PNotify modules. They are used to provide
// additional functionality.
modules: {},
// This runs an event on all the modules.
runModules: function(event, arg){
var curArg;
for (var module in this.modules) {
curArg = ((typeof arg === "object" && module in arg) ? arg[module] : arg);
if (typeof this.modules[module][event] === 'function')
this.modules[module][event](this, typeof this.options[module] === 'object' ? this.options[module] : {}, curArg);
}
},
// === Class Variables ===
state: "initializing", // The state can be "initializing", "opening", "open", "closing", and "closed".
timer: null, // Auto close timer.
styles: null,
elem: null,
container: null,
title_container: null,
text_container: null,
animating: false, // Stores what is currently being animated (in or out).
timerHide: false, // Stores whether the notice was hidden by a timer.
// === Events ===
init: function(){
var that = this;
// First and foremost, we don't want our module objects all referencing the prototype.
this.modules = {};
$.extend(true, this.modules, PNotify.prototype.modules);
// Get our styling object.
if (typeof this.options.styling === "object") {
this.styles = this.options.styling;
} else {
this.styles = PNotify.styling[this.options.styling];
}
// Create our widget.
// Stop animation, reset the removal timer when the user mouses over.
this.elem = $("<div />", {
"class": "ui-pnotify "+this.options.addclass,
"css": {"display": "none"},
"aria-live": "assertive",
"mouseenter": function(e){
if (that.options.mouse_reset && that.animating === "out") {
if (!that.timerHide)
return;
that.cancelRemove();
}
// Stop the close timer.
if (that.options.hide && that.options.mouse_reset) that.cancelRemove();
},
"mouseleave": function(e){
// Start the close timer.
if (that.options.hide && that.options.mouse_reset && that.animating !== "out") that.queueRemove();
PNotify.positionAll();
}
});
// Create a container for the notice contents.
this.container = $("<div />", {
"class": this.styles.container+" ui-pnotify-container "+(this.options.type === "error" ? this.styles.error : (this.options.type === "info" ? this.styles.info : (this.options.type === "success" ? this.styles.success : this.styles.notice))),
"role": "alert"
}).appendTo(this.elem);
if (this.options.cornerclass !== "")
this.container.removeClass("ui-corner-all").addClass(this.options.cornerclass);
// Create a drop shadow.
if (this.options.shadow)
this.container.addClass("ui-pnotify-shadow");
// Add the appropriate icon.
if (this.options.icon !== false) {
$("<div />", {"class": "ui-pnotify-icon"})
.append($("<span />", {"class": this.options.icon === true ? (this.options.type === "error" ? this.styles.error_icon : (this.options.type === "info" ? this.styles.info_icon : (this.options.type === "success" ? this.styles.success_icon : this.styles.notice_icon))) : this.options.icon}))
.prependTo(this.container);
}
// Add a title.
this.title_container = $("<h4 />", {
"class": "ui-pnotify-title"
})
.appendTo(this.container);
if (this.options.title === false)
this.title_container.hide();
else if (this.options.title_escape)
this.title_container.text(this.options.title);
else
this.title_container.html(this.options.title);
// Add text.
this.text_container = $("<div />", {
"class": "ui-pnotify-text"
})
.appendTo(this.container);
if (this.options.text === false)
this.text_container.hide();
else if (this.options.text_escape)
this.text_container.text(this.options.text);
else
this.text_container.html(this.options.insert_brs ? String(this.options.text).replace(/\n/g, "<br />") : this.options.text);
// Set width and min height.
if (typeof this.options.width === "string")
this.elem.css("width", this.options.width);
if (typeof this.options.min_height === "string")
this.container.css("min-height", this.options.min_height);
// Add the notice to the notice array.
if (this.options.stack.push === "top")
PNotify.notices = $.merge([this], PNotify.notices);
else
PNotify.notices = $.merge(PNotify.notices, [this]);
// Now position all the notices if they are to push to the top.
if (this.options.stack.push === "top")
this.queuePosition(false, 1);
// Mark the stack so it won't animate the new notice.
this.options.stack.animation = false;
// Run the modules.
this.runModules('init');
// Display the notice.
if (this.options.auto_display)
this.open();
return this;
},
// This function is for updating the notice.
update: function(options){
// Save old options.
var oldOpts = this.options;
// Then update to the new options.
this.parseOptions(oldOpts, options);
// Update the corner class.
if (this.options.cornerclass !== oldOpts.cornerclass)
this.container.removeClass("ui-corner-all "+oldOpts.cornerclass).addClass(this.options.cornerclass);
// Update the shadow.
if (this.options.shadow !== oldOpts.shadow) {
if (this.options.shadow)
this.container.addClass("ui-pnotify-shadow");
else
this.container.removeClass("ui-pnotify-shadow");
}
// Update the additional classes.
if (this.options.addclass === false)
this.elem.removeClass(oldOpts.addclass);
else if (this.options.addclass !== oldOpts.addclass)
this.elem.removeClass(oldOpts.addclass).addClass(this.options.addclass);
// Update the title.
if (this.options.title === false)
this.title_container.slideUp("fast");
else if (this.options.title !== oldOpts.title) {
if (this.options.title_escape)
this.title_container.text(this.options.title);
else
this.title_container.html(this.options.title);
if (oldOpts.title === false)
this.title_container.slideDown(200)
}
// Update the text.
if (this.options.text === false) {
this.text_container.slideUp("fast");
} else if (this.options.text !== oldOpts.text) {
if (this.options.text_escape)
this.text_container.text(this.options.text);
else
this.text_container.html(this.options.insert_brs ? String(this.options.text).replace(/\n/g, "<br />") : this.options.text);
if (oldOpts.text === false)
this.text_container.slideDown(200)
}
// Change the notice type.
if (this.options.type !== oldOpts.type)
this.container.removeClass(
this.styles.error+" "+this.styles.notice+" "+this.styles.success+" "+this.styles.info
).addClass(this.options.type === "error" ?
this.styles.error :
(this.options.type === "info" ?
this.styles.info :
(this.options.type === "success" ?
this.styles.success :
this.styles.notice
)
)
);
if (this.options.icon !== oldOpts.icon || (this.options.icon === true && this.options.type !== oldOpts.type)) {
// Remove any old icon.
this.container.find("div.ui-pnotify-icon").remove();
if (this.options.icon !== false) {
// Build the new icon.
$("<div />", {"class": "ui-pnotify-icon"})
.append($("<span />", {"class": this.options.icon === true ? (this.options.type === "error" ? this.styles.error_icon : (this.options.type === "info" ? this.styles.info_icon : (this.options.type === "success" ? this.styles.success_icon : this.styles.notice_icon))) : this.options.icon}))
.prependTo(this.container);
}
}
// Update the width.
if (this.options.width !== oldOpts.width)
this.elem.animate({width: this.options.width});
// Update the minimum height.
if (this.options.min_height !== oldOpts.min_height)
this.container.animate({minHeight: this.options.min_height});
// Update the opacity.
if (this.options.opacity !== oldOpts.opacity)
this.elem.fadeTo(this.options.animate_speed, this.options.opacity);
// Update the timed hiding.
if (!this.options.hide)
this.cancelRemove();
else if (!oldOpts.hide)
this.queueRemove();
this.queuePosition(true);
// Run the modules.
this.runModules('update', oldOpts);
return this;
},
// Display the notice.
open: function(){
this.state = "opening";
// Run the modules.
this.runModules('beforeOpen');
var that = this;
// If the notice is not in the DOM, append it.
if (!this.elem.parent().length)
this.elem.appendTo(this.options.stack.context ? this.options.stack.context : body);
// Try to put it in the right position.
if (this.options.stack.push !== "top")
this.position(true);
// First show it, then set its opacity, then hide it.
if (this.options.animation === "fade" || this.options.animation.effect_in === "fade") {
// If it's fading in, it should start at 0.
this.elem.show().fadeTo(0, 0).hide();
} else {
// Or else it should be set to the opacity.
if (this.options.opacity !== 1)
this.elem.show().fadeTo(0, this.options.opacity).hide();
}
this.animateIn(function(){
that.queuePosition(true);
// Now set it to hide.
if (that.options.hide)
that.queueRemove();
that.state = "open";
// Run the modules.
that.runModules('afterOpen');
});
return this;
},
// Remove the notice.
remove: function(timer_hide) {
this.state = "closing";
this.timerHide = !!timer_hide; // Make sure it's a boolean.
// Run the modules.
this.runModules('beforeClose');
var that = this;
if (this.timer) {
window.clearTimeout(this.timer);
this.timer = null;
}
this.animateOut(function(){
that.state = "closed";
// Run the modules.
that.runModules('afterClose');
that.queuePosition(true);
// If we're supposed to remove the notice from the DOM, do it.
if (that.options.remove)
that.elem.detach();
// Run the modules.
that.runModules('beforeDestroy');
// Remove object from PNotify.notices to prevent memory leak (issue #49)
// unless destroy is off
if (that.options.destroy) {
if (PNotify.notices !== null) {
var idx = $.inArray(that,PNotify.notices);
if (idx !== -1) {
PNotify.notices.splice(idx,1);
}
}
}
// Run the modules.
that.runModules('afterDestroy');
});
return this;
},
// === Class Methods ===
// Get the DOM element.
get: function(){ return this.elem; },
// Put all the options in the right places.
parseOptions: function(options, moreOptions){
this.options = $.extend(true, {}, PNotify.prototype.options);
// This is the only thing that *should* be copied by reference.
this.options.stack = PNotify.prototype.options.stack;
var optArray = [options, moreOptions], curOpts;
for (var curIndex=0; curIndex < optArray.length; curIndex++) {
curOpts = optArray[curIndex];
if (typeof curOpts == "undefined")
break;
if (typeof curOpts !== 'object') {
this.options.text = curOpts;
} else {
for (var option in curOpts) {
if (this.modules[option]) {
// Avoid overwriting module defaults.
$.extend(true, this.options[option], curOpts[option]);
} else {
this.options[option] = curOpts[option];
}
}
}
}
},
// Animate the notice in.
animateIn: function(callback){
// Declare that the notice is animating in. (Or has completed animating in.)
this.animating = "in";
var animation;
if (typeof this.options.animation.effect_in !== "undefined")
animation = this.options.animation.effect_in;
else
animation = this.options.animation;
if (animation === "none") {
this.elem.show();
callback();
} else if (animation === "show")
this.elem.show(this.options.animate_speed, callback);
else if (animation === "fade")
this.elem.show().fadeTo(this.options.animate_speed, this.options.opacity, callback);
else if (animation === "slide")
this.elem.slideDown(this.options.animate_speed, callback);
else if (typeof animation === "function")
animation("in", callback, this.elem);
else
this.elem.show(animation, (typeof this.options.animation.options_in === "object" ? this.options.animation.options_in : {}), this.options.animate_speed, callback);
if (this.elem.parent().hasClass('ui-effects-wrapper'))
this.elem.parent().css({"position": "fixed", "overflow": "visible"});
if (animation !== "slide")
this.elem.css("overflow", "visible");
this.container.css("overflow", "hidden");
},
// Animate the notice out.
animateOut: function(callback){
// Declare that the notice is animating out. (Or has completed animating out.)
this.animating = "out";
var animation;
if (typeof this.options.animation.effect_out !== "undefined")
animation = this.options.animation.effect_out;
else
animation = this.options.animation;
if (animation === "none") {
this.elem.hide();
callback();
} else if (animation === "show")
this.elem.hide(this.options.animate_speed, callback);
else if (animation === "fade")
this.elem.fadeOut(this.options.animate_speed, callback);
else if (animation === "slide")
this.elem.slideUp(this.options.animate_speed, callback);
else if (typeof animation === "function")
animation("out", callback, this.elem);
else
this.elem.hide(animation, (typeof this.options.animation.options_out === "object" ? this.options.animation.options_out : {}), this.options.animate_speed, callback);
if (this.elem.parent().hasClass('ui-effects-wrapper'))
this.elem.parent().css({"position": "fixed", "overflow": "visible"});
if (animation !== "slide")
this.elem.css("overflow", "visible");
this.container.css("overflow", "hidden");
},
// Position the notice. dont_skip_hidden causes the notice to
// position even if it's not visible.
position: function(dontSkipHidden){
// Get the notice's stack.
var s = this.options.stack,
e = this.elem;
if (e.parent().hasClass('ui-effects-wrapper'))
e = this.elem.css({"left": "0", "top": "0", "right": "0", "bottom": "0"}).parent();
if (typeof s.context === "undefined")
s.context = body;
if (!s) return;
if (typeof s.nextpos1 !== "number")
s.nextpos1 = s.firstpos1;
if (typeof s.nextpos2 !== "number")
s.nextpos2 = s.firstpos2;
if (typeof s.addpos2 !== "number")
s.addpos2 = 0;
var hidden = e.css("display") === "none";
// Skip this notice if it's not shown.
if (!hidden || dontSkipHidden) {
var curpos1, curpos2;
// Store what will need to be animated.
var animate = {};
// Calculate the current pos1 value.
var csspos1;
switch (s.dir1) {
case "down":
csspos1 = "top";
break;
case "up":
csspos1 = "bottom";
break;
case "left":
csspos1 = "right";
break;
case "right":
csspos1 = "left";
break;
}
curpos1 = parseInt(e.css(csspos1).replace(/(?:\..*|[^0-9.])/g, ''));
if (isNaN(curpos1))
curpos1 = 0;
// Remember the first pos1, so the first visible notice goes there.
if (typeof s.firstpos1 === "undefined" && !hidden) {
s.firstpos1 = curpos1;
s.nextpos1 = s.firstpos1;
}
// Calculate the current pos2 value.
var csspos2;
switch (s.dir2) {
case "down":
csspos2 = "top";
break;
case "up":
csspos2 = "bottom";
break;
case "left":
csspos2 = "right";
break;
case "right":
csspos2 = "left";
break;
}
curpos2 = parseInt(e.css(csspos2).replace(/(?:\..*|[^0-9.])/g, ''));
if (isNaN(curpos2))
curpos2 = 0;
// Remember the first pos2, so the first visible notice goes there.
if (typeof s.firstpos2 === "undefined" && !hidden) {
s.firstpos2 = curpos2;
s.nextpos2 = s.firstpos2;
}
// Check that it's not beyond the viewport edge.
if ((s.dir1 === "down" && s.nextpos1 + e.height() > (s.context.is(body) ? jwindow.height() : s.context.prop('scrollHeight')) ) ||
(s.dir1 === "up" && s.nextpos1 + e.height() > (s.context.is(body) ? jwindow.height() : s.context.prop('scrollHeight')) ) ||
(s.dir1 === "left" && s.nextpos1 + e.width() > (s.context.is(body) ? jwindow.width() : s.context.prop('scrollWidth')) ) ||
(s.dir1 === "right" && s.nextpos1 + e.width() > (s.context.is(body) ? jwindow.width() : s.context.prop('scrollWidth')) ) ) {
// If it is, it needs to go back to the first pos1, and over on pos2.
s.nextpos1 = s.firstpos1;
s.nextpos2 += s.addpos2 + (typeof s.spacing2 === "undefined" ? 25 : s.spacing2);
s.addpos2 = 0;
}
// Animate if we're moving on dir2.
if (s.animation && s.nextpos2 < curpos2) {
switch (s.dir2) {
case "down":
animate.top = s.nextpos2+"px";
break;
case "up":
animate.bottom = s.nextpos2+"px";
break;
case "left":
animate.right = s.nextpos2+"px";
break;
case "right":
animate.left = s.nextpos2+"px";
break;
}
} else {
if(typeof s.nextpos2 === "number")
e.css(csspos2, s.nextpos2+"px");
}
// Keep track of the widest/tallest notice in the column/row, so we can push the next column/row.
switch (s.dir2) {
case "down":
case "up":
if (e.outerHeight(true) > s.addpos2)
s.addpos2 = e.height();
break;
case "left":
case "right":
if (e.outerWidth(true) > s.addpos2)
s.addpos2 = e.width();
break;
}
// Move the notice on dir1.
if (typeof s.nextpos1 === "number") {
// Animate if we're moving toward the first pos.
if (s.animation && (curpos1 > s.nextpos1 || animate.top || animate.bottom || animate.right || animate.left)) {
switch (s.dir1) {
case "down":
animate.top = s.nextpos1+"px";
break;
case "up":
animate.bottom = s.nextpos1+"px";
break;
case "left":
animate.right = s.nextpos1+"px";
break;
case "right":
animate.left = s.nextpos1+"px";
break;
}
} else
e.css(csspos1, s.nextpos1+"px");
}
// Run the animation.
if (animate.top || animate.bottom || animate.right || animate.left)
e.animate(animate, {duration: this.options.position_animate_speed, queue: false});
// Calculate the next dir1 position.
switch (s.dir1) {
case "down":
case "up":
s.nextpos1 += e.height() + (typeof s.spacing1 === "undefined" ? 25 : s.spacing1);
break;
case "left":
case "right":
s.nextpos1 += e.width() + (typeof s.spacing1 === "undefined" ? 25 : s.spacing1);
break;
}
}
return this;
},
// Queue the position all function so it doesn't run repeatedly and
// use up resources.
queuePosition: function(animate, milliseconds){
if (timer)
clearTimeout(timer);
if (!milliseconds)
milliseconds = 10;
timer = setTimeout(function(){ PNotify.positionAll(animate) }, milliseconds);
return this;
},
// Cancel any pending removal timer.
cancelRemove: function(){
if (this.timer)
window.clearTimeout(this.timer);
if (this.state === "closing") {
// If it's animating out, animate back in really quickly.
this.elem.stop(true);
this.state = "open";
this.animating = "in";
this.elem.css("height", "auto").animate({"width": this.options.width, "opacity": this.options.opacity}, "fast");
}
return this;
},
// Queue a removal timer.
queueRemove: function(){
var that = this;
// Cancel any current removal timer.
this.cancelRemove();
this.timer = window.setTimeout(function(){
that.remove(true);
}, (isNaN(this.options.delay) ? 0 : this.options.delay));
return this;
}
});
// These functions affect all notices.
$.extend(PNotify, {
// This holds all the notices.
notices: [],
removeAll: function () {
$.each(PNotify.notices, function(){
if (this.remove)
this.remove(false);
});
},
positionAll: function (animate) {
// This timer is used for queueing this function so it doesn't run
// repeatedly.
if (timer)
clearTimeout(timer);
timer = null;
// Reset the next position data.
if (PNotify.notices && PNotify.notices.length) {
$.each(PNotify.notices, function(){
var s = this.options.stack;
if (!s) return;
s.nextpos1 = s.firstpos1;
s.nextpos2 = s.firstpos2;
s.addpos2 = 0;
s.animation = animate;
});
$.each(PNotify.notices, function(){
this.position();
});
} else {
var s = PNotify.prototype.options.stack;
if (s) {
delete s.nextpos1;
delete s.nextpos2;
}
}
},
styling: {
jqueryui: {
container: "ui-widget ui-widget-content ui-corner-all",
notice: "ui-state-highlight",
// (The actual jQUI notice icon looks terrible.)
notice_icon: "ui-icon ui-icon-info",
info: "",
info_icon: "ui-icon ui-icon-info",
success: "ui-state-default",
success_icon: "ui-icon ui-icon-circle-check",
error: "ui-state-error",
error_icon: "ui-icon ui-icon-alert"
},
bootstrap2: {
container: "alert",
notice: "",
notice_icon: "icon-exclamation-sign",
info: "alert-info",
info_icon: "icon-info-sign",
success: "alert-success",
success_icon: "icon-ok-sign",
error: "alert-error",
error_icon: "icon-warning-sign"
},
bootstrap3: {
container: "alert",
notice: "alert-warning",
notice_icon: "glyphicon glyphicon-exclamation-sign",
info: "alert-info",
info_icon: "glyphicon glyphicon-info-sign",
success: "alert-success",
success_icon: "glyphicon glyphicon-ok-sign",
error: "alert-danger",
error_icon: "glyphicon glyphicon-warning-sign"
}
}
});
/*
* uses icons from http://fontawesome.io/
* version 4.0.3
*/
PNotify.styling.fontawesome = $.extend({}, PNotify.styling.bootstrap3);
$.extend(PNotify.styling.fontawesome, {
notice_icon: "fa fa-exclamation-circle",
info_icon: "fa fa-info",
success_icon: "fa fa-check",
error_icon: "fa fa-warning"
});
if (document.body)
do_when_ready();
else
$(do_when_ready);
return PNotify;
}));