@materializecss/materialize 2.0.0-alpha → 2.0.2-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 +7 -4
- package/README.md +24 -12
- package/dist/css/materialize.css +90 -86
- package/dist/css/materialize.min.css +2 -2
- package/dist/js/materialize.js +2869 -2764
- package/dist/js/materialize.min.js +2 -2
- package/dist/js/materialize.min.js.map +1 -1
- package/package.json +1 -1
- package/sass/components/_collapsible.scss +0 -41
- package/sass/components/_global.scss +3 -2
- package/sass/components/_icons-material-design.scss +2 -1
- package/sass/components/_navbar.scss +6 -3
- package/sass/components/_sidenav.scss +66 -37
- package/sass/components/_theme_variables.scss +98 -0
- package/sass/components/_typography.scss +2 -2
- package/sass/components/forms/_input-fields.scss +4 -10
- package/sass/materialize.scss +0 -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 +576 -484
- package/src/edges.ts +4 -4
- package/src/forms.ts +17 -14
- package/src/global.ts +56 -325
- 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 +284 -227
- 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/materialbox.ts
CHANGED
|
@@ -1,8 +1,42 @@
|
|
|
1
|
-
import { Component } from "./component";
|
|
2
1
|
import anim from "animejs";
|
|
3
|
-
import { M } from "./global";
|
|
4
2
|
|
|
5
|
-
|
|
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
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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
|
-
|
|
56
|
-
|
|
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
|
-
|
|
60
|
-
|
|
61
|
-
|
|
94
|
+
static get defaults(): MaterialboxOptions {
|
|
95
|
+
return _defaults;
|
|
96
|
+
}
|
|
62
97
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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
|
-
|
|
69
|
-
|
|
70
|
-
|
|
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
|
-
|
|
78
|
-
|
|
79
|
-
|
|
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
|
-
|
|
83
|
-
|
|
84
|
-
|
|
132
|
+
_setupEventHandlers() {
|
|
133
|
+
this.el.addEventListener('click', this._handleMaterialboxClick);
|
|
134
|
+
}
|
|
85
135
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
this.close();
|
|
90
|
-
else
|
|
91
|
-
this.open();
|
|
92
|
-
}
|
|
136
|
+
_removeEventHandlers() {
|
|
137
|
+
this.el.removeEventListener('click', this._handleMaterialboxClick);
|
|
138
|
+
}
|
|
93
139
|
|
|
94
|
-
|
|
95
|
-
|
|
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
|
-
|
|
99
|
-
|
|
100
|
-
|
|
148
|
+
_handleWindowScroll = () => {
|
|
149
|
+
if (this.overlayActive) this.close();
|
|
150
|
+
}
|
|
101
151
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
}
|
|
152
|
+
_handleWindowResize = () => {
|
|
153
|
+
if (this.overlayActive) this.close();
|
|
154
|
+
}
|
|
106
155
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
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
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
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
|
-
|
|
130
|
-
|
|
131
|
-
|
|
182
|
+
_animateImageIn() {
|
|
183
|
+
this.el.style.maxHeight = this.newHeight.toString()+'px';
|
|
184
|
+
this.el.style.maxWidth = this.newWidth.toString()+'px';
|
|
132
185
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
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
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
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
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
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
|
-
|
|
200
|
-
|
|
250
|
+
}
|
|
251
|
+
};
|
|
252
|
+
anim(animOptions);
|
|
253
|
+
}
|
|
201
254
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
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
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
this.
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
this.
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
this.
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
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.
|
|
331
|
+
targets: this._photoCaption,
|
|
262
332
|
opacity: 1,
|
|
263
333
|
duration: this.options.inDuration,
|
|
264
334
|
easing: 'easeOutQuad'
|
|
265
335
|
});
|
|
266
|
-
|
|
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
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
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
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
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
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
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.
|
|
394
|
+
targets: this._photoCaption,
|
|
326
395
|
opacity: 0,
|
|
327
396
|
duration: this.options.outDuration,
|
|
328
397
|
easing: 'easeOutQuad',
|
|
329
398
|
complete: () => {
|
|
330
|
-
this.
|
|
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
|
+
}
|