1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,173 @@ |
1 |
+/** |
|
2 |
+ * jBox Notice plugin: Opens a popup notice |
|
3 |
+ * |
|
4 |
+ * Author: Stephan Wagner <stephanwagner.me@gmail.com> (https://stephanwagner.me) |
|
5 |
+ * |
|
6 |
+ * License: MIT (https://opensource.org/licenses/MIT) |
|
7 |
+ * |
|
8 |
+ * Requires: jBox (https://cdn.jsdelivr.net/gh/StephanWagner/jBox@latest/dist/jBox.min.js) |
|
9 |
+ */ |
|
10 |
+ |
|
11 |
+function jBoxNoticeWrapper(jBox, jQuery) { |
|
12 |
+ |
|
13 |
+ new jBox.plugin('Notice', { |
|
14 |
+ |
|
15 |
+ |
|
16 |
+ // Options (https://stephanwagner.me/jBox/options#options-notice) |
|
17 |
+ |
|
18 |
+ color: null, // Add a color to your notices, use 'gray' (default), 'black', 'red', 'green', 'blue' or 'yellow' |
|
19 |
+ stack: true, // Set to false to disable notice-stacking |
|
20 |
+ stackSpacing: 10, // Spacing between notices when they stack |
|
21 |
+ autoClose: 6000, // Time in ms after which the notice will disappear |
|
22 |
+ attributes: { // Defines where the notice will pop up |
|
23 |
+ x: 'right', // 'left' or 'right' |
|
24 |
+ y: 'top' // 'top' or 'bottom' |
|
25 |
+ }, |
|
26 |
+ position: { // Defines the distance to the viewport boundary |
|
27 |
+ x: 15, |
|
28 |
+ y: 15 |
|
29 |
+ }, |
|
30 |
+ responsivePositions: { // Responsive positions |
|
31 |
+ 500: { // The key defines the maximum width of the viewport, the values will replace the default position options |
|
32 |
+ x: 5, // Start with the lowest viewport |
|
33 |
+ y: 5 |
|
34 |
+ }, |
|
35 |
+ 768: { |
|
36 |
+ x: 10, |
|
37 |
+ y: 10 |
|
38 |
+ } |
|
39 |
+ }, |
|
40 |
+ target: window, |
|
41 |
+ fixed: true, |
|
42 |
+ animation: 'zoomIn', |
|
43 |
+ closeOnClick: 'box', |
|
44 |
+ zIndex: 12000, |
|
45 |
+ |
|
46 |
+ |
|
47 |
+ // Triggered when notice is initialized |
|
48 |
+ |
|
49 |
+ _onInit: function () |
|
50 |
+ { |
|
51 |
+ // Cache position values |
|
52 |
+ this.defaultNoticePosition = jQuery.extend({}, this.options.position); |
|
53 |
+ |
|
54 |
+ // Type Notice has its own adjust position function |
|
55 |
+ this._adjustNoticePositon = function () { |
|
56 |
+ var win = jQuery(window); |
|
57 |
+ var windowDimensions = { |
|
58 |
+ x: win.width(), |
|
59 |
+ y: win.height() |
|
60 |
+ }; |
|
61 |
+ |
|
62 |
+ // Reset default position |
|
63 |
+ this.options.position = jQuery.extend({}, this.defaultNoticePosition); |
|
64 |
+ |
|
65 |
+ // Adjust depending on viewport |
|
66 |
+ jQuery.each(this.options.responsivePositions, function (viewport, position) { |
|
67 |
+ if (windowDimensions.x <= viewport) { |
|
68 |
+ this.options.position = position; |
|
69 |
+ return false; |
|
70 |
+ } |
|
71 |
+ }.bind(this)); |
|
72 |
+ |
|
73 |
+ // Set new padding options |
|
74 |
+ this.options.adjustDistance = { |
|
75 |
+ top: this.options.position.y, |
|
76 |
+ right: this.options.position.x, |
|
77 |
+ bottom: this.options.position.y, |
|
78 |
+ left: this.options.position.x |
|
79 |
+ }; |
|
80 |
+ }; |
|
81 |
+ |
|
82 |
+ // If jBox grabs an element as content, crab a clone instead |
|
83 |
+ this.options.content instanceof jQuery && (this.options.content = this.options.content.clone().attr('id', '')); |
|
84 |
+ |
|
85 |
+ // Adjust paddings when window resizes |
|
86 |
+ jQuery(window).on('resize.responsivejBoxNotice-' + this.id, function (ev) { if (this.isOpen) { this._adjustNoticePositon(); } }.bind(this)); |
|
87 |
+ |
|
88 |
+ this.open(); |
|
89 |
+ }, |
|
90 |
+ |
|
91 |
+ |
|
92 |
+ // Triggered when notice was created |
|
93 |
+ |
|
94 |
+ _onCreated: function () |
|
95 |
+ { |
|
96 |
+ // Add color class |
|
97 |
+ this.wrapper.addClass('jBox-Notice-color jBox-Notice-' + (this.options.color || 'gray')); |
|
98 |
+ |
|
99 |
+ // Store position in jBox wrapper |
|
100 |
+ this.wrapper.data('jBox-Notice-position', this.options.attributes.x + '-' + this.options.attributes.y); |
|
101 |
+ }, |
|
102 |
+ |
|
103 |
+ |
|
104 |
+ // Triggered when notice opens |
|
105 |
+ |
|
106 |
+ _onOpen: function () |
|
107 |
+ { |
|
108 |
+ // Bail if we're stacking |
|
109 |
+ if (this.options.stack) { |
|
110 |
+ return; |
|
111 |
+ } |
|
112 |
+ |
|
113 |
+ // Adjust position when opening |
|
114 |
+ this._adjustNoticePositon(); |
|
115 |
+ |
|
116 |
+ // Loop through notices at same window corner destroy them |
|
117 |
+ jQuery.each(jQuery('.jBox-Notice'), function (index, el) |
|
118 |
+ { |
|
119 |
+ el = jQuery(el); |
|
120 |
+ |
|
121 |
+ // Abort if the element is this notice or when it's not at the same position |
|
122 |
+ if (el.attr('id') == this.id || el.data('jBox-Notice-position') != this.options.attributes.x + '-' + this.options.attributes.y) { |
|
123 |
+ return; |
|
124 |
+ } |
|
125 |
+ |
|
126 |
+ // Remove notice when we don't wont to stack them |
|
127 |
+ if (!this.options.stack) { |
|
128 |
+ el.data('jBox').close({ignoreDelay: true}); |
|
129 |
+ return; |
|
130 |
+ } |
|
131 |
+ }.bind(this)); |
|
132 |
+ }, |
|
133 |
+ |
|
134 |
+ // Triggered when resizing window etc. |
|
135 |
+ |
|
136 |
+ _onPosition: function () |
|
137 |
+ { |
|
138 |
+ var stacks = {}; |
|
139 |
+ jQuery.each(jQuery('.jBox-Notice'), function (index, el) |
|
140 |
+ { |
|
141 |
+ el = jQuery(el); |
|
142 |
+ var pos = el.data('jBox-Notice-position'); |
|
143 |
+ if (!stacks[pos]) { |
|
144 |
+ stacks[pos] = []; |
|
145 |
+ } |
|
146 |
+ stacks[pos].push(el); |
|
147 |
+ }); |
|
148 |
+ for (var pos in stacks) { |
|
149 |
+ var position = pos.split('-'); |
|
150 |
+ var direction = position[1]; |
|
151 |
+ stacks[pos].reverse(); |
|
152 |
+ var margin = 0; |
|
153 |
+ for (var i in stacks[pos]) { |
|
154 |
+ var el = jQuery(stacks[pos][i]); |
|
155 |
+ el.css('margin-' + direction, margin); |
|
156 |
+ margin += el.outerHeight() + this.options.stackSpacing; |
|
157 |
+ } |
|
158 |
+ } |
|
159 |
+ }, |
|
160 |
+ |
|
161 |
+ // Remove notice from DOM and reposition other notices when closing finishes |
|
162 |
+ |
|
163 |
+ _onCloseComplete: function () |
|
164 |
+ { |
|
165 |
+ this.destroy(); |
|
166 |
+ this.options._onPosition.bind(this).call(); |
|
167 |
+ } |
|
168 |
+ |
|
169 |
+ }); |
|
170 |
+ |
|
171 |
+}; |
|
172 |
+ |
|
173 |
+//# sourceMappingURL=jBox.Notice.js.map |
1 | 1 |
deleted file mode 100644 |
... | ... |
@@ -1,173 +0,0 @@ |
1 |
-/** |
|
2 |
- * jBox Notice plugin: Opens a popup notice |
|
3 |
- * |
|
4 |
- * Author: Stephan Wagner <stephanwagner.me@gmail.com> (https://stephanwagner.me) |
|
5 |
- * |
|
6 |
- * License: MIT (https://opensource.org/licenses/MIT) |
|
7 |
- * |
|
8 |
- * Requires: jBox (https://cdn.jsdelivr.net/gh/StephanWagner/jBox@latest/dist/jBox.min.js) |
|
9 |
- */ |
|
10 |
- |
|
11 |
-function jBoxNoticeWrapper(jBox, jQuery) { |
|
12 |
- |
|
13 |
- new jBox.plugin('Notice', { |
|
14 |
- |
|
15 |
- |
|
16 |
- // Options (https://stephanwagner.me/jBox/options#options-notice) |
|
17 |
- |
|
18 |
- color: null, // Add a color to your notices, use 'gray' (default), 'black', 'red', 'green', 'blue' or 'yellow' |
|
19 |
- stack: true, // Set to false to disable notice-stacking |
|
20 |
- stackSpacing: 10, // Spacing between notices when they stack |
|
21 |
- autoClose: 6000, // Time in ms after which the notice will disappear |
|
22 |
- attributes: { // Defines where the notice will pop up |
|
23 |
- x: 'right', // 'left' or 'right' |
|
24 |
- y: 'top' // 'top' or 'bottom' |
|
25 |
- }, |
|
26 |
- position: { // Defines the distance to the viewport boundary |
|
27 |
- x: 15, |
|
28 |
- y: 15 |
|
29 |
- }, |
|
30 |
- responsivePositions: { // Responsive positions |
|
31 |
- 500: { // The key defines the maximum width of the viewport, the values will replace the default position options |
|
32 |
- x: 5, // Start with the lowest viewport |
|
33 |
- y: 5 |
|
34 |
- }, |
|
35 |
- 768: { |
|
36 |
- x: 10, |
|
37 |
- y: 10 |
|
38 |
- } |
|
39 |
- }, |
|
40 |
- target: window, |
|
41 |
- fixed: true, |
|
42 |
- animation: 'zoomIn', |
|
43 |
- closeOnClick: 'box', |
|
44 |
- zIndex: 12000, |
|
45 |
- |
|
46 |
- |
|
47 |
- // Triggered when notice is initialized |
|
48 |
- |
|
49 |
- _onInit: function () |
|
50 |
- { |
|
51 |
- // Cache position values |
|
52 |
- this.defaultNoticePosition = jQuery.extend({}, this.options.position); |
|
53 |
- |
|
54 |
- // Type Notice has its own adjust position function |
|
55 |
- this._adjustNoticePositon = function () { |
|
56 |
- var win = jQuery(window); |
|
57 |
- var windowDimensions = { |
|
58 |
- x: win.width(), |
|
59 |
- y: win.height() |
|
60 |
- }; |
|
61 |
- |
|
62 |
- // Reset default position |
|
63 |
- this.options.position = jQuery.extend({}, this.defaultNoticePosition); |
|
64 |
- |
|
65 |
- // Adjust depending on viewport |
|
66 |
- jQuery.each(this.options.responsivePositions, function (viewport, position) { |
|
67 |
- if (windowDimensions.x <= viewport) { |
|
68 |
- this.options.position = position; |
|
69 |
- return false; |
|
70 |
- } |
|
71 |
- }.bind(this)); |
|
72 |
- |
|
73 |
- // Set new padding options |
|
74 |
- this.options.adjustDistance = { |
|
75 |
- top: this.options.position.y, |
|
76 |
- right: this.options.position.x, |
|
77 |
- bottom: this.options.position.y, |
|
78 |
- left: this.options.position.x |
|
79 |
- }; |
|
80 |
- }; |
|
81 |
- |
|
82 |
- // If jBox grabs an element as content, crab a clone instead |
|
83 |
- this.options.content instanceof jQuery && (this.options.content = this.options.content.clone().attr('id', '')); |
|
84 |
- |
|
85 |
- // Adjust paddings when window resizes |
|
86 |
- jQuery(window).on('resize.responsivejBoxNotice-' + this.id, function (ev) { if (this.isOpen) { this._adjustNoticePositon(); } }.bind(this)); |
|
87 |
- |
|
88 |
- this.open(); |
|
89 |
- }, |
|
90 |
- |
|
91 |
- |
|
92 |
- // Triggered when notice was created |
|
93 |
- |
|
94 |
- _onCreated: function () |
|
95 |
- { |
|
96 |
- // Add color class |
|
97 |
- this.wrapper.addClass('jBox-Notice-color jBox-Notice-' + (this.options.color || 'gray')); |
|
98 |
- |
|
99 |
- // Store position in jBox wrapper |
|
100 |
- this.wrapper.data('jBox-Notice-position', this.options.attributes.x + '-' + this.options.attributes.y); |
|
101 |
- }, |
|
102 |
- |
|
103 |
- |
|
104 |
- // Triggered when notice opens |
|
105 |
- |
|
106 |
- _onOpen: function () |
|
107 |
- { |
|
108 |
- // Bail if we're stacking |
|
109 |
- if (this.options.stack) { |
|
110 |
- return; |
|
111 |
- } |
|
112 |
- |
|
113 |
- // Adjust position when opening |
|
114 |
- this._adjustNoticePositon(); |
|
115 |
- |
|
116 |
- // Loop through notices at same window corner destroy them |
|
117 |
- jQuery.each(jQuery('.jBox-Notice'), function (index, el) |
|
118 |
- { |
|
119 |
- el = jQuery(el); |
|
120 |
- |
|
121 |
- // Abort if the element is this notice or when it's not at the same position |
|
122 |
- if (el.attr('id') == this.id || el.data('jBox-Notice-position') != this.options.attributes.x + '-' + this.options.attributes.y) { |
|
123 |
- return; |
|
124 |
- } |
|
125 |
- |
|
126 |
- // Remove notice when we don't wont to stack them |
|
127 |
- if (!this.options.stack) { |
|
128 |
- el.data('jBox').close({ignoreDelay: true}); |
|
129 |
- return; |
|
130 |
- } |
|
131 |
- }.bind(this)); |
|
132 |
- }, |
|
133 |
- |
|
134 |
- // Triggered when resizing window etc. |
|
135 |
- |
|
136 |
- _onPosition: function () |
|
137 |
- { |
|
138 |
- var stacks = {}; |
|
139 |
- jQuery.each(jQuery('.jBox-Notice'), function (index, el) |
|
140 |
- { |
|
141 |
- el = jQuery(el); |
|
142 |
- var pos = el.data('jBox-Notice-position'); |
|
143 |
- if (!stacks[pos]) { |
|
144 |
- stacks[pos] = []; |
|
145 |
- } |
|
146 |
- stacks[pos].push(el); |
|
147 |
- }); |
|
148 |
- for (var pos in stacks) { |
|
149 |
- var position = pos.split('-'); |
|
150 |
- var direction = position[1]; |
|
151 |
- stacks[pos].reverse(); |
|
152 |
- var margin = 0; |
|
153 |
- for (var i in stacks[pos]) { |
|
154 |
- var el = jQuery(stacks[pos][i]); |
|
155 |
- el.css('margin-' + direction, margin); |
|
156 |
- margin += el.outerHeight() + this.options.stackSpacing; |
|
157 |
- } |
|
158 |
- } |
|
159 |
- }, |
|
160 |
- |
|
161 |
- // Remove notice from DOM and reposition other notices when closing finishes |
|
162 |
- |
|
163 |
- _onCloseComplete: function () |
|
164 |
- { |
|
165 |
- this.destroy(); |
|
166 |
- this.options._onPosition.bind(this).call(); |
|
167 |
- } |
|
168 |
- |
|
169 |
- }); |
|
170 |
- |
|
171 |
-}; |
|
172 |
- |
|
173 |
-//# sourceMappingURL=jBox.Notice.js.map |
1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,173 @@ |
1 |
+/** |
|
2 |
+ * jBox Notice plugin: Opens a popup notice |
|
3 |
+ * |
|
4 |
+ * Author: Stephan Wagner <stephanwagner.me@gmail.com> (https://stephanwagner.me) |
|
5 |
+ * |
|
6 |
+ * License: MIT (https://opensource.org/licenses/MIT) |
|
7 |
+ * |
|
8 |
+ * Requires: jBox (https://cdn.jsdelivr.net/gh/StephanWagner/jBox@latest/dist/jBox.min.js) |
|
9 |
+ */ |
|
10 |
+ |
|
11 |
+function jBoxNoticeWrapper(jBox, jQuery) { |
|
12 |
+ |
|
13 |
+ new jBox.plugin('Notice', { |
|
14 |
+ |
|
15 |
+ |
|
16 |
+ // Options (https://stephanwagner.me/jBox/options#options-notice) |
|
17 |
+ |
|
18 |
+ color: null, // Add a color to your notices, use 'gray' (default), 'black', 'red', 'green', 'blue' or 'yellow' |
|
19 |
+ stack: true, // Set to false to disable notice-stacking |
|
20 |
+ stackSpacing: 10, // Spacing between notices when they stack |
|
21 |
+ autoClose: 6000, // Time in ms after which the notice will disappear |
|
22 |
+ attributes: { // Defines where the notice will pop up |
|
23 |
+ x: 'right', // 'left' or 'right' |
|
24 |
+ y: 'top' // 'top' or 'bottom' |
|
25 |
+ }, |
|
26 |
+ position: { // Defines the distance to the viewport boundary |
|
27 |
+ x: 15, |
|
28 |
+ y: 15 |
|
29 |
+ }, |
|
30 |
+ responsivePositions: { // Responsive positions |
|
31 |
+ 500: { // The key defines the maximum width of the viewport, the values will replace the default position options |
|
32 |
+ x: 5, // Start with the lowest viewport |
|
33 |
+ y: 5 |
|
34 |
+ }, |
|
35 |
+ 768: { |
|
36 |
+ x: 10, |
|
37 |
+ y: 10 |
|
38 |
+ } |
|
39 |
+ }, |
|
40 |
+ target: window, |
|
41 |
+ fixed: true, |
|
42 |
+ animation: 'zoomIn', |
|
43 |
+ closeOnClick: 'box', |
|
44 |
+ zIndex: 12000, |
|
45 |
+ |
|
46 |
+ |
|
47 |
+ // Triggered when notice is initialized |
|
48 |
+ |
|
49 |
+ _onInit: function () |
|
50 |
+ { |
|
51 |
+ // Cache position values |
|
52 |
+ this.defaultNoticePosition = jQuery.extend({}, this.options.position); |
|
53 |
+ |
|
54 |
+ // Type Notice has its own adjust position function |
|
55 |
+ this._adjustNoticePositon = function () { |
|
56 |
+ var win = jQuery(window); |
|
57 |
+ var windowDimensions = { |
|
58 |
+ x: win.width(), |
|
59 |
+ y: win.height() |
|
60 |
+ }; |
|
61 |
+ |
|
62 |
+ // Reset default position |
|
63 |
+ this.options.position = jQuery.extend({}, this.defaultNoticePosition); |
|
64 |
+ |
|
65 |
+ // Adjust depending on viewport |
|
66 |
+ jQuery.each(this.options.responsivePositions, function (viewport, position) { |
|
67 |
+ if (windowDimensions.x <= viewport) { |
|
68 |
+ this.options.position = position; |
|
69 |
+ return false; |
|
70 |
+ } |
|
71 |
+ }.bind(this)); |
|
72 |
+ |
|
73 |
+ // Set new padding options |
|
74 |
+ this.options.adjustDistance = { |
|
75 |
+ top: this.options.position.y, |
|
76 |
+ right: this.options.position.x, |
|
77 |
+ bottom: this.options.position.y, |
|
78 |
+ left: this.options.position.x |
|
79 |
+ }; |
|
80 |
+ }; |
|
81 |
+ |
|
82 |
+ // If jBox grabs an element as content, crab a clone instead |
|
83 |
+ this.options.content instanceof jQuery && (this.options.content = this.options.content.clone().attr('id', '')); |
|
84 |
+ |
|
85 |
+ // Adjust paddings when window resizes |
|
86 |
+ jQuery(window).on('resize.responsivejBoxNotice-' + this.id, function (ev) { if (this.isOpen) { this._adjustNoticePositon(); } }.bind(this)); |
|
87 |
+ |
|
88 |
+ this.open(); |
|
89 |
+ }, |
|
90 |
+ |
|
91 |
+ |
|
92 |
+ // Triggered when notice was created |
|
93 |
+ |
|
94 |
+ _onCreated: function () |
|
95 |
+ { |
|
96 |
+ // Add color class |
|
97 |
+ this.wrapper.addClass('jBox-Notice-color jBox-Notice-' + (this.options.color || 'gray')); |
|
98 |
+ |
|
99 |
+ // Store position in jBox wrapper |
|
100 |
+ this.wrapper.data('jBox-Notice-position', this.options.attributes.x + '-' + this.options.attributes.y); |
|
101 |
+ }, |
|
102 |
+ |
|
103 |
+ |
|
104 |
+ // Triggered when notice opens |
|
105 |
+ |
|
106 |
+ _onOpen: function () |
|
107 |
+ { |
|
108 |
+ // Bail if we're stacking |
|
109 |
+ if (this.options.stack) { |
|
110 |
+ return; |
|
111 |
+ } |
|
112 |
+ |
|
113 |
+ // Adjust position when opening |
|
114 |
+ this._adjustNoticePositon(); |
|
115 |
+ |
|
116 |
+ // Loop through notices at same window corner destroy them |
|
117 |
+ jQuery.each(jQuery('.jBox-Notice'), function (index, el) |
|
118 |
+ { |
|
119 |
+ el = jQuery(el); |
|
120 |
+ |
|
121 |
+ // Abort if the element is this notice or when it's not at the same position |
|
122 |
+ if (el.attr('id') == this.id || el.data('jBox-Notice-position') != this.options.attributes.x + '-' + this.options.attributes.y) { |
|
123 |
+ return; |
|
124 |
+ } |
|
125 |
+ |
|
126 |
+ // Remove notice when we don't wont to stack them |
|
127 |
+ if (!this.options.stack) { |
|
128 |
+ el.data('jBox').close({ignoreDelay: true}); |
|
129 |
+ return; |
|
130 |
+ } |
|
131 |
+ }.bind(this)); |
|
132 |
+ }, |
|
133 |
+ |
|
134 |
+ // Triggered when resizing window etc. |
|
135 |
+ |
|
136 |
+ _onPosition: function () |
|
137 |
+ { |
|
138 |
+ var stacks = {}; |
|
139 |
+ jQuery.each(jQuery('.jBox-Notice'), function (index, el) |
|
140 |
+ { |
|
141 |
+ el = jQuery(el); |
|
142 |
+ var pos = el.data('jBox-Notice-position'); |
|
143 |
+ if (!stacks[pos]) { |
|
144 |
+ stacks[pos] = []; |
|
145 |
+ } |
|
146 |
+ stacks[pos].push(el); |
|
147 |
+ }); |
|
148 |
+ for (var pos in stacks) { |
|
149 |
+ var position = pos.split('-'); |
|
150 |
+ var direction = position[1]; |
|
151 |
+ stacks[pos].reverse(); |
|
152 |
+ var margin = 0; |
|
153 |
+ for (var i in stacks[pos]) { |
|
154 |
+ var el = jQuery(stacks[pos][i]); |
|
155 |
+ el.css('margin-' + direction, margin); |
|
156 |
+ margin += el.outerHeight() + this.options.stackSpacing; |
|
157 |
+ } |
|
158 |
+ } |
|
159 |
+ }, |
|
160 |
+ |
|
161 |
+ // Remove notice from DOM and reposition other notices when closing finishes |
|
162 |
+ |
|
163 |
+ _onCloseComplete: function () |
|
164 |
+ { |
|
165 |
+ this.destroy(); |
|
166 |
+ this.options._onPosition.bind(this).call(); |
|
167 |
+ } |
|
168 |
+ |
|
169 |
+ }); |
|
170 |
+ |
|
171 |
+}; |
|
172 |
+ |
|
173 |
+//# sourceMappingURL=jBox.Notice.js.map |