@maplat/ui 0.10.5 → 0.10.6

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.
Files changed (37) hide show
  1. package/LICENSE +223 -223
  2. package/README.md +91 -91
  3. package/dist/assets/locales/en/translation.json +64 -64
  4. package/dist/assets/locales/ja/translation.json +64 -64
  5. package/dist/assets/locales/ko/translation.json +65 -65
  6. package/dist/assets/locales/zh/translation.json +65 -65
  7. package/dist/assets/locales/zh-TW/translation.json +65 -65
  8. package/dist/assets/maplat.css +1 -1
  9. package/dist/assets/maplat.css.map +1 -1
  10. package/dist/assets/maplat.js +1 -1
  11. package/dist/assets/maplat.js.LICENSE.txt +1 -1
  12. package/dist/assets/maplat.js.map +1 -1
  13. package/dist/index.html +125 -39
  14. package/dist/service-worker.js +1 -1
  15. package/dist/service-worker.js.LICENSE.txt +1 -1
  16. package/legacy/bootstrap-native.js +1934 -1934
  17. package/legacy/detect-element-resize.js +153 -153
  18. package/legacy/iziToast.js +1301 -1301
  19. package/legacy/page.js +1153 -1153
  20. package/legacy/qrcode.js +616 -616
  21. package/less/bootstrap.less +7010 -7010
  22. package/less/font-awesome.less +30 -30
  23. package/less/font-face.less +10 -10
  24. package/less/font-face_packed.less +11 -11
  25. package/less/iziToast.less +1732 -1732
  26. package/less/maplat-specific.less +652 -652
  27. package/less/ui.less +11 -11
  28. package/less/ui_packed.less +10 -10
  29. package/locales/en/translation.json +64 -64
  30. package/locales/ja/translation.json +64 -64
  31. package/locales/ko/translation.json +65 -65
  32. package/locales/zh/translation.json +65 -65
  33. package/locales/zh-TW/translation.json +65 -65
  34. package/package.json +106 -106
  35. package/src/index.js +27 -11
  36. package/src/maplat_control.js +12 -18
  37. package/src/service-worker.js +1 -1
@@ -1,1301 +1,1301 @@
1
- const Global = function() {};
2
-
3
- Global.prototype.dispatch = function() {
4
- /*
5
- * iziToast | v1.4.0
6
- * http://izitoast.marcelodolce.com
7
- * by Marcelo Dolce.
8
- */
9
- (function (root, factory) {
10
- if(typeof define === 'function' && define.amd) {
11
- define([], factory(root));
12
- } else if(typeof exports === 'object') {
13
- module.exports = factory(root);
14
- } else {
15
- root.iziToast = factory(root);
16
- }
17
- })(this, function (root) {
18
-
19
- 'use strict';
20
-
21
- //
22
- // Variables
23
- //
24
- var $iziToast = {},
25
- PLUGIN_NAME = 'iziToast',
26
- BODY = document.querySelector('body'),
27
- ISMOBILE = (/Mobi/.test(navigator.userAgent)) ? true : false,
28
- ISCHROME = /Chrome/.test(navigator.userAgent) && /Google Inc/.test(navigator.vendor),
29
- ISFIREFOX = typeof InstallTrigger !== 'undefined',
30
- ACCEPTSTOUCH = 'ontouchstart' in document.documentElement,
31
- POSITIONS = ['bottomRight','bottomLeft','bottomCenter','topRight','topLeft','topCenter','center'],
32
- THEMES = {
33
- info: {
34
- color: 'blue',
35
- icon: 'ico-info'
36
- },
37
- success: {
38
- color: 'green',
39
- icon: 'ico-success'
40
- },
41
- warning: {
42
- color: 'orange',
43
- icon: 'ico-warning'
44
- },
45
- error: {
46
- color: 'red',
47
- icon: 'ico-error'
48
- },
49
- question: {
50
- color: 'yellow',
51
- icon: 'ico-question'
52
- }
53
- },
54
- MOBILEWIDTH = 568,
55
- CONFIG = {};
56
-
57
- $iziToast.children = {};
58
-
59
- // Default settings
60
- var defaults = {
61
- id: null,
62
- class: '',
63
- title: '',
64
- titleColor: '',
65
- titleSize: '',
66
- titleLineHeight: '',
67
- message: '',
68
- messageColor: '',
69
- messageSize: '',
70
- messageLineHeight: '',
71
- backgroundColor: '',
72
- theme: 'light', // dark
73
- color: '', // blue, red, green, yellow
74
- icon: '',
75
- iconText: '',
76
- iconColor: '',
77
- iconUrl: null,
78
- image: '',
79
- imageWidth: 50,
80
- maxWidth: null,
81
- zindex: null,
82
- layout: 1,
83
- balloon: false,
84
- close: true,
85
- closeOnEscape: false,
86
- closeOnClick: false,
87
- displayMode: 0,
88
- position: 'bottomRight', // bottomRight, bottomLeft, topRight, topLeft, topCenter, bottomCenter, center
89
- target: '',
90
- targetFirst: true,
91
- timeout: 5000,
92
- rtl: false,
93
- animateInside: true,
94
- drag: true,
95
- pauseOnHover: true,
96
- resetOnHover: false,
97
- progressBar: true,
98
- progressBarColor: '',
99
- progressBarEasing: 'linear',
100
- overlay: false,
101
- overlayClose: false,
102
- overlayColor: 'rgba(0, 0, 0, 0.6)',
103
- transitionIn: 'fadeInUp', // bounceInLeft, bounceInRight, bounceInUp, bounceInDown, fadeIn, fadeInDown, fadeInUp, fadeInLeft, fadeInRight, flipInX
104
- transitionOut: 'fadeOut', // fadeOut, fadeOutUp, fadeOutDown, fadeOutLeft, fadeOutRight, flipOutX
105
- transitionInMobile: 'fadeInUp',
106
- transitionOutMobile: 'fadeOutDown',
107
- buttons: {},
108
- inputs: {},
109
- onOpening: function () {},
110
- onOpened: function () {},
111
- onClosing: function () {},
112
- onClosed: function () {}
113
- };
114
-
115
- //
116
- // Methods
117
- //
118
-
119
-
120
- /**
121
- * Polyfill for remove() method
122
- */
123
- if(!('remove' in Element.prototype)) {
124
- Element.prototype.remove = function() {
125
- if(this.parentNode) {
126
- this.parentNode.removeChild(this);
127
- }
128
- };
129
- }
130
-
131
- /*
132
- * Polyfill for CustomEvent for IE >= 9
133
- * https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent/CustomEvent#Polyfill
134
- */
135
- if(typeof window.CustomEvent !== 'function') {
136
- var CustomEventPolyfill = function (event, params) {
137
- params = params || { bubbles: false, cancelable: false, detail: undefined };
138
- var evt = document.createEvent('CustomEvent');
139
- evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail);
140
- return evt;
141
- };
142
-
143
- CustomEventPolyfill.prototype = window.Event.prototype;
144
-
145
- window.CustomEvent = CustomEventPolyfill;
146
- }
147
-
148
- /**
149
- * A simple forEach() implementation for Arrays, Objects and NodeLists
150
- * @private
151
- * @param {Array|Object|NodeList} collection Collection of items to iterate
152
- * @param {Function} callback Callback function for each iteration
153
- * @param {Array|Object|NodeList} scope Object/NodeList/Array that forEach is iterating over (aka `this`)
154
- */
155
- var forEach = function (collection, callback, scope) {
156
- if(Object.prototype.toString.call(collection) === '[object Object]') {
157
- for (var prop in collection) {
158
- if(Object.prototype.hasOwnProperty.call(collection, prop)) {
159
- callback.call(scope, collection[prop], prop, collection);
160
- }
161
- }
162
- } else {
163
- if(collection){
164
- for (var i = 0, len = collection.length; i < len; i++) {
165
- callback.call(scope, collection[i], i, collection);
166
- }
167
- }
168
- }
169
- };
170
-
171
- /**
172
- * Merge defaults with user options
173
- * @private
174
- * @param {Object} defaults Default settings
175
- * @param {Object} options User options
176
- * @returns {Object} Merged values of defaults and options
177
- */
178
- var extend = function (defaults, options) {
179
- var extended = {};
180
- forEach(defaults, function (value, prop) {
181
- extended[prop] = defaults[prop];
182
- });
183
- forEach(options, function (value, prop) {
184
- extended[prop] = options[prop];
185
- });
186
- return extended;
187
- };
188
-
189
-
190
- /**
191
- * Create a fragment DOM elements
192
- * @private
193
- */
194
- var createFragElem = function(htmlStr) {
195
- var frag = document.createDocumentFragment(),
196
- temp = document.createElement('div');
197
- temp.innerHTML = htmlStr;
198
- while (temp.firstChild) {
199
- frag.appendChild(temp.firstChild);
200
- }
201
- return frag;
202
- };
203
-
204
-
205
- /**
206
- * Generate new ID
207
- * @private
208
- */
209
- var generateId = function(params) {
210
- var newId = btoa(encodeURIComponent(params));
211
- return newId.replace(/=/g, "");
212
- };
213
-
214
-
215
- /**
216
- * Check if is a color
217
- * @private
218
- */
219
- var isColor = function(color){
220
- if( color.substring(0,1) == '#' || color.substring(0,3) == 'rgb' || color.substring(0,3) == 'hsl' ){
221
- return true;
222
- } else {
223
- return false;
224
- }
225
- };
226
-
227
-
228
- /**
229
- * Check if is a Base64 string
230
- * @private
231
- */
232
- var isBase64 = function(str) {
233
- try {
234
- return btoa(atob(str)) == str;
235
- } catch (err) {
236
- return false;
237
- }
238
- };
239
-
240
-
241
- /**
242
- * Drag method of toasts
243
- * @private
244
- */
245
- var drag = function() {
246
-
247
- return {
248
- move: function(toast, instance, settings, xpos) {
249
-
250
- var opacity,
251
- opacityRange = 0.3,
252
- distance = 180;
253
-
254
- if(xpos !== 0){
255
-
256
- toast.classList.add(PLUGIN_NAME+'-dragged');
257
-
258
- toast.style.transform = 'translateX('+xpos + 'px)';
259
-
260
- if(xpos > 0){
261
- opacity = (distance-xpos) / distance;
262
- if(opacity < opacityRange){
263
- instance.hide(extend(settings, { transitionOut: 'fadeOutRight', transitionOutMobile: 'fadeOutRight' }), toast, 'drag');
264
- }
265
- } else {
266
- opacity = (distance+xpos) / distance;
267
- if(opacity < opacityRange){
268
- instance.hide(extend(settings, { transitionOut: 'fadeOutLeft', transitionOutMobile: 'fadeOutLeft' }), toast, 'drag');
269
- }
270
- }
271
- toast.style.opacity = opacity;
272
-
273
- if(opacity < opacityRange){
274
-
275
- if(ISCHROME || ISFIREFOX)
276
- toast.style.left = xpos+'px';
277
-
278
- toast.parentNode.style.opacity = opacityRange;
279
-
280
- this.stopMoving(toast, null);
281
- }
282
- }
283
-
284
-
285
- },
286
- startMoving: function(toast, instance, settings, e) {
287
-
288
- e = e || window.event;
289
- var posX = ((ACCEPTSTOUCH) ? e.touches[0].clientX : e.clientX),
290
- toastLeft = toast.style.transform.replace('px)', '');
291
- toastLeft = toastLeft.replace('translateX(', '');
292
- var offsetX = posX - toastLeft;
293
-
294
- if(settings.transitionIn){
295
- toast.classList.remove(settings.transitionIn);
296
- }
297
- if(settings.transitionInMobile){
298
- toast.classList.remove(settings.transitionInMobile);
299
- }
300
- toast.style.transition = '';
301
-
302
- if(ACCEPTSTOUCH) {
303
- document.ontouchmove = function(e) {
304
- e.preventDefault();
305
- e = e || window.event;
306
- var posX = e.touches[0].clientX,
307
- finalX = posX - offsetX;
308
- drag.move(toast, instance, settings, finalX);
309
- };
310
- } else {
311
- document.onmousemove = function(e) {
312
- e.preventDefault();
313
- e = e || window.event;
314
- var posX = e.clientX,
315
- finalX = posX - offsetX;
316
- drag.move(toast, instance, settings, finalX);
317
- };
318
- }
319
-
320
- },
321
- stopMoving: function(toast, e) {
322
-
323
- if(ACCEPTSTOUCH) {
324
- document.ontouchmove = function() {};
325
- } else {
326
- document.onmousemove = function() {};
327
- }
328
-
329
- toast.style.opacity = '';
330
- toast.style.transform = '';
331
-
332
- if(toast.classList.contains(PLUGIN_NAME+'-dragged')){
333
-
334
- toast.classList.remove(PLUGIN_NAME+'-dragged');
335
-
336
- toast.style.transition = 'transform 0.4s ease, opacity 0.4s ease';
337
- setTimeout(function() {
338
- toast.style.transition = '';
339
- }, 400);
340
- }
341
-
342
- }
343
- };
344
-
345
- }();
346
-
347
-
348
-
349
-
350
-
351
- $iziToast.setSetting = function (ref, option, value) {
352
-
353
- $iziToast.children[ref][option] = value;
354
-
355
- };
356
-
357
-
358
- $iziToast.getSetting = function (ref, option) {
359
-
360
- return $iziToast.children[ref][option];
361
-
362
- };
363
-
364
-
365
- /**
366
- * Destroy the current initialization.
367
- * @public
368
- */
369
- $iziToast.destroy = function () {
370
-
371
- forEach(document.querySelectorAll('.'+PLUGIN_NAME+'-overlay'), function(element, index) {
372
- element.remove();
373
- });
374
-
375
- forEach(document.querySelectorAll('.'+PLUGIN_NAME+'-wrapper'), function(element, index) {
376
- element.remove();
377
- });
378
-
379
- forEach(document.querySelectorAll('.'+PLUGIN_NAME), function(element, index) {
380
- element.remove();
381
- });
382
-
383
- this.children = {};
384
-
385
- // Remove event listeners
386
- document.removeEventListener(PLUGIN_NAME+'-opened', {}, false);
387
- document.removeEventListener(PLUGIN_NAME+'-opening', {}, false);
388
- document.removeEventListener(PLUGIN_NAME+'-closing', {}, false);
389
- document.removeEventListener(PLUGIN_NAME+'-closed', {}, false);
390
- document.removeEventListener('keyup', {}, false);
391
-
392
- // Reset variables
393
- CONFIG = {};
394
- };
395
-
396
- /**
397
- * Initialize Plugin
398
- * @public
399
- * @param {Object} options User settings
400
- */
401
- $iziToast.settings = function (options) {
402
-
403
- // Destroy any existing initializations
404
- $iziToast.destroy();
405
-
406
- CONFIG = options;
407
- defaults = extend(defaults, options || {});
408
- };
409
-
410
-
411
- /**
412
- * Building themes functions.
413
- * @public
414
- * @param {Object} options User settings
415
- */
416
- forEach(THEMES, function (theme, name) {
417
-
418
- $iziToast[name] = function (options) {
419
-
420
- var settings = extend(CONFIG, options || {});
421
- settings = extend(theme, settings || {});
422
-
423
- this.show(settings);
424
- };
425
-
426
- });
427
-
428
-
429
- /**
430
- * Do the calculation to move the progress bar
431
- * @private
432
- */
433
- $iziToast.progress = function (options, $toast, callback) {
434
-
435
-
436
- var that = this,
437
- ref = $toast.getAttribute('data-iziToast-ref'),
438
- settings = extend(this.children[ref], options || {}),
439
- $elem = $toast.querySelector('.'+PLUGIN_NAME+'-progressbar div');
440
-
441
- return {
442
- start: function() {
443
-
444
- if(typeof settings.time.REMAINING == 'undefined'){
445
-
446
- $toast.classList.remove(PLUGIN_NAME+'-reseted');
447
-
448
- if($elem !== null){
449
- $elem.style.transition = 'width '+ settings.timeout +'ms '+settings.progressBarEasing;
450
- $elem.style.width = '0%';
451
- }
452
-
453
- settings.time.START = new Date().getTime();
454
- settings.time.END = settings.time.START + settings.timeout;
455
- settings.time.TIMER = setTimeout(function() {
456
-
457
- clearTimeout(settings.time.TIMER);
458
-
459
- if(!$toast.classList.contains(PLUGIN_NAME+'-closing')){
460
-
461
- that.hide(settings, $toast, 'timeout');
462
-
463
- if(typeof callback === 'function'){
464
- callback.apply(that);
465
- }
466
- }
467
-
468
- }, settings.timeout);
469
- that.setSetting(ref, 'time', settings.time);
470
- }
471
- },
472
- pause: function() {
473
-
474
- if(typeof settings.time.START !== 'undefined' && !$toast.classList.contains(PLUGIN_NAME+'-paused') && !$toast.classList.contains(PLUGIN_NAME+'-reseted')){
475
-
476
- $toast.classList.add(PLUGIN_NAME+'-paused');
477
-
478
- settings.time.REMAINING = settings.time.END - new Date().getTime();
479
-
480
- clearTimeout(settings.time.TIMER);
481
-
482
- that.setSetting(ref, 'time', settings.time);
483
-
484
- if($elem !== null){
485
- var computedStyle = window.getComputedStyle($elem),
486
- propertyWidth = computedStyle.getPropertyValue('width');
487
-
488
- $elem.style.transition = 'none';
489
- $elem.style.width = propertyWidth;
490
- }
491
-
492
- if(typeof callback === 'function'){
493
- setTimeout(function() {
494
- callback.apply(that);
495
- }, 10);
496
- }
497
- }
498
- },
499
- resume: function() {
500
-
501
- if(typeof settings.time.REMAINING !== 'undefined'){
502
-
503
- $toast.classList.remove(PLUGIN_NAME+'-paused');
504
-
505
- if($elem !== null){
506
- $elem.style.transition = 'width '+ settings.time.REMAINING +'ms '+settings.progressBarEasing;
507
- $elem.style.width = '0%';
508
- }
509
-
510
- settings.time.END = new Date().getTime() + settings.time.REMAINING;
511
- settings.time.TIMER = setTimeout(function() {
512
-
513
- clearTimeout(settings.time.TIMER);
514
-
515
- if(!$toast.classList.contains(PLUGIN_NAME+'-closing')){
516
-
517
- that.hide(settings, $toast, 'timeout');
518
-
519
- if(typeof callback === 'function'){
520
- callback.apply(that);
521
- }
522
- }
523
-
524
-
525
- }, settings.time.REMAINING);
526
-
527
- that.setSetting(ref, 'time', settings.time);
528
- } else {
529
- this.start();
530
- }
531
- },
532
- reset: function(){
533
-
534
- clearTimeout(settings.time.TIMER);
535
-
536
- delete settings.time.REMAINING;
537
-
538
- that.setSetting(ref, 'time', settings.time);
539
-
540
- $toast.classList.add(PLUGIN_NAME+'-reseted');
541
-
542
- $toast.classList.remove(PLUGIN_NAME+'-paused');
543
-
544
- if($elem !== null){
545
- $elem.style.transition = 'none';
546
- $elem.style.width = '100%';
547
- }
548
-
549
- if(typeof callback === 'function'){
550
- setTimeout(function() {
551
- callback.apply(that);
552
- }, 10);
553
- }
554
- }
555
- };
556
-
557
- };
558
-
559
-
560
- /**
561
- * Close the specific Toast
562
- * @public
563
- * @param {Object} options User settings
564
- */
565
- $iziToast.hide = function (options, $toast, closedBy) {
566
-
567
- if(typeof $toast != 'object'){
568
- $toast = document.querySelector($toast);
569
- }
570
-
571
- var that = this,
572
- settings = extend(this.children[$toast.getAttribute('data-iziToast-ref')], options || {});
573
- settings.closedBy = closedBy || null;
574
-
575
- delete settings.time.REMAINING;
576
-
577
- $toast.classList.add(PLUGIN_NAME+'-closing');
578
-
579
- // Overlay
580
- (function(){
581
-
582
- var $overlay = document.querySelector('.'+PLUGIN_NAME+'-overlay');
583
- if($overlay !== null){
584
- var refs = $overlay.getAttribute('data-iziToast-ref');
585
- refs = refs.split(',');
586
- var index = refs.indexOf(String(settings.ref));
587
-
588
- if(index !== -1){
589
- refs.splice(index, 1);
590
- }
591
- $overlay.setAttribute('data-iziToast-ref', refs.join());
592
-
593
- if(refs.length === 0){
594
- $overlay.classList.remove('fadeIn');
595
- $overlay.classList.add('fadeOut');
596
- setTimeout(function() {
597
- $overlay.remove();
598
- }, 700);
599
- }
600
- }
601
-
602
- })();
603
-
604
- if(settings.transitionIn){
605
- $toast.classList.remove(settings.transitionIn);
606
- }
607
-
608
- if(settings.transitionInMobile){
609
- $toast.classList.remove(settings.transitionInMobile);
610
- }
611
-
612
- if(ISMOBILE || window.innerWidth <= MOBILEWIDTH){
613
- if(settings.transitionOutMobile)
614
- $toast.classList.add(settings.transitionOutMobile);
615
- } else {
616
- if(settings.transitionOut)
617
- $toast.classList.add(settings.transitionOut);
618
- }
619
- var H = $toast.parentNode.offsetHeight;
620
- $toast.parentNode.style.height = H+'px';
621
- $toast.style.pointerEvents = 'none';
622
-
623
- if(!ISMOBILE || window.innerWidth > MOBILEWIDTH){
624
- $toast.parentNode.style.transitionDelay = '0.2s';
625
- }
626
-
627
- try {
628
- var event = new CustomEvent(PLUGIN_NAME+'-closing', {detail: settings, bubbles: true, cancelable: true});
629
- document.dispatchEvent(event);
630
- } catch(ex){
631
- console.warn(ex);
632
- }
633
-
634
- setTimeout(function() {
635
-
636
- $toast.parentNode.style.height = '0px';
637
- $toast.parentNode.style.overflow = '';
638
-
639
- setTimeout(function(){
640
-
641
- delete that.children[settings.ref];
642
-
643
- $toast.parentNode.remove();
644
-
645
- try {
646
- var event = new CustomEvent(PLUGIN_NAME+'-closed', {detail: settings, bubbles: true, cancelable: true});
647
- document.dispatchEvent(event);
648
- } catch(ex){
649
- console.warn(ex);
650
- }
651
-
652
- if(typeof settings.onClosed !== 'undefined'){
653
- settings.onClosed.apply(null, [settings, $toast, closedBy]);
654
- }
655
-
656
- }, 1000);
657
- }, 200);
658
-
659
-
660
- if(typeof settings.onClosing !== 'undefined'){
661
- settings.onClosing.apply(null, [settings, $toast, closedBy]);
662
- }
663
- };
664
-
665
- /**
666
- * Create and show the Toast
667
- * @public
668
- * @param {Object} options User settings
669
- */
670
- $iziToast.show = function (options) {
671
-
672
- var that = this;
673
-
674
- // Merge user options with defaults
675
- var settings = extend(CONFIG, options || {});
676
- settings = extend(defaults, settings);
677
- settings.time = {};
678
-
679
- if(settings.id === null){
680
- settings.id = generateId(settings.title+settings.message+settings.color);
681
- }
682
-
683
- if(settings.displayMode === 1 || settings.displayMode == 'once'){
684
- try {
685
- if(document.querySelectorAll('.'+PLUGIN_NAME+'#'+settings.id).length > 0){
686
- return false;
687
- }
688
- } catch (exc) {
689
- console.warn('['+PLUGIN_NAME+'] Could not find an element with this selector: '+'#'+settings.id+'. Try to set an valid id.');
690
- }
691
- }
692
-
693
- if(settings.displayMode === 2 || settings.displayMode == 'replace'){
694
- try {
695
- forEach(document.querySelectorAll('.'+PLUGIN_NAME+'#'+settings.id), function(element, index) {
696
- that.hide(settings, element, 'replaced');
697
- });
698
- } catch (exc) {
699
- console.warn('['+PLUGIN_NAME+'] Could not find an element with this selector: '+'#'+settings.id+'. Try to set an valid id.');
700
- }
701
- }
702
-
703
- settings.ref = new Date().getTime() + Math.floor((Math.random() * 10000000) + 1);
704
-
705
- $iziToast.children[settings.ref] = settings;
706
-
707
- var $DOM = {
708
- body: document.querySelector('body'),
709
- overlay: document.createElement('div'),
710
- toast: document.createElement('div'),
711
- toastBody: document.createElement('div'),
712
- toastTexts: document.createElement('div'),
713
- toastCapsule: document.createElement('div'),
714
- cover: document.createElement('div'),
715
- buttons: document.createElement('div'),
716
- inputs: document.createElement('div'),
717
- icon: !settings.iconUrl ? document.createElement('i') : document.createElement('img'),
718
- wrapper: null
719
- };
720
-
721
- $DOM.toast.setAttribute('data-iziToast-ref', settings.ref);
722
- $DOM.toast.appendChild($DOM.toastBody);
723
- $DOM.toastCapsule.appendChild($DOM.toast);
724
-
725
- // CSS Settings
726
- (function(){
727
-
728
- $DOM.toast.classList.add(PLUGIN_NAME);
729
- $DOM.toast.classList.add(PLUGIN_NAME+'-opening');
730
- $DOM.toastCapsule.classList.add(PLUGIN_NAME+'-capsule');
731
- $DOM.toastBody.classList.add(PLUGIN_NAME + '-body');
732
- $DOM.toastTexts.classList.add(PLUGIN_NAME + '-texts');
733
-
734
- if(ISMOBILE || window.innerWidth <= MOBILEWIDTH){
735
- if(settings.transitionInMobile)
736
- $DOM.toast.classList.add(settings.transitionInMobile);
737
- } else {
738
- if(settings.transitionIn)
739
- $DOM.toast.classList.add(settings.transitionIn);
740
- }
741
-
742
- if(settings.class){
743
- var classes = settings.class.split(' ');
744
- forEach(classes, function (value, index) {
745
- $DOM.toast.classList.add(value);
746
- });
747
- }
748
-
749
- if(settings.id){ $DOM.toast.id = settings.id; }
750
-
751
- if(settings.rtl){
752
- $DOM.toast.classList.add(PLUGIN_NAME + '-rtl');
753
- $DOM.toast.setAttribute('dir', 'rtl');
754
- }
755
-
756
- if(settings.layout > 1){ $DOM.toast.classList.add(PLUGIN_NAME+'-layout'+settings.layout); }
757
-
758
- if(settings.balloon){ $DOM.toast.classList.add(PLUGIN_NAME+'-balloon'); }
759
-
760
- if(settings.maxWidth){
761
- if( !isNaN(settings.maxWidth) ){
762
- $DOM.toast.style.maxWidth = settings.maxWidth+'px';
763
- } else {
764
- $DOM.toast.style.maxWidth = settings.maxWidth;
765
- }
766
- }
767
-
768
- if(settings.theme !== '' || settings.theme !== 'light') {
769
-
770
- $DOM.toast.classList.add(PLUGIN_NAME+'-theme-'+settings.theme);
771
- }
772
-
773
- if(settings.color) { //#, rgb, rgba, hsl
774
-
775
- if( isColor(settings.color) ){
776
- $DOM.toast.style.background = settings.color;
777
- } else {
778
- $DOM.toast.classList.add(PLUGIN_NAME+'-color-'+settings.color);
779
- }
780
- }
781
-
782
- if(settings.backgroundColor) {
783
- $DOM.toast.style.background = settings.backgroundColor;
784
- if(settings.balloon){
785
- $DOM.toast.style.borderColor = settings.backgroundColor;
786
- }
787
- }
788
- })();
789
-
790
- // Cover image
791
- (function(){
792
- if(settings.image) {
793
- $DOM.cover.classList.add(PLUGIN_NAME + '-cover');
794
- $DOM.cover.style.width = settings.imageWidth + 'px';
795
-
796
- if(isBase64(settings.image.replace(/ /g,''))){
797
- $DOM.cover.style.backgroundImage = 'url(data:image/png;base64,' + settings.image.replace(/ /g,'') + ')';
798
- } else {
799
- $DOM.cover.style.backgroundImage = 'url(' + settings.image + ')';
800
- }
801
-
802
- if(settings.rtl){
803
- $DOM.toastBody.style.marginRight = (settings.imageWidth + 10) + 'px';
804
- } else {
805
- $DOM.toastBody.style.marginLeft = (settings.imageWidth + 10) + 'px';
806
- }
807
- $DOM.toast.appendChild($DOM.cover);
808
- }
809
- })();
810
-
811
- // Button close
812
- (function(){
813
- if(settings.close){
814
-
815
- $DOM.buttonClose = document.createElement('button');
816
- $DOM.buttonClose.type = 'button';
817
- $DOM.buttonClose.classList.add(PLUGIN_NAME + '-close');
818
- $DOM.buttonClose.addEventListener('click', function (e) {
819
- var button = e.target;
820
- that.hide(settings, $DOM.toast, 'button');
821
- });
822
- $DOM.toast.appendChild($DOM.buttonClose);
823
- } else {
824
- if(settings.rtl){
825
- $DOM.toast.style.paddingLeft = '18px';
826
- } else {
827
- $DOM.toast.style.paddingRight = '18px';
828
- }
829
- }
830
- })();
831
-
832
- // Progress Bar & Timeout
833
- (function(){
834
-
835
- if(settings.progressBar){
836
- $DOM.progressBar = document.createElement('div');
837
- $DOM.progressBarDiv = document.createElement('div');
838
- $DOM.progressBar.classList.add(PLUGIN_NAME + '-progressbar');
839
- $DOM.progressBarDiv.style.background = settings.progressBarColor;
840
- $DOM.progressBar.appendChild($DOM.progressBarDiv);
841
- $DOM.toast.appendChild($DOM.progressBar);
842
- }
843
-
844
- if(settings.timeout) {
845
-
846
- if(settings.pauseOnHover && !settings.resetOnHover){
847
-
848
- $DOM.toast.addEventListener('mouseenter', function (e) {
849
- that.progress(settings, $DOM.toast).pause();
850
- });
851
- $DOM.toast.addEventListener('mouseleave', function (e) {
852
- that.progress(settings, $DOM.toast).resume();
853
- });
854
- }
855
-
856
- if(settings.resetOnHover){
857
-
858
- $DOM.toast.addEventListener('mouseenter', function (e) {
859
- that.progress(settings, $DOM.toast).reset();
860
- });
861
- $DOM.toast.addEventListener('mouseleave', function (e) {
862
- that.progress(settings, $DOM.toast).start();
863
- });
864
- }
865
- }
866
- })();
867
-
868
- // Icon
869
- (function(){
870
-
871
- if(settings.iconUrl) {
872
-
873
- $DOM.icon.setAttribute('class', PLUGIN_NAME + '-icon');
874
- $DOM.icon.setAttribute('src', settings.iconUrl);
875
-
876
- } else if(settings.icon) {
877
- $DOM.icon.setAttribute('class', PLUGIN_NAME + '-icon ' + settings.icon);
878
-
879
- if(settings.iconText){
880
- $DOM.icon.appendChild(document.createTextNode(settings.iconText));
881
- }
882
-
883
- if(settings.iconColor){
884
- $DOM.icon.style.color = settings.iconColor;
885
- }
886
- }
887
-
888
- if(settings.icon || settings.iconUrl) {
889
-
890
- if(settings.rtl){
891
- $DOM.toastBody.style.paddingRight = '33px';
892
- } else {
893
- $DOM.toastBody.style.paddingLeft = '33px';
894
- }
895
-
896
- $DOM.toastBody.appendChild($DOM.icon);
897
- }
898
-
899
- })();
900
-
901
- // Title & Message
902
- (function(){
903
- if(settings.title.length > 0) {
904
-
905
- $DOM.strong = document.createElement('strong');
906
- $DOM.strong.classList.add(PLUGIN_NAME + '-title');
907
- $DOM.strong.appendChild(createFragElem(settings.title));
908
- $DOM.toastTexts.appendChild($DOM.strong);
909
-
910
- if(settings.titleColor) {
911
- $DOM.strong.style.color = settings.titleColor;
912
- }
913
- if(settings.titleSize) {
914
- if( !isNaN(settings.titleSize) ){
915
- $DOM.strong.style.fontSize = settings.titleSize+'px';
916
- } else {
917
- $DOM.strong.style.fontSize = settings.titleSize;
918
- }
919
- }
920
- if(settings.titleLineHeight) {
921
- if( !isNaN(settings.titleSize) ){
922
- $DOM.strong.style.lineHeight = settings.titleLineHeight+'px';
923
- } else {
924
- $DOM.strong.style.lineHeight = settings.titleLineHeight;
925
- }
926
- }
927
- }
928
-
929
- if(settings.message.length > 0) {
930
-
931
- $DOM.p = document.createElement('p');
932
- $DOM.p.classList.add(PLUGIN_NAME + '-message');
933
- $DOM.p.appendChild(createFragElem(settings.message));
934
- $DOM.toastTexts.appendChild($DOM.p);
935
-
936
- if(settings.messageColor) {
937
- $DOM.p.style.color = settings.messageColor;
938
- }
939
- if(settings.messageSize) {
940
- if( !isNaN(settings.titleSize) ){
941
- $DOM.p.style.fontSize = settings.messageSize+'px';
942
- } else {
943
- $DOM.p.style.fontSize = settings.messageSize;
944
- }
945
- }
946
- if(settings.messageLineHeight) {
947
-
948
- if( !isNaN(settings.titleSize) ){
949
- $DOM.p.style.lineHeight = settings.messageLineHeight+'px';
950
- } else {
951
- $DOM.p.style.lineHeight = settings.messageLineHeight;
952
- }
953
- }
954
- }
955
-
956
- if(settings.title.length > 0 && settings.message.length > 0) {
957
- if(settings.rtl){
958
- $DOM.strong.style.marginLeft = '10px';
959
- } else if(settings.layout !== 2 && !settings.rtl) {
960
- $DOM.strong.style.marginRight = '10px';
961
- }
962
- }
963
- })();
964
-
965
- $DOM.toastBody.appendChild($DOM.toastTexts);
966
-
967
- // Inputs
968
- var $inputs;
969
- (function(){
970
- if(settings.inputs.length > 0) {
971
-
972
- $DOM.inputs.classList.add(PLUGIN_NAME + '-inputs');
973
-
974
- forEach(settings.inputs, function (value, index) {
975
- $DOM.inputs.appendChild(createFragElem(value[0]));
976
-
977
- $inputs = $DOM.inputs.childNodes;
978
-
979
- $inputs[index].classList.add(PLUGIN_NAME + '-inputs-child');
980
-
981
- if(value[3]){
982
- setTimeout(function() {
983
- $inputs[index].focus();
984
- }, 300);
985
- }
986
-
987
- $inputs[index].addEventListener(value[1], function (e) {
988
- var ts = value[2];
989
- return ts(that, $DOM.toast, this, e);
990
- });
991
- });
992
- $DOM.toastBody.appendChild($DOM.inputs);
993
- }
994
- })();
995
-
996
- // Buttons
997
- (function(){
998
- if(settings.buttons.length > 0) {
999
-
1000
- $DOM.buttons.classList.add(PLUGIN_NAME + '-buttons');
1001
-
1002
- forEach(settings.buttons, function (value, index) {
1003
- $DOM.buttons.appendChild(createFragElem(value[0]));
1004
-
1005
- var $btns = $DOM.buttons.childNodes;
1006
-
1007
- $btns[index].classList.add(PLUGIN_NAME + '-buttons-child');
1008
-
1009
- if(value[2]){
1010
- setTimeout(function() {
1011
- $btns[index].focus();
1012
- }, 300);
1013
- }
1014
-
1015
- $btns[index].addEventListener('click', function (e) {
1016
- e.preventDefault();
1017
- var ts = value[1];
1018
- return ts(that, $DOM.toast, this, e, $inputs);
1019
- });
1020
- });
1021
- }
1022
- $DOM.toastBody.appendChild($DOM.buttons);
1023
- })();
1024
-
1025
- if(settings.message.length > 0 && (settings.inputs.length > 0 || settings.buttons.length > 0)) {
1026
- $DOM.p.style.marginBottom = '0';
1027
- }
1028
-
1029
- if(settings.inputs.length > 0 || settings.buttons.length > 0){
1030
- if(settings.rtl){
1031
- $DOM.toastTexts.style.marginLeft = '10px';
1032
- } else {
1033
- $DOM.toastTexts.style.marginRight = '10px';
1034
- }
1035
- if(settings.inputs.length > 0 && settings.buttons.length > 0){
1036
- if(settings.rtl){
1037
- $DOM.inputs.style.marginLeft = '8px';
1038
- } else {
1039
- $DOM.inputs.style.marginRight = '8px';
1040
- }
1041
- }
1042
- }
1043
-
1044
- // Wrap
1045
- (function(){
1046
- $DOM.toastCapsule.style.visibility = 'hidden';
1047
- setTimeout(function() {
1048
- var H = $DOM.toast.offsetHeight;
1049
- var style = $DOM.toast.currentStyle || window.getComputedStyle($DOM.toast);
1050
- var marginTop = style.marginTop;
1051
- marginTop = marginTop.split('px');
1052
- marginTop = parseInt(marginTop[0]);
1053
- var marginBottom = style.marginBottom;
1054
- marginBottom = marginBottom.split('px');
1055
- marginBottom = parseInt(marginBottom[0]);
1056
-
1057
- $DOM.toastCapsule.style.visibility = '';
1058
- $DOM.toastCapsule.style.height = (H+marginBottom+marginTop)+'px';
1059
-
1060
- setTimeout(function() {
1061
- $DOM.toastCapsule.style.height = 'auto';
1062
- if(settings.target){
1063
- $DOM.toastCapsule.style.overflow = 'visible';
1064
- }
1065
- }, 500);
1066
-
1067
- if(settings.timeout) {
1068
- that.progress(settings, $DOM.toast).start();
1069
- }
1070
- }, 100);
1071
- })();
1072
-
1073
- // Target
1074
- (function(){
1075
- var position = settings.position;
1076
-
1077
- if(settings.target){
1078
-
1079
- $DOM.wrapper = document.querySelector(settings.target);
1080
- $DOM.wrapper.classList.add(PLUGIN_NAME + '-target');
1081
-
1082
- if(settings.targetFirst) {
1083
- $DOM.wrapper.insertBefore($DOM.toastCapsule, $DOM.wrapper.firstChild);
1084
- } else {
1085
- $DOM.wrapper.appendChild($DOM.toastCapsule);
1086
- }
1087
-
1088
- } else {
1089
-
1090
- if( POSITIONS.indexOf(settings.position) == -1 ){
1091
- console.warn('['+PLUGIN_NAME+'] Incorrect position.\nIt can be › ' + POSITIONS);
1092
- return;
1093
- }
1094
-
1095
- if(ISMOBILE || window.innerWidth <= MOBILEWIDTH){
1096
- if(settings.position == 'bottomLeft' || settings.position == 'bottomRight' || settings.position == 'bottomCenter'){
1097
- position = PLUGIN_NAME+'-wrapper-bottomCenter';
1098
- }
1099
- else if(settings.position == 'topLeft' || settings.position == 'topRight' || settings.position == 'topCenter'){
1100
- position = PLUGIN_NAME+'-wrapper-topCenter';
1101
- }
1102
- else {
1103
- position = PLUGIN_NAME+'-wrapper-center';
1104
- }
1105
- } else {
1106
- position = PLUGIN_NAME+'-wrapper-'+position;
1107
- }
1108
- $DOM.wrapper = document.querySelector('.' + PLUGIN_NAME + '-wrapper.'+position);
1109
-
1110
- if(!$DOM.wrapper) {
1111
- $DOM.wrapper = document.createElement('div');
1112
- $DOM.wrapper.classList.add(PLUGIN_NAME + '-wrapper');
1113
- $DOM.wrapper.classList.add(position);
1114
- document.body.appendChild($DOM.wrapper);
1115
- }
1116
- if(settings.position == 'topLeft' || settings.position == 'topCenter' || settings.position == 'topRight'){
1117
- $DOM.wrapper.insertBefore($DOM.toastCapsule, $DOM.wrapper.firstChild);
1118
- } else {
1119
- $DOM.wrapper.appendChild($DOM.toastCapsule);
1120
- }
1121
- }
1122
-
1123
- if(!isNaN(settings.zindex)) {
1124
- $DOM.wrapper.style.zIndex = settings.zindex;
1125
- } else {
1126
- console.warn('['+PLUGIN_NAME+'] Invalid zIndex.');
1127
- }
1128
- })();
1129
-
1130
- // Overlay
1131
- (function(){
1132
-
1133
- if(settings.overlay) {
1134
-
1135
- if( document.querySelector('.'+PLUGIN_NAME+'-overlay.fadeIn') !== null ){
1136
-
1137
- $DOM.overlay = document.querySelector('.'+PLUGIN_NAME+'-overlay');
1138
- $DOM.overlay.setAttribute('data-iziToast-ref', $DOM.overlay.getAttribute('data-iziToast-ref') + ',' + settings.ref);
1139
-
1140
- if(!isNaN(settings.zindex) && settings.zindex !== null) {
1141
- $DOM.overlay.style.zIndex = settings.zindex-1;
1142
- }
1143
-
1144
- } else {
1145
-
1146
- $DOM.overlay.classList.add(PLUGIN_NAME+'-overlay');
1147
- $DOM.overlay.classList.add('fadeIn');
1148
- $DOM.overlay.style.background = settings.overlayColor;
1149
- $DOM.overlay.setAttribute('data-iziToast-ref', settings.ref);
1150
- if(!isNaN(settings.zindex) && settings.zindex !== null) {
1151
- $DOM.overlay.style.zIndex = settings.zindex-1;
1152
- }
1153
- document.querySelector('body').appendChild($DOM.overlay);
1154
- }
1155
-
1156
- if(settings.overlayClose) {
1157
-
1158
- $DOM.overlay.removeEventListener('click', {});
1159
- $DOM.overlay.addEventListener('click', function (e) {
1160
- that.hide(settings, $DOM.toast, 'overlay');
1161
- });
1162
- } else {
1163
- $DOM.overlay.removeEventListener('click', {});
1164
- }
1165
- }
1166
- })();
1167
-
1168
- // Inside animations
1169
- (function(){
1170
- if(settings.animateInside){
1171
- $DOM.toast.classList.add(PLUGIN_NAME+'-animateInside');
1172
-
1173
- var animationTimes = [200, 100, 300];
1174
- if(settings.transitionIn == 'bounceInLeft' || settings.transitionIn == 'bounceInRight'){
1175
- animationTimes = [400, 200, 400];
1176
- }
1177
-
1178
- if(settings.title.length > 0) {
1179
- setTimeout(function(){
1180
- $DOM.strong.classList.add('slideIn');
1181
- }, animationTimes[0]);
1182
- }
1183
-
1184
- if(settings.message.length > 0) {
1185
- setTimeout(function(){
1186
- $DOM.p.classList.add('slideIn');
1187
- }, animationTimes[1]);
1188
- }
1189
-
1190
- if(settings.icon || settings.iconUrl) {
1191
- setTimeout(function(){
1192
- $DOM.icon.classList.add('revealIn');
1193
- }, animationTimes[2]);
1194
- }
1195
-
1196
- var counter = 150;
1197
- if(settings.buttons.length > 0 && $DOM.buttons) {
1198
-
1199
- setTimeout(function(){
1200
-
1201
- forEach($DOM.buttons.childNodes, function(element, index) {
1202
-
1203
- setTimeout(function(){
1204
- element.classList.add('revealIn');
1205
- }, counter);
1206
- counter = counter + 150;
1207
- });
1208
-
1209
- }, settings.inputs.length > 0 ? 150 : 0);
1210
- }
1211
-
1212
- if(settings.inputs.length > 0 && $DOM.inputs) {
1213
- counter = 150;
1214
- forEach($DOM.inputs.childNodes, function(element, index) {
1215
-
1216
- setTimeout(function(){
1217
- element.classList.add('revealIn');
1218
- }, counter);
1219
- counter = counter + 150;
1220
- });
1221
- }
1222
- }
1223
- })();
1224
-
1225
- settings.onOpening.apply(null, [settings, $DOM.toast]);
1226
-
1227
- try {
1228
- var event = new CustomEvent(PLUGIN_NAME + '-opening', {detail: settings, bubbles: true, cancelable: true});
1229
- document.dispatchEvent(event);
1230
- } catch(ex){
1231
- console.warn(ex);
1232
- }
1233
-
1234
- setTimeout(function() {
1235
-
1236
- $DOM.toast.classList.remove(PLUGIN_NAME+'-opening');
1237
- $DOM.toast.classList.add(PLUGIN_NAME+'-opened');
1238
-
1239
- try {
1240
- var event = new CustomEvent(PLUGIN_NAME + '-opened', {detail: settings, bubbles: true, cancelable: true});
1241
- document.dispatchEvent(event);
1242
- } catch(ex){
1243
- console.warn(ex);
1244
- }
1245
-
1246
- settings.onOpened.apply(null, [settings, $DOM.toast]);
1247
- }, 1000);
1248
-
1249
- if(settings.drag){
1250
-
1251
- if(ACCEPTSTOUCH) {
1252
-
1253
- $DOM.toast.addEventListener('touchstart', function(e) {
1254
- drag.startMoving(this, that, settings, e);
1255
- }, false);
1256
-
1257
- $DOM.toast.addEventListener('touchend', function(e) {
1258
- drag.stopMoving(this, e);
1259
- }, false);
1260
- } else {
1261
-
1262
- $DOM.toast.addEventListener('mousedown', function(e) {
1263
- e.preventDefault();
1264
- drag.startMoving(this, that, settings, e);
1265
- }, false);
1266
-
1267
- $DOM.toast.addEventListener('mouseup', function(e) {
1268
- e.preventDefault();
1269
- drag.stopMoving(this, e);
1270
- }, false);
1271
- }
1272
- }
1273
-
1274
- if(settings.closeOnEscape) {
1275
-
1276
- document.addEventListener('keyup', function (evt) {
1277
- evt = evt || window.event;
1278
- if(evt.keyCode == 27) {
1279
- that.hide(settings, $DOM.toast, 'esc');
1280
- }
1281
- });
1282
- }
1283
-
1284
- if(settings.closeOnClick) {
1285
- $DOM.toast.addEventListener('click', function (evt) {
1286
- that.hide(settings, $DOM.toast, 'toast');
1287
- });
1288
- }
1289
-
1290
- that.toast = $DOM.toast;
1291
- };
1292
-
1293
-
1294
- return $iziToast;
1295
- });
1296
- return this;
1297
- };
1298
-
1299
- const global = new Global().dispatch();
1300
-
1301
- export default global.iziToast;
1
+ const Global = function() {};
2
+
3
+ Global.prototype.dispatch = function() {
4
+ /*
5
+ * iziToast | v1.4.0
6
+ * http://izitoast.marcelodolce.com
7
+ * by Marcelo Dolce.
8
+ */
9
+ (function (root, factory) {
10
+ if(typeof define === 'function' && define.amd) {
11
+ define([], factory(root));
12
+ } else if(typeof exports === 'object') {
13
+ module.exports = factory(root);
14
+ } else {
15
+ root.iziToast = factory(root);
16
+ }
17
+ })(this, function (root) {
18
+
19
+ 'use strict';
20
+
21
+ //
22
+ // Variables
23
+ //
24
+ var $iziToast = {},
25
+ PLUGIN_NAME = 'iziToast',
26
+ BODY = document.querySelector('body'),
27
+ ISMOBILE = (/Mobi/.test(navigator.userAgent)) ? true : false,
28
+ ISCHROME = /Chrome/.test(navigator.userAgent) && /Google Inc/.test(navigator.vendor),
29
+ ISFIREFOX = typeof InstallTrigger !== 'undefined',
30
+ ACCEPTSTOUCH = 'ontouchstart' in document.documentElement,
31
+ POSITIONS = ['bottomRight','bottomLeft','bottomCenter','topRight','topLeft','topCenter','center'],
32
+ THEMES = {
33
+ info: {
34
+ color: 'blue',
35
+ icon: 'ico-info'
36
+ },
37
+ success: {
38
+ color: 'green',
39
+ icon: 'ico-success'
40
+ },
41
+ warning: {
42
+ color: 'orange',
43
+ icon: 'ico-warning'
44
+ },
45
+ error: {
46
+ color: 'red',
47
+ icon: 'ico-error'
48
+ },
49
+ question: {
50
+ color: 'yellow',
51
+ icon: 'ico-question'
52
+ }
53
+ },
54
+ MOBILEWIDTH = 568,
55
+ CONFIG = {};
56
+
57
+ $iziToast.children = {};
58
+
59
+ // Default settings
60
+ var defaults = {
61
+ id: null,
62
+ class: '',
63
+ title: '',
64
+ titleColor: '',
65
+ titleSize: '',
66
+ titleLineHeight: '',
67
+ message: '',
68
+ messageColor: '',
69
+ messageSize: '',
70
+ messageLineHeight: '',
71
+ backgroundColor: '',
72
+ theme: 'light', // dark
73
+ color: '', // blue, red, green, yellow
74
+ icon: '',
75
+ iconText: '',
76
+ iconColor: '',
77
+ iconUrl: null,
78
+ image: '',
79
+ imageWidth: 50,
80
+ maxWidth: null,
81
+ zindex: null,
82
+ layout: 1,
83
+ balloon: false,
84
+ close: true,
85
+ closeOnEscape: false,
86
+ closeOnClick: false,
87
+ displayMode: 0,
88
+ position: 'bottomRight', // bottomRight, bottomLeft, topRight, topLeft, topCenter, bottomCenter, center
89
+ target: '',
90
+ targetFirst: true,
91
+ timeout: 5000,
92
+ rtl: false,
93
+ animateInside: true,
94
+ drag: true,
95
+ pauseOnHover: true,
96
+ resetOnHover: false,
97
+ progressBar: true,
98
+ progressBarColor: '',
99
+ progressBarEasing: 'linear',
100
+ overlay: false,
101
+ overlayClose: false,
102
+ overlayColor: 'rgba(0, 0, 0, 0.6)',
103
+ transitionIn: 'fadeInUp', // bounceInLeft, bounceInRight, bounceInUp, bounceInDown, fadeIn, fadeInDown, fadeInUp, fadeInLeft, fadeInRight, flipInX
104
+ transitionOut: 'fadeOut', // fadeOut, fadeOutUp, fadeOutDown, fadeOutLeft, fadeOutRight, flipOutX
105
+ transitionInMobile: 'fadeInUp',
106
+ transitionOutMobile: 'fadeOutDown',
107
+ buttons: {},
108
+ inputs: {},
109
+ onOpening: function () {},
110
+ onOpened: function () {},
111
+ onClosing: function () {},
112
+ onClosed: function () {}
113
+ };
114
+
115
+ //
116
+ // Methods
117
+ //
118
+
119
+
120
+ /**
121
+ * Polyfill for remove() method
122
+ */
123
+ if(!('remove' in Element.prototype)) {
124
+ Element.prototype.remove = function() {
125
+ if(this.parentNode) {
126
+ this.parentNode.removeChild(this);
127
+ }
128
+ };
129
+ }
130
+
131
+ /*
132
+ * Polyfill for CustomEvent for IE >= 9
133
+ * https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent/CustomEvent#Polyfill
134
+ */
135
+ if(typeof window.CustomEvent !== 'function') {
136
+ var CustomEventPolyfill = function (event, params) {
137
+ params = params || { bubbles: false, cancelable: false, detail: undefined };
138
+ var evt = document.createEvent('CustomEvent');
139
+ evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail);
140
+ return evt;
141
+ };
142
+
143
+ CustomEventPolyfill.prototype = window.Event.prototype;
144
+
145
+ window.CustomEvent = CustomEventPolyfill;
146
+ }
147
+
148
+ /**
149
+ * A simple forEach() implementation for Arrays, Objects and NodeLists
150
+ * @private
151
+ * @param {Array|Object|NodeList} collection Collection of items to iterate
152
+ * @param {Function} callback Callback function for each iteration
153
+ * @param {Array|Object|NodeList} scope Object/NodeList/Array that forEach is iterating over (aka `this`)
154
+ */
155
+ var forEach = function (collection, callback, scope) {
156
+ if(Object.prototype.toString.call(collection) === '[object Object]') {
157
+ for (var prop in collection) {
158
+ if(Object.prototype.hasOwnProperty.call(collection, prop)) {
159
+ callback.call(scope, collection[prop], prop, collection);
160
+ }
161
+ }
162
+ } else {
163
+ if(collection){
164
+ for (var i = 0, len = collection.length; i < len; i++) {
165
+ callback.call(scope, collection[i], i, collection);
166
+ }
167
+ }
168
+ }
169
+ };
170
+
171
+ /**
172
+ * Merge defaults with user options
173
+ * @private
174
+ * @param {Object} defaults Default settings
175
+ * @param {Object} options User options
176
+ * @returns {Object} Merged values of defaults and options
177
+ */
178
+ var extend = function (defaults, options) {
179
+ var extended = {};
180
+ forEach(defaults, function (value, prop) {
181
+ extended[prop] = defaults[prop];
182
+ });
183
+ forEach(options, function (value, prop) {
184
+ extended[prop] = options[prop];
185
+ });
186
+ return extended;
187
+ };
188
+
189
+
190
+ /**
191
+ * Create a fragment DOM elements
192
+ * @private
193
+ */
194
+ var createFragElem = function(htmlStr) {
195
+ var frag = document.createDocumentFragment(),
196
+ temp = document.createElement('div');
197
+ temp.innerHTML = htmlStr;
198
+ while (temp.firstChild) {
199
+ frag.appendChild(temp.firstChild);
200
+ }
201
+ return frag;
202
+ };
203
+
204
+
205
+ /**
206
+ * Generate new ID
207
+ * @private
208
+ */
209
+ var generateId = function(params) {
210
+ var newId = btoa(encodeURIComponent(params));
211
+ return newId.replace(/=/g, "");
212
+ };
213
+
214
+
215
+ /**
216
+ * Check if is a color
217
+ * @private
218
+ */
219
+ var isColor = function(color){
220
+ if( color.substring(0,1) == '#' || color.substring(0,3) == 'rgb' || color.substring(0,3) == 'hsl' ){
221
+ return true;
222
+ } else {
223
+ return false;
224
+ }
225
+ };
226
+
227
+
228
+ /**
229
+ * Check if is a Base64 string
230
+ * @private
231
+ */
232
+ var isBase64 = function(str) {
233
+ try {
234
+ return btoa(atob(str)) == str;
235
+ } catch (err) {
236
+ return false;
237
+ }
238
+ };
239
+
240
+
241
+ /**
242
+ * Drag method of toasts
243
+ * @private
244
+ */
245
+ var drag = function() {
246
+
247
+ return {
248
+ move: function(toast, instance, settings, xpos) {
249
+
250
+ var opacity,
251
+ opacityRange = 0.3,
252
+ distance = 180;
253
+
254
+ if(xpos !== 0){
255
+
256
+ toast.classList.add(PLUGIN_NAME+'-dragged');
257
+
258
+ toast.style.transform = 'translateX('+xpos + 'px)';
259
+
260
+ if(xpos > 0){
261
+ opacity = (distance-xpos) / distance;
262
+ if(opacity < opacityRange){
263
+ instance.hide(extend(settings, { transitionOut: 'fadeOutRight', transitionOutMobile: 'fadeOutRight' }), toast, 'drag');
264
+ }
265
+ } else {
266
+ opacity = (distance+xpos) / distance;
267
+ if(opacity < opacityRange){
268
+ instance.hide(extend(settings, { transitionOut: 'fadeOutLeft', transitionOutMobile: 'fadeOutLeft' }), toast, 'drag');
269
+ }
270
+ }
271
+ toast.style.opacity = opacity;
272
+
273
+ if(opacity < opacityRange){
274
+
275
+ if(ISCHROME || ISFIREFOX)
276
+ toast.style.left = xpos+'px';
277
+
278
+ toast.parentNode.style.opacity = opacityRange;
279
+
280
+ this.stopMoving(toast, null);
281
+ }
282
+ }
283
+
284
+
285
+ },
286
+ startMoving: function(toast, instance, settings, e) {
287
+
288
+ e = e || window.event;
289
+ var posX = ((ACCEPTSTOUCH) ? e.touches[0].clientX : e.clientX),
290
+ toastLeft = toast.style.transform.replace('px)', '');
291
+ toastLeft = toastLeft.replace('translateX(', '');
292
+ var offsetX = posX - toastLeft;
293
+
294
+ if(settings.transitionIn){
295
+ toast.classList.remove(settings.transitionIn);
296
+ }
297
+ if(settings.transitionInMobile){
298
+ toast.classList.remove(settings.transitionInMobile);
299
+ }
300
+ toast.style.transition = '';
301
+
302
+ if(ACCEPTSTOUCH) {
303
+ document.ontouchmove = function(e) {
304
+ e.preventDefault();
305
+ e = e || window.event;
306
+ var posX = e.touches[0].clientX,
307
+ finalX = posX - offsetX;
308
+ drag.move(toast, instance, settings, finalX);
309
+ };
310
+ } else {
311
+ document.onmousemove = function(e) {
312
+ e.preventDefault();
313
+ e = e || window.event;
314
+ var posX = e.clientX,
315
+ finalX = posX - offsetX;
316
+ drag.move(toast, instance, settings, finalX);
317
+ };
318
+ }
319
+
320
+ },
321
+ stopMoving: function(toast, e) {
322
+
323
+ if(ACCEPTSTOUCH) {
324
+ document.ontouchmove = function() {};
325
+ } else {
326
+ document.onmousemove = function() {};
327
+ }
328
+
329
+ toast.style.opacity = '';
330
+ toast.style.transform = '';
331
+
332
+ if(toast.classList.contains(PLUGIN_NAME+'-dragged')){
333
+
334
+ toast.classList.remove(PLUGIN_NAME+'-dragged');
335
+
336
+ toast.style.transition = 'transform 0.4s ease, opacity 0.4s ease';
337
+ setTimeout(function() {
338
+ toast.style.transition = '';
339
+ }, 400);
340
+ }
341
+
342
+ }
343
+ };
344
+
345
+ }();
346
+
347
+
348
+
349
+
350
+
351
+ $iziToast.setSetting = function (ref, option, value) {
352
+
353
+ $iziToast.children[ref][option] = value;
354
+
355
+ };
356
+
357
+
358
+ $iziToast.getSetting = function (ref, option) {
359
+
360
+ return $iziToast.children[ref][option];
361
+
362
+ };
363
+
364
+
365
+ /**
366
+ * Destroy the current initialization.
367
+ * @public
368
+ */
369
+ $iziToast.destroy = function () {
370
+
371
+ forEach(document.querySelectorAll('.'+PLUGIN_NAME+'-overlay'), function(element, index) {
372
+ element.remove();
373
+ });
374
+
375
+ forEach(document.querySelectorAll('.'+PLUGIN_NAME+'-wrapper'), function(element, index) {
376
+ element.remove();
377
+ });
378
+
379
+ forEach(document.querySelectorAll('.'+PLUGIN_NAME), function(element, index) {
380
+ element.remove();
381
+ });
382
+
383
+ this.children = {};
384
+
385
+ // Remove event listeners
386
+ document.removeEventListener(PLUGIN_NAME+'-opened', {}, false);
387
+ document.removeEventListener(PLUGIN_NAME+'-opening', {}, false);
388
+ document.removeEventListener(PLUGIN_NAME+'-closing', {}, false);
389
+ document.removeEventListener(PLUGIN_NAME+'-closed', {}, false);
390
+ document.removeEventListener('keyup', {}, false);
391
+
392
+ // Reset variables
393
+ CONFIG = {};
394
+ };
395
+
396
+ /**
397
+ * Initialize Plugin
398
+ * @public
399
+ * @param {Object} options User settings
400
+ */
401
+ $iziToast.settings = function (options) {
402
+
403
+ // Destroy any existing initializations
404
+ $iziToast.destroy();
405
+
406
+ CONFIG = options;
407
+ defaults = extend(defaults, options || {});
408
+ };
409
+
410
+
411
+ /**
412
+ * Building themes functions.
413
+ * @public
414
+ * @param {Object} options User settings
415
+ */
416
+ forEach(THEMES, function (theme, name) {
417
+
418
+ $iziToast[name] = function (options) {
419
+
420
+ var settings = extend(CONFIG, options || {});
421
+ settings = extend(theme, settings || {});
422
+
423
+ this.show(settings);
424
+ };
425
+
426
+ });
427
+
428
+
429
+ /**
430
+ * Do the calculation to move the progress bar
431
+ * @private
432
+ */
433
+ $iziToast.progress = function (options, $toast, callback) {
434
+
435
+
436
+ var that = this,
437
+ ref = $toast.getAttribute('data-iziToast-ref'),
438
+ settings = extend(this.children[ref], options || {}),
439
+ $elem = $toast.querySelector('.'+PLUGIN_NAME+'-progressbar div');
440
+
441
+ return {
442
+ start: function() {
443
+
444
+ if(typeof settings.time.REMAINING == 'undefined'){
445
+
446
+ $toast.classList.remove(PLUGIN_NAME+'-reseted');
447
+
448
+ if($elem !== null){
449
+ $elem.style.transition = 'width '+ settings.timeout +'ms '+settings.progressBarEasing;
450
+ $elem.style.width = '0%';
451
+ }
452
+
453
+ settings.time.START = new Date().getTime();
454
+ settings.time.END = settings.time.START + settings.timeout;
455
+ settings.time.TIMER = setTimeout(function() {
456
+
457
+ clearTimeout(settings.time.TIMER);
458
+
459
+ if(!$toast.classList.contains(PLUGIN_NAME+'-closing')){
460
+
461
+ that.hide(settings, $toast, 'timeout');
462
+
463
+ if(typeof callback === 'function'){
464
+ callback.apply(that);
465
+ }
466
+ }
467
+
468
+ }, settings.timeout);
469
+ that.setSetting(ref, 'time', settings.time);
470
+ }
471
+ },
472
+ pause: function() {
473
+
474
+ if(typeof settings.time.START !== 'undefined' && !$toast.classList.contains(PLUGIN_NAME+'-paused') && !$toast.classList.contains(PLUGIN_NAME+'-reseted')){
475
+
476
+ $toast.classList.add(PLUGIN_NAME+'-paused');
477
+
478
+ settings.time.REMAINING = settings.time.END - new Date().getTime();
479
+
480
+ clearTimeout(settings.time.TIMER);
481
+
482
+ that.setSetting(ref, 'time', settings.time);
483
+
484
+ if($elem !== null){
485
+ var computedStyle = window.getComputedStyle($elem),
486
+ propertyWidth = computedStyle.getPropertyValue('width');
487
+
488
+ $elem.style.transition = 'none';
489
+ $elem.style.width = propertyWidth;
490
+ }
491
+
492
+ if(typeof callback === 'function'){
493
+ setTimeout(function() {
494
+ callback.apply(that);
495
+ }, 10);
496
+ }
497
+ }
498
+ },
499
+ resume: function() {
500
+
501
+ if(typeof settings.time.REMAINING !== 'undefined'){
502
+
503
+ $toast.classList.remove(PLUGIN_NAME+'-paused');
504
+
505
+ if($elem !== null){
506
+ $elem.style.transition = 'width '+ settings.time.REMAINING +'ms '+settings.progressBarEasing;
507
+ $elem.style.width = '0%';
508
+ }
509
+
510
+ settings.time.END = new Date().getTime() + settings.time.REMAINING;
511
+ settings.time.TIMER = setTimeout(function() {
512
+
513
+ clearTimeout(settings.time.TIMER);
514
+
515
+ if(!$toast.classList.contains(PLUGIN_NAME+'-closing')){
516
+
517
+ that.hide(settings, $toast, 'timeout');
518
+
519
+ if(typeof callback === 'function'){
520
+ callback.apply(that);
521
+ }
522
+ }
523
+
524
+
525
+ }, settings.time.REMAINING);
526
+
527
+ that.setSetting(ref, 'time', settings.time);
528
+ } else {
529
+ this.start();
530
+ }
531
+ },
532
+ reset: function(){
533
+
534
+ clearTimeout(settings.time.TIMER);
535
+
536
+ delete settings.time.REMAINING;
537
+
538
+ that.setSetting(ref, 'time', settings.time);
539
+
540
+ $toast.classList.add(PLUGIN_NAME+'-reseted');
541
+
542
+ $toast.classList.remove(PLUGIN_NAME+'-paused');
543
+
544
+ if($elem !== null){
545
+ $elem.style.transition = 'none';
546
+ $elem.style.width = '100%';
547
+ }
548
+
549
+ if(typeof callback === 'function'){
550
+ setTimeout(function() {
551
+ callback.apply(that);
552
+ }, 10);
553
+ }
554
+ }
555
+ };
556
+
557
+ };
558
+
559
+
560
+ /**
561
+ * Close the specific Toast
562
+ * @public
563
+ * @param {Object} options User settings
564
+ */
565
+ $iziToast.hide = function (options, $toast, closedBy) {
566
+
567
+ if(typeof $toast != 'object'){
568
+ $toast = document.querySelector($toast);
569
+ }
570
+
571
+ var that = this,
572
+ settings = extend(this.children[$toast.getAttribute('data-iziToast-ref')], options || {});
573
+ settings.closedBy = closedBy || null;
574
+
575
+ delete settings.time.REMAINING;
576
+
577
+ $toast.classList.add(PLUGIN_NAME+'-closing');
578
+
579
+ // Overlay
580
+ (function(){
581
+
582
+ var $overlay = document.querySelector('.'+PLUGIN_NAME+'-overlay');
583
+ if($overlay !== null){
584
+ var refs = $overlay.getAttribute('data-iziToast-ref');
585
+ refs = refs.split(',');
586
+ var index = refs.indexOf(String(settings.ref));
587
+
588
+ if(index !== -1){
589
+ refs.splice(index, 1);
590
+ }
591
+ $overlay.setAttribute('data-iziToast-ref', refs.join());
592
+
593
+ if(refs.length === 0){
594
+ $overlay.classList.remove('fadeIn');
595
+ $overlay.classList.add('fadeOut');
596
+ setTimeout(function() {
597
+ $overlay.remove();
598
+ }, 700);
599
+ }
600
+ }
601
+
602
+ })();
603
+
604
+ if(settings.transitionIn){
605
+ $toast.classList.remove(settings.transitionIn);
606
+ }
607
+
608
+ if(settings.transitionInMobile){
609
+ $toast.classList.remove(settings.transitionInMobile);
610
+ }
611
+
612
+ if(ISMOBILE || window.innerWidth <= MOBILEWIDTH){
613
+ if(settings.transitionOutMobile)
614
+ $toast.classList.add(settings.transitionOutMobile);
615
+ } else {
616
+ if(settings.transitionOut)
617
+ $toast.classList.add(settings.transitionOut);
618
+ }
619
+ var H = $toast.parentNode.offsetHeight;
620
+ $toast.parentNode.style.height = H+'px';
621
+ $toast.style.pointerEvents = 'none';
622
+
623
+ if(!ISMOBILE || window.innerWidth > MOBILEWIDTH){
624
+ $toast.parentNode.style.transitionDelay = '0.2s';
625
+ }
626
+
627
+ try {
628
+ var event = new CustomEvent(PLUGIN_NAME+'-closing', {detail: settings, bubbles: true, cancelable: true});
629
+ document.dispatchEvent(event);
630
+ } catch(ex){
631
+ console.warn(ex);
632
+ }
633
+
634
+ setTimeout(function() {
635
+
636
+ $toast.parentNode.style.height = '0px';
637
+ $toast.parentNode.style.overflow = '';
638
+
639
+ setTimeout(function(){
640
+
641
+ delete that.children[settings.ref];
642
+
643
+ $toast.parentNode.remove();
644
+
645
+ try {
646
+ var event = new CustomEvent(PLUGIN_NAME+'-closed', {detail: settings, bubbles: true, cancelable: true});
647
+ document.dispatchEvent(event);
648
+ } catch(ex){
649
+ console.warn(ex);
650
+ }
651
+
652
+ if(typeof settings.onClosed !== 'undefined'){
653
+ settings.onClosed.apply(null, [settings, $toast, closedBy]);
654
+ }
655
+
656
+ }, 1000);
657
+ }, 200);
658
+
659
+
660
+ if(typeof settings.onClosing !== 'undefined'){
661
+ settings.onClosing.apply(null, [settings, $toast, closedBy]);
662
+ }
663
+ };
664
+
665
+ /**
666
+ * Create and show the Toast
667
+ * @public
668
+ * @param {Object} options User settings
669
+ */
670
+ $iziToast.show = function (options) {
671
+
672
+ var that = this;
673
+
674
+ // Merge user options with defaults
675
+ var settings = extend(CONFIG, options || {});
676
+ settings = extend(defaults, settings);
677
+ settings.time = {};
678
+
679
+ if(settings.id === null){
680
+ settings.id = generateId(settings.title+settings.message+settings.color);
681
+ }
682
+
683
+ if(settings.displayMode === 1 || settings.displayMode == 'once'){
684
+ try {
685
+ if(document.querySelectorAll('.'+PLUGIN_NAME+'#'+settings.id).length > 0){
686
+ return false;
687
+ }
688
+ } catch (exc) {
689
+ console.warn('['+PLUGIN_NAME+'] Could not find an element with this selector: '+'#'+settings.id+'. Try to set an valid id.');
690
+ }
691
+ }
692
+
693
+ if(settings.displayMode === 2 || settings.displayMode == 'replace'){
694
+ try {
695
+ forEach(document.querySelectorAll('.'+PLUGIN_NAME+'#'+settings.id), function(element, index) {
696
+ that.hide(settings, element, 'replaced');
697
+ });
698
+ } catch (exc) {
699
+ console.warn('['+PLUGIN_NAME+'] Could not find an element with this selector: '+'#'+settings.id+'. Try to set an valid id.');
700
+ }
701
+ }
702
+
703
+ settings.ref = new Date().getTime() + Math.floor((Math.random() * 10000000) + 1);
704
+
705
+ $iziToast.children[settings.ref] = settings;
706
+
707
+ var $DOM = {
708
+ body: document.querySelector('body'),
709
+ overlay: document.createElement('div'),
710
+ toast: document.createElement('div'),
711
+ toastBody: document.createElement('div'),
712
+ toastTexts: document.createElement('div'),
713
+ toastCapsule: document.createElement('div'),
714
+ cover: document.createElement('div'),
715
+ buttons: document.createElement('div'),
716
+ inputs: document.createElement('div'),
717
+ icon: !settings.iconUrl ? document.createElement('i') : document.createElement('img'),
718
+ wrapper: null
719
+ };
720
+
721
+ $DOM.toast.setAttribute('data-iziToast-ref', settings.ref);
722
+ $DOM.toast.appendChild($DOM.toastBody);
723
+ $DOM.toastCapsule.appendChild($DOM.toast);
724
+
725
+ // CSS Settings
726
+ (function(){
727
+
728
+ $DOM.toast.classList.add(PLUGIN_NAME);
729
+ $DOM.toast.classList.add(PLUGIN_NAME+'-opening');
730
+ $DOM.toastCapsule.classList.add(PLUGIN_NAME+'-capsule');
731
+ $DOM.toastBody.classList.add(PLUGIN_NAME + '-body');
732
+ $DOM.toastTexts.classList.add(PLUGIN_NAME + '-texts');
733
+
734
+ if(ISMOBILE || window.innerWidth <= MOBILEWIDTH){
735
+ if(settings.transitionInMobile)
736
+ $DOM.toast.classList.add(settings.transitionInMobile);
737
+ } else {
738
+ if(settings.transitionIn)
739
+ $DOM.toast.classList.add(settings.transitionIn);
740
+ }
741
+
742
+ if(settings.class){
743
+ var classes = settings.class.split(' ');
744
+ forEach(classes, function (value, index) {
745
+ $DOM.toast.classList.add(value);
746
+ });
747
+ }
748
+
749
+ if(settings.id){ $DOM.toast.id = settings.id; }
750
+
751
+ if(settings.rtl){
752
+ $DOM.toast.classList.add(PLUGIN_NAME + '-rtl');
753
+ $DOM.toast.setAttribute('dir', 'rtl');
754
+ }
755
+
756
+ if(settings.layout > 1){ $DOM.toast.classList.add(PLUGIN_NAME+'-layout'+settings.layout); }
757
+
758
+ if(settings.balloon){ $DOM.toast.classList.add(PLUGIN_NAME+'-balloon'); }
759
+
760
+ if(settings.maxWidth){
761
+ if( !isNaN(settings.maxWidth) ){
762
+ $DOM.toast.style.maxWidth = settings.maxWidth+'px';
763
+ } else {
764
+ $DOM.toast.style.maxWidth = settings.maxWidth;
765
+ }
766
+ }
767
+
768
+ if(settings.theme !== '' || settings.theme !== 'light') {
769
+
770
+ $DOM.toast.classList.add(PLUGIN_NAME+'-theme-'+settings.theme);
771
+ }
772
+
773
+ if(settings.color) { //#, rgb, rgba, hsl
774
+
775
+ if( isColor(settings.color) ){
776
+ $DOM.toast.style.background = settings.color;
777
+ } else {
778
+ $DOM.toast.classList.add(PLUGIN_NAME+'-color-'+settings.color);
779
+ }
780
+ }
781
+
782
+ if(settings.backgroundColor) {
783
+ $DOM.toast.style.background = settings.backgroundColor;
784
+ if(settings.balloon){
785
+ $DOM.toast.style.borderColor = settings.backgroundColor;
786
+ }
787
+ }
788
+ })();
789
+
790
+ // Cover image
791
+ (function(){
792
+ if(settings.image) {
793
+ $DOM.cover.classList.add(PLUGIN_NAME + '-cover');
794
+ $DOM.cover.style.width = settings.imageWidth + 'px';
795
+
796
+ if(isBase64(settings.image.replace(/ /g,''))){
797
+ $DOM.cover.style.backgroundImage = 'url(data:image/png;base64,' + settings.image.replace(/ /g,'') + ')';
798
+ } else {
799
+ $DOM.cover.style.backgroundImage = 'url(' + settings.image + ')';
800
+ }
801
+
802
+ if(settings.rtl){
803
+ $DOM.toastBody.style.marginRight = (settings.imageWidth + 10) + 'px';
804
+ } else {
805
+ $DOM.toastBody.style.marginLeft = (settings.imageWidth + 10) + 'px';
806
+ }
807
+ $DOM.toast.appendChild($DOM.cover);
808
+ }
809
+ })();
810
+
811
+ // Button close
812
+ (function(){
813
+ if(settings.close){
814
+
815
+ $DOM.buttonClose = document.createElement('button');
816
+ $DOM.buttonClose.type = 'button';
817
+ $DOM.buttonClose.classList.add(PLUGIN_NAME + '-close');
818
+ $DOM.buttonClose.addEventListener('click', function (e) {
819
+ var button = e.target;
820
+ that.hide(settings, $DOM.toast, 'button');
821
+ });
822
+ $DOM.toast.appendChild($DOM.buttonClose);
823
+ } else {
824
+ if(settings.rtl){
825
+ $DOM.toast.style.paddingLeft = '18px';
826
+ } else {
827
+ $DOM.toast.style.paddingRight = '18px';
828
+ }
829
+ }
830
+ })();
831
+
832
+ // Progress Bar & Timeout
833
+ (function(){
834
+
835
+ if(settings.progressBar){
836
+ $DOM.progressBar = document.createElement('div');
837
+ $DOM.progressBarDiv = document.createElement('div');
838
+ $DOM.progressBar.classList.add(PLUGIN_NAME + '-progressbar');
839
+ $DOM.progressBarDiv.style.background = settings.progressBarColor;
840
+ $DOM.progressBar.appendChild($DOM.progressBarDiv);
841
+ $DOM.toast.appendChild($DOM.progressBar);
842
+ }
843
+
844
+ if(settings.timeout) {
845
+
846
+ if(settings.pauseOnHover && !settings.resetOnHover){
847
+
848
+ $DOM.toast.addEventListener('mouseenter', function (e) {
849
+ that.progress(settings, $DOM.toast).pause();
850
+ });
851
+ $DOM.toast.addEventListener('mouseleave', function (e) {
852
+ that.progress(settings, $DOM.toast).resume();
853
+ });
854
+ }
855
+
856
+ if(settings.resetOnHover){
857
+
858
+ $DOM.toast.addEventListener('mouseenter', function (e) {
859
+ that.progress(settings, $DOM.toast).reset();
860
+ });
861
+ $DOM.toast.addEventListener('mouseleave', function (e) {
862
+ that.progress(settings, $DOM.toast).start();
863
+ });
864
+ }
865
+ }
866
+ })();
867
+
868
+ // Icon
869
+ (function(){
870
+
871
+ if(settings.iconUrl) {
872
+
873
+ $DOM.icon.setAttribute('class', PLUGIN_NAME + '-icon');
874
+ $DOM.icon.setAttribute('src', settings.iconUrl);
875
+
876
+ } else if(settings.icon) {
877
+ $DOM.icon.setAttribute('class', PLUGIN_NAME + '-icon ' + settings.icon);
878
+
879
+ if(settings.iconText){
880
+ $DOM.icon.appendChild(document.createTextNode(settings.iconText));
881
+ }
882
+
883
+ if(settings.iconColor){
884
+ $DOM.icon.style.color = settings.iconColor;
885
+ }
886
+ }
887
+
888
+ if(settings.icon || settings.iconUrl) {
889
+
890
+ if(settings.rtl){
891
+ $DOM.toastBody.style.paddingRight = '33px';
892
+ } else {
893
+ $DOM.toastBody.style.paddingLeft = '33px';
894
+ }
895
+
896
+ $DOM.toastBody.appendChild($DOM.icon);
897
+ }
898
+
899
+ })();
900
+
901
+ // Title & Message
902
+ (function(){
903
+ if(settings.title.length > 0) {
904
+
905
+ $DOM.strong = document.createElement('strong');
906
+ $DOM.strong.classList.add(PLUGIN_NAME + '-title');
907
+ $DOM.strong.appendChild(createFragElem(settings.title));
908
+ $DOM.toastTexts.appendChild($DOM.strong);
909
+
910
+ if(settings.titleColor) {
911
+ $DOM.strong.style.color = settings.titleColor;
912
+ }
913
+ if(settings.titleSize) {
914
+ if( !isNaN(settings.titleSize) ){
915
+ $DOM.strong.style.fontSize = settings.titleSize+'px';
916
+ } else {
917
+ $DOM.strong.style.fontSize = settings.titleSize;
918
+ }
919
+ }
920
+ if(settings.titleLineHeight) {
921
+ if( !isNaN(settings.titleSize) ){
922
+ $DOM.strong.style.lineHeight = settings.titleLineHeight+'px';
923
+ } else {
924
+ $DOM.strong.style.lineHeight = settings.titleLineHeight;
925
+ }
926
+ }
927
+ }
928
+
929
+ if(settings.message.length > 0) {
930
+
931
+ $DOM.p = document.createElement('p');
932
+ $DOM.p.classList.add(PLUGIN_NAME + '-message');
933
+ $DOM.p.appendChild(createFragElem(settings.message));
934
+ $DOM.toastTexts.appendChild($DOM.p);
935
+
936
+ if(settings.messageColor) {
937
+ $DOM.p.style.color = settings.messageColor;
938
+ }
939
+ if(settings.messageSize) {
940
+ if( !isNaN(settings.titleSize) ){
941
+ $DOM.p.style.fontSize = settings.messageSize+'px';
942
+ } else {
943
+ $DOM.p.style.fontSize = settings.messageSize;
944
+ }
945
+ }
946
+ if(settings.messageLineHeight) {
947
+
948
+ if( !isNaN(settings.titleSize) ){
949
+ $DOM.p.style.lineHeight = settings.messageLineHeight+'px';
950
+ } else {
951
+ $DOM.p.style.lineHeight = settings.messageLineHeight;
952
+ }
953
+ }
954
+ }
955
+
956
+ if(settings.title.length > 0 && settings.message.length > 0) {
957
+ if(settings.rtl){
958
+ $DOM.strong.style.marginLeft = '10px';
959
+ } else if(settings.layout !== 2 && !settings.rtl) {
960
+ $DOM.strong.style.marginRight = '10px';
961
+ }
962
+ }
963
+ })();
964
+
965
+ $DOM.toastBody.appendChild($DOM.toastTexts);
966
+
967
+ // Inputs
968
+ var $inputs;
969
+ (function(){
970
+ if(settings.inputs.length > 0) {
971
+
972
+ $DOM.inputs.classList.add(PLUGIN_NAME + '-inputs');
973
+
974
+ forEach(settings.inputs, function (value, index) {
975
+ $DOM.inputs.appendChild(createFragElem(value[0]));
976
+
977
+ $inputs = $DOM.inputs.childNodes;
978
+
979
+ $inputs[index].classList.add(PLUGIN_NAME + '-inputs-child');
980
+
981
+ if(value[3]){
982
+ setTimeout(function() {
983
+ $inputs[index].focus();
984
+ }, 300);
985
+ }
986
+
987
+ $inputs[index].addEventListener(value[1], function (e) {
988
+ var ts = value[2];
989
+ return ts(that, $DOM.toast, this, e);
990
+ });
991
+ });
992
+ $DOM.toastBody.appendChild($DOM.inputs);
993
+ }
994
+ })();
995
+
996
+ // Buttons
997
+ (function(){
998
+ if(settings.buttons.length > 0) {
999
+
1000
+ $DOM.buttons.classList.add(PLUGIN_NAME + '-buttons');
1001
+
1002
+ forEach(settings.buttons, function (value, index) {
1003
+ $DOM.buttons.appendChild(createFragElem(value[0]));
1004
+
1005
+ var $btns = $DOM.buttons.childNodes;
1006
+
1007
+ $btns[index].classList.add(PLUGIN_NAME + '-buttons-child');
1008
+
1009
+ if(value[2]){
1010
+ setTimeout(function() {
1011
+ $btns[index].focus();
1012
+ }, 300);
1013
+ }
1014
+
1015
+ $btns[index].addEventListener('click', function (e) {
1016
+ e.preventDefault();
1017
+ var ts = value[1];
1018
+ return ts(that, $DOM.toast, this, e, $inputs);
1019
+ });
1020
+ });
1021
+ }
1022
+ $DOM.toastBody.appendChild($DOM.buttons);
1023
+ })();
1024
+
1025
+ if(settings.message.length > 0 && (settings.inputs.length > 0 || settings.buttons.length > 0)) {
1026
+ $DOM.p.style.marginBottom = '0';
1027
+ }
1028
+
1029
+ if(settings.inputs.length > 0 || settings.buttons.length > 0){
1030
+ if(settings.rtl){
1031
+ $DOM.toastTexts.style.marginLeft = '10px';
1032
+ } else {
1033
+ $DOM.toastTexts.style.marginRight = '10px';
1034
+ }
1035
+ if(settings.inputs.length > 0 && settings.buttons.length > 0){
1036
+ if(settings.rtl){
1037
+ $DOM.inputs.style.marginLeft = '8px';
1038
+ } else {
1039
+ $DOM.inputs.style.marginRight = '8px';
1040
+ }
1041
+ }
1042
+ }
1043
+
1044
+ // Wrap
1045
+ (function(){
1046
+ $DOM.toastCapsule.style.visibility = 'hidden';
1047
+ setTimeout(function() {
1048
+ var H = $DOM.toast.offsetHeight;
1049
+ var style = $DOM.toast.currentStyle || window.getComputedStyle($DOM.toast);
1050
+ var marginTop = style.marginTop;
1051
+ marginTop = marginTop.split('px');
1052
+ marginTop = parseInt(marginTop[0]);
1053
+ var marginBottom = style.marginBottom;
1054
+ marginBottom = marginBottom.split('px');
1055
+ marginBottom = parseInt(marginBottom[0]);
1056
+
1057
+ $DOM.toastCapsule.style.visibility = '';
1058
+ $DOM.toastCapsule.style.height = (H+marginBottom+marginTop)+'px';
1059
+
1060
+ setTimeout(function() {
1061
+ $DOM.toastCapsule.style.height = 'auto';
1062
+ if(settings.target){
1063
+ $DOM.toastCapsule.style.overflow = 'visible';
1064
+ }
1065
+ }, 500);
1066
+
1067
+ if(settings.timeout) {
1068
+ that.progress(settings, $DOM.toast).start();
1069
+ }
1070
+ }, 100);
1071
+ })();
1072
+
1073
+ // Target
1074
+ (function(){
1075
+ var position = settings.position;
1076
+
1077
+ if(settings.target){
1078
+
1079
+ $DOM.wrapper = document.querySelector(settings.target);
1080
+ $DOM.wrapper.classList.add(PLUGIN_NAME + '-target');
1081
+
1082
+ if(settings.targetFirst) {
1083
+ $DOM.wrapper.insertBefore($DOM.toastCapsule, $DOM.wrapper.firstChild);
1084
+ } else {
1085
+ $DOM.wrapper.appendChild($DOM.toastCapsule);
1086
+ }
1087
+
1088
+ } else {
1089
+
1090
+ if( POSITIONS.indexOf(settings.position) == -1 ){
1091
+ console.warn('['+PLUGIN_NAME+'] Incorrect position.\nIt can be › ' + POSITIONS);
1092
+ return;
1093
+ }
1094
+
1095
+ if(ISMOBILE || window.innerWidth <= MOBILEWIDTH){
1096
+ if(settings.position == 'bottomLeft' || settings.position == 'bottomRight' || settings.position == 'bottomCenter'){
1097
+ position = PLUGIN_NAME+'-wrapper-bottomCenter';
1098
+ }
1099
+ else if(settings.position == 'topLeft' || settings.position == 'topRight' || settings.position == 'topCenter'){
1100
+ position = PLUGIN_NAME+'-wrapper-topCenter';
1101
+ }
1102
+ else {
1103
+ position = PLUGIN_NAME+'-wrapper-center';
1104
+ }
1105
+ } else {
1106
+ position = PLUGIN_NAME+'-wrapper-'+position;
1107
+ }
1108
+ $DOM.wrapper = document.querySelector('.' + PLUGIN_NAME + '-wrapper.'+position);
1109
+
1110
+ if(!$DOM.wrapper) {
1111
+ $DOM.wrapper = document.createElement('div');
1112
+ $DOM.wrapper.classList.add(PLUGIN_NAME + '-wrapper');
1113
+ $DOM.wrapper.classList.add(position);
1114
+ document.body.appendChild($DOM.wrapper);
1115
+ }
1116
+ if(settings.position == 'topLeft' || settings.position == 'topCenter' || settings.position == 'topRight'){
1117
+ $DOM.wrapper.insertBefore($DOM.toastCapsule, $DOM.wrapper.firstChild);
1118
+ } else {
1119
+ $DOM.wrapper.appendChild($DOM.toastCapsule);
1120
+ }
1121
+ }
1122
+
1123
+ if(!isNaN(settings.zindex)) {
1124
+ $DOM.wrapper.style.zIndex = settings.zindex;
1125
+ } else {
1126
+ console.warn('['+PLUGIN_NAME+'] Invalid zIndex.');
1127
+ }
1128
+ })();
1129
+
1130
+ // Overlay
1131
+ (function(){
1132
+
1133
+ if(settings.overlay) {
1134
+
1135
+ if( document.querySelector('.'+PLUGIN_NAME+'-overlay.fadeIn') !== null ){
1136
+
1137
+ $DOM.overlay = document.querySelector('.'+PLUGIN_NAME+'-overlay');
1138
+ $DOM.overlay.setAttribute('data-iziToast-ref', $DOM.overlay.getAttribute('data-iziToast-ref') + ',' + settings.ref);
1139
+
1140
+ if(!isNaN(settings.zindex) && settings.zindex !== null) {
1141
+ $DOM.overlay.style.zIndex = settings.zindex-1;
1142
+ }
1143
+
1144
+ } else {
1145
+
1146
+ $DOM.overlay.classList.add(PLUGIN_NAME+'-overlay');
1147
+ $DOM.overlay.classList.add('fadeIn');
1148
+ $DOM.overlay.style.background = settings.overlayColor;
1149
+ $DOM.overlay.setAttribute('data-iziToast-ref', settings.ref);
1150
+ if(!isNaN(settings.zindex) && settings.zindex !== null) {
1151
+ $DOM.overlay.style.zIndex = settings.zindex-1;
1152
+ }
1153
+ document.querySelector('body').appendChild($DOM.overlay);
1154
+ }
1155
+
1156
+ if(settings.overlayClose) {
1157
+
1158
+ $DOM.overlay.removeEventListener('click', {});
1159
+ $DOM.overlay.addEventListener('click', function (e) {
1160
+ that.hide(settings, $DOM.toast, 'overlay');
1161
+ });
1162
+ } else {
1163
+ $DOM.overlay.removeEventListener('click', {});
1164
+ }
1165
+ }
1166
+ })();
1167
+
1168
+ // Inside animations
1169
+ (function(){
1170
+ if(settings.animateInside){
1171
+ $DOM.toast.classList.add(PLUGIN_NAME+'-animateInside');
1172
+
1173
+ var animationTimes = [200, 100, 300];
1174
+ if(settings.transitionIn == 'bounceInLeft' || settings.transitionIn == 'bounceInRight'){
1175
+ animationTimes = [400, 200, 400];
1176
+ }
1177
+
1178
+ if(settings.title.length > 0) {
1179
+ setTimeout(function(){
1180
+ $DOM.strong.classList.add('slideIn');
1181
+ }, animationTimes[0]);
1182
+ }
1183
+
1184
+ if(settings.message.length > 0) {
1185
+ setTimeout(function(){
1186
+ $DOM.p.classList.add('slideIn');
1187
+ }, animationTimes[1]);
1188
+ }
1189
+
1190
+ if(settings.icon || settings.iconUrl) {
1191
+ setTimeout(function(){
1192
+ $DOM.icon.classList.add('revealIn');
1193
+ }, animationTimes[2]);
1194
+ }
1195
+
1196
+ var counter = 150;
1197
+ if(settings.buttons.length > 0 && $DOM.buttons) {
1198
+
1199
+ setTimeout(function(){
1200
+
1201
+ forEach($DOM.buttons.childNodes, function(element, index) {
1202
+
1203
+ setTimeout(function(){
1204
+ element.classList.add('revealIn');
1205
+ }, counter);
1206
+ counter = counter + 150;
1207
+ });
1208
+
1209
+ }, settings.inputs.length > 0 ? 150 : 0);
1210
+ }
1211
+
1212
+ if(settings.inputs.length > 0 && $DOM.inputs) {
1213
+ counter = 150;
1214
+ forEach($DOM.inputs.childNodes, function(element, index) {
1215
+
1216
+ setTimeout(function(){
1217
+ element.classList.add('revealIn');
1218
+ }, counter);
1219
+ counter = counter + 150;
1220
+ });
1221
+ }
1222
+ }
1223
+ })();
1224
+
1225
+ settings.onOpening.apply(null, [settings, $DOM.toast]);
1226
+
1227
+ try {
1228
+ var event = new CustomEvent(PLUGIN_NAME + '-opening', {detail: settings, bubbles: true, cancelable: true});
1229
+ document.dispatchEvent(event);
1230
+ } catch(ex){
1231
+ console.warn(ex);
1232
+ }
1233
+
1234
+ setTimeout(function() {
1235
+
1236
+ $DOM.toast.classList.remove(PLUGIN_NAME+'-opening');
1237
+ $DOM.toast.classList.add(PLUGIN_NAME+'-opened');
1238
+
1239
+ try {
1240
+ var event = new CustomEvent(PLUGIN_NAME + '-opened', {detail: settings, bubbles: true, cancelable: true});
1241
+ document.dispatchEvent(event);
1242
+ } catch(ex){
1243
+ console.warn(ex);
1244
+ }
1245
+
1246
+ settings.onOpened.apply(null, [settings, $DOM.toast]);
1247
+ }, 1000);
1248
+
1249
+ if(settings.drag){
1250
+
1251
+ if(ACCEPTSTOUCH) {
1252
+
1253
+ $DOM.toast.addEventListener('touchstart', function(e) {
1254
+ drag.startMoving(this, that, settings, e);
1255
+ }, false);
1256
+
1257
+ $DOM.toast.addEventListener('touchend', function(e) {
1258
+ drag.stopMoving(this, e);
1259
+ }, false);
1260
+ } else {
1261
+
1262
+ $DOM.toast.addEventListener('mousedown', function(e) {
1263
+ e.preventDefault();
1264
+ drag.startMoving(this, that, settings, e);
1265
+ }, false);
1266
+
1267
+ $DOM.toast.addEventListener('mouseup', function(e) {
1268
+ e.preventDefault();
1269
+ drag.stopMoving(this, e);
1270
+ }, false);
1271
+ }
1272
+ }
1273
+
1274
+ if(settings.closeOnEscape) {
1275
+
1276
+ document.addEventListener('keyup', function (evt) {
1277
+ evt = evt || window.event;
1278
+ if(evt.keyCode == 27) {
1279
+ that.hide(settings, $DOM.toast, 'esc');
1280
+ }
1281
+ });
1282
+ }
1283
+
1284
+ if(settings.closeOnClick) {
1285
+ $DOM.toast.addEventListener('click', function (evt) {
1286
+ that.hide(settings, $DOM.toast, 'toast');
1287
+ });
1288
+ }
1289
+
1290
+ that.toast = $DOM.toast;
1291
+ };
1292
+
1293
+
1294
+ return $iziToast;
1295
+ });
1296
+ return this;
1297
+ };
1298
+
1299
+ const global = new Global().dispatch();
1300
+
1301
+ export default global.iziToast;