@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
@@ -1,8 +1,42 @@
1
- import { Component } from "./component";
2
1
  import anim from "animejs";
3
- import { M } from "./global";
4
2
 
5
- const _defaults = {
3
+ import { Utils } from "./utils";
4
+ import { BaseOptions, Component, InitElements, MElement } from "./component";
5
+
6
+ export interface MaterialboxOptions extends BaseOptions {
7
+ /**
8
+ * Transition in duration in milliseconds.
9
+ * @default 275
10
+ */
11
+ inDuration: number;
12
+ /**
13
+ * Transition out duration in milliseconds.
14
+ * @default 200
15
+ */
16
+ outDuration: number;
17
+ /**
18
+ * Callback function called before materialbox is opened.
19
+ * @default null
20
+ */
21
+ onOpenStart: (el: Element) => void;
22
+ /**
23
+ * Callback function called after materialbox is opened.
24
+ * @default null
25
+ */
26
+ onOpenEnd: (el: Element) => void;
27
+ /**
28
+ * Callback function called before materialbox is closed.
29
+ * @default null
30
+ */
31
+ onCloseStart: (el: Element) => void;
32
+ /**
33
+ * Callback function called after materialbox is closed.
34
+ * @default null
35
+ */
36
+ onCloseEnd: (el: Element) => void;
37
+ }
38
+
39
+ const _defaults: MaterialboxOptions = {
6
40
  inDuration: 275,
7
41
  outDuration: 200,
8
42
  onOpenStart: null,
@@ -11,338 +45,360 @@ const _defaults = {
11
45
  onCloseEnd: null
12
46
  };
13
47
 
14
- export class Materialbox extends Component {
15
- el: HTMLElement;
16
- overlayActive: boolean;
17
- doneAnimating: boolean;
18
- caption: string;
19
- originalWidth: number;
20
- originalHeight: number;
21
- private originInlineStyles: string;
22
- private placeholder: HTMLElement;
23
- private _changedAncestorList: HTMLElement[];
24
- private newHeight: number;
25
- private newWidth: number;
26
- private windowWidth: number;
27
- private windowHeight: number;
28
- private attrWidth: string;
29
- private attrHeight: string;
30
- private _overlay: HTMLElement;
31
- private _photoCaption: HTMLElement;
32
- private _handleMaterialboxClickBound: any;
33
- private _handleWindowScrollBound: any;
34
- private _handleWindowResizeBound: any;
35
- private _handleWindowEscapeBound: any;
48
+ export class Materialbox extends Component<MaterialboxOptions> {
49
+ /** If the materialbox overlay is showing. */
50
+ overlayActive: boolean;
51
+ /** If the materialbox is no longer being animated. */
52
+ doneAnimating: boolean;
53
+ /** Caption, if specified. */
54
+ caption: string;
55
+ /** Original width of image. */
56
+ originalWidth: number;
57
+ /** Original height of image. */
58
+ originalHeight: number;
59
+ private originInlineStyles: string;
60
+ private placeholder: HTMLElement;
61
+ private _changedAncestorList: HTMLElement[];
62
+ private newHeight: number;
63
+ private newWidth: number;
64
+ private windowWidth: number;
65
+ private windowHeight: number;
66
+ private attrWidth: string;
67
+ private attrHeight: string;
68
+ private _overlay: HTMLElement;
69
+ private _photoCaption: HTMLElement;
36
70
 
37
- constructor(el, options) {
38
- super(Materialbox, el, options);
39
- (this.el as any).M_Materialbox = this;
40
- this.options = {...Materialbox.defaults, ...options};
41
- this.overlayActive = false;
42
- this.doneAnimating = true;
43
- this.placeholder = document.createElement('div');
44
- this.placeholder.classList.add('material-placeholder');
45
- this.originalWidth = 0;
46
- this.originalHeight = 0;
47
- this.originInlineStyles = this.el.getAttribute('style');
48
- this.caption = this.el.getAttribute('data-caption') || '';
49
- // Wrap
50
- this.el.before(this.placeholder);
51
- this.placeholder.append(this.el);
52
- this._setupEventHandlers();
53
- }
71
+ constructor(el: HTMLElement, options: Partial<MaterialboxOptions>) {
72
+ super(el, options, Materialbox);
73
+ (this.el as any).M_Materialbox = this;
54
74
 
55
- static get defaults() {
56
- return _defaults;
57
- }
75
+ this.options = {
76
+ ...Materialbox.defaults,
77
+ ...options
78
+ };
79
+
80
+ this.overlayActive = false;
81
+ this.doneAnimating = true;
82
+ this.placeholder = document.createElement('div');
83
+ this.placeholder.classList.add('material-placeholder');
84
+ this.originalWidth = 0;
85
+ this.originalHeight = 0;
86
+ this.originInlineStyles = this.el.getAttribute('style');
87
+ this.caption = this.el.getAttribute('data-caption') || '';
88
+ // Wrap
89
+ this.el.before(this.placeholder);
90
+ this.placeholder.append(this.el);
91
+ this._setupEventHandlers();
92
+ }
58
93
 
59
- static init(els, options) {
60
- return super.init(this, els, options);
61
- }
94
+ static get defaults(): MaterialboxOptions {
95
+ return _defaults;
96
+ }
62
97
 
63
- static getInstance(el) {
64
- const domElem = !!el.jquery ? el[0] : el;
65
- return domElem.M_Materialbox;
66
- }
98
+ /**
99
+ * Initializes instance of MaterialBox.
100
+ * @param el HTML element.
101
+ * @param options Component options.
102
+ */
103
+ static init(el: HTMLElement, options?: Partial<MaterialboxOptions>): Materialbox;
104
+ /**
105
+ * Initializes instances of MaterialBox.
106
+ * @param els HTML elements.
107
+ * @param options Component options.
108
+ */
109
+ static init(els: InitElements<MElement>, options?: Partial<MaterialboxOptions>): Materialbox[];
110
+ /**
111
+ * Initializes instances of MaterialBox.
112
+ * @param els HTML elements.
113
+ * @param options Component options.
114
+ */
115
+ static init(els: HTMLElement | InitElements<MElement>, options: Partial<MaterialboxOptions> = {}): Materialbox | Materialbox[]{
116
+ return super.init(els, options, Materialbox);
117
+ }
67
118
 
68
- destroy() {
69
- this._removeEventHandlers();
70
- (this.el as any).M_Materialbox = undefined;
71
- // Unwrap image
72
- //this.placeholder.after(this.el).remove();
73
- this.placeholder.remove();
74
- this.el.removeAttribute('style');
75
- }
119
+ static getInstance(el: HTMLElement): Materialbox {
120
+ return (el as any).M_Materialbox;
121
+ }
76
122
 
77
- _setupEventHandlers() {
78
- this._handleMaterialboxClickBound = this._handleMaterialboxClick.bind(this);
79
- this.el.addEventListener('click', this._handleMaterialboxClickBound);
80
- }
123
+ destroy() {
124
+ this._removeEventHandlers();
125
+ (this.el as any).M_Materialbox = undefined;
126
+ // Unwrap image
127
+ //this.placeholder.after(this.el).remove();
128
+ this.placeholder.remove();
129
+ this.el.removeAttribute('style');
130
+ }
81
131
 
82
- _removeEventHandlers() {
83
- this.el.removeEventListener('click', this._handleMaterialboxClickBound);
84
- }
132
+ _setupEventHandlers() {
133
+ this.el.addEventListener('click', this._handleMaterialboxClick);
134
+ }
85
135
 
86
- _handleMaterialboxClick(e) {
87
- // If already modal, return to original
88
- if (this.doneAnimating === false || (this.overlayActive && this.doneAnimating))
89
- this.close();
90
- else
91
- this.open();
92
- }
136
+ _removeEventHandlers() {
137
+ this.el.removeEventListener('click', this._handleMaterialboxClick);
138
+ }
93
139
 
94
- _handleWindowScroll() {
95
- if (this.overlayActive) this.close();
96
- }
140
+ _handleMaterialboxClick = () => {
141
+ // If already modal, return to original
142
+ if (this.doneAnimating === false || (this.overlayActive && this.doneAnimating))
143
+ this.close();
144
+ else
145
+ this.open();
146
+ }
97
147
 
98
- _handleWindowResize() {
99
- if (this.overlayActive) this.close();
100
- }
148
+ _handleWindowScroll = () => {
149
+ if (this.overlayActive) this.close();
150
+ }
101
151
 
102
- _handleWindowEscape(e) {
103
- // ESC key
104
- if (e.keyCode === 27 && this.doneAnimating && this.overlayActive) this.close();
105
- }
152
+ _handleWindowResize = () => {
153
+ if (this.overlayActive) this.close();
154
+ }
106
155
 
107
- _makeAncestorsOverflowVisible() {
108
- this._changedAncestorList = [];
109
- let ancestor = this.placeholder.parentNode;
110
- while (ancestor !== null && ancestor !== document) {
111
- const curr = <HTMLElement>ancestor;
112
- if (curr.style.overflow !== 'visible') {
113
- curr.style.overflow = 'visible';
114
- this._changedAncestorList.push(curr);
115
- }
116
- ancestor = ancestor.parentNode;
156
+ _handleWindowEscape = (e: KeyboardEvent) => {
157
+ if (Utils.keys.ESC.includes(e.key) && this.doneAnimating && this.overlayActive) this.close();
158
+ }
159
+
160
+ _makeAncestorsOverflowVisible() {
161
+ this._changedAncestorList = [];
162
+ let ancestor = this.placeholder.parentNode;
163
+ while (ancestor !== null && ancestor !== document) {
164
+ const curr = <HTMLElement>ancestor;
165
+ if (curr.style.overflow !== 'visible') {
166
+ curr.style.overflow = 'visible';
167
+ this._changedAncestorList.push(curr);
117
168
  }
169
+ ancestor = ancestor.parentNode;
118
170
  }
171
+ }
119
172
 
120
- private _offset(el) {
121
- const box = el.getBoundingClientRect();
122
- const docElem = document.documentElement;
123
- return {
124
- top: box.top + window.pageYOffset - docElem.clientTop,
125
- left: box.left + window.pageXOffset - docElem.clientLeft
126
- };
127
- }
173
+ private _offset(el: HTMLElement) {
174
+ const box = el.getBoundingClientRect();
175
+ const docElem = document.documentElement;
176
+ return {
177
+ top: box.top + window.pageYOffset - docElem.clientTop,
178
+ left: box.left + window.pageXOffset - docElem.clientLeft
179
+ };
180
+ }
128
181
 
129
- _animateImageIn() {
130
- this.el.style.maxHeight = this.newHeight.toString()+'px';
131
- this.el.style.maxWidth = this.newWidth.toString()+'px';
182
+ _animateImageIn() {
183
+ this.el.style.maxHeight = this.newHeight.toString()+'px';
184
+ this.el.style.maxWidth = this.newWidth.toString()+'px';
132
185
 
133
- const animOptions = {
134
- targets: this.el, // image
135
- height: [this.originalHeight, this.newHeight],
136
- width: [this.originalWidth, this.newWidth],
137
- left:
138
- M.getDocumentScrollLeft() +
139
- this.windowWidth / 2 -
140
- this._offset(this.placeholder).left -
141
- this.newWidth / 2,
142
- top:
143
- M.getDocumentScrollTop() +
144
- this.windowHeight / 2 -
145
- this._offset(this.placeholder).top -
146
- this.newHeight / 2,
147
- duration: this.options.inDuration,
148
- easing: 'easeOutQuad',
149
- complete: () => {
150
- this.doneAnimating = true;
151
- // onOpenEnd callback
152
- if (typeof this.options.onOpenEnd === 'function') {
153
- this.options.onOpenEnd.call(this, this.el);
154
- }
186
+ const animOptions = {
187
+ targets: this.el, // image
188
+ height: [this.originalHeight, this.newHeight],
189
+ width: [this.originalWidth, this.newWidth],
190
+ left:
191
+ Utils.getDocumentScrollLeft() +
192
+ this.windowWidth / 2 -
193
+ this._offset(this.placeholder).left -
194
+ this.newWidth / 2,
195
+ top:
196
+ Utils.getDocumentScrollTop() +
197
+ this.windowHeight / 2 -
198
+ this._offset(this.placeholder).top -
199
+ this.newHeight / 2,
200
+ duration: this.options.inDuration,
201
+ easing: 'easeOutQuad',
202
+ complete: () => {
203
+ this.doneAnimating = true;
204
+ // onOpenEnd callback
205
+ if (typeof this.options.onOpenEnd === 'function') {
206
+ this.options.onOpenEnd.call(this, this.el);
155
207
  }
156
- };
157
- // Override max-width or max-height if needed
158
- //const elStyle = this.el.style;
159
- //console.log('mh', elStyle.maxHeight, '->', this.newHeight);
160
- //console.log('mw', elStyle.maxWidth, '->', this.newWidth);
161
- //if (elStyle.maxWidth !== 'none') animOptions.maxWidth = this.newWidth;
162
- //if (elStyle.maxHeight !== 'none') animOptions.maxHeight = this.newHeight;
163
- //console.log('>>> animate');
164
- //console.log(JSON.stringify(animOptions));
165
- anim(animOptions);
166
- }
208
+ }
209
+ };
210
+ // Override max-width or max-height if needed
211
+ //const elStyle = this.el.style;
212
+ //console.log('mh', elStyle.maxHeight, '->', this.newHeight);
213
+ //console.log('mw', elStyle.maxWidth, '->', this.newWidth);
214
+ //if (elStyle.maxWidth !== 'none') animOptions.maxWidth = this.newWidth;
215
+ //if (elStyle.maxHeight !== 'none') animOptions.maxHeight = this.newHeight;
216
+ //console.log('>>> animate');
217
+ //console.log(JSON.stringify(animOptions));
218
+ anim(animOptions);
219
+ }
167
220
 
168
- _animateImageOut() {
169
- const animOptions = {
170
- targets: this.el,
171
- width: this.originalWidth,
172
- height: this.originalHeight,
173
- left: 0,
174
- top: 0,
175
- duration: this.options.outDuration,
176
- easing: 'easeOutQuad',
177
- complete: () => {
178
- this.placeholder.style.height = '';
179
- this.placeholder.style.width = '';
180
- this.placeholder.style.position = '';
181
- this.placeholder.style.top = '';
182
- this.placeholder.style.left = '';
183
- // Revert to width or height attribute
184
- if (this.attrWidth) this.el.setAttribute('width', this.attrWidth.toString());
185
- if (this.attrHeight) this.el.setAttribute('height', this.attrHeight.toString());
186
- this.el.removeAttribute('style');
187
- this.originInlineStyles && this.el.setAttribute('style', this.originInlineStyles);
188
- // Remove class
189
- this.el.classList.remove('active');
190
- this.doneAnimating = true;
191
- // Remove overflow overrides on ancestors
192
- this._changedAncestorList.forEach(anchestor => anchestor.style.overflow = '');
193
- // onCloseEnd callback
194
- if (typeof this.options.onCloseEnd === 'function') {
195
- this.options.onCloseEnd.call(this, this.el);
196
- }
221
+ _animateImageOut() {
222
+ const animOptions = {
223
+ targets: this.el,
224
+ width: this.originalWidth,
225
+ height: this.originalHeight,
226
+ left: 0,
227
+ top: 0,
228
+ duration: this.options.outDuration,
229
+ easing: 'easeOutQuad',
230
+ complete: () => {
231
+ this.placeholder.style.height = '';
232
+ this.placeholder.style.width = '';
233
+ this.placeholder.style.position = '';
234
+ this.placeholder.style.top = '';
235
+ this.placeholder.style.left = '';
236
+ // Revert to width or height attribute
237
+ if (this.attrWidth) this.el.setAttribute('width', this.attrWidth.toString());
238
+ if (this.attrHeight) this.el.setAttribute('height', this.attrHeight.toString());
239
+ this.el.removeAttribute('style');
240
+ this.originInlineStyles && this.el.setAttribute('style', this.originInlineStyles);
241
+ // Remove class
242
+ this.el.classList.remove('active');
243
+ this.doneAnimating = true;
244
+ // Remove overflow overrides on ancestors
245
+ this._changedAncestorList.forEach(anchestor => anchestor.style.overflow = '');
246
+ // onCloseEnd callback
247
+ if (typeof this.options.onCloseEnd === 'function') {
248
+ this.options.onCloseEnd.call(this, this.el);
197
249
  }
198
- };
199
- anim(animOptions);
200
- }
250
+ }
251
+ };
252
+ anim(animOptions);
253
+ }
201
254
 
202
- _updateVars() {
203
- this.windowWidth = window.innerWidth;
204
- this.windowHeight = window.innerHeight;
205
- this.caption = this.el.getAttribute('data-caption') || '';
206
- }
255
+ _updateVars() {
256
+ this.windowWidth = window.innerWidth;
257
+ this.windowHeight = window.innerHeight;
258
+ this.caption = this.el.getAttribute('data-caption') || '';
259
+ }
207
260
 
208
- open() {
209
- this._updateVars();
210
- this.originalWidth = this.el.getBoundingClientRect().width;
211
- this.originalHeight = this.el.getBoundingClientRect().height;
212
- // Set states
213
- this.doneAnimating = false;
214
- this.el.classList.add('active');
215
- this.overlayActive = true;
216
- // onOpenStart callback
217
- if (typeof this.options.onOpenStart === 'function') {
218
- this.options.onOpenStart.call(this, this.el);
219
- }
220
- // Set positioning for placeholder
221
- this.placeholder.style.width = this.placeholder.getBoundingClientRect().width+'px';
222
- this.placeholder.style.height = this.placeholder.getBoundingClientRect().height+'px';
223
- this.placeholder.style.position = 'relative';
224
- this.placeholder.style.top = '0';
225
- this.placeholder.style.left = '0';
226
- this._makeAncestorsOverflowVisible();
227
- // Set css on origin
228
- this.el.style.position = 'absolute';
229
- this.el.style.zIndex = '1000';
230
- this.el.style.willChange = 'left, top, width, height';
231
- // Change from width or height attribute to css
232
- this.attrWidth = this.el.getAttribute('width');
233
- this.attrHeight = this.el.getAttribute('height');
234
- if (this.attrWidth) {
235
- this.el.style.width = this.attrWidth+'px';
236
- this.el.removeAttribute('width');
237
- }
238
- if (this.attrHeight) {
239
- this.el.style.width = this.attrHeight+'px';
240
- this.el.removeAttribute('height');
241
- }
242
- // Add overlay
243
- this._overlay = document.createElement('div');
244
- this._overlay.id = 'materialbox-overlay';
245
- this._overlay.style.opacity = '0';
246
- this._overlay.addEventListener('click', e => {
247
- if (this.doneAnimating) this.close();
248
- }, {once: true});
249
- // Put before in origin image to preserve z-index layering.
250
- this.el.before(this._overlay);
251
- // Set dimensions if needed
252
- const overlayOffset = this._overlay.getBoundingClientRect();
253
- this._overlay.style.width = this.windowWidth+'px';
254
- this._overlay.style.height = this.windowHeight+'px';
255
- this._overlay.style.left = -1 * overlayOffset.left+'px';
256
- this._overlay.style.top = -1 * overlayOffset.top+'px';
257
- anim.remove(this.el);
258
- anim.remove(this._overlay);
259
- // Animate Overlay
261
+ /**
262
+ * Open materialbox.
263
+ */
264
+ open = () => {
265
+ this._updateVars();
266
+ this.originalWidth = this.el.getBoundingClientRect().width;
267
+ this.originalHeight = this.el.getBoundingClientRect().height;
268
+ // Set states
269
+ this.doneAnimating = false;
270
+ this.el.classList.add('active');
271
+ this.overlayActive = true;
272
+ // onOpenStart callback
273
+ if (typeof this.options.onOpenStart === 'function') {
274
+ this.options.onOpenStart.call(this, this.el);
275
+ }
276
+ // Set positioning for placeholder
277
+ this.placeholder.style.width = this.placeholder.getBoundingClientRect().width+'px';
278
+ this.placeholder.style.height = this.placeholder.getBoundingClientRect().height+'px';
279
+ this.placeholder.style.position = 'relative';
280
+ this.placeholder.style.top = '0';
281
+ this.placeholder.style.left = '0';
282
+ this._makeAncestorsOverflowVisible();
283
+ // Set css on origin
284
+ this.el.style.position = 'absolute';
285
+ this.el.style.zIndex = '1000';
286
+ this.el.style.willChange = 'left, top, width, height';
287
+ // Change from width or height attribute to css
288
+ this.attrWidth = this.el.getAttribute('width');
289
+ this.attrHeight = this.el.getAttribute('height');
290
+ if (this.attrWidth) {
291
+ this.el.style.width = this.attrWidth+'px';
292
+ this.el.removeAttribute('width');
293
+ }
294
+ if (this.attrHeight) {
295
+ this.el.style.width = this.attrHeight+'px';
296
+ this.el.removeAttribute('height');
297
+ }
298
+ // Add overlay
299
+ this._overlay = document.createElement('div');
300
+ this._overlay.id = 'materialbox-overlay';
301
+ this._overlay.style.opacity = '0';
302
+ this._overlay.addEventListener('click', e => {
303
+ if (this.doneAnimating) this.close();
304
+ }, {once: true});
305
+ // Put before in origin image to preserve z-index layering.
306
+ this.el.before(this._overlay);
307
+ // Set dimensions if needed
308
+ const overlayOffset = this._overlay.getBoundingClientRect();
309
+ this._overlay.style.width = this.windowWidth+'px';
310
+ this._overlay.style.height = this.windowHeight+'px';
311
+ this._overlay.style.left = -1 * overlayOffset.left+'px';
312
+ this._overlay.style.top = -1 * overlayOffset.top+'px';
313
+ anim.remove(this.el);
314
+ anim.remove(this._overlay);
315
+ // Animate Overlay
316
+ anim({
317
+ targets: this._overlay,
318
+ opacity: 1,
319
+ duration: this.options.inDuration,
320
+ easing: 'easeOutQuad'
321
+ });
322
+ // Add and animate caption if it exists
323
+ if (this.caption !== '') {
324
+ if (this._photoCaption) anim.remove(this._photoCaption);
325
+ this._photoCaption = document.createElement('div');
326
+ this._photoCaption.classList.add('materialbox-caption');
327
+ this._photoCaption.innerText = this.caption;
328
+ document.body.append(this._photoCaption);
329
+ this._photoCaption.style.display = 'inline';
260
330
  anim({
261
- targets: this._overlay,
331
+ targets: this._photoCaption,
262
332
  opacity: 1,
263
333
  duration: this.options.inDuration,
264
334
  easing: 'easeOutQuad'
265
335
  });
266
- // Add and animate caption if it exists
267
- if (this.caption !== '') {
268
- if (this._photoCaption) anim.remove(this._photoCaption);
269
- this._photoCaption = document.createElement('div');
270
- this._photoCaption.classList.add('materialbox-caption');
271
- this._photoCaption.innerText = this.caption;
272
- document.body.append(this._photoCaption);
273
- this._photoCaption.style.display = 'inline';
274
- anim({
275
- targets: this._photoCaption,
276
- opacity: 1,
277
- duration: this.options.inDuration,
278
- easing: 'easeOutQuad'
279
- });
280
- }
281
-
282
- // Resize Image
283
- const widthPercent = this.originalWidth / this.windowWidth;
284
- const heightPercent = this.originalHeight / this.windowHeight;
285
- this.newWidth = 0;
286
- this.newHeight = 0;
287
- if (widthPercent > heightPercent) {
288
- // Width first
289
- const ratio = this.originalHeight / this.originalWidth;
290
- this.newWidth = this.windowWidth * 0.9;
291
- this.newHeight = this.windowWidth * 0.9 * ratio;
292
- }
293
- else {
294
- // Height first
295
- const ratio = this.originalWidth / this.originalHeight;
296
- this.newWidth = this.windowHeight * 0.9 * ratio;
297
- this.newHeight = this.windowHeight * 0.9;
298
- }
299
- this._animateImageIn();
336
+ }
300
337
 
301
- // Handle Exit triggers
302
- this._handleWindowScrollBound = this._handleWindowScroll.bind(this);
303
- this._handleWindowResizeBound = this._handleWindowResize.bind(this);
304
- this._handleWindowEscapeBound = this._handleWindowEscape.bind(this);
305
- window.addEventListener('scroll', this._handleWindowScrollBound);
306
- window.addEventListener('resize', this._handleWindowResizeBound);
307
- window.addEventListener('keyup', this._handleWindowEscapeBound);
338
+ // Resize Image
339
+ const widthPercent = this.originalWidth / this.windowWidth;
340
+ const heightPercent = this.originalHeight / this.windowHeight;
341
+ this.newWidth = 0;
342
+ this.newHeight = 0;
343
+ if (widthPercent > heightPercent) {
344
+ // Width first
345
+ const ratio = this.originalHeight / this.originalWidth;
346
+ this.newWidth = this.windowWidth * 0.9;
347
+ this.newHeight = this.windowWidth * 0.9 * ratio;
308
348
  }
349
+ else {
350
+ // Height first
351
+ const ratio = this.originalWidth / this.originalHeight;
352
+ this.newWidth = this.windowHeight * 0.9 * ratio;
353
+ this.newHeight = this.windowHeight * 0.9;
354
+ }
355
+ this._animateImageIn();
309
356
 
310
- close() {
311
- this._updateVars();
312
- this.doneAnimating = false;
313
- // onCloseStart callback
314
- if (typeof this.options.onCloseStart === 'function') {
315
- this.options.onCloseStart.call(this, this.el);
357
+ // Handle Exit triggers
358
+ window.addEventListener('scroll', this._handleWindowScroll);
359
+ window.addEventListener('resize', this._handleWindowResize);
360
+ window.addEventListener('keyup', this._handleWindowEscape);
361
+ }
362
+
363
+ /**
364
+ * Close materialbox.
365
+ */
366
+ close = () => {
367
+ this._updateVars();
368
+ this.doneAnimating = false;
369
+ // onCloseStart callback
370
+ if (typeof this.options.onCloseStart === 'function') {
371
+ this.options.onCloseStart.call(this, this.el);
372
+ }
373
+ anim.remove(this.el);
374
+ anim.remove(this._overlay);
375
+ if (this.caption !== '') anim.remove(this._photoCaption);
376
+ // disable exit handlers
377
+ window.removeEventListener('scroll', this._handleWindowScroll);
378
+ window.removeEventListener('resize', this._handleWindowResize);
379
+ window.removeEventListener('keyup', this._handleWindowEscape);
380
+ anim({
381
+ targets: this._overlay,
382
+ opacity: 0,
383
+ duration: this.options.outDuration,
384
+ easing: 'easeOutQuad',
385
+ complete: () => {
386
+ this.overlayActive = false;
387
+ this._overlay.remove();
316
388
  }
317
- anim.remove(this.el);
318
- anim.remove(this._overlay);
319
- if (this.caption !== '') anim.remove(this._photoCaption);
320
- // disable exit handlers
321
- window.removeEventListener('scroll', this._handleWindowScrollBound);
322
- window.removeEventListener('resize', this._handleWindowResizeBound);
323
- window.removeEventListener('keyup', this._handleWindowEscapeBound);
389
+ });
390
+ this._animateImageOut();
391
+ // Remove Caption + reset css settings on image
392
+ if (this.caption !== '') {
324
393
  anim({
325
- targets: this._overlay,
394
+ targets: this._photoCaption,
326
395
  opacity: 0,
327
396
  duration: this.options.outDuration,
328
397
  easing: 'easeOutQuad',
329
398
  complete: () => {
330
- this.overlayActive = false;
331
- this._overlay.remove();
399
+ this._photoCaption.remove();
332
400
  }
333
401
  });
334
- this._animateImageOut();
335
- // Remove Caption + reset css settings on image
336
- if (this.caption !== '') {
337
- anim({
338
- targets: this._photoCaption,
339
- opacity: 0,
340
- duration: this.options.outDuration,
341
- easing: 'easeOutQuad',
342
- complete: () => {
343
- this._photoCaption.remove();
344
- }
345
- });
346
- }
347
402
  }
348
403
  }
404
+ }