@materializecss/materialize 2.0.1-alpha → 2.0.3-alpha
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 +5 -2
- package/dist/css/materialize.css +1510 -288
- package/dist/css/materialize.min.css +2 -2
- package/dist/js/materialize.js +2782 -2688
- package/dist/js/materialize.min.js +2 -8967
- package/dist/js/materialize.min.js.map +1 -1
- package/dist/src/autocomplete.d.ts +143 -0
- package/dist/src/autocomplete.d.ts.map +1 -0
- package/dist/src/bounding.d.ts +7 -0
- package/dist/src/bounding.d.ts.map +1 -0
- package/dist/src/buttons.d.ts +65 -0
- package/dist/src/buttons.d.ts.map +1 -0
- package/dist/src/cards.d.ts +4 -0
- package/dist/src/cards.d.ts.map +1 -0
- package/dist/src/carousel.d.ts +131 -0
- package/dist/src/carousel.d.ts.map +1 -0
- package/dist/src/characterCounter.d.ts +37 -0
- package/dist/src/characterCounter.d.ts.map +1 -0
- package/dist/src/chips.d.ts +131 -0
- package/dist/src/chips.d.ts.map +1 -0
- package/dist/src/collapsible.d.ts +74 -0
- package/dist/src/collapsible.d.ts.map +1 -0
- package/dist/src/component.d.ts +74 -0
- package/dist/src/component.d.ts.map +1 -0
- package/dist/src/datepicker.d.ts +248 -0
- package/dist/src/datepicker.d.ts.map +1 -0
- package/dist/src/dropdown.d.ts +148 -0
- package/dist/src/dropdown.d.ts.map +1 -0
- package/dist/src/edges.d.ts +7 -0
- package/dist/src/edges.d.ts.map +1 -0
- package/dist/src/forms.d.ts +12 -0
- package/dist/src/forms.d.ts.map +1 -0
- package/dist/src/global.d.ts +60 -0
- package/dist/src/global.d.ts.map +1 -0
- package/dist/src/index.d.ts +27 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/materialbox.d.ts +92 -0
- package/dist/src/materialbox.d.ts.map +1 -0
- package/dist/src/modal.d.ts +119 -0
- package/dist/src/modal.d.ts.map +1 -0
- package/dist/src/parallax.d.ts +40 -0
- package/dist/src/parallax.d.ts.map +1 -0
- package/dist/src/pushpin.d.ts +52 -0
- package/dist/src/pushpin.d.ts.map +1 -0
- package/dist/src/range.d.ts +41 -0
- package/dist/src/range.d.ts.map +1 -0
- package/dist/src/scrollspy.d.ts +62 -0
- package/dist/src/scrollspy.d.ts.map +1 -0
- package/dist/src/select.d.ts +77 -0
- package/dist/src/select.d.ts.map +1 -0
- package/dist/src/sidenav.d.ts +122 -0
- package/dist/src/sidenav.d.ts.map +1 -0
- package/dist/src/slider.d.ts +103 -0
- package/dist/src/slider.d.ts.map +1 -0
- package/dist/src/tabs.d.ts +80 -0
- package/dist/src/tabs.d.ts.map +1 -0
- package/dist/src/tapTarget.d.ts +59 -0
- package/dist/src/tapTarget.d.ts.map +1 -0
- package/dist/src/timepicker.d.ts +208 -0
- package/dist/src/timepicker.d.ts.map +1 -0
- package/dist/src/toasts.d.ts +90 -0
- package/dist/src/toasts.d.ts.map +1 -0
- package/dist/src/tooltip.d.ts +112 -0
- package/dist/src/tooltip.d.ts.map +1 -0
- package/dist/src/utils.d.ts +97 -0
- package/dist/src/utils.d.ts.map +1 -0
- package/dist/src/waves.d.ts +16 -0
- package/dist/src/waves.d.ts.map +1 -0
- package/package.json +4 -1
- package/sass/components/_cards.scss +1 -1
- package/sass/components/_collapsible.scss +0 -41
- package/sass/components/_global.scss +53 -2
- package/sass/components/_grid.scss +28 -47
- package/sass/components/_icons-material-design.scss +2 -1
- package/sass/components/_navbar.scss +30 -27
- package/sass/components/_pulse.scss +1 -0
- package/sass/components/_sidenav.scss +63 -45
- package/sass/components/_theme_variables.scss +29 -49
- package/sass/components/_typography.scss +2 -2
- package/sass/components/_variables.scss +2 -0
- package/sass/components/colors.module.scss +180 -0
- package/sass/components/forms/_input-fields.scss +4 -10
- package/sass/components/theme.dark.module.scss +32 -0
- package/sass/components/theme.light.module.scss +32 -0
- package/sass/components/tokens.module.scss +272 -0
- package/sass/components/typography.module.scss +150 -0
- package/sass/materialize.scss +6 -4
- package/src/autocomplete.ts +188 -94
- package/src/buttons.ts +225 -260
- package/src/cards.ts +5 -6
- package/src/carousel.ts +611 -542
- package/src/characterCounter.ts +50 -21
- package/src/chips.ts +152 -63
- package/src/collapsible.ts +97 -32
- package/src/component.ts +99 -10
- package/src/datepicker.ts +905 -726
- package/src/dropdown.ts +573 -484
- package/src/edges.ts +4 -4
- package/src/forms.ts +36 -24
- package/src/global.ts +57 -328
- package/src/index.ts +26 -0
- package/src/materialbox.ts +354 -298
- package/src/modal.ts +296 -211
- package/src/parallax.ts +129 -105
- package/src/pushpin.ts +148 -103
- package/src/range.ts +166 -150
- package/src/scrollspy.ts +214 -174
- package/src/select.ts +434 -398
- package/src/sidenav.ts +447 -381
- package/src/slider.ts +421 -362
- package/src/tabs.ts +276 -222
- package/src/tapTarget.ts +246 -213
- package/src/timepicker.ts +738 -614
- package/src/toasts.ts +254 -230
- package/src/tooltip.ts +315 -252
- package/src/utils.ts +271 -0
- package/src/waves.ts +10 -10
package/src/modal.ts
CHANGED
|
@@ -1,6 +1,65 @@
|
|
|
1
|
-
import { Component } from "./component";
|
|
2
1
|
import anim from "animejs";
|
|
3
|
-
|
|
2
|
+
|
|
3
|
+
import { Utils } from "./utils";
|
|
4
|
+
import { Component, BaseOptions, InitElements, MElement } from "./component";
|
|
5
|
+
|
|
6
|
+
export interface ModalOptions extends BaseOptions {
|
|
7
|
+
/**
|
|
8
|
+
* Opacity of the modal overlay.
|
|
9
|
+
* @default 0.5
|
|
10
|
+
*/
|
|
11
|
+
opacity: number;
|
|
12
|
+
/**
|
|
13
|
+
* Transition in duration in milliseconds.
|
|
14
|
+
* @default 250
|
|
15
|
+
*/
|
|
16
|
+
inDuration: number;
|
|
17
|
+
/**
|
|
18
|
+
* Transition out duration in milliseconds.
|
|
19
|
+
* @default 250
|
|
20
|
+
*/
|
|
21
|
+
outDuration: number;
|
|
22
|
+
/**
|
|
23
|
+
* Prevent page from scrolling while modal is open.
|
|
24
|
+
* @default true
|
|
25
|
+
*/
|
|
26
|
+
preventScrolling: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Callback function called before modal is opened.
|
|
29
|
+
* @default null
|
|
30
|
+
*/
|
|
31
|
+
onOpenStart: (this: Modal, el: HTMLElement) => void;
|
|
32
|
+
/**
|
|
33
|
+
* Callback function called after modal is opened.
|
|
34
|
+
* @default null
|
|
35
|
+
*/
|
|
36
|
+
onOpenEnd: (this: Modal, el: HTMLElement) => void;
|
|
37
|
+
/**
|
|
38
|
+
* Callback function called before modal is closed.
|
|
39
|
+
* @default null
|
|
40
|
+
*/
|
|
41
|
+
onCloseStart: (el: HTMLElement) => void;
|
|
42
|
+
/**
|
|
43
|
+
* Callback function called after modal is closed.
|
|
44
|
+
* @default null
|
|
45
|
+
*/
|
|
46
|
+
onCloseEnd: (el: HTMLElement) => void;
|
|
47
|
+
/**
|
|
48
|
+
* Allow modal to be dismissed by keyboard or overlay click.
|
|
49
|
+
* @default true
|
|
50
|
+
*/
|
|
51
|
+
dismissible: boolean;
|
|
52
|
+
/**
|
|
53
|
+
* Starting top offset.
|
|
54
|
+
* @default '4%'
|
|
55
|
+
*/
|
|
56
|
+
startingTop: string;
|
|
57
|
+
/**
|
|
58
|
+
* Ending top offset.
|
|
59
|
+
* @default '10%'
|
|
60
|
+
*/
|
|
61
|
+
endingTop: string;
|
|
62
|
+
}
|
|
4
63
|
|
|
5
64
|
const _defaults = {
|
|
6
65
|
opacity: 0.5,
|
|
@@ -16,241 +75,267 @@ const _defaults = {
|
|
|
16
75
|
endingTop: '10%'
|
|
17
76
|
};
|
|
18
77
|
|
|
19
|
-
|
|
20
|
-
el: HTMLElement;
|
|
21
|
-
static _modalsOpen: number;
|
|
22
|
-
static _count: number;
|
|
23
|
-
isOpen: boolean;
|
|
24
|
-
id: string;
|
|
25
|
-
private _openingTrigger: any;
|
|
26
|
-
private _overlay: HTMLElement;
|
|
27
|
-
private _nthModalOpened: number;
|
|
28
|
-
private _handleOverlayClickBound: any;
|
|
29
|
-
private _handleModalCloseClickBound: any;
|
|
30
|
-
private _handleKeydownBound: any;
|
|
31
|
-
private _handleFocusBound: any;
|
|
78
|
+
export class Modal extends Component<ModalOptions> {
|
|
32
79
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
80
|
+
static _modalsOpen: number;
|
|
81
|
+
static _count: number;
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* ID of the modal element.
|
|
85
|
+
*/
|
|
86
|
+
id: string;
|
|
87
|
+
/**
|
|
88
|
+
* If the modal is open.
|
|
89
|
+
*/
|
|
90
|
+
isOpen: boolean;
|
|
91
|
+
|
|
92
|
+
private _openingTrigger: any;
|
|
93
|
+
private _overlay: HTMLElement;
|
|
94
|
+
private _nthModalOpened: number;
|
|
47
95
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
96
|
+
constructor(el: HTMLElement, options: Partial<ModalOptions>) {
|
|
97
|
+
super(el, options, Modal);
|
|
98
|
+
(this.el as any).M_Modal = this;
|
|
51
99
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
100
|
+
this.options = {
|
|
101
|
+
...Modal.defaults,
|
|
102
|
+
...options
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
this.isOpen = false;
|
|
106
|
+
this.id = this.el.id;
|
|
107
|
+
this._openingTrigger = undefined;
|
|
108
|
+
this._overlay = document.createElement('div');
|
|
109
|
+
this._overlay.classList.add('modal-overlay');
|
|
110
|
+
this.el.tabIndex = 0;
|
|
111
|
+
this._nthModalOpened = 0;
|
|
112
|
+
Modal._count++;
|
|
113
|
+
this._setupEventHandlers();
|
|
114
|
+
}
|
|
55
115
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
116
|
+
static get defaults() {
|
|
117
|
+
return _defaults;
|
|
118
|
+
}
|
|
60
119
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
120
|
+
/**
|
|
121
|
+
* Initializes instance of Modal.
|
|
122
|
+
* @param el HTML element.
|
|
123
|
+
* @param options Component options.
|
|
124
|
+
*/
|
|
125
|
+
static init(el: HTMLElement, options?: Partial<ModalOptions>): Modal;
|
|
126
|
+
/**
|
|
127
|
+
* Initializes instances of Modal.
|
|
128
|
+
* @param els HTML elements.
|
|
129
|
+
* @param options Component options.
|
|
130
|
+
*/
|
|
131
|
+
static init(els: InitElements<MElement>, options?: Partial<ModalOptions>): Modal[];
|
|
132
|
+
/**
|
|
133
|
+
* Initializes instances of Modal.
|
|
134
|
+
* @param els HTML elements.
|
|
135
|
+
* @param options Component options.
|
|
136
|
+
*/
|
|
137
|
+
static init(els: HTMLElement | InitElements<MElement>, options: Partial<ModalOptions> = {}): Modal | Modal[] {
|
|
138
|
+
return super.init(els, options, Modal);
|
|
139
|
+
}
|
|
68
140
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
if (Modal._count === 1) {
|
|
73
|
-
document.body.addEventListener('click', this._handleTriggerClick);
|
|
74
|
-
}
|
|
75
|
-
this._overlay.addEventListener('click', this._handleOverlayClickBound);
|
|
76
|
-
this.el.addEventListener('click', this._handleModalCloseClickBound);
|
|
77
|
-
}
|
|
141
|
+
static getInstance(el: HTMLElement): Modal {
|
|
142
|
+
return (el as any).M_Modal;
|
|
143
|
+
}
|
|
78
144
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
145
|
+
destroy() {
|
|
146
|
+
Modal._count--;
|
|
147
|
+
this._removeEventHandlers();
|
|
148
|
+
this.el.removeAttribute('style');
|
|
149
|
+
this._overlay.remove();
|
|
150
|
+
(this.el as any).M_Modal = undefined;
|
|
151
|
+
}
|
|
86
152
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
const modalId = M.getIdFromTrigger(trigger);
|
|
91
|
-
const modalInstance = (document.getElementById(modalId) as any).M_Modal;
|
|
92
|
-
if (modalInstance) modalInstance.open(trigger);
|
|
93
|
-
e.preventDefault();
|
|
153
|
+
_setupEventHandlers() {
|
|
154
|
+
if (Modal._count === 1) {
|
|
155
|
+
document.body.addEventListener('click', this._handleTriggerClick);
|
|
94
156
|
}
|
|
157
|
+
this._overlay.addEventListener('click', this._handleOverlayClick);
|
|
158
|
+
this.el.addEventListener('click', this._handleModalCloseClick);
|
|
159
|
+
}
|
|
95
160
|
|
|
96
|
-
|
|
97
|
-
|
|
161
|
+
_removeEventHandlers() {
|
|
162
|
+
if (Modal._count === 0) {
|
|
163
|
+
document.body.removeEventListener('click', this._handleTriggerClick);
|
|
98
164
|
}
|
|
165
|
+
this._overlay.removeEventListener('click', this._handleOverlayClick);
|
|
166
|
+
this.el.removeEventListener('click', this._handleModalCloseClick);
|
|
167
|
+
}
|
|
99
168
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
169
|
+
_handleTriggerClick = (e: MouseEvent) => {
|
|
170
|
+
const trigger = (e.target as HTMLElement).closest('.modal-trigger');
|
|
171
|
+
if (!trigger) return;
|
|
172
|
+
const modalId = Utils.getIdFromTrigger(trigger as HTMLElement);
|
|
173
|
+
const modalInstance = (document.getElementById(modalId) as any).M_Modal;
|
|
174
|
+
if (modalInstance) modalInstance.open(trigger);
|
|
175
|
+
e.preventDefault();
|
|
176
|
+
}
|
|
104
177
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
}
|
|
178
|
+
_handleOverlayClick = () => {
|
|
179
|
+
if (this.options.dismissible) this.close();
|
|
180
|
+
}
|
|
109
181
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
182
|
+
_handleModalCloseClick = (e: MouseEvent) => {
|
|
183
|
+
const closeTrigger = (e.target as HTMLElement).closest('.modal-close');
|
|
184
|
+
if (closeTrigger) this.close();
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
_handleKeydown = (e: KeyboardEvent) => {
|
|
188
|
+
if (Utils.keys.ESC.includes(e.key) && this.options.dismissible) this.close();
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
_handleFocus = (e: FocusEvent) => {
|
|
192
|
+
// Only trap focus if this modal is the last model opened (prevents loops in nested modals).
|
|
193
|
+
if (!this.el.contains(e.target as HTMLElement) && this._nthModalOpened === Modal._modalsOpen) {
|
|
194
|
+
this.el.focus();
|
|
115
195
|
}
|
|
196
|
+
}
|
|
116
197
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
}
|
|
198
|
+
_animateIn() {
|
|
199
|
+
// Set initial styles
|
|
200
|
+
this.el.style.display = 'block';
|
|
201
|
+
this.el.style.opacity = '0';
|
|
202
|
+
this._overlay.style.display = 'block';
|
|
203
|
+
this._overlay.style.opacity = '0';
|
|
204
|
+
// Animate overlay
|
|
205
|
+
anim({
|
|
206
|
+
targets: this._overlay,
|
|
207
|
+
opacity: this.options.opacity,
|
|
208
|
+
duration: this.options.inDuration,
|
|
209
|
+
easing: 'easeOutQuad'
|
|
210
|
+
});
|
|
211
|
+
// Define modal animation options
|
|
212
|
+
const enterAnimOptions = {
|
|
213
|
+
targets: this.el,
|
|
214
|
+
duration: this.options.inDuration,
|
|
215
|
+
easing: 'easeOutCubic',
|
|
216
|
+
// Handle modal onOpenEnd callback
|
|
217
|
+
complete: () => {
|
|
218
|
+
if (typeof this.options.onOpenEnd === 'function') {
|
|
219
|
+
this.options.onOpenEnd.call(this, this.el, this._openingTrigger);
|
|
140
220
|
}
|
|
141
|
-
};
|
|
142
|
-
// Bottom sheet animation
|
|
143
|
-
if (this.el.classList.contains('bottom-sheet')) {
|
|
144
|
-
enterAnimOptions['bottom'] = 0;
|
|
145
|
-
enterAnimOptions['opacity'] = 1;
|
|
146
|
-
}
|
|
147
|
-
// Normal modal animation
|
|
148
|
-
else {
|
|
149
|
-
enterAnimOptions['top'] = [this.options.startingTop, this.options.endingTop];
|
|
150
|
-
enterAnimOptions['opacity'] = 1;
|
|
151
|
-
enterAnimOptions['scaleX'] = [0.8, 1];
|
|
152
|
-
enterAnimOptions['scaleY'] = [0.8, 1];
|
|
153
221
|
}
|
|
154
|
-
|
|
222
|
+
};
|
|
223
|
+
// Bottom sheet animation
|
|
224
|
+
if (this.el.classList.contains('bottom-sheet')) {
|
|
225
|
+
enterAnimOptions['bottom'] = 0;
|
|
226
|
+
enterAnimOptions['opacity'] = 1;
|
|
227
|
+
}
|
|
228
|
+
// Normal modal animation
|
|
229
|
+
else {
|
|
230
|
+
enterAnimOptions['top'] = [this.options.startingTop, this.options.endingTop];
|
|
231
|
+
enterAnimOptions['opacity'] = 1;
|
|
232
|
+
enterAnimOptions['scaleX'] = [0.8, 1];
|
|
233
|
+
enterAnimOptions['scaleY'] = [0.8, 1];
|
|
155
234
|
}
|
|
235
|
+
anim(enterAnimOptions);
|
|
236
|
+
}
|
|
156
237
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
}
|
|
238
|
+
_animateOut() {
|
|
239
|
+
// Animate overlay
|
|
240
|
+
anim({
|
|
241
|
+
targets: this._overlay,
|
|
242
|
+
opacity: 0,
|
|
243
|
+
duration: this.options.outDuration,
|
|
244
|
+
easing: 'easeOutQuart'
|
|
245
|
+
});
|
|
246
|
+
// Define modal animation options
|
|
247
|
+
const exitAnimOptions = {
|
|
248
|
+
targets: this.el,
|
|
249
|
+
duration: this.options.outDuration,
|
|
250
|
+
easing: 'easeOutCubic',
|
|
251
|
+
// Handle modal ready callback
|
|
252
|
+
complete: () => {
|
|
253
|
+
this.el.style.display = 'none';
|
|
254
|
+
this._overlay.remove();
|
|
255
|
+
// Call onCloseEnd callback
|
|
256
|
+
if (typeof this.options.onCloseEnd === 'function') {
|
|
257
|
+
this.options.onCloseEnd.call(this, this.el);
|
|
178
258
|
}
|
|
179
|
-
};
|
|
180
|
-
// Bottom sheet animation
|
|
181
|
-
if (this.el.classList.contains('bottom-sheet')) {
|
|
182
|
-
exitAnimOptions['bottom'] = '-100%';
|
|
183
|
-
exitAnimOptions['opacity'] = 0;
|
|
184
|
-
}
|
|
185
|
-
// Normal modal animation
|
|
186
|
-
else {
|
|
187
|
-
exitAnimOptions['top'] = [this.options.endingTop, this.options.startingTop];
|
|
188
|
-
exitAnimOptions['opacity'] = 0;
|
|
189
|
-
exitAnimOptions['scaleX'] = 0.8;
|
|
190
|
-
exitAnimOptions['scaleY'] = 0.8;
|
|
191
259
|
}
|
|
192
|
-
|
|
260
|
+
};
|
|
261
|
+
// Bottom sheet animation
|
|
262
|
+
if (this.el.classList.contains('bottom-sheet')) {
|
|
263
|
+
exitAnimOptions['bottom'] = '-100%';
|
|
264
|
+
exitAnimOptions['opacity'] = 0;
|
|
193
265
|
}
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
// Set Z-Index based on number of currently open modals
|
|
201
|
-
this._overlay.style.zIndex = (1000 + Modal._modalsOpen * 2).toString();
|
|
202
|
-
this.el.style.zIndex = (1000 + Modal._modalsOpen * 2 + 1).toString();
|
|
203
|
-
// Set opening trigger, undefined indicates modal was opened by javascript
|
|
204
|
-
this._openingTrigger = !!trigger ? trigger : undefined;
|
|
205
|
-
// onOpenStart callback
|
|
206
|
-
if (typeof this.options.onOpenStart === 'function') {
|
|
207
|
-
this.options.onOpenStart.call(this, this.el, this._openingTrigger);
|
|
208
|
-
}
|
|
209
|
-
if (this.options.preventScrolling) {
|
|
210
|
-
document.body.style.overflow = 'hidden';
|
|
211
|
-
}
|
|
212
|
-
this.el.classList.add('open');
|
|
213
|
-
this.el.insertAdjacentElement('afterend', this._overlay);
|
|
214
|
-
if (this.options.dismissible) {
|
|
215
|
-
this._handleKeydownBound = this._handleKeydown.bind(this);
|
|
216
|
-
this._handleFocusBound = this._handleFocus.bind(this);
|
|
217
|
-
document.addEventListener('keydown', this._handleKeydownBound);
|
|
218
|
-
document.addEventListener('focus', this._handleFocusBound, true);
|
|
219
|
-
}
|
|
220
|
-
anim.remove(this.el);
|
|
221
|
-
anim.remove(this._overlay);
|
|
222
|
-
this._animateIn();
|
|
223
|
-
// Focus modal
|
|
224
|
-
this.el.focus();
|
|
225
|
-
return this;
|
|
266
|
+
// Normal modal animation
|
|
267
|
+
else {
|
|
268
|
+
exitAnimOptions['top'] = [this.options.endingTop, this.options.startingTop];
|
|
269
|
+
exitAnimOptions['opacity'] = 0;
|
|
270
|
+
exitAnimOptions['scaleX'] = 0.8;
|
|
271
|
+
exitAnimOptions['scaleY'] = 0.8;
|
|
226
272
|
}
|
|
273
|
+
anim(exitAnimOptions);
|
|
274
|
+
}
|
|
227
275
|
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
anim.remove(this._overlay);
|
|
248
|
-
this._animateOut();
|
|
249
|
-
return this;
|
|
276
|
+
/**
|
|
277
|
+
* Open modal.
|
|
278
|
+
*/
|
|
279
|
+
open = (trigger?: HTMLElement): Modal => {
|
|
280
|
+
if (this.isOpen) return;
|
|
281
|
+
this.isOpen = true;
|
|
282
|
+
Modal._modalsOpen++;
|
|
283
|
+
this._nthModalOpened = Modal._modalsOpen;
|
|
284
|
+
// Set Z-Index based on number of currently open modals
|
|
285
|
+
this._overlay.style.zIndex = (1000 + Modal._modalsOpen * 2).toString();
|
|
286
|
+
this.el.style.zIndex = (1000 + Modal._modalsOpen * 2 + 1).toString();
|
|
287
|
+
// Set opening trigger, undefined indicates modal was opened by javascript
|
|
288
|
+
this._openingTrigger = !!trigger ? trigger : undefined;
|
|
289
|
+
// onOpenStart callback
|
|
290
|
+
if (typeof this.options.onOpenStart === 'function') {
|
|
291
|
+
this.options.onOpenStart.call(this, this.el, this._openingTrigger);
|
|
292
|
+
}
|
|
293
|
+
if (this.options.preventScrolling) {
|
|
294
|
+
document.body.style.overflow = 'hidden';
|
|
250
295
|
}
|
|
296
|
+
this.el.classList.add('open');
|
|
297
|
+
this.el.insertAdjacentElement('afterend', this._overlay);
|
|
298
|
+
if (this.options.dismissible) {
|
|
299
|
+
document.addEventListener('keydown', this._handleKeydown);
|
|
300
|
+
document.addEventListener('focus', this._handleFocus, true);
|
|
301
|
+
}
|
|
302
|
+
anim.remove(this.el);
|
|
303
|
+
anim.remove(this._overlay);
|
|
304
|
+
this._animateIn();
|
|
305
|
+
// Focus modal
|
|
306
|
+
this.el.focus();
|
|
307
|
+
return this;
|
|
308
|
+
}
|
|
251
309
|
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
310
|
+
/**
|
|
311
|
+
* Close modal.
|
|
312
|
+
*/
|
|
313
|
+
close = () => {
|
|
314
|
+
if (!this.isOpen) return;
|
|
315
|
+
this.isOpen = false;
|
|
316
|
+
Modal._modalsOpen--;
|
|
317
|
+
this._nthModalOpened = 0;
|
|
318
|
+
// Call onCloseStart callback
|
|
319
|
+
if (typeof this.options.onCloseStart === 'function') {
|
|
320
|
+
this.options.onCloseStart.call(this, this.el);
|
|
321
|
+
}
|
|
322
|
+
this.el.classList.remove('open');
|
|
323
|
+
// Enable body scrolling only if there are no more modals open.
|
|
324
|
+
if (Modal._modalsOpen === 0) {
|
|
325
|
+
document.body.style.overflow = '';
|
|
255
326
|
}
|
|
327
|
+
if (this.options.dismissible) {
|
|
328
|
+
document.removeEventListener('keydown', this._handleKeydown);
|
|
329
|
+
document.removeEventListener('focus', this._handleFocus, true);
|
|
330
|
+
}
|
|
331
|
+
anim.remove(this.el);
|
|
332
|
+
anim.remove(this._overlay);
|
|
333
|
+
this._animateOut();
|
|
334
|
+
return this;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
static{
|
|
338
|
+
Modal._modalsOpen = 0;
|
|
339
|
+
Modal._count = 0;
|
|
256
340
|
}
|
|
341
|
+
}
|