@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.
Files changed (117) hide show
  1. package/Gruntfile.js +5 -2
  2. package/dist/css/materialize.css +1510 -288
  3. package/dist/css/materialize.min.css +2 -2
  4. package/dist/js/materialize.js +2782 -2688
  5. package/dist/js/materialize.min.js +2 -8967
  6. package/dist/js/materialize.min.js.map +1 -1
  7. package/dist/src/autocomplete.d.ts +143 -0
  8. package/dist/src/autocomplete.d.ts.map +1 -0
  9. package/dist/src/bounding.d.ts +7 -0
  10. package/dist/src/bounding.d.ts.map +1 -0
  11. package/dist/src/buttons.d.ts +65 -0
  12. package/dist/src/buttons.d.ts.map +1 -0
  13. package/dist/src/cards.d.ts +4 -0
  14. package/dist/src/cards.d.ts.map +1 -0
  15. package/dist/src/carousel.d.ts +131 -0
  16. package/dist/src/carousel.d.ts.map +1 -0
  17. package/dist/src/characterCounter.d.ts +37 -0
  18. package/dist/src/characterCounter.d.ts.map +1 -0
  19. package/dist/src/chips.d.ts +131 -0
  20. package/dist/src/chips.d.ts.map +1 -0
  21. package/dist/src/collapsible.d.ts +74 -0
  22. package/dist/src/collapsible.d.ts.map +1 -0
  23. package/dist/src/component.d.ts +74 -0
  24. package/dist/src/component.d.ts.map +1 -0
  25. package/dist/src/datepicker.d.ts +248 -0
  26. package/dist/src/datepicker.d.ts.map +1 -0
  27. package/dist/src/dropdown.d.ts +148 -0
  28. package/dist/src/dropdown.d.ts.map +1 -0
  29. package/dist/src/edges.d.ts +7 -0
  30. package/dist/src/edges.d.ts.map +1 -0
  31. package/dist/src/forms.d.ts +12 -0
  32. package/dist/src/forms.d.ts.map +1 -0
  33. package/dist/src/global.d.ts +60 -0
  34. package/dist/src/global.d.ts.map +1 -0
  35. package/dist/src/index.d.ts +27 -0
  36. package/dist/src/index.d.ts.map +1 -0
  37. package/dist/src/materialbox.d.ts +92 -0
  38. package/dist/src/materialbox.d.ts.map +1 -0
  39. package/dist/src/modal.d.ts +119 -0
  40. package/dist/src/modal.d.ts.map +1 -0
  41. package/dist/src/parallax.d.ts +40 -0
  42. package/dist/src/parallax.d.ts.map +1 -0
  43. package/dist/src/pushpin.d.ts +52 -0
  44. package/dist/src/pushpin.d.ts.map +1 -0
  45. package/dist/src/range.d.ts +41 -0
  46. package/dist/src/range.d.ts.map +1 -0
  47. package/dist/src/scrollspy.d.ts +62 -0
  48. package/dist/src/scrollspy.d.ts.map +1 -0
  49. package/dist/src/select.d.ts +77 -0
  50. package/dist/src/select.d.ts.map +1 -0
  51. package/dist/src/sidenav.d.ts +122 -0
  52. package/dist/src/sidenav.d.ts.map +1 -0
  53. package/dist/src/slider.d.ts +103 -0
  54. package/dist/src/slider.d.ts.map +1 -0
  55. package/dist/src/tabs.d.ts +80 -0
  56. package/dist/src/tabs.d.ts.map +1 -0
  57. package/dist/src/tapTarget.d.ts +59 -0
  58. package/dist/src/tapTarget.d.ts.map +1 -0
  59. package/dist/src/timepicker.d.ts +208 -0
  60. package/dist/src/timepicker.d.ts.map +1 -0
  61. package/dist/src/toasts.d.ts +90 -0
  62. package/dist/src/toasts.d.ts.map +1 -0
  63. package/dist/src/tooltip.d.ts +112 -0
  64. package/dist/src/tooltip.d.ts.map +1 -0
  65. package/dist/src/utils.d.ts +97 -0
  66. package/dist/src/utils.d.ts.map +1 -0
  67. package/dist/src/waves.d.ts +16 -0
  68. package/dist/src/waves.d.ts.map +1 -0
  69. package/package.json +4 -1
  70. package/sass/components/_cards.scss +1 -1
  71. package/sass/components/_collapsible.scss +0 -41
  72. package/sass/components/_global.scss +53 -2
  73. package/sass/components/_grid.scss +28 -47
  74. package/sass/components/_icons-material-design.scss +2 -1
  75. package/sass/components/_navbar.scss +30 -27
  76. package/sass/components/_pulse.scss +1 -0
  77. package/sass/components/_sidenav.scss +63 -45
  78. package/sass/components/_theme_variables.scss +29 -49
  79. package/sass/components/_typography.scss +2 -2
  80. package/sass/components/_variables.scss +2 -0
  81. package/sass/components/colors.module.scss +180 -0
  82. package/sass/components/forms/_input-fields.scss +4 -10
  83. package/sass/components/theme.dark.module.scss +32 -0
  84. package/sass/components/theme.light.module.scss +32 -0
  85. package/sass/components/tokens.module.scss +272 -0
  86. package/sass/components/typography.module.scss +150 -0
  87. package/sass/materialize.scss +6 -4
  88. package/src/autocomplete.ts +188 -94
  89. package/src/buttons.ts +225 -260
  90. package/src/cards.ts +5 -6
  91. package/src/carousel.ts +611 -542
  92. package/src/characterCounter.ts +50 -21
  93. package/src/chips.ts +152 -63
  94. package/src/collapsible.ts +97 -32
  95. package/src/component.ts +99 -10
  96. package/src/datepicker.ts +905 -726
  97. package/src/dropdown.ts +573 -484
  98. package/src/edges.ts +4 -4
  99. package/src/forms.ts +36 -24
  100. package/src/global.ts +57 -328
  101. package/src/index.ts +26 -0
  102. package/src/materialbox.ts +354 -298
  103. package/src/modal.ts +296 -211
  104. package/src/parallax.ts +129 -105
  105. package/src/pushpin.ts +148 -103
  106. package/src/range.ts +166 -150
  107. package/src/scrollspy.ts +214 -174
  108. package/src/select.ts +434 -398
  109. package/src/sidenav.ts +447 -381
  110. package/src/slider.ts +421 -362
  111. package/src/tabs.ts +276 -222
  112. package/src/tapTarget.ts +246 -213
  113. package/src/timepicker.ts +738 -614
  114. package/src/toasts.ts +254 -230
  115. package/src/tooltip.ts +315 -252
  116. package/src/utils.ts +271 -0
  117. 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
- import { M } from "./global";
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
- export class Modal extends Component {
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
- constructor(el, options) {
34
- super(Modal, el, options);
35
- (this.el as any).M_Modal = this;
36
- this.options = {...Modal.defaults, ...options};
37
- this.isOpen = false;
38
- this.id = this.el.id;
39
- this._openingTrigger = undefined;
40
- this._overlay = document.createElement('div');
41
- this._overlay.classList.add('modal-overlay');
42
- this.el.tabIndex = 0;
43
- this._nthModalOpened = 0;
44
- Modal._count++;
45
- this._setupEventHandlers();
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
- static get defaults() {
49
- return _defaults;
50
- }
96
+ constructor(el: HTMLElement, options: Partial<ModalOptions>) {
97
+ super(el, options, Modal);
98
+ (this.el as any).M_Modal = this;
51
99
 
52
- static init(els, options) {
53
- return super.init(this, els, options);
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
- static getInstance(el) {
57
- const domElem = !!el.jquery ? el[0] : el;
58
- return domElem.M_Modal;
59
- }
116
+ static get defaults() {
117
+ return _defaults;
118
+ }
60
119
 
61
- destroy() {
62
- Modal._count--;
63
- this._removeEventHandlers();
64
- this.el.removeAttribute('style');
65
- this._overlay.remove();
66
- (this.el as any).M_Modal = undefined;
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
- _setupEventHandlers() {
70
- this._handleOverlayClickBound = this._handleOverlayClick.bind(this);
71
- this._handleModalCloseClickBound = this._handleModalCloseClick.bind(this);
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
- _removeEventHandlers() {
80
- if (Modal._count === 0) {
81
- document.body.removeEventListener('click', this._handleTriggerClick);
82
- }
83
- this._overlay.removeEventListener('click', this._handleOverlayClickBound);
84
- this.el.removeEventListener('click', this._handleModalCloseClickBound);
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
- _handleTriggerClick(e) {
88
- const trigger = e.target.closest('.modal-trigger');
89
- if (!trigger) return;
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
- _handleOverlayClick() {
97
- if (this.options.dismissible) this.close();
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
- _handleModalCloseClick(e) {
101
- const closeTrigger = e.target.closest('.modal-close');
102
- if (closeTrigger) this.close();
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
- _handleKeydown(e) {
106
- // ESC key
107
- if (e.keyCode === 27 && this.options.dismissible) this.close();
108
- }
178
+ _handleOverlayClick = () => {
179
+ if (this.options.dismissible) this.close();
180
+ }
109
181
 
110
- _handleFocus(e) {
111
- // Only trap focus if this modal is the last model opened (prevents loops in nested modals).
112
- if (!this.el.contains(e.target) && this._nthModalOpened === Modal._modalsOpen) {
113
- this.el.focus();
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
- _animateIn() {
118
- // Set initial styles
119
- this.el.style.display = 'block';
120
- this.el.style.opacity = '0';
121
- this._overlay.style.display = 'block';
122
- this._overlay.style.opacity = '0';
123
- // Animate overlay
124
- anim({
125
- targets: this._overlay,
126
- opacity: this.options.opacity,
127
- duration: this.options.inDuration,
128
- easing: 'easeOutQuad'
129
- });
130
- // Define modal animation options
131
- const enterAnimOptions = {
132
- targets: this.el,
133
- duration: this.options.inDuration,
134
- easing: 'easeOutCubic',
135
- // Handle modal onOpenEnd callback
136
- complete: () => {
137
- if (typeof this.options.onOpenEnd === 'function') {
138
- this.options.onOpenEnd.call(this, this.el, this._openingTrigger);
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
- anim(enterAnimOptions);
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
- _animateOut() {
158
- // Animate overlay
159
- anim({
160
- targets: this._overlay,
161
- opacity: 0,
162
- duration: this.options.outDuration,
163
- easing: 'easeOutQuart'
164
- });
165
- // Define modal animation options
166
- const exitAnimOptions = {
167
- targets: this.el,
168
- duration: this.options.outDuration,
169
- easing: 'easeOutCubic',
170
- // Handle modal ready callback
171
- complete: () => {
172
- this.el.style.display = 'none';
173
- this._overlay.remove();
174
- // Call onCloseEnd callback
175
- if (typeof this.options.onCloseEnd === 'function') {
176
- this.options.onCloseEnd.call(this, this.el);
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
- anim(exitAnimOptions);
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
- open(trigger: HTMLElement|undefined): Modal {
196
- if (this.isOpen) return;
197
- this.isOpen = true;
198
- Modal._modalsOpen++;
199
- this._nthModalOpened = Modal._modalsOpen;
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
- close() {
229
- if (!this.isOpen) return;
230
- this.isOpen = false;
231
- Modal._modalsOpen--;
232
- this._nthModalOpened = 0;
233
- // Call onCloseStart callback
234
- if (typeof this.options.onCloseStart === 'function') {
235
- this.options.onCloseStart.call(this, this.el);
236
- }
237
- this.el.classList.remove('open');
238
- // Enable body scrolling only if there are no more modals open.
239
- if (Modal._modalsOpen === 0) {
240
- document.body.style.overflow = '';
241
- }
242
- if (this.options.dismissible) {
243
- document.removeEventListener('keydown', this._handleKeydownBound);
244
- document.removeEventListener('focus', this._handleFocusBound, true);
245
- }
246
- anim.remove(this.el);
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
- static{
253
- Modal._modalsOpen = 0;
254
- Modal._count = 0;
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
+ }