@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/scrollspy.ts
CHANGED
|
@@ -1,223 +1,263 @@
|
|
|
1
|
-
import { Component } from "./component";
|
|
2
|
-
import { M } from "./global";
|
|
3
1
|
import anim from "animejs";
|
|
4
2
|
|
|
5
|
-
|
|
3
|
+
import { Utils } from "./utils";
|
|
4
|
+
import { Component, BaseOptions, InitElements, MElement } from "./component";
|
|
5
|
+
|
|
6
|
+
export interface ScrollSpyOptions extends BaseOptions {
|
|
7
|
+
/**
|
|
8
|
+
* Throttle of scroll handler.
|
|
9
|
+
* @default 100
|
|
10
|
+
*/
|
|
11
|
+
throttle: number;
|
|
12
|
+
/**
|
|
13
|
+
* Offset for centering element when scrolled to.
|
|
14
|
+
* @default 200
|
|
15
|
+
*/
|
|
16
|
+
scrollOffset: number;
|
|
17
|
+
/**
|
|
18
|
+
* Class applied to active elements.
|
|
19
|
+
* @default 'active'
|
|
20
|
+
*/
|
|
21
|
+
activeClass: string;
|
|
22
|
+
/**
|
|
23
|
+
* Used to find active element.
|
|
24
|
+
* @default id => 'a[href="#' + id + '"]'
|
|
25
|
+
*/
|
|
26
|
+
getActiveElement: (id: string) => string;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
let _defaults: ScrollSpyOptions = {
|
|
6
30
|
throttle: 100,
|
|
7
31
|
scrollOffset: 200, // offset - 200 allows elements near bottom of page to scroll
|
|
8
32
|
activeClass: 'active',
|
|
9
33
|
getActiveElement: (id: string): string => { return 'a[href="#'+id+'"]'; }
|
|
10
34
|
};
|
|
11
35
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
private _handleThrottledResizeBound: any;
|
|
22
|
-
private _handleWindowScrollBound: any;
|
|
23
|
-
static _ticks: number;
|
|
24
|
-
|
|
25
|
-
constructor(el, options) {
|
|
26
|
-
super(ScrollSpy, el, options);
|
|
27
|
-
(this.el as any).M_ScrollSpy = this;
|
|
28
|
-
this.options = {...ScrollSpy.defaults, ...options};
|
|
29
|
-
ScrollSpy._elements.push(this);
|
|
30
|
-
ScrollSpy._count++;
|
|
31
|
-
ScrollSpy._increment++;
|
|
32
|
-
this.tickId = -1;
|
|
33
|
-
this.id = ScrollSpy._increment;
|
|
34
|
-
this._setupEventHandlers();
|
|
35
|
-
this._handleWindowScroll();
|
|
36
|
-
}
|
|
36
|
+
export class ScrollSpy extends Component<ScrollSpyOptions> {
|
|
37
|
+
static _elements: ScrollSpy[];
|
|
38
|
+
static _count: number;
|
|
39
|
+
static _increment: number;
|
|
40
|
+
tickId: number;
|
|
41
|
+
id: any;
|
|
42
|
+
static _elementsInView: ScrollSpy[];
|
|
43
|
+
static _visibleElements: any[];
|
|
44
|
+
static _ticks: number;
|
|
37
45
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
46
|
+
constructor(el: HTMLElement, options: Partial<ScrollSpyOptions>) {
|
|
47
|
+
super(el, options, ScrollSpy);
|
|
48
|
+
(this.el as any).M_ScrollSpy = this;
|
|
41
49
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
50
|
+
this.options = {
|
|
51
|
+
...ScrollSpy.defaults,
|
|
52
|
+
...options
|
|
53
|
+
};
|
|
45
54
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
55
|
+
ScrollSpy._elements.push(this);
|
|
56
|
+
ScrollSpy._count++;
|
|
57
|
+
ScrollSpy._increment++;
|
|
58
|
+
this.tickId = -1;
|
|
59
|
+
this.id = ScrollSpy._increment;
|
|
60
|
+
this._setupEventHandlers();
|
|
61
|
+
this._handleWindowScroll();
|
|
62
|
+
}
|
|
50
63
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
ScrollSpy._visibleElements.splice(ScrollSpy._visibleElements.indexOf(this.el), 1);
|
|
55
|
-
ScrollSpy._count--;
|
|
56
|
-
this._removeEventHandlers();
|
|
57
|
-
const actElem = document.querySelector(this.options.getActiveElement(this.el.id));
|
|
58
|
-
actElem.classList.remove(this.options.activeClass);
|
|
59
|
-
(this.el as any).M_ScrollSpy = undefined;
|
|
60
|
-
}
|
|
64
|
+
static get defaults(): ScrollSpyOptions {
|
|
65
|
+
return _defaults;
|
|
66
|
+
}
|
|
61
67
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
68
|
+
/**
|
|
69
|
+
* Initializes instance of ScrollSpy.
|
|
70
|
+
* @param el HTML element.
|
|
71
|
+
* @param options Component options.
|
|
72
|
+
*/
|
|
73
|
+
static init(el: HTMLElement, options?: Partial<ScrollSpyOptions>): ScrollSpy;
|
|
74
|
+
/**
|
|
75
|
+
* Initializes instances of ScrollSpy.
|
|
76
|
+
* @param els HTML elements.
|
|
77
|
+
* @param options Component options.
|
|
78
|
+
*/
|
|
79
|
+
static init(els: InitElements<MElement>, options?: Partial<ScrollSpyOptions>): ScrollSpy[];
|
|
80
|
+
/**
|
|
81
|
+
* Initializes instances of ScrollSpy.
|
|
82
|
+
* @param els HTML elements.
|
|
83
|
+
* @param options Component options.
|
|
84
|
+
*/
|
|
85
|
+
static init(els: HTMLElement | InitElements<MElement>, options: Partial<ScrollSpyOptions> = {}): ScrollSpy | ScrollSpy[] {
|
|
86
|
+
return super.init(els, options, ScrollSpy);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
static getInstance(el: HTMLElement): ScrollSpy {
|
|
90
|
+
return (el as any).M_ScrollSpy;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
destroy() {
|
|
94
|
+
ScrollSpy._elements.splice(ScrollSpy._elements.indexOf(this), 1);
|
|
95
|
+
ScrollSpy._elementsInView.splice(ScrollSpy._elementsInView.indexOf(this), 1);
|
|
96
|
+
ScrollSpy._visibleElements.splice(ScrollSpy._visibleElements.indexOf(this.el), 1);
|
|
97
|
+
ScrollSpy._count--;
|
|
98
|
+
this._removeEventHandlers();
|
|
99
|
+
const actElem = document.querySelector(this.options.getActiveElement(this.el.id));
|
|
100
|
+
actElem.classList.remove(this.options.activeClass);
|
|
101
|
+
(this.el as any).M_ScrollSpy = undefined;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
_setupEventHandlers() {
|
|
105
|
+
if (ScrollSpy._count === 1) {
|
|
106
|
+
window.addEventListener('scroll', this._handleWindowScroll);
|
|
107
|
+
window.addEventListener('resize', this._handleThrottledResize);
|
|
108
|
+
document.body.addEventListener('click', this._handleTriggerClick);
|
|
71
109
|
}
|
|
110
|
+
}
|
|
72
111
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
112
|
+
_removeEventHandlers() {
|
|
113
|
+
if (ScrollSpy._count === 0) {
|
|
114
|
+
window.removeEventListener('scroll', this._handleWindowScroll);
|
|
115
|
+
window.removeEventListener('resize', this._handleThrottledResize);
|
|
116
|
+
document.body.removeEventListener('click', this._handleTriggerClick);
|
|
79
117
|
}
|
|
118
|
+
}
|
|
80
119
|
|
|
81
|
-
|
|
82
|
-
const trigger = e.target;
|
|
83
|
-
for (let i = ScrollSpy._elements.length - 1; i >= 0; i--) {
|
|
84
|
-
const scrollspy = ScrollSpy._elements[i];
|
|
120
|
+
_handleThrottledResize: () => void = Utils.throttle(function(){ this._handleWindowScroll(); }, 200).bind(this);
|
|
85
121
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
122
|
+
_handleTriggerClick = (e: MouseEvent) => {
|
|
123
|
+
const trigger = e.target;
|
|
124
|
+
for (let i = ScrollSpy._elements.length - 1; i >= 0; i--) {
|
|
125
|
+
const scrollspy = ScrollSpy._elements[i];
|
|
90
126
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
easing: 'easeOutCubic'
|
|
96
|
-
});
|
|
127
|
+
const x = document.querySelector('a[href="#'+scrollspy.el.id+'"]');
|
|
128
|
+
if (trigger === x) {
|
|
129
|
+
e.preventDefault();
|
|
130
|
+
const offset = ScrollSpy._offset(scrollspy.el).top + 1;
|
|
97
131
|
|
|
98
|
-
|
|
99
|
-
|
|
132
|
+
anim({
|
|
133
|
+
targets: [document.documentElement, document.body],
|
|
134
|
+
scrollTop: offset - scrollspy.options.scrollOffset,
|
|
135
|
+
duration: 400,
|
|
136
|
+
easing: 'easeOutCubic'
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
break;
|
|
100
140
|
}
|
|
101
141
|
}
|
|
142
|
+
}
|
|
102
143
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
// viewport rectangle
|
|
108
|
-
let top = M.getDocumentScrollTop(),
|
|
109
|
-
left = M.getDocumentScrollLeft(),
|
|
110
|
-
right = left + window.innerWidth,
|
|
111
|
-
bottom = top + window.innerHeight;
|
|
112
|
-
|
|
113
|
-
// determine which elements are in view
|
|
114
|
-
let intersections = ScrollSpy._findElements(top, right, bottom, left);
|
|
115
|
-
for (let i = 0; i < intersections.length; i++) {
|
|
116
|
-
let scrollspy = intersections[i];
|
|
117
|
-
let lastTick = scrollspy.tickId;
|
|
118
|
-
if (lastTick < 0) {
|
|
119
|
-
// entered into view
|
|
120
|
-
scrollspy._enter();
|
|
121
|
-
}
|
|
144
|
+
_handleWindowScroll = () => {
|
|
145
|
+
// unique tick id
|
|
146
|
+
ScrollSpy._ticks++;
|
|
122
147
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
148
|
+
// viewport rectangle
|
|
149
|
+
let top = Utils.getDocumentScrollTop(),
|
|
150
|
+
left = Utils.getDocumentScrollLeft(),
|
|
151
|
+
right = left + window.innerWidth,
|
|
152
|
+
bottom = top + window.innerHeight;
|
|
126
153
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
154
|
+
// determine which elements are in view
|
|
155
|
+
let intersections = ScrollSpy._findElements(top, right, bottom, left);
|
|
156
|
+
for (let i = 0; i < intersections.length; i++) {
|
|
157
|
+
let scrollspy = intersections[i];
|
|
158
|
+
let lastTick = scrollspy.tickId;
|
|
159
|
+
if (lastTick < 0) {
|
|
160
|
+
// entered into view
|
|
161
|
+
scrollspy._enter();
|
|
135
162
|
}
|
|
136
|
-
|
|
137
|
-
|
|
163
|
+
|
|
164
|
+
// update tick id
|
|
165
|
+
scrollspy.tickId = ScrollSpy._ticks;
|
|
138
166
|
}
|
|
139
167
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
168
|
+
for (let i = 0; i < ScrollSpy._elementsInView.length; i++) {
|
|
169
|
+
let scrollspy = ScrollSpy._elementsInView[i];
|
|
170
|
+
let lastTick = scrollspy.tickId;
|
|
171
|
+
if (lastTick >= 0 && lastTick !== ScrollSpy._ticks) {
|
|
172
|
+
// exited from view
|
|
173
|
+
scrollspy._exit();
|
|
174
|
+
scrollspy.tickId = -1;
|
|
175
|
+
}
|
|
147
176
|
}
|
|
177
|
+
// remember elements in view for next tick
|
|
178
|
+
ScrollSpy._elementsInView = intersections;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
static _offset(el) {
|
|
182
|
+
const box = el.getBoundingClientRect();
|
|
183
|
+
const docElem = document.documentElement;
|
|
184
|
+
return {
|
|
185
|
+
top: box.top + window.pageYOffset - docElem.clientTop,
|
|
186
|
+
left: box.left + window.pageXOffset - docElem.clientLeft
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
static _findElements(top: number, right: number, bottom: number, left: number): ScrollSpy[] {
|
|
191
|
+
let hits = [];
|
|
192
|
+
for (let i = 0; i < ScrollSpy._elements.length; i++) {
|
|
193
|
+
let scrollspy = ScrollSpy._elements[i];
|
|
194
|
+
let currTop = top + scrollspy.options.scrollOffset || 200;
|
|
195
|
+
|
|
196
|
+
if (scrollspy.el.getBoundingClientRect().height > 0) {
|
|
197
|
+
let elTop = ScrollSpy._offset(scrollspy.el).top,
|
|
198
|
+
elLeft = ScrollSpy._offset(scrollspy.el).left,
|
|
199
|
+
elRight = elLeft + scrollspy.el.getBoundingClientRect().width,
|
|
200
|
+
elBottom = elTop + scrollspy.el.getBoundingClientRect().height;
|
|
201
|
+
|
|
202
|
+
let isIntersect = !(
|
|
203
|
+
elLeft > right ||
|
|
204
|
+
elRight < left ||
|
|
205
|
+
elTop > bottom ||
|
|
206
|
+
elBottom < currTop
|
|
207
|
+
);
|
|
148
208
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
for (let i = 0; i < ScrollSpy._elements.length; i++) {
|
|
152
|
-
let scrollspy = ScrollSpy._elements[i];
|
|
153
|
-
let currTop = top + scrollspy.options.scrollOffset || 200;
|
|
154
|
-
|
|
155
|
-
if (scrollspy.el.getBoundingClientRect().height > 0) {
|
|
156
|
-
let elTop = ScrollSpy._offset(scrollspy.el).top,
|
|
157
|
-
elLeft = ScrollSpy._offset(scrollspy.el).left,
|
|
158
|
-
elRight = elLeft + scrollspy.el.getBoundingClientRect().width,
|
|
159
|
-
elBottom = elTop + scrollspy.el.getBoundingClientRect().height;
|
|
160
|
-
|
|
161
|
-
let isIntersect = !(
|
|
162
|
-
elLeft > right ||
|
|
163
|
-
elRight < left ||
|
|
164
|
-
elTop > bottom ||
|
|
165
|
-
elBottom < currTop
|
|
166
|
-
);
|
|
167
|
-
|
|
168
|
-
if (isIntersect) {
|
|
169
|
-
hits.push(scrollspy);
|
|
170
|
-
}
|
|
209
|
+
if (isIntersect) {
|
|
210
|
+
hits.push(scrollspy);
|
|
171
211
|
}
|
|
172
212
|
}
|
|
173
|
-
return hits;
|
|
174
213
|
}
|
|
214
|
+
return hits;
|
|
215
|
+
}
|
|
175
216
|
|
|
176
|
-
|
|
177
|
-
|
|
217
|
+
_enter() {
|
|
218
|
+
ScrollSpy._visibleElements = ScrollSpy._visibleElements.filter(value => value.getBoundingClientRect().height !== 0);
|
|
178
219
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
220
|
+
if (ScrollSpy._visibleElements[0]) {
|
|
221
|
+
const actElem = document.querySelector(this.options.getActiveElement(ScrollSpy._visibleElements[0].id));
|
|
222
|
+
actElem?.classList.remove(this.options.activeClass);
|
|
182
223
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
}
|
|
186
|
-
else {
|
|
187
|
-
ScrollSpy._visibleElements.push(this.el);
|
|
188
|
-
}
|
|
224
|
+
if (ScrollSpy._visibleElements[0].M_ScrollSpy && this.id < ScrollSpy._visibleElements[0].M_ScrollSpy.id) {
|
|
225
|
+
ScrollSpy._visibleElements.unshift(this.el);
|
|
189
226
|
}
|
|
190
227
|
else {
|
|
191
228
|
ScrollSpy._visibleElements.push(this.el);
|
|
192
229
|
}
|
|
193
|
-
const selector = this.options.getActiveElement(ScrollSpy._visibleElements[0].id);
|
|
194
|
-
document.querySelector(selector)?.classList.add(this.options.activeClass);
|
|
195
230
|
}
|
|
231
|
+
else {
|
|
232
|
+
ScrollSpy._visibleElements.push(this.el);
|
|
233
|
+
}
|
|
234
|
+
const selector = this.options.getActiveElement(ScrollSpy._visibleElements[0].id);
|
|
235
|
+
document.querySelector(selector)?.classList.add(this.options.activeClass);
|
|
236
|
+
}
|
|
196
237
|
|
|
197
|
-
|
|
198
|
-
|
|
238
|
+
_exit() {
|
|
239
|
+
ScrollSpy._visibleElements = ScrollSpy._visibleElements.filter(value => value.getBoundingClientRect().height !== 0);
|
|
199
240
|
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
241
|
+
if (ScrollSpy._visibleElements[0]) {
|
|
242
|
+
const actElem = document.querySelector(this.options.getActiveElement(ScrollSpy._visibleElements[0].id));
|
|
243
|
+
actElem?.classList.remove(this.options.activeClass);
|
|
203
244
|
|
|
204
|
-
|
|
245
|
+
ScrollSpy._visibleElements = ScrollSpy._visibleElements.filter((x) => x.id != this.el.id);
|
|
205
246
|
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
}
|
|
247
|
+
if (ScrollSpy._visibleElements[0]) {
|
|
248
|
+
// Check if empty
|
|
249
|
+
const selector = this.options.getActiveElement(ScrollSpy._visibleElements[0].id);
|
|
250
|
+
document.querySelector(selector)?.classList.add(this.options.activeClass);
|
|
211
251
|
}
|
|
212
252
|
}
|
|
253
|
+
}
|
|
213
254
|
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
}
|
|
255
|
+
static {
|
|
256
|
+
ScrollSpy._elements = [];
|
|
257
|
+
ScrollSpy._elementsInView = [];
|
|
258
|
+
ScrollSpy._visibleElements = []; // Array.<cash>
|
|
259
|
+
ScrollSpy._count = 0;
|
|
260
|
+
ScrollSpy._increment = 0;
|
|
261
|
+
ScrollSpy._ticks = 0;
|
|
222
262
|
}
|
|
223
|
-
|
|
263
|
+
}
|