pnotify-rails 1.2.2 → 2.0.1

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