@materializecss/materialize 1.1.0 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Gruntfile.js +38 -24
- package/LICENSE +21 -21
- package/README.md +91 -97
- package/dist/css/materialize.css +8608 -8631
- package/dist/css/materialize.min.css +12 -12
- package/dist/js/materialize.js +12816 -12669
- package/dist/js/materialize.min.js +6 -6
- package/extras/noUiSlider/nouislider.css +404 -406
- package/extras/noUiSlider/nouislider.js +2147 -2147
- package/extras/noUiSlider/nouislider.min.js +0 -0
- package/js/anime.min.js +34 -34
- package/js/autocomplete.js +479 -479
- package/js/buttons.js +354 -354
- package/js/cards.js +40 -40
- package/js/carousel.js +732 -732
- package/js/cash.js +960 -960
- package/js/characterCounter.js +136 -136
- package/js/chips.js +486 -486
- package/js/collapsible.js +275 -275
- package/js/component.js +44 -44
- package/js/datepicker.js +983 -983
- package/js/dropdown.js +669 -669
- package/js/forms.js +285 -275
- package/js/global.js +428 -424
- package/js/materialbox.js +453 -453
- package/js/modal.js +382 -382
- package/js/parallax.js +138 -138
- package/js/pushpin.js +148 -148
- package/js/range.js +263 -263
- package/js/scrollspy.js +295 -295
- package/js/select.js +391 -310
- package/js/sidenav.js +583 -583
- package/js/slider.js +359 -359
- package/js/tabs.js +402 -402
- package/js/tapTarget.js +315 -315
- package/js/timepicker.js +712 -648
- package/js/toasts.js +325 -322
- package/js/tooltip.js +320 -320
- package/js/waves.js +614 -614
- package/package.json +87 -82
- package/sass/_style.scss +929 -929
- package/sass/components/_badges.scss +55 -55
- package/sass/components/_buttons.scss +322 -322
- package/sass/components/_cards.scss +195 -195
- package/sass/components/_carousel.scss +90 -90
- package/sass/components/_chips.scss +96 -96
- package/sass/components/_collapsible.scss +91 -91
- package/sass/components/_collection.scss +106 -106
- package/sass/components/_color-classes.scss +32 -32
- package/sass/components/_color-variables.scss +370 -370
- package/sass/components/_datepicker.scss +191 -191
- package/sass/components/_dropdown.scss +84 -84
- package/sass/components/_global.scss +646 -642
- package/sass/components/_grid.scss +158 -158
- package/sass/components/_icons-material-design.scss +5 -5
- package/sass/components/_materialbox.scss +42 -42
- package/sass/components/_modal.scss +97 -97
- package/sass/components/_navbar.scss +208 -208
- package/sass/components/_normalize.scss +447 -447
- package/sass/components/_preloader.scss +334 -334
- package/sass/components/_pulse.scss +34 -34
- package/sass/components/_sidenav.scss +214 -214
- package/sass/components/_slider.scss +91 -91
- package/sass/components/_table_of_contents.scss +33 -33
- package/sass/components/_tabs.scss +99 -99
- package/sass/components/_tapTarget.scss +103 -103
- package/sass/components/_timepicker.scss +199 -183
- package/sass/components/_toast.scss +58 -58
- package/sass/components/_tooltip.scss +32 -32
- package/sass/components/_transitions.scss +12 -12
- package/sass/components/_typography.scss +62 -62
- package/sass/components/_variables.scss +352 -352
- package/sass/components/_waves.scss +187 -187
- package/sass/components/forms/_checkboxes.scss +200 -200
- package/sass/components/forms/_file-input.scss +44 -44
- package/sass/components/forms/_forms.scss +22 -22
- package/sass/components/forms/_input-fields.scss +388 -379
- package/sass/components/forms/_radio-buttons.scss +115 -115
- package/sass/components/forms/_range.scss +161 -161
- package/sass/components/forms/_select.scss +199 -199
- package/sass/components/forms/_switches.scss +91 -91
- package/sass/ghpages-materialize.scss +7 -7
- package/sass/materialize.scss +42 -42
package/js/toasts.js
CHANGED
|
@@ -1,322 +1,325 @@
|
|
|
1
|
-
(function($, anim) {
|
|
2
|
-
'use strict';
|
|
3
|
-
|
|
4
|
-
let _defaults = {
|
|
5
|
-
html: '',
|
|
6
|
-
unsafeHTML: '',
|
|
7
|
-
text: '',
|
|
8
|
-
displayLength: 4000,
|
|
9
|
-
inDuration: 300,
|
|
10
|
-
outDuration: 375,
|
|
11
|
-
classes: '',
|
|
12
|
-
completeCallback: null,
|
|
13
|
-
activationPercent: 0.8
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
class Toast {
|
|
17
|
-
constructor(options) {
|
|
18
|
-
/**
|
|
19
|
-
* Options for the toast
|
|
20
|
-
* @member Toast#options
|
|
21
|
-
*/
|
|
22
|
-
this.options = $.extend({}, Toast.defaults, options);
|
|
23
|
-
this.htmlMessage = this.options.html;
|
|
24
|
-
// Warn when using html
|
|
25
|
-
if (!!this.options.html)
|
|
26
|
-
console.warn(
|
|
27
|
-
'The html option is deprecated and will be removed in the future. See https://github.com/materializecss/materialize/pull/49'
|
|
28
|
-
);
|
|
29
|
-
// If the new unsafeHTML is used, prefer that
|
|
30
|
-
if (!!this.options.unsafeHTML) {
|
|
31
|
-
this.htmlMessage = this.options.unsafeHTML;
|
|
32
|
-
}
|
|
33
|
-
this.message = this.options.text;
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Describes current pan state toast
|
|
37
|
-
* @type {Boolean}
|
|
38
|
-
*/
|
|
39
|
-
this.panning = false;
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Time remaining until toast is removed
|
|
43
|
-
*/
|
|
44
|
-
this.timeRemaining = this.options.displayLength;
|
|
45
|
-
|
|
46
|
-
if (Toast._toasts.length === 0) {
|
|
47
|
-
Toast._createContainer();
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// Create new toast
|
|
51
|
-
Toast._toasts.push(this);
|
|
52
|
-
let toastElement = this._createToast();
|
|
53
|
-
toastElement.M_Toast = this;
|
|
54
|
-
this.el = toastElement;
|
|
55
|
-
this.$el = $(toastElement);
|
|
56
|
-
this._animateIn();
|
|
57
|
-
this._setTimer();
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
static get defaults() {
|
|
61
|
-
return _defaults;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Get Instance
|
|
66
|
-
*/
|
|
67
|
-
static getInstance(el) {
|
|
68
|
-
let domElem = !!el.jquery ? el[0] : el;
|
|
69
|
-
return domElem.M_Toast;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Append toast container and add event handlers
|
|
74
|
-
*/
|
|
75
|
-
static _createContainer() {
|
|
76
|
-
let container = document.createElement('div');
|
|
77
|
-
container.setAttribute('id', 'toast-container');
|
|
78
|
-
|
|
79
|
-
// Add event handler
|
|
80
|
-
container.addEventListener('touchstart', Toast._onDragStart);
|
|
81
|
-
container.addEventListener('touchmove', Toast._onDragMove);
|
|
82
|
-
container.addEventListener('touchend', Toast._onDragEnd);
|
|
83
|
-
|
|
84
|
-
container.addEventListener('mousedown', Toast._onDragStart);
|
|
85
|
-
document.addEventListener('mousemove', Toast._onDragMove);
|
|
86
|
-
document.addEventListener('mouseup', Toast._onDragEnd);
|
|
87
|
-
|
|
88
|
-
document.body.appendChild(container);
|
|
89
|
-
Toast._container = container;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Remove toast container and event handlers
|
|
94
|
-
*/
|
|
95
|
-
static _removeContainer() {
|
|
96
|
-
// Add event handler
|
|
97
|
-
document.removeEventListener('mousemove', Toast._onDragMove);
|
|
98
|
-
document.removeEventListener('mouseup', Toast._onDragEnd);
|
|
99
|
-
|
|
100
|
-
$(Toast._container).remove();
|
|
101
|
-
Toast._container = null;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Begin drag handler
|
|
106
|
-
* @param {Event} e
|
|
107
|
-
*/
|
|
108
|
-
static _onDragStart(e) {
|
|
109
|
-
if (e.target && $(e.target).closest('.toast').length) {
|
|
110
|
-
let $toast = $(e.target).closest('.toast');
|
|
111
|
-
let toast = $toast[0].M_Toast;
|
|
112
|
-
toast.panning = true;
|
|
113
|
-
Toast._draggedToast = toast;
|
|
114
|
-
toast.el.classList.add('panning');
|
|
115
|
-
toast.el.style.transition = '';
|
|
116
|
-
toast.startingXPos = Toast._xPos(e);
|
|
117
|
-
toast.time = Date.now();
|
|
118
|
-
toast.xPos = Toast._xPos(e);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* Drag move handler
|
|
124
|
-
* @param {Event} e
|
|
125
|
-
*/
|
|
126
|
-
static _onDragMove(e) {
|
|
127
|
-
if (!!Toast._draggedToast) {
|
|
128
|
-
e.preventDefault();
|
|
129
|
-
let toast = Toast._draggedToast;
|
|
130
|
-
toast.deltaX = Math.abs(toast.xPos - Toast._xPos(e));
|
|
131
|
-
toast.xPos = Toast._xPos(e);
|
|
132
|
-
toast.velocityX = toast.deltaX / (Date.now() - toast.time);
|
|
133
|
-
toast.time = Date.now();
|
|
134
|
-
|
|
135
|
-
let totalDeltaX = toast.xPos - toast.startingXPos;
|
|
136
|
-
let activationDistance = toast.el.offsetWidth * toast.options.activationPercent;
|
|
137
|
-
toast.el.style.transform = `translateX(${totalDeltaX}px)`;
|
|
138
|
-
toast.el.style.opacity = 1 - Math.abs(totalDeltaX / activationDistance);
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
/**
|
|
143
|
-
* End drag handler
|
|
144
|
-
*/
|
|
145
|
-
static _onDragEnd() {
|
|
146
|
-
if (!!Toast._draggedToast) {
|
|
147
|
-
let toast = Toast._draggedToast;
|
|
148
|
-
toast.panning = false;
|
|
149
|
-
toast.el.classList.remove('panning');
|
|
150
|
-
|
|
151
|
-
let totalDeltaX = toast.xPos - toast.startingXPos;
|
|
152
|
-
let activationDistance = toast.el.offsetWidth * toast.options.activationPercent;
|
|
153
|
-
let shouldBeDismissed = Math.abs(totalDeltaX) > activationDistance || toast.velocityX > 1;
|
|
154
|
-
|
|
155
|
-
// Remove toast
|
|
156
|
-
if (shouldBeDismissed) {
|
|
157
|
-
toast.wasSwiped = true;
|
|
158
|
-
toast.dismiss();
|
|
159
|
-
|
|
160
|
-
// Animate toast back to original position
|
|
161
|
-
} else {
|
|
162
|
-
toast.el.style.transition = 'transform .2s, opacity .2s';
|
|
163
|
-
toast.el.style.transform = '';
|
|
164
|
-
toast.el.style.opacity = '';
|
|
165
|
-
}
|
|
166
|
-
Toast._draggedToast = null;
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
/**
|
|
171
|
-
* Get x position of mouse or touch event
|
|
172
|
-
* @param {Event} e
|
|
173
|
-
*/
|
|
174
|
-
static _xPos(e) {
|
|
175
|
-
if (e.targetTouches && e.targetTouches.length >= 1) {
|
|
176
|
-
return e.targetTouches[0].clientX;
|
|
177
|
-
}
|
|
178
|
-
// mouse event
|
|
179
|
-
return e.clientX;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
/**
|
|
183
|
-
* Remove all toasts
|
|
184
|
-
*/
|
|
185
|
-
static dismissAll() {
|
|
186
|
-
for (let toastIndex in Toast._toasts) {
|
|
187
|
-
Toast._toasts[toastIndex].dismiss();
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
/**
|
|
192
|
-
* Create toast and append it to toast container
|
|
193
|
-
*/
|
|
194
|
-
_createToast() {
|
|
195
|
-
let toast = document.createElement('div');
|
|
196
|
-
toast.classList.add('toast');
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
typeof this.htmlMessage
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
//
|
|
218
|
-
|
|
219
|
-
} else {
|
|
220
|
-
//
|
|
221
|
-
$(toast).append(this.htmlMessage);
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
1
|
+
(function($, anim) {
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
let _defaults = {
|
|
5
|
+
html: '',
|
|
6
|
+
unsafeHTML: '',
|
|
7
|
+
text: '',
|
|
8
|
+
displayLength: 4000,
|
|
9
|
+
inDuration: 300,
|
|
10
|
+
outDuration: 375,
|
|
11
|
+
classes: '',
|
|
12
|
+
completeCallback: null,
|
|
13
|
+
activationPercent: 0.8
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
class Toast {
|
|
17
|
+
constructor(options) {
|
|
18
|
+
/**
|
|
19
|
+
* Options for the toast
|
|
20
|
+
* @member Toast#options
|
|
21
|
+
*/
|
|
22
|
+
this.options = $.extend({}, Toast.defaults, options);
|
|
23
|
+
this.htmlMessage = this.options.html;
|
|
24
|
+
// Warn when using html
|
|
25
|
+
if (!!this.options.html)
|
|
26
|
+
console.warn(
|
|
27
|
+
'The html option is deprecated and will be removed in the future. See https://github.com/materializecss/materialize/pull/49'
|
|
28
|
+
);
|
|
29
|
+
// If the new unsafeHTML is used, prefer that
|
|
30
|
+
if (!!this.options.unsafeHTML) {
|
|
31
|
+
this.htmlMessage = this.options.unsafeHTML;
|
|
32
|
+
}
|
|
33
|
+
this.message = this.options.text;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Describes current pan state toast
|
|
37
|
+
* @type {Boolean}
|
|
38
|
+
*/
|
|
39
|
+
this.panning = false;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Time remaining until toast is removed
|
|
43
|
+
*/
|
|
44
|
+
this.timeRemaining = this.options.displayLength;
|
|
45
|
+
|
|
46
|
+
if (Toast._toasts.length === 0) {
|
|
47
|
+
Toast._createContainer();
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Create new toast
|
|
51
|
+
Toast._toasts.push(this);
|
|
52
|
+
let toastElement = this._createToast();
|
|
53
|
+
toastElement.M_Toast = this;
|
|
54
|
+
this.el = toastElement;
|
|
55
|
+
this.$el = $(toastElement);
|
|
56
|
+
this._animateIn();
|
|
57
|
+
this._setTimer();
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
static get defaults() {
|
|
61
|
+
return _defaults;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Get Instance
|
|
66
|
+
*/
|
|
67
|
+
static getInstance(el) {
|
|
68
|
+
let domElem = !!el.jquery ? el[0] : el;
|
|
69
|
+
return domElem.M_Toast;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Append toast container and add event handlers
|
|
74
|
+
*/
|
|
75
|
+
static _createContainer() {
|
|
76
|
+
let container = document.createElement('div');
|
|
77
|
+
container.setAttribute('id', 'toast-container');
|
|
78
|
+
|
|
79
|
+
// Add event handler
|
|
80
|
+
container.addEventListener('touchstart', Toast._onDragStart);
|
|
81
|
+
container.addEventListener('touchmove', Toast._onDragMove);
|
|
82
|
+
container.addEventListener('touchend', Toast._onDragEnd);
|
|
83
|
+
|
|
84
|
+
container.addEventListener('mousedown', Toast._onDragStart);
|
|
85
|
+
document.addEventListener('mousemove', Toast._onDragMove);
|
|
86
|
+
document.addEventListener('mouseup', Toast._onDragEnd);
|
|
87
|
+
|
|
88
|
+
document.body.appendChild(container);
|
|
89
|
+
Toast._container = container;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Remove toast container and event handlers
|
|
94
|
+
*/
|
|
95
|
+
static _removeContainer() {
|
|
96
|
+
// Add event handler
|
|
97
|
+
document.removeEventListener('mousemove', Toast._onDragMove);
|
|
98
|
+
document.removeEventListener('mouseup', Toast._onDragEnd);
|
|
99
|
+
|
|
100
|
+
$(Toast._container).remove();
|
|
101
|
+
Toast._container = null;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Begin drag handler
|
|
106
|
+
* @param {Event} e
|
|
107
|
+
*/
|
|
108
|
+
static _onDragStart(e) {
|
|
109
|
+
if (e.target && $(e.target).closest('.toast').length) {
|
|
110
|
+
let $toast = $(e.target).closest('.toast');
|
|
111
|
+
let toast = $toast[0].M_Toast;
|
|
112
|
+
toast.panning = true;
|
|
113
|
+
Toast._draggedToast = toast;
|
|
114
|
+
toast.el.classList.add('panning');
|
|
115
|
+
toast.el.style.transition = '';
|
|
116
|
+
toast.startingXPos = Toast._xPos(e);
|
|
117
|
+
toast.time = Date.now();
|
|
118
|
+
toast.xPos = Toast._xPos(e);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Drag move handler
|
|
124
|
+
* @param {Event} e
|
|
125
|
+
*/
|
|
126
|
+
static _onDragMove(e) {
|
|
127
|
+
if (!!Toast._draggedToast) {
|
|
128
|
+
e.preventDefault();
|
|
129
|
+
let toast = Toast._draggedToast;
|
|
130
|
+
toast.deltaX = Math.abs(toast.xPos - Toast._xPos(e));
|
|
131
|
+
toast.xPos = Toast._xPos(e);
|
|
132
|
+
toast.velocityX = toast.deltaX / (Date.now() - toast.time);
|
|
133
|
+
toast.time = Date.now();
|
|
134
|
+
|
|
135
|
+
let totalDeltaX = toast.xPos - toast.startingXPos;
|
|
136
|
+
let activationDistance = toast.el.offsetWidth * toast.options.activationPercent;
|
|
137
|
+
toast.el.style.transform = `translateX(${totalDeltaX}px)`;
|
|
138
|
+
toast.el.style.opacity = 1 - Math.abs(totalDeltaX / activationDistance);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* End drag handler
|
|
144
|
+
*/
|
|
145
|
+
static _onDragEnd() {
|
|
146
|
+
if (!!Toast._draggedToast) {
|
|
147
|
+
let toast = Toast._draggedToast;
|
|
148
|
+
toast.panning = false;
|
|
149
|
+
toast.el.classList.remove('panning');
|
|
150
|
+
|
|
151
|
+
let totalDeltaX = toast.xPos - toast.startingXPos;
|
|
152
|
+
let activationDistance = toast.el.offsetWidth * toast.options.activationPercent;
|
|
153
|
+
let shouldBeDismissed = Math.abs(totalDeltaX) > activationDistance || toast.velocityX > 1;
|
|
154
|
+
|
|
155
|
+
// Remove toast
|
|
156
|
+
if (shouldBeDismissed) {
|
|
157
|
+
toast.wasSwiped = true;
|
|
158
|
+
toast.dismiss();
|
|
159
|
+
|
|
160
|
+
// Animate toast back to original position
|
|
161
|
+
} else {
|
|
162
|
+
toast.el.style.transition = 'transform .2s, opacity .2s';
|
|
163
|
+
toast.el.style.transform = '';
|
|
164
|
+
toast.el.style.opacity = '';
|
|
165
|
+
}
|
|
166
|
+
Toast._draggedToast = null;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Get x position of mouse or touch event
|
|
172
|
+
* @param {Event} e
|
|
173
|
+
*/
|
|
174
|
+
static _xPos(e) {
|
|
175
|
+
if (e.targetTouches && e.targetTouches.length >= 1) {
|
|
176
|
+
return e.targetTouches[0].clientX;
|
|
177
|
+
}
|
|
178
|
+
// mouse event
|
|
179
|
+
return e.clientX;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Remove all toasts
|
|
184
|
+
*/
|
|
185
|
+
static dismissAll() {
|
|
186
|
+
for (let toastIndex in Toast._toasts) {
|
|
187
|
+
Toast._toasts[toastIndex].dismiss();
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Create toast and append it to toast container
|
|
193
|
+
*/
|
|
194
|
+
_createToast() {
|
|
195
|
+
let toast = document.createElement('div');
|
|
196
|
+
toast.classList.add('toast');
|
|
197
|
+
toast.setAttribute('role', 'alert');
|
|
198
|
+
toast.setAttribute('aria-live', 'assertive');
|
|
199
|
+
toast.setAttribute('aria-atomic', true);
|
|
200
|
+
|
|
201
|
+
// Add custom classes onto toast
|
|
202
|
+
if (!!this.options.classes.length) {
|
|
203
|
+
$(toast).addClass(this.options.classes);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// Set safe text content
|
|
207
|
+
toast.textContent = this.message;
|
|
208
|
+
if (
|
|
209
|
+
typeof HTMLElement === 'object'
|
|
210
|
+
? this.htmlMessage instanceof HTMLElement
|
|
211
|
+
: this.htmlMessage &&
|
|
212
|
+
typeof this.htmlMessage === 'object' &&
|
|
213
|
+
this.htmlMessage !== null &&
|
|
214
|
+
this.htmlMessage.nodeType === 1 &&
|
|
215
|
+
typeof this.htmlMessage.nodeName === 'string'
|
|
216
|
+
) {
|
|
217
|
+
//if the htmlMessage is an HTML node, append it directly
|
|
218
|
+
toast.appendChild(this.htmlMessage);
|
|
219
|
+
} else if (!!this.htmlMessage.jquery) {
|
|
220
|
+
// Check if it is jQuery object, append the node
|
|
221
|
+
$(toast).append(this.htmlMessage[0]);
|
|
222
|
+
} else {
|
|
223
|
+
// Append as unsanitized html;
|
|
224
|
+
$(toast).append(this.htmlMessage);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
// Append toast
|
|
228
|
+
Toast._container.appendChild(toast);
|
|
229
|
+
return toast;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* Animate in toast
|
|
234
|
+
*/
|
|
235
|
+
_animateIn() {
|
|
236
|
+
// Animate toast in
|
|
237
|
+
anim({
|
|
238
|
+
targets: this.el,
|
|
239
|
+
top: 0,
|
|
240
|
+
opacity: 1,
|
|
241
|
+
duration: this.options.inDuration,
|
|
242
|
+
easing: 'easeOutCubic'
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Create setInterval which automatically removes toast when timeRemaining >= 0
|
|
248
|
+
* has been reached
|
|
249
|
+
*/
|
|
250
|
+
_setTimer() {
|
|
251
|
+
if (this.timeRemaining !== Infinity) {
|
|
252
|
+
this.counterInterval = setInterval(() => {
|
|
253
|
+
// If toast is not being dragged, decrease its time remaining
|
|
254
|
+
if (!this.panning) {
|
|
255
|
+
this.timeRemaining -= 20;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
// Animate toast out
|
|
259
|
+
if (this.timeRemaining <= 0) {
|
|
260
|
+
this.dismiss();
|
|
261
|
+
}
|
|
262
|
+
}, 20);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Dismiss toast with animation
|
|
268
|
+
*/
|
|
269
|
+
dismiss() {
|
|
270
|
+
window.clearInterval(this.counterInterval);
|
|
271
|
+
let activationDistance = this.el.offsetWidth * this.options.activationPercent;
|
|
272
|
+
|
|
273
|
+
if (this.wasSwiped) {
|
|
274
|
+
this.el.style.transition = 'transform .05s, opacity .05s';
|
|
275
|
+
this.el.style.transform = `translateX(${activationDistance}px)`;
|
|
276
|
+
this.el.style.opacity = 0;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
anim({
|
|
280
|
+
targets: this.el,
|
|
281
|
+
opacity: 0,
|
|
282
|
+
marginTop: -40,
|
|
283
|
+
duration: this.options.outDuration,
|
|
284
|
+
easing: 'easeOutExpo',
|
|
285
|
+
complete: () => {
|
|
286
|
+
// Call the optional callback
|
|
287
|
+
if (typeof this.options.completeCallback === 'function') {
|
|
288
|
+
this.options.completeCallback();
|
|
289
|
+
}
|
|
290
|
+
// Remove toast from DOM
|
|
291
|
+
this.$el.remove();
|
|
292
|
+
Toast._toasts.splice(Toast._toasts.indexOf(this), 1);
|
|
293
|
+
if (Toast._toasts.length === 0) {
|
|
294
|
+
Toast._removeContainer();
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* @static
|
|
303
|
+
* @memberof Toast
|
|
304
|
+
* @type {Array.<Toast>}
|
|
305
|
+
*/
|
|
306
|
+
Toast._toasts = [];
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* @static
|
|
310
|
+
* @memberof Toast
|
|
311
|
+
*/
|
|
312
|
+
Toast._container = null;
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* @static
|
|
316
|
+
* @memberof Toast
|
|
317
|
+
* @type {Toast}
|
|
318
|
+
*/
|
|
319
|
+
Toast._draggedToast = null;
|
|
320
|
+
|
|
321
|
+
M.Toast = Toast;
|
|
322
|
+
M.toast = function(options) {
|
|
323
|
+
return new Toast(options);
|
|
324
|
+
};
|
|
325
|
+
})(cash, M.anime);
|