izitoast 1.1.1 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +0 -0
- data/CODE_OF_CONDUCT.md +0 -0
- data/Gemfile +0 -0
- data/LICENSE.txt +0 -0
- data/README.md +3 -3
- data/Rakefile +0 -0
- data/bin/console +0 -0
- data/bin/setup +0 -0
- data/izitoast.gemspec +0 -0
- data/lib/izitoast.rb +0 -0
- data/lib/izitoast/version.rb +1 -1
- data/vendor/assets/javascripts/iziToast.js +729 -381
- data/vendor/assets/stylesheets/iziToast.css +313 -226
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 21e2c9991adaafe4f9aa92bf1d3bad62a94dd48a
|
4
|
+
data.tar.gz: 48f3507dd14d5eb13a8cf6e1b9a950d8597152f9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 49b942abd214ae947fda56ebc2b233fa37fc313ca245776f813856967aabec92ba966b750f670fb2009aa88a037283551173633e292a600da955f2d1d3833779
|
7
|
+
data.tar.gz: 50448bde1f7a9cead6089f1cf6f82c97b87ae45fe26b65cce9ec0933372191c26e608d5cf6a6a7eccbd876b40c6e66741527d0430e3eec15f462647e58491a11
|
data/.gitignore
CHANGED
File without changes
|
data/CODE_OF_CONDUCT.md
CHANGED
File without changes
|
data/Gemfile
CHANGED
File without changes
|
data/LICENSE.txt
CHANGED
File without changes
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Izitoast
|
2
2
|
|
3
|
-
Simple wrapper around [IZITOAST](
|
3
|
+
Simple wrapper around [IZITOAST](https://github.com/dolce/iziToast) js notification plugin [visit Authors website.](http://izitoast.marcelodolce.com)
|
4
4
|
|
5
5
|
|
6
6
|
## Installation
|
@@ -41,11 +41,11 @@ iziToast.success({
|
|
41
41
|
|
42
42
|
You will see notification in the bottom-right corner of your browser.
|
43
43
|
|
44
|
-
To find more about usage options, please [visit Authors website.](
|
44
|
+
To find more about usage options, please [visit Authors website.](http://izitoast.marcelodolce.com)
|
45
45
|
|
46
46
|
## Contributing
|
47
47
|
|
48
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/BadAllOff/
|
48
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/BadAllOff/iziToast-rails. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
49
49
|
|
50
50
|
|
51
51
|
## License
|
data/Rakefile
CHANGED
File without changes
|
data/bin/console
CHANGED
File without changes
|
data/bin/setup
CHANGED
File without changes
|
data/izitoast.gemspec
CHANGED
File without changes
|
data/lib/izitoast.rb
CHANGED
File without changes
|
data/lib/izitoast/version.rb
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
/*
|
2
|
-
* iziToast | v1.
|
2
|
+
* iziToast | v1.2.0
|
3
3
|
* http://izitoast.marcelodolce.com
|
4
4
|
* by Marcelo Dolce.
|
5
5
|
*/
|
6
6
|
(function (root, factory) {
|
7
|
-
if
|
7
|
+
if(typeof define === 'function' && define.amd) {
|
8
8
|
define([], factory(root));
|
9
|
-
} else if
|
9
|
+
} else if(typeof exports === 'object') {
|
10
10
|
module.exports = factory(root);
|
11
11
|
} else {
|
12
12
|
root.iziToast = factory(root);
|
13
13
|
}
|
14
|
-
})(typeof global !==
|
14
|
+
})(typeof global !== 'undefined' ? global : window || this.window || this.global, function (root) {
|
15
15
|
|
16
16
|
'use strict';
|
17
17
|
|
@@ -28,61 +28,81 @@
|
|
28
28
|
POSITIONS = ['bottomRight','bottomLeft','bottomCenter','topRight','topLeft','topCenter','center'],
|
29
29
|
THEMES = {
|
30
30
|
info: {
|
31
|
-
color:
|
32
|
-
icon:
|
31
|
+
color: 'blue',
|
32
|
+
icon: 'ico-info'
|
33
33
|
},
|
34
34
|
success: {
|
35
|
-
color:
|
36
|
-
icon:
|
35
|
+
color: 'green',
|
36
|
+
icon: 'ico-success'
|
37
37
|
},
|
38
38
|
warning: {
|
39
|
-
color:
|
40
|
-
icon:
|
39
|
+
color: 'orange',
|
40
|
+
icon: 'ico-warning'
|
41
41
|
},
|
42
42
|
error: {
|
43
|
-
color:
|
44
|
-
icon:
|
43
|
+
color: 'red',
|
44
|
+
icon: 'ico-error'
|
45
|
+
},
|
46
|
+
question: {
|
47
|
+
color: 'yellow',
|
48
|
+
icon: 'ico-question'
|
45
49
|
}
|
46
50
|
},
|
47
51
|
MOBILEWIDTH = 568,
|
48
52
|
CONFIG = {};
|
49
53
|
|
54
|
+
|
50
55
|
// Default settings
|
51
56
|
var defaults = {
|
57
|
+
id: null,
|
52
58
|
class: '',
|
53
59
|
title: '',
|
54
60
|
titleColor: '',
|
61
|
+
titleSize: '',
|
62
|
+
titleLineHeight: '',
|
55
63
|
message: '',
|
56
64
|
messageColor: '',
|
65
|
+
messageSize: '',
|
66
|
+
messageLineHeight: '',
|
57
67
|
backgroundColor: '',
|
68
|
+
theme: 'light', // dark
|
58
69
|
color: '', // blue, red, green, yellow
|
59
70
|
icon: '',
|
60
71
|
iconText: '',
|
61
72
|
iconColor: '',
|
62
73
|
image: '',
|
63
74
|
imageWidth: 50,
|
64
|
-
|
75
|
+
maxWidth: null,
|
76
|
+
zindex: null,
|
65
77
|
layout: 1,
|
66
78
|
balloon: false,
|
67
79
|
close: true,
|
80
|
+
closeOnEscape: false,
|
68
81
|
rtl: false,
|
69
82
|
position: 'bottomRight', // bottomRight, bottomLeft, topRight, topLeft, topCenter, bottomCenter, center
|
70
83
|
target: '',
|
71
84
|
targetFirst: true,
|
85
|
+
toastOnce: false,
|
72
86
|
timeout: 5000,
|
87
|
+
animateInside: true,
|
73
88
|
drag: true,
|
74
89
|
pauseOnHover: true,
|
75
90
|
resetOnHover: false,
|
76
91
|
progressBar: true,
|
77
92
|
progressBarColor: '',
|
78
|
-
|
79
|
-
|
93
|
+
progressBarEasing: 'linear',
|
94
|
+
overlay: false,
|
95
|
+
overlayClose: false,
|
96
|
+
overlayColor: 'rgba(0, 0, 0, 0.6)',
|
80
97
|
transitionIn: 'fadeInUp', // bounceInLeft, bounceInRight, bounceInUp, bounceInDown, fadeIn, fadeInDown, fadeInUp, fadeInLeft, fadeInRight, flipInX
|
81
98
|
transitionOut: 'fadeOut', // fadeOut, fadeOutUp, fadeOutDown, fadeOutLeft, fadeOutRight, flipOutX
|
82
99
|
transitionInMobile: 'fadeInUp',
|
83
100
|
transitionOutMobile: 'fadeOutDown',
|
84
|
-
|
85
|
-
|
101
|
+
buttons: {},
|
102
|
+
onOpening: function () {},
|
103
|
+
onOpened: function () {},
|
104
|
+
onClosing: function () {},
|
105
|
+
onClosed: function () {}
|
86
106
|
};
|
87
107
|
|
88
108
|
//
|
@@ -93,14 +113,31 @@
|
|
93
113
|
/**
|
94
114
|
* Polyfill for remove() method
|
95
115
|
*/
|
96
|
-
if
|
116
|
+
if(!('remove' in Element.prototype)) {
|
97
117
|
Element.prototype.remove = function() {
|
98
|
-
if
|
118
|
+
if(this.parentNode) {
|
99
119
|
this.parentNode.removeChild(this);
|
100
120
|
}
|
101
121
|
};
|
102
122
|
}
|
103
123
|
|
124
|
+
/*
|
125
|
+
* Polyfill for CustomEvent for IE >= 9
|
126
|
+
* https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent/CustomEvent#Polyfill
|
127
|
+
*/
|
128
|
+
if(typeof window.CustomEvent !== 'function') {
|
129
|
+
var CustomEventPolyfill = function (event, params) {
|
130
|
+
params = params || { bubbles: false, cancelable: false, detail: undefined };
|
131
|
+
var evt = document.createEvent('CustomEvent');
|
132
|
+
evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail);
|
133
|
+
return evt;
|
134
|
+
};
|
135
|
+
|
136
|
+
CustomEventPolyfill.prototype = window.Event.prototype;
|
137
|
+
|
138
|
+
window.CustomEvent = CustomEventPolyfill;
|
139
|
+
}
|
140
|
+
|
104
141
|
/**
|
105
142
|
* A simple forEach() implementation for Arrays, Objects and NodeLists
|
106
143
|
* @private
|
@@ -109,9 +146,9 @@
|
|
109
146
|
* @param {Array|Object|NodeList} scope Object/NodeList/Array that forEach is iterating over (aka `this`)
|
110
147
|
*/
|
111
148
|
var forEach = function (collection, callback, scope) {
|
112
|
-
if
|
149
|
+
if(Object.prototype.toString.call(collection) === '[object Object]') {
|
113
150
|
for (var prop in collection) {
|
114
|
-
if
|
151
|
+
if(Object.prototype.hasOwnProperty.call(collection, prop)) {
|
115
152
|
callback.call(scope, collection[prop], prop, collection);
|
116
153
|
}
|
117
154
|
}
|
@@ -163,7 +200,7 @@
|
|
163
200
|
* @private
|
164
201
|
*/
|
165
202
|
var isColor = function(color){
|
166
|
-
if( color.substring(0,1) ==
|
203
|
+
if( color.substring(0,1) == '#' || color.substring(0,3) == 'rgb' || color.substring(0,3) == 'hsl' ){
|
167
204
|
return true;
|
168
205
|
} else {
|
169
206
|
return false;
|
@@ -171,6 +208,19 @@
|
|
171
208
|
};
|
172
209
|
|
173
210
|
|
211
|
+
/**
|
212
|
+
* Check if is a Base64 string
|
213
|
+
* @private
|
214
|
+
*/
|
215
|
+
var isBase64 = function(str) {
|
216
|
+
try {
|
217
|
+
return btoa(atob(str)) == str;
|
218
|
+
} catch (err) {
|
219
|
+
return false;
|
220
|
+
}
|
221
|
+
};
|
222
|
+
|
223
|
+
|
174
224
|
/**
|
175
225
|
* Drag method of toasts
|
176
226
|
* @private
|
@@ -184,30 +234,36 @@
|
|
184
234
|
opacityRange = 0.3,
|
185
235
|
distance = 180;
|
186
236
|
|
187
|
-
|
237
|
+
if(xpos !== 0){
|
238
|
+
|
239
|
+
toast.classList.add(PLUGIN_NAME+'-dragged');
|
240
|
+
|
241
|
+
toast.style.transform = 'translateX('+xpos + 'px)';
|
242
|
+
|
243
|
+
if(xpos > 0){
|
244
|
+
opacity = (distance-xpos) / distance;
|
245
|
+
if(opacity < opacityRange){
|
246
|
+
instance.hide(toast, extend(settings, { transitionOut: 'fadeOutRight', transitionOutMobile: 'fadeOutRight' }), 'drag');
|
247
|
+
}
|
248
|
+
} else {
|
249
|
+
opacity = (distance+xpos) / distance;
|
250
|
+
if(opacity < opacityRange){
|
251
|
+
instance.hide(toast, extend(settings, { transitionOut: 'fadeOutLeft', transitionOutMobile: 'fadeOutLeft' }), 'drag');
|
252
|
+
}
|
253
|
+
}
|
254
|
+
toast.style.opacity = opacity;
|
255
|
+
|
256
|
+
if(opacity < opacityRange){
|
188
257
|
|
189
|
-
|
190
|
-
|
191
|
-
if(opacity < opacityRange){
|
192
|
-
instance.hide(extend(settings, { transitionOut: 'fadeOutRight', transitionOutMobile: 'fadeOutRight' }), toast, 'drag');
|
193
|
-
}
|
194
|
-
} else {
|
195
|
-
opacity = (distance+xpos) / distance;
|
196
|
-
if(opacity < opacityRange){
|
197
|
-
instance.hide(extend(settings, { transitionOut: 'fadeOutLeft', transitionOutMobile: 'fadeOutLeft' }), toast, 'drag');
|
198
|
-
}
|
199
|
-
}
|
200
|
-
toast.style.opacity = opacity;
|
201
|
-
|
202
|
-
if(opacity < opacityRange){
|
258
|
+
if(ISCHROME || ISFIREFOX)
|
259
|
+
toast.style.left = xpos+'px';
|
203
260
|
|
204
|
-
|
205
|
-
toast.style.left = xpos+'px';
|
261
|
+
toast.parentNode.style.opacity = opacityRange;
|
206
262
|
|
207
|
-
|
263
|
+
this.stopMoving(toast, null);
|
264
|
+
}
|
265
|
+
}
|
208
266
|
|
209
|
-
this.stopMoving(toast, null);
|
210
|
-
}
|
211
267
|
|
212
268
|
},
|
213
269
|
startMoving: function(toast, instance, settings, e) {
|
@@ -220,9 +276,9 @@
|
|
220
276
|
|
221
277
|
toast.classList.remove(settings.transitionIn);
|
222
278
|
toast.classList.remove(settings.transitionInMobile);
|
223
|
-
toast.style.transition =
|
279
|
+
toast.style.transition = '';
|
224
280
|
|
225
|
-
if
|
281
|
+
if(ACCEPTSTOUCH) {
|
226
282
|
document.ontouchmove = function(e) {
|
227
283
|
e.preventDefault();
|
228
284
|
e = e || window.event;
|
@@ -243,75 +299,31 @@
|
|
243
299
|
},
|
244
300
|
stopMoving: function(toast, e) {
|
245
301
|
|
246
|
-
if
|
302
|
+
if(ACCEPTSTOUCH) {
|
247
303
|
document.ontouchmove = function() {};
|
248
304
|
} else {
|
249
305
|
document.onmousemove = function() {};
|
250
306
|
}
|
251
|
-
|
252
|
-
toast.style.opacity =
|
253
|
-
toast.style.transform =
|
254
|
-
|
255
|
-
|
256
|
-
|
307
|
+
|
308
|
+
toast.style.opacity = '';
|
309
|
+
toast.style.transform = '';
|
310
|
+
|
311
|
+
if(toast.classList.contains(PLUGIN_NAME+'-dragged')){
|
312
|
+
|
313
|
+
toast.classList.remove(PLUGIN_NAME+'-dragged');
|
314
|
+
|
315
|
+
toast.style.transition = 'transform 0.4s ease, opacity 0.4s ease';
|
316
|
+
setTimeout(function() {
|
317
|
+
toast.style.transition = '';
|
318
|
+
}, 400);
|
319
|
+
}
|
320
|
+
|
257
321
|
}
|
258
322
|
};
|
259
323
|
|
260
324
|
}();
|
261
325
|
|
262
326
|
|
263
|
-
/**
|
264
|
-
* Do the calculation to move the progress bar
|
265
|
-
* @private
|
266
|
-
*/
|
267
|
-
var moveProgress = function(toast, settings, callback){
|
268
|
-
|
269
|
-
var isPaused = false;
|
270
|
-
var isReseted = false;
|
271
|
-
var isClosed = false;
|
272
|
-
var timerTimeout = null;
|
273
|
-
var elem = toast.querySelector("."+PLUGIN_NAME+"-progressbar div");
|
274
|
-
var progressBar = {
|
275
|
-
hideEta: null,
|
276
|
-
maxHideTime: null,
|
277
|
-
currentTime: new Date().getTime(),
|
278
|
-
updateProgress: function()
|
279
|
-
{
|
280
|
-
isPaused = toast.classList.contains(PLUGIN_NAME+'-paused') ? true : false;
|
281
|
-
isReseted = toast.classList.contains(PLUGIN_NAME+'-reseted') ? true : false;
|
282
|
-
isClosed = toast.classList.contains(PLUGIN_NAME+'-closed') ? true : false;
|
283
|
-
|
284
|
-
if(isReseted){
|
285
|
-
clearTimeout(timerTimeout);
|
286
|
-
elem.style.width = '100%';
|
287
|
-
moveProgress(toast, settings, callback);
|
288
|
-
toast.classList.remove(PLUGIN_NAME+'-reseted');
|
289
|
-
}
|
290
|
-
if(isClosed){
|
291
|
-
clearTimeout(timerTimeout);
|
292
|
-
toast.classList.remove(PLUGIN_NAME+'-closed');
|
293
|
-
}
|
294
|
-
|
295
|
-
if(!isPaused && !isReseted && !isClosed){
|
296
|
-
progressBar.currentTime = progressBar.currentTime+10;
|
297
|
-
var percentage = ((progressBar.hideEta - (progressBar.currentTime)) / progressBar.maxHideTime) * 100;
|
298
|
-
elem.style.width = percentage + '%';
|
299
|
-
|
300
|
-
if(Math.round(percentage) < 0 || typeof toast != 'object'){
|
301
|
-
clearTimeout(timerTimeout);
|
302
|
-
callback.apply();
|
303
|
-
}
|
304
|
-
}
|
305
|
-
|
306
|
-
}
|
307
|
-
};
|
308
|
-
if (settings.timeout > 0) {
|
309
|
-
progressBar.maxHideTime = parseFloat(settings.timeout);
|
310
|
-
progressBar.hideEta = new Date().getTime() + progressBar.maxHideTime;
|
311
|
-
timerTimeout = setInterval(progressBar.updateProgress, 10);
|
312
|
-
}
|
313
|
-
};
|
314
|
-
|
315
327
|
/**
|
316
328
|
* Destroy the current initialization.
|
317
329
|
* @public
|
@@ -327,8 +339,11 @@
|
|
327
339
|
});
|
328
340
|
|
329
341
|
// Remove event listeners
|
330
|
-
document.removeEventListener(PLUGIN_NAME+'-
|
331
|
-
document.removeEventListener(PLUGIN_NAME+'-
|
342
|
+
document.removeEventListener(PLUGIN_NAME+'-opened', {}, false);
|
343
|
+
document.removeEventListener(PLUGIN_NAME+'-opening', {}, false);
|
344
|
+
document.removeEventListener(PLUGIN_NAME+'-closing', {}, false);
|
345
|
+
document.removeEventListener(PLUGIN_NAME+'-closed', {}, false);
|
346
|
+
document.removeEventListener('keyup', {}, false);
|
332
347
|
|
333
348
|
// Reset variables
|
334
349
|
CONFIG = {};
|
@@ -367,20 +382,151 @@
|
|
367
382
|
});
|
368
383
|
|
369
384
|
|
385
|
+
/**
|
386
|
+
* Do the calculation to move the progress bar
|
387
|
+
* @private
|
388
|
+
*/
|
389
|
+
$iziToast.progress = function ($toast, options, callback) {
|
390
|
+
|
391
|
+
var that = this,
|
392
|
+
settings = extend(that.settings, options || {}),
|
393
|
+
$elem = $toast.querySelector('.'+PLUGIN_NAME+'-progressbar div');
|
394
|
+
|
395
|
+
return {
|
396
|
+
start: function() {
|
397
|
+
|
398
|
+
if($elem !== null){
|
399
|
+
$elem.style.transition = 'width '+ settings.timeout +'ms '+settings.progressBarEasing;
|
400
|
+
$elem.style.width = '0%';
|
401
|
+
}
|
402
|
+
settings.TIME.START = new Date().getTime();
|
403
|
+
settings.TIME.END = settings.TIME.START + settings.timeout;
|
404
|
+
settings.TIME.TIMER = setTimeout(function() {
|
405
|
+
|
406
|
+
clearTimeout(settings.TIME.TIMER);
|
407
|
+
|
408
|
+
if(!$toast.classList.contains(PLUGIN_NAME+'-closing')){
|
409
|
+
|
410
|
+
that.hide($toast, settings, 'timeout');
|
411
|
+
|
412
|
+
if(typeof callback === 'function'){
|
413
|
+
callback.apply(that);
|
414
|
+
}
|
415
|
+
}
|
416
|
+
|
417
|
+
}, settings.timeout);
|
418
|
+
|
419
|
+
},
|
420
|
+
pause: function() {
|
421
|
+
|
422
|
+
settings.TIME.REMAINING = settings.TIME.END - new Date().getTime();
|
423
|
+
|
424
|
+
clearTimeout(settings.TIME.TIMER);
|
425
|
+
|
426
|
+
if($elem !== null){
|
427
|
+
var computedStyle = window.getComputedStyle($elem),
|
428
|
+
propertyWidth = computedStyle.getPropertyValue('width');
|
429
|
+
|
430
|
+
$elem.style.transition = 'none';
|
431
|
+
$elem.style.width = propertyWidth;
|
432
|
+
}
|
433
|
+
|
434
|
+
if(typeof callback === 'function'){
|
435
|
+
setTimeout(function() {
|
436
|
+
callback.apply(that);
|
437
|
+
}, 10);
|
438
|
+
}
|
439
|
+
|
440
|
+
},
|
441
|
+
resume: function() {
|
442
|
+
|
443
|
+
if($elem !== null){
|
444
|
+
$elem.style.transition = 'width '+ settings.TIME.REMAINING +'ms '+settings.progressBarEasing;
|
445
|
+
$elem.style.width = '0%';
|
446
|
+
}
|
447
|
+
|
448
|
+
settings.TIME.END = new Date().getTime() + settings.TIME.REMAINING;
|
449
|
+
settings.TIME.TIMER = setTimeout(function() {
|
450
|
+
|
451
|
+
clearTimeout(settings.TIME.TIMER);
|
452
|
+
|
453
|
+
if(!$toast.classList.contains(PLUGIN_NAME+'-closing')){
|
454
|
+
|
455
|
+
that.hide($toast, settings, 'timeout');
|
456
|
+
|
457
|
+
if(typeof callback === 'function'){
|
458
|
+
callback.apply(that);
|
459
|
+
}
|
460
|
+
}
|
461
|
+
|
462
|
+
|
463
|
+
}, settings.TIME.REMAINING);
|
464
|
+
|
465
|
+
},
|
466
|
+
reset: function(){
|
467
|
+
|
468
|
+
clearTimeout(settings.TIME.TIMER);
|
469
|
+
|
470
|
+
if($elem !== null){
|
471
|
+
$elem.style.transition = 'none';
|
472
|
+
$elem.style.width = '100%';
|
473
|
+
}
|
474
|
+
|
475
|
+
if(typeof callback === 'function'){
|
476
|
+
setTimeout(function() {
|
477
|
+
callback.apply(that);
|
478
|
+
}, 10);
|
479
|
+
}
|
480
|
+
|
481
|
+
}
|
482
|
+
};
|
483
|
+
|
484
|
+
};
|
485
|
+
|
486
|
+
|
370
487
|
/**
|
371
488
|
* Close the specific Toast
|
372
489
|
* @public
|
373
490
|
* @param {Object} options User settings
|
374
491
|
*/
|
375
|
-
$iziToast.hide = function (
|
492
|
+
$iziToast.hide = function ($toast, options, closedBy) {
|
376
493
|
|
377
|
-
var settings = extend(
|
378
|
-
closedBy = closedBy ||
|
494
|
+
var settings = extend(this.settings, options || {});
|
495
|
+
closedBy = closedBy || null;
|
379
496
|
|
380
497
|
if(typeof $toast != 'object'){
|
381
498
|
$toast = document.querySelector($toast);
|
382
499
|
}
|
383
|
-
|
500
|
+
|
501
|
+
$toast.classList.add(PLUGIN_NAME+'-closing');
|
502
|
+
|
503
|
+
settings.closedBy = closedBy;
|
504
|
+
settings.REF = $toast.getAttribute('data-iziToast-ref');
|
505
|
+
|
506
|
+
// Overlay
|
507
|
+
(function(){
|
508
|
+
|
509
|
+
var $overlay = document.querySelector('.'+PLUGIN_NAME+'-overlay');
|
510
|
+
if($overlay !== null){
|
511
|
+
var refs = $overlay.getAttribute('data-iziToast-ref');
|
512
|
+
refs = refs.split(',');
|
513
|
+
var index = refs.indexOf(settings.REF);
|
514
|
+
|
515
|
+
if(index !== -1){
|
516
|
+
refs.splice(index, 1);
|
517
|
+
}
|
518
|
+
$overlay.setAttribute('data-iziToast-ref', refs.join());
|
519
|
+
|
520
|
+
if(refs.length === 0){
|
521
|
+
$overlay.classList.remove('fadeIn');
|
522
|
+
$overlay.classList.add('fadeOut');
|
523
|
+
setTimeout(function() {
|
524
|
+
$overlay.remove();
|
525
|
+
}, 700);
|
526
|
+
}
|
527
|
+
}
|
528
|
+
|
529
|
+
})();
|
384
530
|
|
385
531
|
if(settings.transitionIn || settings.transitionInMobile){
|
386
532
|
$toast.classList.remove(settings.transitionIn);
|
@@ -390,7 +536,7 @@
|
|
390
536
|
if(ISMOBILE || window.innerWidth <= MOBILEWIDTH){
|
391
537
|
if(settings.transitionOutMobile)
|
392
538
|
$toast.classList.add(settings.transitionOutMobile);
|
393
|
-
} else{
|
539
|
+
} else {
|
394
540
|
if(settings.transitionOut)
|
395
541
|
$toast.classList.add(settings.transitionOut);
|
396
542
|
}
|
@@ -402,31 +548,40 @@
|
|
402
548
|
$toast.parentNode.style.transitionDelay = '0.2s';
|
403
549
|
}
|
404
550
|
|
551
|
+
try {
|
552
|
+
settings.closedBy = closedBy;
|
553
|
+
var event = new CustomEvent(PLUGIN_NAME+'-closing', {detail: settings, bubbles: true, cancelable: true});
|
554
|
+
document.dispatchEvent(event);
|
555
|
+
} catch(ex){
|
556
|
+
console.warn(ex);
|
557
|
+
}
|
558
|
+
|
405
559
|
setTimeout(function() {
|
560
|
+
|
406
561
|
$toast.parentNode.style.height = '0px';
|
407
562
|
$toast.parentNode.style.overflow = '';
|
408
|
-
|
563
|
+
|
564
|
+
setTimeout(function(){
|
565
|
+
|
409
566
|
$toast.parentNode.remove();
|
410
|
-
|
411
|
-
|
567
|
+
try {
|
568
|
+
settings.closedBy = closedBy;
|
569
|
+
var event = new CustomEvent(PLUGIN_NAME+'-closed', {detail: settings, bubbles: true, cancelable: true});
|
570
|
+
document.dispatchEvent(event);
|
571
|
+
} catch(ex){
|
572
|
+
console.warn(ex);
|
573
|
+
}
|
412
574
|
|
413
|
-
|
414
|
-
|
415
|
-
var event;
|
416
|
-
if (window.CustomEvent) {
|
417
|
-
event = new CustomEvent(PLUGIN_NAME+'-close', {detail: {class: settings.class}});
|
418
|
-
} else {
|
419
|
-
event = document.createEvent('CustomEvent');
|
420
|
-
event.initCustomEvent(PLUGIN_NAME+'-close', true, true, {class: settings.class});
|
575
|
+
if(typeof settings.onClosed !== 'undefined'){
|
576
|
+
settings.onClosed.apply(null, [settings, $toast, closedBy]);
|
421
577
|
}
|
422
|
-
document.dispatchEvent(event);
|
423
|
-
} catch(ex){
|
424
|
-
console.warn(ex);
|
425
|
-
}
|
426
|
-
}
|
427
578
|
|
428
|
-
|
429
|
-
|
579
|
+
}, 1000);
|
580
|
+
}, 200);
|
581
|
+
|
582
|
+
|
583
|
+
if(typeof settings.onClosing !== 'undefined'){
|
584
|
+
settings.onClosing.apply(null, [settings, $toast, closedBy]);
|
430
585
|
}
|
431
586
|
};
|
432
587
|
|
@@ -443,349 +598,542 @@
|
|
443
598
|
var settings = extend(CONFIG, options || {});
|
444
599
|
settings = extend(defaults, settings);
|
445
600
|
|
446
|
-
|
447
|
-
$toastCapsule.classList.add(PLUGIN_NAME+"-capsule");
|
448
|
-
|
449
|
-
var $toast = document.createElement("div");
|
450
|
-
$toast.classList.add(PLUGIN_NAME);
|
601
|
+
settings.TIME = {};
|
451
602
|
|
452
|
-
if(
|
453
|
-
|
454
|
-
$toast.classList.add(settings.transitionInMobile);
|
455
|
-
} else {
|
456
|
-
if(settings.transitionIn.length>0)
|
457
|
-
$toast.classList.add(settings.transitionIn);
|
603
|
+
if(settings.toastOnce && settings.id && document.querySelectorAll('.'+PLUGIN_NAME+'#'+settings.id).length > 0){
|
604
|
+
return false;
|
458
605
|
}
|
459
606
|
|
460
|
-
|
461
|
-
|
462
|
-
|
607
|
+
settings.REF = new Date().getTime() + Math.floor((Math.random() * 10000000) + 1);
|
608
|
+
|
609
|
+
var $DOM = {
|
610
|
+
body: document.querySelector('body'),
|
611
|
+
overlay: document.createElement('div'),
|
612
|
+
toast: document.createElement('div'),
|
613
|
+
toastBody: document.createElement('div'),
|
614
|
+
toastTexts: document.createElement('div'),
|
615
|
+
toastCapsule: document.createElement('div'),
|
616
|
+
icon: document.createElement('i'),
|
617
|
+
cover: document.createElement('div'),
|
618
|
+
buttons: document.createElement('div'),
|
619
|
+
wrapper: null
|
620
|
+
};
|
463
621
|
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
$toast.style.background = settings.color;
|
468
|
-
} else {
|
469
|
-
$toast.classList.add(PLUGIN_NAME+'-color-'+settings.color);
|
470
|
-
}
|
471
|
-
}
|
472
|
-
if (settings.backgroundColor.length > 0) {
|
473
|
-
$toast.style.background = settings.backgroundColor;
|
474
|
-
}
|
622
|
+
$DOM.toast.setAttribute('data-iziToast-ref', settings.REF);
|
623
|
+
$DOM.toast.appendChild($DOM.toastBody);
|
624
|
+
$DOM.toastCapsule.appendChild($DOM.toast);
|
475
625
|
|
476
|
-
|
477
|
-
|
478
|
-
}
|
626
|
+
// CSS Settings
|
627
|
+
(function(){
|
479
628
|
|
480
|
-
|
481
|
-
|
482
|
-
$
|
483
|
-
$
|
484
|
-
$
|
485
|
-
$toast.appendChild($cover);
|
486
|
-
}
|
629
|
+
$DOM.toast.classList.add(PLUGIN_NAME);
|
630
|
+
$DOM.toast.classList.add(PLUGIN_NAME+'-opening');
|
631
|
+
$DOM.toastCapsule.classList.add(PLUGIN_NAME+'-capsule');
|
632
|
+
$DOM.toastBody.classList.add(PLUGIN_NAME + '-body');
|
633
|
+
$DOM.toastTexts.classList.add(PLUGIN_NAME + '-texts');
|
487
634
|
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
$buttonClose.classList.add(PLUGIN_NAME + '-close');
|
492
|
-
$toast.appendChild($buttonClose);
|
493
|
-
} else {
|
494
|
-
if(settings.rtl){
|
495
|
-
$toast.style.paddingLeft = "30px";
|
635
|
+
if(ISMOBILE || window.innerWidth <= MOBILEWIDTH){
|
636
|
+
if(settings.transitionInMobile)
|
637
|
+
$DOM.toast.classList.add(settings.transitionInMobile);
|
496
638
|
} else {
|
497
|
-
|
639
|
+
if(settings.transitionIn)
|
640
|
+
$DOM.toast.classList.add(settings.transitionIn);
|
498
641
|
}
|
499
|
-
}
|
500
642
|
|
501
|
-
|
643
|
+
if(settings.class){
|
644
|
+
var classes = settings.class.split(' ');
|
645
|
+
forEach(classes, function (value, index) {
|
646
|
+
$DOM.toast.classList.add(value);
|
647
|
+
});
|
648
|
+
}
|
502
649
|
|
503
|
-
|
504
|
-
$progressBar.classList.add(PLUGIN_NAME + '-progressbar');
|
650
|
+
if(settings.id){ $DOM.toast.id = settings.id; }
|
505
651
|
|
506
|
-
|
507
|
-
$progressBarDiv.style.background = settings.progressBarColor;
|
652
|
+
if(settings.rtl){ $DOM.toast.classList.add(PLUGIN_NAME + '-rtl'); }
|
508
653
|
|
509
|
-
$
|
510
|
-
$toast.appendChild($progressBar);
|
511
|
-
|
512
|
-
setTimeout(function() {
|
513
|
-
moveProgress($toast, settings, function(){
|
514
|
-
that.hide(settings, $toast);
|
515
|
-
});
|
516
|
-
},300);
|
517
|
-
}
|
518
|
-
else if( settings.progressBar === false && settings.timeout > 0){
|
519
|
-
setTimeout(function() {
|
520
|
-
that.hide(settings, $toast);
|
521
|
-
}, settings.timeout);
|
522
|
-
}
|
654
|
+
if(settings.layout > 1){ $DOM.toast.classList.add(PLUGIN_NAME+'-layout'+settings.layout); }
|
523
655
|
|
524
|
-
|
525
|
-
$toastBody.classList.add(PLUGIN_NAME + '-body');
|
656
|
+
if(settings.balloon){ $DOM.toast.classList.add(PLUGIN_NAME+'-balloon'); }
|
526
657
|
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
658
|
+
if(settings.maxWidth){
|
659
|
+
if( !isNaN(settings.maxWidth) ){
|
660
|
+
$DOM.toast.style.maxWidth = settings.maxWidth+'px';
|
661
|
+
} else {
|
662
|
+
$DOM.toast.style.maxWidth = settings.maxWidth;
|
663
|
+
}
|
532
664
|
}
|
533
|
-
}
|
534
665
|
|
535
|
-
|
536
|
-
|
537
|
-
$
|
538
|
-
|
539
|
-
if (settings.iconText){
|
540
|
-
$icon.appendChild(document.createTextNode(settings.iconText));
|
666
|
+
if(settings.theme !== '' || settings.theme !== 'light') {
|
667
|
+
|
668
|
+
$DOM.toast.classList.add(PLUGIN_NAME+'-theme-'+settings.theme);
|
541
669
|
}
|
542
670
|
|
543
|
-
if(settings.
|
544
|
-
|
671
|
+
if(settings.color) { //#, rgb, rgba, hsl
|
672
|
+
|
673
|
+
if( isColor(settings.color) ){
|
674
|
+
$DOM.toast.style.background = settings.color;
|
675
|
+
} else {
|
676
|
+
$DOM.toast.classList.add(PLUGIN_NAME+'-color-'+settings.color);
|
677
|
+
}
|
678
|
+
}
|
679
|
+
|
680
|
+
if(settings.backgroundColor) {
|
681
|
+
$DOM.toast.style.background = settings.backgroundColor;
|
682
|
+
if(settings.balloon){
|
683
|
+
$DOM.toast.style.borderColor = settings.backgroundColor;
|
684
|
+
}
|
685
|
+
}
|
686
|
+
})();
|
687
|
+
|
688
|
+
// Cover image
|
689
|
+
(function(){
|
690
|
+
if(settings.image) {
|
691
|
+
$DOM.cover.classList.add(PLUGIN_NAME + '-cover');
|
692
|
+
$DOM.cover.style.width = settings.imageWidth + 'px';
|
693
|
+
|
694
|
+
if(isBase64(settings.image.replace(/ /g,''))){
|
695
|
+
$DOM.cover.style.backgroundImage = 'url(data:image/png;base64,' + settings.image.replace(/ /g,'') + ')';
|
696
|
+
} else {
|
697
|
+
$DOM.cover.style.backgroundImage = 'url(' + settings.image + ')';
|
698
|
+
}
|
699
|
+
|
700
|
+
if(settings.rtl){
|
701
|
+
$DOM.toastBody.style.marginRight = (settings.imageWidth + 10) + 'px';
|
702
|
+
} else {
|
703
|
+
$DOM.toastBody.style.marginLeft = (settings.imageWidth + 10) + 'px';
|
704
|
+
}
|
705
|
+
$DOM.toast.appendChild($DOM.cover);
|
706
|
+
}
|
707
|
+
})();
|
708
|
+
|
709
|
+
// Button close
|
710
|
+
(function(){
|
711
|
+
if(settings.close){
|
712
|
+
|
713
|
+
$DOM.buttonClose = document.createElement('button');
|
714
|
+
|
715
|
+
$DOM.buttonClose.classList.add(PLUGIN_NAME + '-close');
|
716
|
+
$DOM.buttonClose.addEventListener('click', function (e) {
|
717
|
+
var button = e.target;
|
718
|
+
that.hide($DOM.toast, settings, 'button');
|
719
|
+
});
|
720
|
+
$DOM.toast.appendChild($DOM.buttonClose);
|
545
721
|
} else {
|
546
|
-
|
722
|
+
if(settings.rtl){
|
723
|
+
$DOM.toast.style.paddingLeft = '20px';
|
724
|
+
} else {
|
725
|
+
$DOM.toast.style.paddingRight = '20px';
|
726
|
+
}
|
547
727
|
}
|
548
|
-
|
549
|
-
|
550
|
-
|
728
|
+
})();
|
729
|
+
|
730
|
+
// Progress Bar & Timeout
|
731
|
+
(function(){
|
732
|
+
if(settings.timeout) {
|
733
|
+
|
734
|
+
if(settings.progressBar){
|
735
|
+
$DOM.progressBar = document.createElement('div');
|
736
|
+
$DOM.progressBarDiv = document.createElement('div');
|
737
|
+
$DOM.progressBar.classList.add(PLUGIN_NAME + '-progressbar');
|
738
|
+
$DOM.progressBarDiv.style.background = settings.progressBarColor;
|
739
|
+
$DOM.progressBar.appendChild($DOM.progressBarDiv);
|
740
|
+
$DOM.toast.appendChild($DOM.progressBar);
|
741
|
+
}
|
742
|
+
|
743
|
+
if(settings.pauseOnHover && !settings.resetOnHover){
|
744
|
+
|
745
|
+
$DOM.toast.addEventListener('mouseenter', function (e) {
|
746
|
+
this.classList.add(PLUGIN_NAME+'-paused');
|
747
|
+
|
748
|
+
that.progress($DOM.toast, settings).pause();
|
749
|
+
});
|
750
|
+
$DOM.toast.addEventListener('mouseleave', function (e) {
|
751
|
+
this.classList.remove(PLUGIN_NAME+'-paused');
|
752
|
+
|
753
|
+
that.progress($DOM.toast, settings).resume();
|
754
|
+
});
|
755
|
+
}
|
756
|
+
|
757
|
+
if(settings.resetOnHover){
|
758
|
+
|
759
|
+
$DOM.toast.addEventListener('mouseenter', function (e) {
|
760
|
+
this.classList.add(PLUGIN_NAME+'-reseted');
|
761
|
+
|
762
|
+
that.progress($DOM.toast, settings).reset();
|
763
|
+
});
|
764
|
+
$DOM.toast.addEventListener('mouseleave', function (e) {
|
765
|
+
this.classList.remove(PLUGIN_NAME+'-reseted');
|
766
|
+
|
767
|
+
that.progress($DOM.toast, settings).start();
|
768
|
+
});
|
769
|
+
}
|
551
770
|
}
|
552
|
-
|
553
|
-
}
|
771
|
+
})();
|
554
772
|
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
773
|
+
// Icon
|
774
|
+
(function(){
|
775
|
+
if(settings.icon) {
|
776
|
+
$DOM.icon.setAttribute('class', PLUGIN_NAME + '-icon ' + settings.icon);
|
777
|
+
|
778
|
+
if(settings.iconText){
|
779
|
+
$DOM.icon.appendChild(document.createTextNode(settings.iconText));
|
780
|
+
}
|
560
781
|
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
782
|
+
if(settings.rtl){
|
783
|
+
$DOM.toastBody.style.paddingRight = '33px';
|
784
|
+
} else {
|
785
|
+
$DOM.toastBody.style.paddingLeft = '33px';
|
786
|
+
}
|
787
|
+
|
788
|
+
if(settings.iconColor){
|
789
|
+
$DOM.icon.style.color = settings.iconColor;
|
790
|
+
}
|
791
|
+
$DOM.toastBody.appendChild($DOM.icon);
|
792
|
+
}
|
793
|
+
})();
|
566
794
|
|
567
|
-
|
568
|
-
|
569
|
-
|
795
|
+
// Title
|
796
|
+
(function(){
|
797
|
+
if(settings.title.length > 0) {
|
798
|
+
|
799
|
+
$DOM.strong = document.createElement('strong');
|
800
|
+
$DOM.strong.classList.add(PLUGIN_NAME + '-title');
|
801
|
+
$DOM.strong.appendChild(createFragElem(settings.title));
|
802
|
+
$DOM.toastTexts.appendChild($DOM.strong);
|
803
|
+
|
804
|
+
if(settings.titleColor) {
|
805
|
+
$DOM.strong.style.color = settings.titleColor;
|
806
|
+
}
|
807
|
+
if(settings.titleSize) {
|
808
|
+
if( !isNaN(settings.titleSize) ){
|
809
|
+
$DOM.strong.style.fontSize = settings.titleSize+'px';
|
810
|
+
} else {
|
811
|
+
$DOM.strong.style.fontSize = settings.titleSize;
|
812
|
+
}
|
813
|
+
}
|
814
|
+
if(settings.titleLineHeight) {
|
815
|
+
if( !isNaN(settings.titleSize) ){
|
816
|
+
$DOM.strong.style.lineHeight = settings.titleLineHeight+'px';
|
817
|
+
} else {
|
818
|
+
$DOM.strong.style.lineHeight = settings.titleLineHeight;
|
819
|
+
}
|
820
|
+
}
|
821
|
+
}
|
822
|
+
})();
|
823
|
+
|
824
|
+
// Message
|
825
|
+
(function(){
|
826
|
+
if(settings.message.length > 0) {
|
827
|
+
|
828
|
+
$DOM.p = document.createElement('p');
|
829
|
+
$DOM.p.classList.add(PLUGIN_NAME + '-message');
|
830
|
+
$DOM.p.appendChild(createFragElem(settings.message));
|
831
|
+
$DOM.toastTexts.appendChild($DOM.p);
|
832
|
+
|
833
|
+
if(settings.messageColor) {
|
834
|
+
$DOM.p.style.color = settings.messageColor;
|
835
|
+
}
|
836
|
+
if(settings.messageSize) {
|
837
|
+
if( !isNaN(settings.titleSize) ){
|
838
|
+
$DOM.p.style.fontSize = settings.messageSize+'px';
|
839
|
+
} else {
|
840
|
+
$DOM.p.style.fontSize = settings.messageSize;
|
841
|
+
}
|
842
|
+
}
|
843
|
+
if(settings.messageLineHeight) {
|
844
|
+
|
845
|
+
if( !isNaN(settings.titleSize) ){
|
846
|
+
$DOM.p.style.lineHeight = settings.messageLineHeight+'px';
|
847
|
+
} else {
|
848
|
+
$DOM.p.style.lineHeight = settings.messageLineHeight;
|
849
|
+
}
|
850
|
+
}
|
851
|
+
}
|
852
|
+
})();
|
570
853
|
|
571
|
-
if(settings.
|
572
|
-
|
854
|
+
if(settings.title.length > 0 && settings.message.length > 0) {
|
855
|
+
if(settings.rtl){
|
856
|
+
$DOM.strong.style.marginLeft = '10px';
|
857
|
+
} else if(settings.layout !== 2 && !settings.rtl) {
|
858
|
+
$DOM.strong.style.marginRight = '10px';
|
859
|
+
}
|
573
860
|
}
|
574
861
|
|
575
|
-
$toastBody.appendChild($
|
576
|
-
$toastBody.appendChild($p);
|
862
|
+
$DOM.toastBody.appendChild($DOM.toastTexts);
|
577
863
|
|
578
|
-
|
579
|
-
|
864
|
+
// Buttons
|
865
|
+
(function(){
|
866
|
+
if(settings.buttons.length > 0) {
|
580
867
|
|
581
|
-
|
582
|
-
$buttons.classList.add(PLUGIN_NAME + '-buttons');
|
868
|
+
$DOM.buttons.classList.add(PLUGIN_NAME + '-buttons');
|
583
869
|
|
584
|
-
|
870
|
+
if(settings.title.length > 0 && settings.message.length === 0) {
|
871
|
+
if(settings.rtl){
|
872
|
+
$DOM.strong.style.marginLeft = '15px';
|
873
|
+
} else {
|
874
|
+
$DOM.strong.style.marginRight = '15px';
|
875
|
+
}
|
876
|
+
}
|
877
|
+
if(settings.message.length > 0) {
|
878
|
+
if(settings.rtl){
|
879
|
+
$DOM.p.style.marginLeft = '15px';
|
880
|
+
} else {
|
881
|
+
$DOM.p.style.marginRight = '15px';
|
882
|
+
}
|
883
|
+
$DOM.p.style.marginBottom = '0';
|
884
|
+
}
|
585
885
|
|
586
|
-
|
587
|
-
|
588
|
-
$buttons.appendChild(createFragElem(value[0]));
|
886
|
+
forEach(settings.buttons, function (value, index) {
|
887
|
+
$DOM.buttons.appendChild(createFragElem(value[0]));
|
589
888
|
|
590
|
-
|
889
|
+
var $btns = $DOM.buttons.childNodes;
|
591
890
|
|
592
|
-
|
593
|
-
e.preventDefault();
|
594
|
-
var ts = value[1];
|
595
|
-
return new ts(that, $toast);
|
596
|
-
});
|
891
|
+
$btns[index].classList.add(PLUGIN_NAME + '-buttons-child');
|
597
892
|
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
893
|
+
if(value[2]){
|
894
|
+
setTimeout(function() {
|
895
|
+
$btns[index].focus();
|
896
|
+
}, 300);
|
897
|
+
}
|
602
898
|
|
603
|
-
|
604
|
-
|
605
|
-
|
899
|
+
$btns[index].addEventListener('click', function (e) {
|
900
|
+
e.preventDefault();
|
901
|
+
var ts = value[1];
|
902
|
+
return ts(that, $DOM.toast);
|
903
|
+
});
|
904
|
+
});
|
905
|
+
}
|
906
|
+
$DOM.toastBody.appendChild($DOM.buttons);
|
907
|
+
})();
|
606
908
|
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
var marginTop = style.marginTop;
|
611
|
-
marginTop = marginTop.split("px");
|
612
|
-
marginTop = parseInt(marginTop[0]);
|
613
|
-
var marginBottom = style.marginBottom;
|
614
|
-
marginBottom = marginBottom.split("px");
|
615
|
-
marginBottom = parseInt(marginBottom[0]);
|
616
|
-
|
617
|
-
$toastCapsule.style.visibility = '';
|
618
|
-
$toastCapsule.style.height = (H+marginBottom+marginTop)+'px';
|
909
|
+
// Target
|
910
|
+
(function(){
|
911
|
+
$DOM.toastCapsule.style.visibility = 'hidden';
|
619
912
|
setTimeout(function() {
|
620
|
-
$
|
621
|
-
|
622
|
-
|
913
|
+
var H = $DOM.toast.offsetHeight;
|
914
|
+
var style = $DOM.toast.currentStyle || window.getComputedStyle($DOM.toast);
|
915
|
+
var marginTop = style.marginTop;
|
916
|
+
marginTop = marginTop.split('px');
|
917
|
+
marginTop = parseInt(marginTop[0]);
|
918
|
+
var marginBottom = style.marginBottom;
|
919
|
+
marginBottom = marginBottom.split('px');
|
920
|
+
marginBottom = parseInt(marginBottom[0]);
|
921
|
+
|
922
|
+
$DOM.toastCapsule.style.visibility = '';
|
923
|
+
$DOM.toastCapsule.style.height = (H+marginBottom+marginTop)+'px';
|
924
|
+
|
925
|
+
setTimeout(function() {
|
926
|
+
$DOM.toastCapsule.style.height = 'auto';
|
927
|
+
if(settings.target){
|
928
|
+
$DOM.toastCapsule.style.overflow = 'visible';
|
929
|
+
}
|
930
|
+
}, 500);
|
931
|
+
|
932
|
+
if(settings.timeout) {
|
933
|
+
that.progress($DOM.toast, settings).start();
|
623
934
|
}
|
624
|
-
},
|
625
|
-
}
|
935
|
+
}, 100);
|
936
|
+
})();
|
626
937
|
|
627
|
-
|
628
|
-
|
938
|
+
// Target
|
939
|
+
(function(){
|
940
|
+
var position = settings.position;
|
629
941
|
|
630
|
-
|
942
|
+
if(settings.target){
|
631
943
|
|
632
|
-
|
633
|
-
|
944
|
+
$DOM.wrapper = document.querySelector(settings.target);
|
945
|
+
$DOM.wrapper.classList.add(PLUGIN_NAME + '-target');
|
634
946
|
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
947
|
+
if(settings.targetFirst) {
|
948
|
+
$DOM.wrapper.insertBefore($DOM.toastCapsule, $DOM.wrapper.firstChild);
|
949
|
+
} else {
|
950
|
+
$DOM.wrapper.appendChild($DOM.toastCapsule);
|
951
|
+
}
|
640
952
|
|
641
|
-
|
953
|
+
} else {
|
642
954
|
|
643
|
-
|
644
|
-
|
645
|
-
|
646
|
-
|
955
|
+
if( POSITIONS.indexOf(settings.position) == -1 ){
|
956
|
+
console.warn('['+PLUGIN_NAME+'] Incorrect position.\nIt can be › ' + POSITIONS);
|
957
|
+
return;
|
958
|
+
}
|
647
959
|
|
648
|
-
|
649
|
-
|
650
|
-
|
960
|
+
if(ISMOBILE || window.innerWidth <= MOBILEWIDTH){
|
961
|
+
if(settings.position == 'bottomLeft' || settings.position == 'bottomRight' || settings.position == 'bottomCenter'){
|
962
|
+
position = PLUGIN_NAME+'-wrapper-bottomCenter';
|
963
|
+
}
|
964
|
+
else if(settings.position == 'topLeft' || settings.position == 'topRight' || settings.position == 'topCenter'){
|
965
|
+
position = PLUGIN_NAME+'-wrapper-topCenter';
|
966
|
+
}
|
967
|
+
else {
|
968
|
+
position = PLUGIN_NAME+'-wrapper-center';
|
969
|
+
}
|
970
|
+
} else {
|
971
|
+
position = PLUGIN_NAME+'-wrapper-'+position;
|
651
972
|
}
|
652
|
-
|
653
|
-
|
973
|
+
$DOM.wrapper = document.querySelector('.' + PLUGIN_NAME + '-wrapper.'+position);
|
974
|
+
|
975
|
+
if(!$DOM.wrapper) {
|
976
|
+
$DOM.wrapper = document.createElement('div');
|
977
|
+
$DOM.wrapper.classList.add(PLUGIN_NAME + '-wrapper');
|
978
|
+
$DOM.wrapper.classList.add(position);
|
979
|
+
document.body.appendChild($DOM.wrapper);
|
654
980
|
}
|
655
|
-
|
656
|
-
|
981
|
+
if(settings.position == 'topLeft' || settings.position == 'topCenter' || settings.position == 'topRight'){
|
982
|
+
$DOM.wrapper.insertBefore($DOM.toastCapsule, $DOM.wrapper.firstChild);
|
983
|
+
} else {
|
984
|
+
$DOM.wrapper.appendChild($DOM.toastCapsule);
|
657
985
|
}
|
658
|
-
} else {
|
659
|
-
position = PLUGIN_NAME+'-wrapper-'+position;
|
660
986
|
}
|
661
|
-
$wrapper = document.querySelector('.' + PLUGIN_NAME + '-wrapper.'+position);
|
662
987
|
|
663
|
-
if
|
664
|
-
$wrapper =
|
665
|
-
$wrapper.classList.add(PLUGIN_NAME + '-wrapper');
|
666
|
-
$wrapper.classList.add(position);
|
667
|
-
document.body.appendChild($wrapper);
|
668
|
-
}
|
669
|
-
if(settings.position == "topLeft" || settings.position == "topCenter" || settings.position == "topRight"){
|
670
|
-
$wrapper.insertBefore($toastCapsule, $wrapper.firstChild);
|
988
|
+
if(!isNaN(settings.zindex)) {
|
989
|
+
$DOM.wrapper.style.zIndex = settings.zindex;
|
671
990
|
} else {
|
672
|
-
|
991
|
+
console.warn('['+PLUGIN_NAME+'] Invalid zIndex.');
|
673
992
|
}
|
674
|
-
}
|
993
|
+
})();
|
675
994
|
|
676
|
-
|
677
|
-
|
678
|
-
} else {
|
679
|
-
console.warn("["+PLUGIN_NAME+"] Invalid zIndex.");
|
680
|
-
}
|
995
|
+
// Overlay
|
996
|
+
(function(){
|
681
997
|
|
682
|
-
|
998
|
+
if(settings.overlay) {
|
683
999
|
|
684
|
-
|
685
|
-
var event;
|
686
|
-
if (window.CustomEvent) {
|
687
|
-
event = new CustomEvent(PLUGIN_NAME+'-open', {detail: {class: settings.class}});
|
688
|
-
} else {
|
689
|
-
event = document.createEvent('CustomEvent');
|
690
|
-
event.initCustomEvent(PLUGIN_NAME+'-open', true, true, {class: settings.class});
|
691
|
-
}
|
692
|
-
document.dispatchEvent(event);
|
693
|
-
} catch(ex){
|
694
|
-
console.warn(ex);
|
695
|
-
}
|
1000
|
+
if( document.querySelector('.'+PLUGIN_NAME+'-overlay.fadeIn') !== null ){
|
696
1001
|
|
697
|
-
|
698
|
-
|
699
|
-
|
700
|
-
var timeAnimation1 = 200;
|
701
|
-
var timeAnimation2 = 100;
|
702
|
-
var timeAnimation3 = 300;
|
703
|
-
if(settings.transitionIn == "bounceInLeft"){
|
704
|
-
timeAnimation1 = 400;
|
705
|
-
timeAnimation2 = 200;
|
706
|
-
timeAnimation3 = 400;
|
707
|
-
}
|
1002
|
+
$DOM.overlay = document.querySelector('.'+PLUGIN_NAME+'-overlay');
|
1003
|
+
$DOM.overlay.setAttribute('data-iziToast-ref', $DOM.overlay.getAttribute('data-iziToast-ref') + ',' + settings.REF);
|
708
1004
|
|
709
|
-
|
710
|
-
|
711
|
-
|
1005
|
+
if(!isNaN(settings.zindex) && settings.zindex !== null) {
|
1006
|
+
$DOM.overlay.style.zIndex = settings.zindex-1;
|
1007
|
+
}
|
1008
|
+
} else {
|
712
1009
|
|
713
|
-
|
714
|
-
|
715
|
-
|
1010
|
+
$DOM.overlay.classList.add(PLUGIN_NAME+'-overlay');
|
1011
|
+
$DOM.overlay.classList.add('fadeIn');
|
1012
|
+
$DOM.overlay.style.background = settings.overlayColor;
|
1013
|
+
$DOM.overlay.setAttribute('data-iziToast-ref', settings.REF);
|
1014
|
+
if(!isNaN(settings.zindex) && settings.zindex !== null) {
|
1015
|
+
$DOM.overlay.style.zIndex = settings.zindex-1;
|
1016
|
+
}
|
1017
|
+
document.querySelector('body').appendChild($DOM.overlay);
|
1018
|
+
}
|
716
1019
|
|
717
|
-
|
718
|
-
window.setTimeout(function(){
|
719
|
-
$icon.classList.add('revealIn');
|
720
|
-
},timeAnimation3);
|
721
|
-
}
|
1020
|
+
if(settings.overlayClose) {
|
722
1021
|
|
723
|
-
|
724
|
-
|
725
|
-
|
1022
|
+
$DOM.overlay.removeEventListener('click', {});
|
1023
|
+
$DOM.overlay.addEventListener('click', function (e) {
|
1024
|
+
that.hide($DOM.toast, settings, 'overlay');
|
1025
|
+
});
|
1026
|
+
} else {
|
1027
|
+
$DOM.overlay.removeEventListener('click', {});
|
1028
|
+
}
|
726
1029
|
|
727
|
-
window.setTimeout(function(){
|
728
|
-
element.classList.add('revealIn');
|
729
|
-
},counter);
|
730
|
-
counter = counter + counter;
|
731
|
-
});
|
732
1030
|
}
|
733
|
-
}
|
734
|
-
|
735
|
-
if($buttonClose){
|
736
|
-
$buttonClose.addEventListener('click', function (e) {
|
737
|
-
var button = e.target;
|
738
|
-
that.hide(settings, $toast, 'button');
|
739
|
-
});
|
740
|
-
}
|
741
1031
|
|
742
|
-
|
1032
|
+
})();
|
1033
|
+
|
1034
|
+
// Inside animations
|
1035
|
+
(function(){
|
1036
|
+
if(settings.animateInside){
|
1037
|
+
$DOM.toast.classList.add(PLUGIN_NAME+'-animateInside');
|
743
1038
|
|
744
|
-
|
745
|
-
|
746
|
-
|
747
|
-
|
748
|
-
this.classList.remove(PLUGIN_NAME+'-paused');
|
749
|
-
});
|
750
|
-
}
|
1039
|
+
var animationTimes = [200, 100, 300];
|
1040
|
+
if(settings.transitionIn == 'bounceInLeft'){
|
1041
|
+
animationTimes = [400, 200, 400];
|
1042
|
+
}
|
751
1043
|
|
752
|
-
|
1044
|
+
if(settings.title.length > 0) {
|
1045
|
+
setTimeout(function(){
|
1046
|
+
$DOM.strong.classList.add('slideIn');
|
1047
|
+
}, animationTimes[0]);
|
1048
|
+
}
|
753
1049
|
|
754
|
-
|
755
|
-
|
756
|
-
|
757
|
-
|
758
|
-
|
759
|
-
|
1050
|
+
if(settings.message.length > 0) {
|
1051
|
+
setTimeout(function(){
|
1052
|
+
$DOM.p.classList.add('slideIn');
|
1053
|
+
}, animationTimes[1]);
|
1054
|
+
}
|
1055
|
+
|
1056
|
+
if(settings.icon) {
|
1057
|
+
setTimeout(function(){
|
1058
|
+
$DOM.icon.classList.add('revealIn');
|
1059
|
+
}, animationTimes[2]);
|
1060
|
+
}
|
1061
|
+
|
1062
|
+
if(settings.buttons.length > 0 && $DOM.buttons) {
|
1063
|
+
var counter = 150;
|
1064
|
+
forEach($DOM.buttons.childNodes, function(element, index) {
|
1065
|
+
|
1066
|
+
setTimeout(function(){
|
1067
|
+
element.classList.add('revealIn');
|
1068
|
+
}, counter);
|
1069
|
+
counter = counter + 150;
|
1070
|
+
});
|
1071
|
+
}
|
1072
|
+
}
|
1073
|
+
})();
|
1074
|
+
|
1075
|
+
settings.onOpening.apply(null, [settings, $DOM.toast]);
|
1076
|
+
|
1077
|
+
try {
|
1078
|
+
var event = new CustomEvent(PLUGIN_NAME + '-opening', {detail: settings, bubbles: true, cancelable: true});
|
1079
|
+
document.dispatchEvent(event);
|
1080
|
+
} catch(ex){
|
1081
|
+
console.warn(ex);
|
760
1082
|
}
|
761
1083
|
|
1084
|
+
setTimeout(function() {
|
1085
|
+
|
1086
|
+
$DOM.toast.classList.remove(PLUGIN_NAME+'-opening');
|
1087
|
+
$DOM.toast.classList.add(PLUGIN_NAME+'-opened');
|
1088
|
+
|
1089
|
+
try {
|
1090
|
+
var event = new CustomEvent(PLUGIN_NAME + '-opened', {detail: settings, bubbles: true, cancelable: true});
|
1091
|
+
document.dispatchEvent(event);
|
1092
|
+
} catch(ex){
|
1093
|
+
console.warn(ex);
|
1094
|
+
}
|
1095
|
+
|
1096
|
+
settings.onOpened.apply(null, [settings, $DOM.toast]);
|
1097
|
+
}, 1000);
|
1098
|
+
|
762
1099
|
if(settings.drag){
|
763
1100
|
|
764
|
-
if
|
1101
|
+
if(ACCEPTSTOUCH) {
|
765
1102
|
|
766
|
-
$toast.addEventListener('touchstart', function(e) {
|
1103
|
+
$DOM.toast.addEventListener('touchstart', function(e) {
|
767
1104
|
drag.startMoving(this, that, settings, e);
|
768
1105
|
}, false);
|
769
1106
|
|
770
|
-
$toast.addEventListener('touchend', function(e) {
|
1107
|
+
$DOM.toast.addEventListener('touchend', function(e) {
|
771
1108
|
drag.stopMoving(this, e);
|
772
1109
|
}, false);
|
773
1110
|
} else {
|
774
1111
|
|
775
|
-
$toast.addEventListener('mousedown', function(e) {
|
1112
|
+
$DOM.toast.addEventListener('mousedown', function(e) {
|
776
1113
|
e.preventDefault();
|
777
1114
|
drag.startMoving(this, that, settings, e);
|
778
1115
|
}, false);
|
779
1116
|
|
780
|
-
$toast.addEventListener('mouseup', function(e) {
|
1117
|
+
$DOM.toast.addEventListener('mouseup', function(e) {
|
781
1118
|
e.preventDefault();
|
782
1119
|
drag.stopMoving(this, e);
|
783
1120
|
}, false);
|
784
1121
|
}
|
785
1122
|
}
|
786
1123
|
|
1124
|
+
if(settings.closeOnEscape) {
|
1125
|
+
|
1126
|
+
document.addEventListener('keyup', function (evt) {
|
1127
|
+
evt = evt || window.event;
|
1128
|
+
if(evt.keyCode == 27) {
|
1129
|
+
that.hide($DOM.toast, settings, 'esc');
|
1130
|
+
}
|
1131
|
+
});
|
1132
|
+
}
|
787
1133
|
|
1134
|
+
that.toast = $DOM.toast;
|
788
1135
|
};
|
1136
|
+
|
789
1137
|
|
790
1138
|
return $iziToast;
|
791
|
-
});
|
1139
|
+
});
|