@finqu/cool 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/build/.eslintrc.json +10 -0
- package/build/banner.js +14 -0
- package/build/build-plugins.js +92 -0
- package/build/rollup.config.js +78 -0
- package/dist/css/cool-grid.css +3672 -0
- package/dist/css/cool-grid.css.map +30 -0
- package/dist/css/cool-grid.min.css +7 -0
- package/dist/css/cool-grid.min.css.map +1 -0
- package/dist/css/cool-reboot.css +281 -0
- package/dist/css/cool-reboot.css.map +58 -0
- package/dist/css/cool-reboot.min.css +7 -0
- package/dist/css/cool-reboot.min.css.map +1 -0
- package/dist/css/cool.css +14841 -0
- package/dist/css/cool.css.map +144 -0
- package/dist/css/cool.min.css +7 -0
- package/dist/css/cool.min.css.map +1 -0
- package/dist/js/cool.bundle.js +15304 -0
- package/dist/js/cool.bundle.js.map +1 -0
- package/dist/js/cool.bundle.min.js +45 -0
- package/dist/js/cool.bundle.min.js.map +1 -0
- package/dist/js/cool.esm.js +4766 -0
- package/dist/js/cool.esm.js.map +1 -0
- package/dist/js/cool.esm.min.js +7 -0
- package/dist/js/cool.esm.min.js.map +1 -0
- package/dist/js/cool.js +4948 -0
- package/dist/js/cool.js.map +1 -0
- package/dist/js/cool.min.js +7 -0
- package/dist/js/cool.min.js.map +1 -0
- package/html/index.html +892 -0
- package/js/dist/collapse.js +321 -0
- package/js/dist/collapse.js.map +1 -0
- package/js/dist/common.js +1474 -0
- package/js/dist/common.js.map +1 -0
- package/js/dist/cooldropdown.js +467 -0
- package/js/dist/cooldropdown.js.map +1 -0
- package/js/dist/coolpopover.js +391 -0
- package/js/dist/coolpopover.js.map +1 -0
- package/js/dist/coolsectiontabs.js +256 -0
- package/js/dist/coolsectiontabs.js.map +1 -0
- package/js/dist/coolselect.js +796 -0
- package/js/dist/coolselect.js.map +1 -0
- package/js/dist/cooltooltip.js +360 -0
- package/js/dist/cooltooltip.js.map +1 -0
- package/js/dist/coolui.js +73 -0
- package/js/dist/coolui.js.map +1 -0
- package/js/dist/dropdown.js +1716 -0
- package/js/dist/dropdown.js.map +1 -0
- package/js/dist/popover.js +587 -0
- package/js/dist/popover.js.map +1 -0
- package/js/dist/sectiontabs.js +263 -0
- package/js/dist/sectiontabs.js.map +1 -0
- package/js/dist/select.js +2029 -0
- package/js/dist/select.js.map +1 -0
- package/js/dist/tooltip.js +555 -0
- package/js/dist/tooltip.js.map +1 -0
- package/js/index.esm.js +21 -0
- package/js/index.umd.js +21 -0
- package/js/src/abstract-ui-component.js +70 -0
- package/js/src/collapse.js +258 -0
- package/js/src/common.js +280 -0
- package/js/src/dialog.js +570 -0
- package/js/src/dropdown.js +443 -0
- package/js/src/popover.js +615 -0
- package/js/src/section-tabs.js +204 -0
- package/js/src/select.js +832 -0
- package/js/src/toast.js +581 -0
- package/js/src/tooltip.js +575 -0
- package/js/src/util/animate-css.js +22 -0
- package/js/src/util/index.js +112 -0
- package/js/src/util/perfect-scrollbar.js +1316 -0
- package/less/alert.less +345 -0
- package/less/badge.less +38 -0
- package/less/bootstrap-noconflict.less +23 -0
- package/less/bootstrap.less +23 -0
- package/less/button-group.less +153 -0
- package/less/buttons.less +287 -0
- package/less/dialog-noconflict.less +174 -0
- package/less/dialog.less +203 -0
- package/less/dropdown.less +209 -0
- package/less/forms.less +770 -0
- package/less/images.less +242 -0
- package/less/input-group.less +163 -0
- package/less/list-group.less +73 -0
- package/less/mixins/aspect-ratio.less +23 -0
- package/less/mixins/border-radius.less +24 -0
- package/less/mixins/box-shadow.less +4 -0
- package/less/mixins/buttons.less +17 -0
- package/less/mixins/caret.less +51 -0
- package/less/mixins/clearfix.less +10 -0
- package/less/mixins/gradients.less +34 -0
- package/less/mixins/nav-divider.less +7 -0
- package/less/mixins/object-fit.less +13 -0
- package/less/mixins/reset-text.less +16 -0
- package/less/mixins.less +11 -0
- package/less/package.json +11 -0
- package/less/pagination.less +69 -0
- package/less/popover.less +143 -0
- package/less/project.sublime-workspace +774 -0
- package/less/reboot.less +235 -0
- package/less/section.less +793 -0
- package/less/select.less +150 -0
- package/less/tables.less +737 -0
- package/less/tabs.less +162 -0
- package/less/tooltip.less +87 -0
- package/less/type.less +71 -0
- package/less/utilities/align.less +27 -0
- package/less/utilities/animate.less +3512 -0
- package/less/utilities/background.less +70 -0
- package/less/utilities/borders.less +16 -0
- package/less/utilities/color.less +70 -0
- package/less/utilities/cursor.less +8 -0
- package/less/utilities/display.less +38 -0
- package/less/utilities/embed.less +61 -0
- package/less/utilities/flex.less +76 -0
- package/less/utilities/jquery-ui.less +116 -0
- package/less/utilities/lazyload.less +29 -0
- package/less/utilities/overflow.less +11 -0
- package/less/utilities/pace.less +25 -0
- package/less/utilities/placeholder.less +60 -0
- package/less/utilities/position.less +42 -0
- package/less/utilities/scrollbar.less +152 -0
- package/less/utilities/spacing.less +197 -0
- package/less/utilities/text.less +68 -0
- package/less/utilities/transform.less +7 -0
- package/less/utilities.less +21 -0
- package/less/variables.less +343 -0
- package/package.json +71 -0
- package/scss/LISENCE +15 -0
- package/scss/_alert.scss +125 -0
- package/scss/_badge.scss +58 -0
- package/scss/_button-group.scss +124 -0
- package/scss/_buttons.scss +206 -0
- package/scss/_custom-forms.scss +423 -0
- package/scss/_dialog.scss +149 -0
- package/scss/_dropdown.scss +234 -0
- package/scss/_forms.scss +257 -0
- package/scss/_frame.scss +523 -0
- package/scss/_functions.scss +114 -0
- package/scss/_grid.scss +35 -0
- package/scss/_images.scss +312 -0
- package/scss/_input-group.scss +245 -0
- package/scss/_list-group.scss +82 -0
- package/scss/_mixins.scss +32 -0
- package/scss/_navbar.scss +214 -0
- package/scss/_pagination.scss +79 -0
- package/scss/_popover.scss +165 -0
- package/scss/_reboot.scss +279 -0
- package/scss/_root.scss +15 -0
- package/scss/_section.scss +851 -0
- package/scss/_select.scss +166 -0
- package/scss/_tables.scss +707 -0
- package/scss/_tabs.scss +175 -0
- package/scss/_toast.scss +182 -0
- package/scss/_tooltip.scss +101 -0
- package/scss/_type.scss +90 -0
- package/scss/_utilities.scss +21 -0
- package/scss/_variables.scss +697 -0
- package/scss/cool-grid.scss +29 -0
- package/scss/cool-reboot.scss +11 -0
- package/scss/cool.scss +36 -0
- package/scss/mixins/_alert-variant.scss +40 -0
- package/scss/mixins/_aspect-ratio.scss +29 -0
- package/scss/mixins/_background-variant.scss +25 -0
- package/scss/mixins/_badge-variant.scss +13 -0
- package/scss/mixins/_breakpoints.scss +102 -0
- package/scss/mixins/_buttons.scss +104 -0
- package/scss/mixins/_caret.scss +80 -0
- package/scss/mixins/_clearfix.scss +10 -0
- package/scss/mixins/_float.scss +14 -0
- package/scss/mixins/_forms.scss +51 -0
- package/scss/mixins/_gradients.scss +40 -0
- package/scss/mixins/_grid-framework.scss +72 -0
- package/scss/mixins/_grid.scss +60 -0
- package/scss/mixins/_nav-divider.scss +9 -0
- package/scss/mixins/_object-fit.scss +16 -0
- package/scss/mixins/_reset-text.scss +19 -0
- package/scss/mixins/_text-emphasis.scss +21 -0
- package/scss/mixins/_text-hide.scss +10 -0
- package/scss/mixins/_text-truncate.scss +8 -0
- package/scss/project.sublime-workspace +491 -0
- package/scss/utilities/_align.scss +41 -0
- package/scss/utilities/_animate.scss +3512 -0
- package/scss/utilities/_background.scss +14 -0
- package/scss/utilities/_borders.scss +146 -0
- package/scss/utilities/_clearfix.scss +6 -0
- package/scss/utilities/_collapse.scss +33 -0
- package/scss/utilities/_cursor.scss +10 -0
- package/scss/utilities/_display.scss +16 -0
- package/scss/utilities/_embed.scss +78 -0
- package/scss/utilities/_flex.scss +50 -0
- package/scss/utilities/_lazyload.scss +31 -0
- package/scss/utilities/_overflow.scss +6 -0
- package/scss/utilities/_perfect-scrollbar.scss +154 -0
- package/scss/utilities/_placeholder.scss +76 -0
- package/scss/utilities/_position.scss +30 -0
- package/scss/utilities/_sizing.scss +32 -0
- package/scss/utilities/_spacing.scss +92 -0
- package/scss/utilities/_text.scss +97 -0
package/js/src/toast.js
ADDED
|
@@ -0,0 +1,581 @@
|
|
|
1
|
+
import 'jquery';
|
|
2
|
+
import { debounce } from './util/index';
|
|
3
|
+
import AbstractUIComponent from './abstract-ui-component';
|
|
4
|
+
|
|
5
|
+
const NAME = 'coolToast';
|
|
6
|
+
const DATA_KEY = 'plugin_coolToast';
|
|
7
|
+
|
|
8
|
+
class Toast {
|
|
9
|
+
|
|
10
|
+
constructor(container, opts) {
|
|
11
|
+
|
|
12
|
+
this.settings = {};
|
|
13
|
+
|
|
14
|
+
if (window.Cool.settings.toast) {
|
|
15
|
+
|
|
16
|
+
$.extend(true, this.settings, $.fn[NAME].defaults, window.Cool.settings.toast, opts);
|
|
17
|
+
|
|
18
|
+
} else {
|
|
19
|
+
|
|
20
|
+
$.extend(true, this.settings, $.fn[NAME].defaults, opts);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
this.container = container;
|
|
24
|
+
this.$container = $(this.container);
|
|
25
|
+
this.debug = this.settings.debug;
|
|
26
|
+
this.faPro = this.settings.faPro;
|
|
27
|
+
this.toasts = [];
|
|
28
|
+
this.queue = [];
|
|
29
|
+
this.processingQueue = false;
|
|
30
|
+
this.onInitialize = this.settings.onInitialize;
|
|
31
|
+
this.onDestroy = this.settings.onDestroy;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Add item to queue
|
|
35
|
+
addQueue(toast) {
|
|
36
|
+
|
|
37
|
+
this.queue.push(toast);
|
|
38
|
+
|
|
39
|
+
if (this.processingQueue) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return this.processQueue();
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Process queue
|
|
47
|
+
processQueue() {
|
|
48
|
+
|
|
49
|
+
if (this.processingQueue) {
|
|
50
|
+
|
|
51
|
+
this.queue.shift();
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (!this.queue.length) {
|
|
55
|
+
|
|
56
|
+
this.processingQueue = false;
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
this.processingQueue = true;
|
|
61
|
+
|
|
62
|
+
return this.show(this.queue[0]);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Init toast
|
|
66
|
+
init(opts) {
|
|
67
|
+
|
|
68
|
+
let settings = {};
|
|
69
|
+
|
|
70
|
+
$.extend(true, settings, this.settings, opts);
|
|
71
|
+
|
|
72
|
+
let toast = this.buildToast(settings);
|
|
73
|
+
|
|
74
|
+
this.addQueue(toast);
|
|
75
|
+
this.onInit(toast);
|
|
76
|
+
|
|
77
|
+
return toast;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Remove plugin instance completely
|
|
81
|
+
destroy() {
|
|
82
|
+
|
|
83
|
+
this.$container.removeData(DATA_KEY);
|
|
84
|
+
this.onDestroy();
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// Build toast
|
|
88
|
+
buildToast(settings) {
|
|
89
|
+
|
|
90
|
+
let toast = {
|
|
91
|
+
uuid: 'toast-'+this.generateUUID(),
|
|
92
|
+
placement: settings.placement,
|
|
93
|
+
placementX: settings.placementX,
|
|
94
|
+
placementY: settings.placementY,
|
|
95
|
+
offset: settings.offset,
|
|
96
|
+
animation: settings.animation,
|
|
97
|
+
animationIn: settings.animationIn,
|
|
98
|
+
animationOut: settings.animationOut,
|
|
99
|
+
animationSpeed: settings.animationSpeed,
|
|
100
|
+
dismiss: settings.dismiss,
|
|
101
|
+
size: settings.size,
|
|
102
|
+
header: settings.header,
|
|
103
|
+
theme: settings.theme,
|
|
104
|
+
title: settings.title,
|
|
105
|
+
content: settings.content,
|
|
106
|
+
template: settings.template,
|
|
107
|
+
maxBodyHeight: settings.maxBodyHeight,
|
|
108
|
+
onInit: settings.onInit,
|
|
109
|
+
onShow: settings.onShow,
|
|
110
|
+
onClose: settings.onClose
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
if (typeof toast.content === 'function') {
|
|
114
|
+
|
|
115
|
+
toast.$el = $(toast.template());
|
|
116
|
+
|
|
117
|
+
} else {
|
|
118
|
+
|
|
119
|
+
toast.$el = $(this._renderTemplate(toast));
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
toast.$inner = toast.$el.find('.toast-inner');
|
|
123
|
+
toast.$closeBtn = toast.$el.find('[data-toast-close]');
|
|
124
|
+
|
|
125
|
+
this.log(toast);
|
|
126
|
+
this.toasts.push(toast);
|
|
127
|
+
|
|
128
|
+
return toast;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// Bind events that trigger methods
|
|
132
|
+
bindEvents(toast) {
|
|
133
|
+
|
|
134
|
+
let self = this;
|
|
135
|
+
|
|
136
|
+
toast.$el.on('click', '[data-toast-close]', () => {
|
|
137
|
+
|
|
138
|
+
if (toast.$el) {
|
|
139
|
+
self.close(toast);
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
$(window).on('resize', debounce(() => {
|
|
144
|
+
|
|
145
|
+
if (toast.$el) {
|
|
146
|
+
this.setPosition(toast);
|
|
147
|
+
}
|
|
148
|
+
}, 250));
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// Generate UUID
|
|
152
|
+
generateUUID() {
|
|
153
|
+
|
|
154
|
+
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
|
|
155
|
+
let r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
|
|
156
|
+
return v.toString(16);
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// Set positions
|
|
161
|
+
setPosition(toast, placement, placementY, placementX) {
|
|
162
|
+
|
|
163
|
+
if (typeof placementY === 'undefined' || placementY === null) {
|
|
164
|
+
placementY = toast.placementY;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
if (typeof placementX === 'undefined' || placementX === null) {
|
|
168
|
+
placementX = toast.placementX;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
if (!placementX || !placementY) {
|
|
172
|
+
placement = toast.placement
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
if (toast.offset) {
|
|
176
|
+
|
|
177
|
+
let offsets = toast.offset.split(',')
|
|
178
|
+
let offsetX = parseInt(offsets[0], 10);
|
|
179
|
+
let offsetY = parseInt(offsets[1], 10);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
let toastWidth = toast.$el.outerWidth(true);
|
|
183
|
+
let toastHeight = toast.$el.outerHeight(true);
|
|
184
|
+
let toastPosX;
|
|
185
|
+
let toastPosY;
|
|
186
|
+
|
|
187
|
+
if (placement) {
|
|
188
|
+
|
|
189
|
+
if (placement === 'top-left') {
|
|
190
|
+
|
|
191
|
+
toastPosX = 0;
|
|
192
|
+
toastPosY = 0;
|
|
193
|
+
|
|
194
|
+
if (toast.offset) {
|
|
195
|
+
toastPosX += offsetX;
|
|
196
|
+
toastPosY += offsetY;
|
|
197
|
+
} else {
|
|
198
|
+
toastPosX += 30;
|
|
199
|
+
toastPosY += 30;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
} else if (placement === 'top-center') {
|
|
203
|
+
|
|
204
|
+
toastPosX = (this.$container.width() / 2) - toastWidth / 2;
|
|
205
|
+
toastPosY = 0;
|
|
206
|
+
|
|
207
|
+
this.log(this.$container.width);
|
|
208
|
+
|
|
209
|
+
if (toast.offset) {
|
|
210
|
+
toastPosX += offsetX;
|
|
211
|
+
toastPosY += offsetY;
|
|
212
|
+
} else {
|
|
213
|
+
toastPosY += 30;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
} else if (placement === 'top-right') {
|
|
217
|
+
|
|
218
|
+
toastPosX = this.$container.width() - toastWidth;
|
|
219
|
+
toastPosY = 0;
|
|
220
|
+
|
|
221
|
+
if (toast.offset) {
|
|
222
|
+
toastPosX += -offsetX;
|
|
223
|
+
toastPosY += offsetY;
|
|
224
|
+
} else {
|
|
225
|
+
toastPosX += -30;
|
|
226
|
+
toastPosY += 30;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
} else if (placement === 'center-left') {
|
|
230
|
+
|
|
231
|
+
toastPosX = 0;
|
|
232
|
+
toastPosY = (this.$container.height() / 2) - toastHeight / 2;
|
|
233
|
+
|
|
234
|
+
if (toast.offset) {
|
|
235
|
+
toastPosX += offsetX;
|
|
236
|
+
toastPosY += offsetY;
|
|
237
|
+
} else {
|
|
238
|
+
toastPosX += 30;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
} else if (placement === 'center-center') {
|
|
242
|
+
|
|
243
|
+
toastPosX = (this.$container.width() / 2) - toastWidth / 2;
|
|
244
|
+
toastPosY = (this.$container.height() / 2) - toastHeight / 2;
|
|
245
|
+
|
|
246
|
+
if (toast.offset) {
|
|
247
|
+
toastPosX += offsetX;
|
|
248
|
+
toastPosY += offsetY;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
} else if (placement === 'center-right') {
|
|
252
|
+
|
|
253
|
+
toastPosX = this.$container.width() - toastWidth;
|
|
254
|
+
toastPosY = (this.$container.height() / 2) - toastHeight / 2;
|
|
255
|
+
|
|
256
|
+
if (toast.offset) {
|
|
257
|
+
toastPosX += -offsetX;
|
|
258
|
+
toastPosY += offsetY;
|
|
259
|
+
} else {
|
|
260
|
+
toastPosX += -30;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
} else if (placement === 'bottom-left') {
|
|
264
|
+
|
|
265
|
+
toastPosX = 0;
|
|
266
|
+
toastPosY = this.$container.height() - toastHeight;
|
|
267
|
+
|
|
268
|
+
if (toast.offset) {
|
|
269
|
+
toastPosX += offsetX;
|
|
270
|
+
toastPosY += -offsetY;
|
|
271
|
+
} else {
|
|
272
|
+
toastPosX += 30;
|
|
273
|
+
toastPosY += -30;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
} else if (placement === 'bottom-center') {
|
|
277
|
+
|
|
278
|
+
toastPosX = (this.$container.width() / 2) - toastWidth / 2;
|
|
279
|
+
toastPosY = this.$container.height() - toastHeight;
|
|
280
|
+
|
|
281
|
+
if (toast.offset) {
|
|
282
|
+
toastPosX += offsetX;
|
|
283
|
+
toastPosY += -offsetY;
|
|
284
|
+
} else {
|
|
285
|
+
toastPosY += -30;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
} else if (placement === 'bottom-right') {
|
|
289
|
+
|
|
290
|
+
toastPosX = this.$container.width() - toastWidth
|
|
291
|
+
toastPosY = this.$container.height() - toastHeight;
|
|
292
|
+
|
|
293
|
+
if (toast.offset) {
|
|
294
|
+
toastPosX += -offsetX;
|
|
295
|
+
toastPosY += -offsetY;
|
|
296
|
+
} else {
|
|
297
|
+
toastPosX += -30;
|
|
298
|
+
toastPosY += -30;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
} else {
|
|
303
|
+
|
|
304
|
+
toastPosX = placementX;
|
|
305
|
+
toastPosY = placementY;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
toast.$el.css({
|
|
309
|
+
position: 'absolute',
|
|
310
|
+
top: '0px',
|
|
311
|
+
left: '0px',
|
|
312
|
+
transform: 'translate3d('+toastPosX+'px, '+toastPosY+'px, 0px)',
|
|
313
|
+
'will-change': 'transform'
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
this.log('Toast width: '+toastWidth+'px');
|
|
317
|
+
this.log('Toast height: '+toastHeight+'px');
|
|
318
|
+
this.log('Toast position Y: '+toastPosX+'px');
|
|
319
|
+
this.log('Toast position x: '+toastPosY+'px');
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
// Show
|
|
323
|
+
show(toast) {
|
|
324
|
+
|
|
325
|
+
this.$container.append(toast.$el);
|
|
326
|
+
this.bindEvents(toast);
|
|
327
|
+
this.setPosition(toast);
|
|
328
|
+
|
|
329
|
+
if (toast.animation) {
|
|
330
|
+
|
|
331
|
+
toast.$el.addClass('show');
|
|
332
|
+
toast.$inner.addClass(toast.animationSpeed);
|
|
333
|
+
toast.$inner.animateCss(toast.animationIn);
|
|
334
|
+
|
|
335
|
+
} else {
|
|
336
|
+
|
|
337
|
+
toast.$el.addClass('show');
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
if (toast.dismiss) {
|
|
341
|
+
|
|
342
|
+
setTimeout(() => {
|
|
343
|
+
this.close(toast);
|
|
344
|
+
}, toast.dismiss * 1000);
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
this.onShow(toast);
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
// Close
|
|
351
|
+
close(toast) {
|
|
352
|
+
|
|
353
|
+
if (toast.animation && !toast.$inner.hasClass('animated')) {
|
|
354
|
+
|
|
355
|
+
toast.$el.removeClass('show');
|
|
356
|
+
toast.$inner.animateCss(toast.animationOut, () => {
|
|
357
|
+
|
|
358
|
+
toast.$el.remove();
|
|
359
|
+
|
|
360
|
+
this.toasts = $.grep(this.toasts, function(item) {
|
|
361
|
+
return item.uuid != toast.uuid;
|
|
362
|
+
});
|
|
363
|
+
|
|
364
|
+
this.processQueue();
|
|
365
|
+
this.onClose(toast);
|
|
366
|
+
});
|
|
367
|
+
|
|
368
|
+
} else {
|
|
369
|
+
|
|
370
|
+
toast.$el.remove();
|
|
371
|
+
|
|
372
|
+
this.toasts = $.grep(this.toasts, function(item) {
|
|
373
|
+
return item.uuid != toast.uuid;
|
|
374
|
+
});
|
|
375
|
+
|
|
376
|
+
this.processQueue();
|
|
377
|
+
this.onClose(toast);
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
// Initialize callback
|
|
382
|
+
onInitialize() {
|
|
383
|
+
|
|
384
|
+
let onInitialize = this.onInitialize;
|
|
385
|
+
|
|
386
|
+
if (typeof onInitialize === 'function') {
|
|
387
|
+
|
|
388
|
+
onInitialize.call(this.container);
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
// Destroy callback
|
|
393
|
+
onDestroy() {
|
|
394
|
+
|
|
395
|
+
let onDestroy = this.onDestroy;
|
|
396
|
+
|
|
397
|
+
if (typeof onDestroy === 'function') {
|
|
398
|
+
|
|
399
|
+
onDestroy.call(this.container);
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
// Init callback
|
|
404
|
+
onInit(toast) {
|
|
405
|
+
|
|
406
|
+
let onInit = toast.onInit;
|
|
407
|
+
|
|
408
|
+
if (typeof onInit === 'function') {
|
|
409
|
+
|
|
410
|
+
onInit.call(toast);
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
// Show callback
|
|
415
|
+
onShow(toast) {
|
|
416
|
+
|
|
417
|
+
let onShow = toast.onShow;
|
|
418
|
+
|
|
419
|
+
if (typeof onShow === 'function') {
|
|
420
|
+
|
|
421
|
+
onShow.call(toast);
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
// Close callback
|
|
426
|
+
onClose(toast) {
|
|
427
|
+
|
|
428
|
+
let onClose = toast.onClose;
|
|
429
|
+
|
|
430
|
+
if (typeof onClose === 'function') {
|
|
431
|
+
|
|
432
|
+
onClose.call(toast);
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
// Debug log
|
|
437
|
+
log(...args) {
|
|
438
|
+
|
|
439
|
+
if (this.debug) {
|
|
440
|
+
|
|
441
|
+
if (typeof this.debug === 'function') {
|
|
442
|
+
this.debug(...args);
|
|
443
|
+
} else {
|
|
444
|
+
console.log(...args);
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
// Render template
|
|
450
|
+
_renderTemplate(toast) {
|
|
451
|
+
|
|
452
|
+
let faNameSpace = this.faPro ? 'far' : 'fas';
|
|
453
|
+
let content = '';
|
|
454
|
+
let header = '';
|
|
455
|
+
let body = '';
|
|
456
|
+
let bodyCloseBtn = '';
|
|
457
|
+
|
|
458
|
+
if (typeof toast.content === 'function') {
|
|
459
|
+
|
|
460
|
+
content = toast.content();
|
|
461
|
+
|
|
462
|
+
} else {
|
|
463
|
+
|
|
464
|
+
content = toast.content;
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
if (toast.header) {
|
|
468
|
+
|
|
469
|
+
header = `
|
|
470
|
+
<div class="toast-header">
|
|
471
|
+
|
|
472
|
+
<span>${toast.title}</span>
|
|
473
|
+
|
|
474
|
+
<button type="button" data-toast-close>
|
|
475
|
+
<i class="${faNameSpace} fa-times icon"></i>
|
|
476
|
+
</button>
|
|
477
|
+
|
|
478
|
+
</div>
|
|
479
|
+
`;
|
|
480
|
+
|
|
481
|
+
} else {
|
|
482
|
+
|
|
483
|
+
bodyCloseBtn = `
|
|
484
|
+
<button type="button" data-toast-close>
|
|
485
|
+
|
|
486
|
+
<i class="${faNameSpace} fa-times icon"></i>
|
|
487
|
+
|
|
488
|
+
</button>
|
|
489
|
+
`;
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
body = `
|
|
493
|
+
<div class="toast-body">
|
|
494
|
+
|
|
495
|
+
<span>${content}</span>
|
|
496
|
+
${bodyCloseBtn}
|
|
497
|
+
|
|
498
|
+
</div>
|
|
499
|
+
`;
|
|
500
|
+
|
|
501
|
+
return `
|
|
502
|
+
<div class="toast toast-${toast.size} toast-${toast.theme}" role="alert" id="${toast.uuid}">
|
|
503
|
+
|
|
504
|
+
<div class="toast-inner">
|
|
505
|
+
|
|
506
|
+
${header}
|
|
507
|
+
${body}
|
|
508
|
+
|
|
509
|
+
</div>
|
|
510
|
+
|
|
511
|
+
</div>
|
|
512
|
+
`;
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
static _jQueryInterface(config) {
|
|
516
|
+
|
|
517
|
+
return this.each(function() {
|
|
518
|
+
|
|
519
|
+
let data = $(this).data(DATA_KEY);
|
|
520
|
+
const _config = typeof config === 'object' && config;
|
|
521
|
+
|
|
522
|
+
if (!data) {
|
|
523
|
+
data = new Toast(this, _config);
|
|
524
|
+
$(this).data(DATA_KEY, data);
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
if (typeof config === 'string') {
|
|
528
|
+
|
|
529
|
+
if (typeof data[config] === 'undefined') {
|
|
530
|
+
throw new TypeError(`No method named "${config}"`)
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
data[config]()
|
|
534
|
+
}
|
|
535
|
+
});
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
if (typeof $ !== 'undefined') {
|
|
540
|
+
|
|
541
|
+
// jQuery
|
|
542
|
+
const JQUERY_NO_CONFLICT = $.fn[NAME];
|
|
543
|
+
|
|
544
|
+
$.fn[NAME] = Toast._jQueryInterface;
|
|
545
|
+
$.fn[NAME].Constructor = Toast;
|
|
546
|
+
|
|
547
|
+
$.fn[NAME].noConflict = () => {
|
|
548
|
+
|
|
549
|
+
$.fn[NAME] = JQUERY_NO_CONFLICT
|
|
550
|
+
|
|
551
|
+
return Toast._jQueryInterface
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
$.fn[NAME].defaults = {
|
|
555
|
+
title: '',
|
|
556
|
+
content: '',
|
|
557
|
+
template: '',
|
|
558
|
+
theme: 'dark',
|
|
559
|
+
placement: 'bottom-center',
|
|
560
|
+
placementX: null,
|
|
561
|
+
placementY: null,
|
|
562
|
+
animation: true,
|
|
563
|
+
animationIn: 'slideInUp',
|
|
564
|
+
animationOut: 'slideOutDown',
|
|
565
|
+
animationSpeed: 'faster',
|
|
566
|
+
offset: null,
|
|
567
|
+
size: null,
|
|
568
|
+
dismiss: 3,
|
|
569
|
+
header: false,
|
|
570
|
+
faPro: false,
|
|
571
|
+
debug: false,
|
|
572
|
+
onInitialize: null,
|
|
573
|
+
onDestroy: null,
|
|
574
|
+
onInit: null,
|
|
575
|
+
onDestroy: null,
|
|
576
|
+
onShow: null,
|
|
577
|
+
onClose: null
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
export default Toast;
|