@materializecss/materialize 1.2.0 → 1.2.1
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 +722 -712
- package/LICENSE +21 -21
- package/README.md +91 -91
- package/dist/css/materialize.css +68 -135
- package/dist/css/materialize.min.css +12 -12
- package/dist/js/materialize.js +1112 -1112
- package/dist/js/materialize.min.js +6 -6
- package/extras/noUiSlider/nouislider.css +403 -403
- package/extras/noUiSlider/nouislider.js +2147 -2147
- package/js/anime.min.js +34 -34
- package/js/autocomplete.js +479 -479
- package/js/buttons.js +354 -354
- package/js/cards.js +40 -40
- package/js/carousel.js +732 -732
- package/js/cash.js +960 -960
- package/js/characterCounter.js +136 -136
- package/js/chips.js +486 -486
- package/js/collapsible.js +275 -275
- package/js/component.js +44 -44
- package/js/datepicker.js +983 -983
- package/js/dropdown.js +669 -669
- package/js/forms.js +285 -285
- package/js/global.js +428 -428
- package/js/materialbox.js +453 -453
- package/js/modal.js +382 -382
- package/js/parallax.js +138 -138
- package/js/pushpin.js +148 -148
- package/js/range.js +263 -263
- package/js/scrollspy.js +295 -295
- package/js/select.js +391 -391
- package/js/sidenav.js +583 -583
- package/js/slider.js +359 -359
- package/js/tabs.js +402 -402
- package/js/tapTarget.js +315 -315
- package/js/timepicker.js +712 -712
- package/js/toasts.js +325 -325
- package/js/tooltip.js +320 -320
- package/js/waves.js +614 -614
- package/package.json +87 -84
- package/sass/_style.scss +929 -929
- package/sass/components/_badges.scss +55 -55
- package/sass/components/_buttons.scss +322 -322
- package/sass/components/_cards.scss +195 -195
- package/sass/components/_carousel.scss +90 -90
- package/sass/components/_chips.scss +96 -96
- package/sass/components/_collapsible.scss +91 -91
- package/sass/components/_collection.scss +106 -106
- package/sass/components/_color-classes.scss +32 -32
- package/sass/components/_color-variables.scss +370 -370
- package/sass/components/_datepicker.scss +191 -191
- package/sass/components/_dropdown.scss +84 -84
- package/sass/components/_global.scss +646 -646
- package/sass/components/_grid.scss +158 -158
- package/sass/components/_icons-material-design.scss +5 -5
- package/sass/components/_materialbox.scss +42 -42
- package/sass/components/_modal.scss +97 -97
- package/sass/components/_navbar.scss +208 -208
- package/sass/components/_normalize.scss +447 -447
- package/sass/components/_preloader.scss +334 -334
- package/sass/components/_pulse.scss +34 -34
- package/sass/components/_sidenav.scss +214 -214
- package/sass/components/_slider.scss +91 -91
- package/sass/components/_table_of_contents.scss +33 -33
- package/sass/components/_tabs.scss +99 -99
- package/sass/components/_tapTarget.scss +103 -103
- package/sass/components/_timepicker.scss +199 -199
- package/sass/components/_toast.scss +58 -58
- package/sass/components/_tooltip.scss +32 -32
- package/sass/components/_transitions.scss +12 -12
- package/sass/components/_typography.scss +62 -62
- package/sass/components/_variables.scss +352 -352
- package/sass/components/_waves.scss +187 -187
- package/sass/components/forms/_checkboxes.scss +200 -200
- package/sass/components/forms/_file-input.scss +44 -44
- package/sass/components/forms/_forms.scss +22 -22
- package/sass/components/forms/_input-fields.scss +388 -388
- package/sass/components/forms/_radio-buttons.scss +115 -115
- package/sass/components/forms/_range.scss +161 -161
- package/sass/components/forms/_select.scss +199 -199
- package/sass/components/forms/_switches.scss +91 -91
- package/sass/ghpages-materialize.scss +7 -7
- package/sass/materialize.scss +42 -42
package/js/scrollspy.js
CHANGED
|
@@ -1,295 +1,295 @@
|
|
|
1
|
-
(function($, anim) {
|
|
2
|
-
'use strict';
|
|
3
|
-
|
|
4
|
-
let _defaults = {
|
|
5
|
-
throttle: 100,
|
|
6
|
-
scrollOffset: 200, // offset - 200 allows elements near bottom of page to scroll
|
|
7
|
-
activeClass: 'active',
|
|
8
|
-
getActiveElement: function(id) {
|
|
9
|
-
return 'a[href="#' + id + '"]';
|
|
10
|
-
}
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* @class
|
|
15
|
-
*
|
|
16
|
-
*/
|
|
17
|
-
class ScrollSpy extends Component {
|
|
18
|
-
/**
|
|
19
|
-
* Construct ScrollSpy instance
|
|
20
|
-
* @constructor
|
|
21
|
-
* @param {Element} el
|
|
22
|
-
* @param {Object} options
|
|
23
|
-
*/
|
|
24
|
-
constructor(el, options) {
|
|
25
|
-
super(ScrollSpy, el, options);
|
|
26
|
-
|
|
27
|
-
this.el.M_ScrollSpy = this;
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Options for the modal
|
|
31
|
-
* @member Modal#options
|
|
32
|
-
* @prop {Number} [throttle=100] - Throttle of scroll handler
|
|
33
|
-
* @prop {Number} [scrollOffset=200] - Offset for centering element when scrolled to
|
|
34
|
-
* @prop {String} [activeClass='active'] - Class applied to active elements
|
|
35
|
-
* @prop {Function} [getActiveElement] - Used to find active element
|
|
36
|
-
*/
|
|
37
|
-
this.options = $.extend({}, ScrollSpy.defaults, options);
|
|
38
|
-
|
|
39
|
-
// setup
|
|
40
|
-
ScrollSpy._elements.push(this);
|
|
41
|
-
ScrollSpy._count++;
|
|
42
|
-
ScrollSpy._increment++;
|
|
43
|
-
this.tickId = -1;
|
|
44
|
-
this.id = ScrollSpy._increment;
|
|
45
|
-
this._setupEventHandlers();
|
|
46
|
-
this._handleWindowScroll();
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
static get defaults() {
|
|
50
|
-
return _defaults;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
static init(els, options) {
|
|
54
|
-
return super.init(this, els, options);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Get Instance
|
|
59
|
-
*/
|
|
60
|
-
static getInstance(el) {
|
|
61
|
-
let domElem = !!el.jquery ? el[0] : el;
|
|
62
|
-
return domElem.M_ScrollSpy;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Teardown component
|
|
67
|
-
*/
|
|
68
|
-
destroy() {
|
|
69
|
-
ScrollSpy._elements.splice(ScrollSpy._elements.indexOf(this), 1);
|
|
70
|
-
ScrollSpy._elementsInView.splice(ScrollSpy._elementsInView.indexOf(this), 1);
|
|
71
|
-
ScrollSpy._visibleElements.splice(ScrollSpy._visibleElements.indexOf(this.$el), 1);
|
|
72
|
-
ScrollSpy._count--;
|
|
73
|
-
this._removeEventHandlers();
|
|
74
|
-
$(this.options.getActiveElement(this.$el.attr('id'))).removeClass(this.options.activeClass);
|
|
75
|
-
this.el.M_ScrollSpy = undefined;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Setup Event Handlers
|
|
80
|
-
*/
|
|
81
|
-
_setupEventHandlers() {
|
|
82
|
-
let throttledResize = M.throttle(this._handleWindowScroll, 200);
|
|
83
|
-
this._handleThrottledResizeBound = throttledResize.bind(this);
|
|
84
|
-
this._handleWindowScrollBound = this._handleWindowScroll.bind(this);
|
|
85
|
-
if (ScrollSpy._count === 1) {
|
|
86
|
-
window.addEventListener('scroll', this._handleWindowScrollBound);
|
|
87
|
-
window.addEventListener('resize', this._handleThrottledResizeBound);
|
|
88
|
-
document.body.addEventListener('click', this._handleTriggerClick);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Remove Event Handlers
|
|
94
|
-
*/
|
|
95
|
-
_removeEventHandlers() {
|
|
96
|
-
if (ScrollSpy._count === 0) {
|
|
97
|
-
window.removeEventListener('scroll', this._handleWindowScrollBound);
|
|
98
|
-
window.removeEventListener('resize', this._handleThrottledResizeBound);
|
|
99
|
-
document.body.removeEventListener('click', this._handleTriggerClick);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* Handle Trigger Click
|
|
105
|
-
* @param {Event} e
|
|
106
|
-
*/
|
|
107
|
-
_handleTriggerClick(e) {
|
|
108
|
-
let $trigger = $(e.target);
|
|
109
|
-
for (let i = ScrollSpy._elements.length - 1; i >= 0; i--) {
|
|
110
|
-
let scrollspy = ScrollSpy._elements[i];
|
|
111
|
-
if ($trigger.is('a[href="#' + scrollspy.$el.attr('id') + '"]')) {
|
|
112
|
-
e.preventDefault();
|
|
113
|
-
let offset = scrollspy.$el.offset().top + 1;
|
|
114
|
-
|
|
115
|
-
anim({
|
|
116
|
-
targets: [document.documentElement, document.body],
|
|
117
|
-
scrollTop: offset - scrollspy.options.scrollOffset,
|
|
118
|
-
duration: 400,
|
|
119
|
-
easing: 'easeOutCubic'
|
|
120
|
-
});
|
|
121
|
-
break;
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* Handle Window Scroll
|
|
128
|
-
*/
|
|
129
|
-
_handleWindowScroll() {
|
|
130
|
-
// unique tick id
|
|
131
|
-
ScrollSpy._ticks++;
|
|
132
|
-
|
|
133
|
-
// viewport rectangle
|
|
134
|
-
let top = M.getDocumentScrollTop(),
|
|
135
|
-
left = M.getDocumentScrollLeft(),
|
|
136
|
-
right = left + window.innerWidth,
|
|
137
|
-
bottom = top + window.innerHeight;
|
|
138
|
-
|
|
139
|
-
// determine which elements are in view
|
|
140
|
-
let intersections = ScrollSpy._findElements(top, right, bottom, left);
|
|
141
|
-
for (let i = 0; i < intersections.length; i++) {
|
|
142
|
-
let scrollspy = intersections[i];
|
|
143
|
-
let lastTick = scrollspy.tickId;
|
|
144
|
-
if (lastTick < 0) {
|
|
145
|
-
// entered into view
|
|
146
|
-
scrollspy._enter();
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
// update tick id
|
|
150
|
-
scrollspy.tickId = ScrollSpy._ticks;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
for (let i = 0; i < ScrollSpy._elementsInView.length; i++) {
|
|
154
|
-
let scrollspy = ScrollSpy._elementsInView[i];
|
|
155
|
-
let lastTick = scrollspy.tickId;
|
|
156
|
-
if (lastTick >= 0 && lastTick !== ScrollSpy._ticks) {
|
|
157
|
-
// exited from view
|
|
158
|
-
scrollspy._exit();
|
|
159
|
-
scrollspy.tickId = -1;
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
// remember elements in view for next tick
|
|
164
|
-
ScrollSpy._elementsInView = intersections;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
* Find elements that are within the boundary
|
|
169
|
-
* @param {number} top
|
|
170
|
-
* @param {number} right
|
|
171
|
-
* @param {number} bottom
|
|
172
|
-
* @param {number} left
|
|
173
|
-
* @return {Array.<ScrollSpy>} A collection of elements
|
|
174
|
-
*/
|
|
175
|
-
static _findElements(top, right, bottom, left) {
|
|
176
|
-
let hits = [];
|
|
177
|
-
for (let i = 0; i < ScrollSpy._elements.length; i++) {
|
|
178
|
-
let scrollspy = ScrollSpy._elements[i];
|
|
179
|
-
let currTop = top + scrollspy.options.scrollOffset || 200;
|
|
180
|
-
|
|
181
|
-
if (scrollspy.$el.height() > 0) {
|
|
182
|
-
let elTop = scrollspy.$el.offset().top,
|
|
183
|
-
elLeft = scrollspy.$el.offset().left,
|
|
184
|
-
elRight = elLeft + scrollspy.$el.width(),
|
|
185
|
-
elBottom = elTop + scrollspy.$el.height();
|
|
186
|
-
|
|
187
|
-
let isIntersect = !(
|
|
188
|
-
elLeft > right ||
|
|
189
|
-
elRight < left ||
|
|
190
|
-
elTop > bottom ||
|
|
191
|
-
elBottom < currTop
|
|
192
|
-
);
|
|
193
|
-
|
|
194
|
-
if (isIntersect) {
|
|
195
|
-
hits.push(scrollspy);
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
return hits;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
_enter() {
|
|
203
|
-
ScrollSpy._visibleElements = ScrollSpy._visibleElements.filter(function(value) {
|
|
204
|
-
return value.height() != 0;
|
|
205
|
-
});
|
|
206
|
-
|
|
207
|
-
if (ScrollSpy._visibleElements[0]) {
|
|
208
|
-
$(this.options.getActiveElement(ScrollSpy._visibleElements[0].attr('id'))).removeClass(
|
|
209
|
-
this.options.activeClass
|
|
210
|
-
);
|
|
211
|
-
if (
|
|
212
|
-
ScrollSpy._visibleElements[0][0].M_ScrollSpy &&
|
|
213
|
-
this.id < ScrollSpy._visibleElements[0][0].M_ScrollSpy.id
|
|
214
|
-
) {
|
|
215
|
-
ScrollSpy._visibleElements.unshift(this.$el);
|
|
216
|
-
} else {
|
|
217
|
-
ScrollSpy._visibleElements.push(this.$el);
|
|
218
|
-
}
|
|
219
|
-
} else {
|
|
220
|
-
ScrollSpy._visibleElements.push(this.$el);
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
$(this.options.getActiveElement(ScrollSpy._visibleElements[0].attr('id'))).addClass(
|
|
224
|
-
this.options.activeClass
|
|
225
|
-
);
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
_exit() {
|
|
229
|
-
ScrollSpy._visibleElements = ScrollSpy._visibleElements.filter(function(value) {
|
|
230
|
-
return value.height() != 0;
|
|
231
|
-
});
|
|
232
|
-
|
|
233
|
-
if (ScrollSpy._visibleElements[0]) {
|
|
234
|
-
$(this.options.getActiveElement(ScrollSpy._visibleElements[0].attr('id'))).removeClass(
|
|
235
|
-
this.options.activeClass
|
|
236
|
-
);
|
|
237
|
-
|
|
238
|
-
ScrollSpy._visibleElements = ScrollSpy._visibleElements.filter((el) => {
|
|
239
|
-
return el.attr('id') != this.$el.attr('id');
|
|
240
|
-
});
|
|
241
|
-
if (ScrollSpy._visibleElements[0]) {
|
|
242
|
-
// Check if empty
|
|
243
|
-
$(this.options.getActiveElement(ScrollSpy._visibleElements[0].attr('id'))).addClass(
|
|
244
|
-
this.options.activeClass
|
|
245
|
-
);
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
/**
|
|
252
|
-
* @static
|
|
253
|
-
* @memberof ScrollSpy
|
|
254
|
-
* @type {Array.<ScrollSpy>}
|
|
255
|
-
*/
|
|
256
|
-
ScrollSpy._elements = [];
|
|
257
|
-
|
|
258
|
-
/**
|
|
259
|
-
* @static
|
|
260
|
-
* @memberof ScrollSpy
|
|
261
|
-
* @type {Array.<ScrollSpy>}
|
|
262
|
-
*/
|
|
263
|
-
ScrollSpy._elementsInView = [];
|
|
264
|
-
|
|
265
|
-
/**
|
|
266
|
-
* @static
|
|
267
|
-
* @memberof ScrollSpy
|
|
268
|
-
* @type {Array.<cash>}
|
|
269
|
-
*/
|
|
270
|
-
ScrollSpy._visibleElements = [];
|
|
271
|
-
|
|
272
|
-
/**
|
|
273
|
-
* @static
|
|
274
|
-
* @memberof ScrollSpy
|
|
275
|
-
*/
|
|
276
|
-
ScrollSpy._count = 0;
|
|
277
|
-
|
|
278
|
-
/**
|
|
279
|
-
* @static
|
|
280
|
-
* @memberof ScrollSpy
|
|
281
|
-
*/
|
|
282
|
-
ScrollSpy._increment = 0;
|
|
283
|
-
|
|
284
|
-
/**
|
|
285
|
-
* @static
|
|
286
|
-
* @memberof ScrollSpy
|
|
287
|
-
*/
|
|
288
|
-
ScrollSpy._ticks = 0;
|
|
289
|
-
|
|
290
|
-
M.ScrollSpy = ScrollSpy;
|
|
291
|
-
|
|
292
|
-
if (M.jQueryLoaded) {
|
|
293
|
-
M.initializeJqueryWrapper(ScrollSpy, 'scrollSpy', 'M_ScrollSpy');
|
|
294
|
-
}
|
|
295
|
-
})(cash, M.anime);
|
|
1
|
+
(function($, anim) {
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
let _defaults = {
|
|
5
|
+
throttle: 100,
|
|
6
|
+
scrollOffset: 200, // offset - 200 allows elements near bottom of page to scroll
|
|
7
|
+
activeClass: 'active',
|
|
8
|
+
getActiveElement: function(id) {
|
|
9
|
+
return 'a[href="#' + id + '"]';
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @class
|
|
15
|
+
*
|
|
16
|
+
*/
|
|
17
|
+
class ScrollSpy extends Component {
|
|
18
|
+
/**
|
|
19
|
+
* Construct ScrollSpy instance
|
|
20
|
+
* @constructor
|
|
21
|
+
* @param {Element} el
|
|
22
|
+
* @param {Object} options
|
|
23
|
+
*/
|
|
24
|
+
constructor(el, options) {
|
|
25
|
+
super(ScrollSpy, el, options);
|
|
26
|
+
|
|
27
|
+
this.el.M_ScrollSpy = this;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Options for the modal
|
|
31
|
+
* @member Modal#options
|
|
32
|
+
* @prop {Number} [throttle=100] - Throttle of scroll handler
|
|
33
|
+
* @prop {Number} [scrollOffset=200] - Offset for centering element when scrolled to
|
|
34
|
+
* @prop {String} [activeClass='active'] - Class applied to active elements
|
|
35
|
+
* @prop {Function} [getActiveElement] - Used to find active element
|
|
36
|
+
*/
|
|
37
|
+
this.options = $.extend({}, ScrollSpy.defaults, options);
|
|
38
|
+
|
|
39
|
+
// setup
|
|
40
|
+
ScrollSpy._elements.push(this);
|
|
41
|
+
ScrollSpy._count++;
|
|
42
|
+
ScrollSpy._increment++;
|
|
43
|
+
this.tickId = -1;
|
|
44
|
+
this.id = ScrollSpy._increment;
|
|
45
|
+
this._setupEventHandlers();
|
|
46
|
+
this._handleWindowScroll();
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
static get defaults() {
|
|
50
|
+
return _defaults;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
static init(els, options) {
|
|
54
|
+
return super.init(this, els, options);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Get Instance
|
|
59
|
+
*/
|
|
60
|
+
static getInstance(el) {
|
|
61
|
+
let domElem = !!el.jquery ? el[0] : el;
|
|
62
|
+
return domElem.M_ScrollSpy;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Teardown component
|
|
67
|
+
*/
|
|
68
|
+
destroy() {
|
|
69
|
+
ScrollSpy._elements.splice(ScrollSpy._elements.indexOf(this), 1);
|
|
70
|
+
ScrollSpy._elementsInView.splice(ScrollSpy._elementsInView.indexOf(this), 1);
|
|
71
|
+
ScrollSpy._visibleElements.splice(ScrollSpy._visibleElements.indexOf(this.$el), 1);
|
|
72
|
+
ScrollSpy._count--;
|
|
73
|
+
this._removeEventHandlers();
|
|
74
|
+
$(this.options.getActiveElement(this.$el.attr('id'))).removeClass(this.options.activeClass);
|
|
75
|
+
this.el.M_ScrollSpy = undefined;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Setup Event Handlers
|
|
80
|
+
*/
|
|
81
|
+
_setupEventHandlers() {
|
|
82
|
+
let throttledResize = M.throttle(this._handleWindowScroll, 200);
|
|
83
|
+
this._handleThrottledResizeBound = throttledResize.bind(this);
|
|
84
|
+
this._handleWindowScrollBound = this._handleWindowScroll.bind(this);
|
|
85
|
+
if (ScrollSpy._count === 1) {
|
|
86
|
+
window.addEventListener('scroll', this._handleWindowScrollBound);
|
|
87
|
+
window.addEventListener('resize', this._handleThrottledResizeBound);
|
|
88
|
+
document.body.addEventListener('click', this._handleTriggerClick);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Remove Event Handlers
|
|
94
|
+
*/
|
|
95
|
+
_removeEventHandlers() {
|
|
96
|
+
if (ScrollSpy._count === 0) {
|
|
97
|
+
window.removeEventListener('scroll', this._handleWindowScrollBound);
|
|
98
|
+
window.removeEventListener('resize', this._handleThrottledResizeBound);
|
|
99
|
+
document.body.removeEventListener('click', this._handleTriggerClick);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Handle Trigger Click
|
|
105
|
+
* @param {Event} e
|
|
106
|
+
*/
|
|
107
|
+
_handleTriggerClick(e) {
|
|
108
|
+
let $trigger = $(e.target);
|
|
109
|
+
for (let i = ScrollSpy._elements.length - 1; i >= 0; i--) {
|
|
110
|
+
let scrollspy = ScrollSpy._elements[i];
|
|
111
|
+
if ($trigger.is('a[href="#' + scrollspy.$el.attr('id') + '"]')) {
|
|
112
|
+
e.preventDefault();
|
|
113
|
+
let offset = scrollspy.$el.offset().top + 1;
|
|
114
|
+
|
|
115
|
+
anim({
|
|
116
|
+
targets: [document.documentElement, document.body],
|
|
117
|
+
scrollTop: offset - scrollspy.options.scrollOffset,
|
|
118
|
+
duration: 400,
|
|
119
|
+
easing: 'easeOutCubic'
|
|
120
|
+
});
|
|
121
|
+
break;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Handle Window Scroll
|
|
128
|
+
*/
|
|
129
|
+
_handleWindowScroll() {
|
|
130
|
+
// unique tick id
|
|
131
|
+
ScrollSpy._ticks++;
|
|
132
|
+
|
|
133
|
+
// viewport rectangle
|
|
134
|
+
let top = M.getDocumentScrollTop(),
|
|
135
|
+
left = M.getDocumentScrollLeft(),
|
|
136
|
+
right = left + window.innerWidth,
|
|
137
|
+
bottom = top + window.innerHeight;
|
|
138
|
+
|
|
139
|
+
// determine which elements are in view
|
|
140
|
+
let intersections = ScrollSpy._findElements(top, right, bottom, left);
|
|
141
|
+
for (let i = 0; i < intersections.length; i++) {
|
|
142
|
+
let scrollspy = intersections[i];
|
|
143
|
+
let lastTick = scrollspy.tickId;
|
|
144
|
+
if (lastTick < 0) {
|
|
145
|
+
// entered into view
|
|
146
|
+
scrollspy._enter();
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// update tick id
|
|
150
|
+
scrollspy.tickId = ScrollSpy._ticks;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
for (let i = 0; i < ScrollSpy._elementsInView.length; i++) {
|
|
154
|
+
let scrollspy = ScrollSpy._elementsInView[i];
|
|
155
|
+
let lastTick = scrollspy.tickId;
|
|
156
|
+
if (lastTick >= 0 && lastTick !== ScrollSpy._ticks) {
|
|
157
|
+
// exited from view
|
|
158
|
+
scrollspy._exit();
|
|
159
|
+
scrollspy.tickId = -1;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// remember elements in view for next tick
|
|
164
|
+
ScrollSpy._elementsInView = intersections;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Find elements that are within the boundary
|
|
169
|
+
* @param {number} top
|
|
170
|
+
* @param {number} right
|
|
171
|
+
* @param {number} bottom
|
|
172
|
+
* @param {number} left
|
|
173
|
+
* @return {Array.<ScrollSpy>} A collection of elements
|
|
174
|
+
*/
|
|
175
|
+
static _findElements(top, right, bottom, left) {
|
|
176
|
+
let hits = [];
|
|
177
|
+
for (let i = 0; i < ScrollSpy._elements.length; i++) {
|
|
178
|
+
let scrollspy = ScrollSpy._elements[i];
|
|
179
|
+
let currTop = top + scrollspy.options.scrollOffset || 200;
|
|
180
|
+
|
|
181
|
+
if (scrollspy.$el.height() > 0) {
|
|
182
|
+
let elTop = scrollspy.$el.offset().top,
|
|
183
|
+
elLeft = scrollspy.$el.offset().left,
|
|
184
|
+
elRight = elLeft + scrollspy.$el.width(),
|
|
185
|
+
elBottom = elTop + scrollspy.$el.height();
|
|
186
|
+
|
|
187
|
+
let isIntersect = !(
|
|
188
|
+
elLeft > right ||
|
|
189
|
+
elRight < left ||
|
|
190
|
+
elTop > bottom ||
|
|
191
|
+
elBottom < currTop
|
|
192
|
+
);
|
|
193
|
+
|
|
194
|
+
if (isIntersect) {
|
|
195
|
+
hits.push(scrollspy);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
return hits;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
_enter() {
|
|
203
|
+
ScrollSpy._visibleElements = ScrollSpy._visibleElements.filter(function(value) {
|
|
204
|
+
return value.height() != 0;
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
if (ScrollSpy._visibleElements[0]) {
|
|
208
|
+
$(this.options.getActiveElement(ScrollSpy._visibleElements[0].attr('id'))).removeClass(
|
|
209
|
+
this.options.activeClass
|
|
210
|
+
);
|
|
211
|
+
if (
|
|
212
|
+
ScrollSpy._visibleElements[0][0].M_ScrollSpy &&
|
|
213
|
+
this.id < ScrollSpy._visibleElements[0][0].M_ScrollSpy.id
|
|
214
|
+
) {
|
|
215
|
+
ScrollSpy._visibleElements.unshift(this.$el);
|
|
216
|
+
} else {
|
|
217
|
+
ScrollSpy._visibleElements.push(this.$el);
|
|
218
|
+
}
|
|
219
|
+
} else {
|
|
220
|
+
ScrollSpy._visibleElements.push(this.$el);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
$(this.options.getActiveElement(ScrollSpy._visibleElements[0].attr('id'))).addClass(
|
|
224
|
+
this.options.activeClass
|
|
225
|
+
);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
_exit() {
|
|
229
|
+
ScrollSpy._visibleElements = ScrollSpy._visibleElements.filter(function(value) {
|
|
230
|
+
return value.height() != 0;
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
if (ScrollSpy._visibleElements[0]) {
|
|
234
|
+
$(this.options.getActiveElement(ScrollSpy._visibleElements[0].attr('id'))).removeClass(
|
|
235
|
+
this.options.activeClass
|
|
236
|
+
);
|
|
237
|
+
|
|
238
|
+
ScrollSpy._visibleElements = ScrollSpy._visibleElements.filter((el) => {
|
|
239
|
+
return el.attr('id') != this.$el.attr('id');
|
|
240
|
+
});
|
|
241
|
+
if (ScrollSpy._visibleElements[0]) {
|
|
242
|
+
// Check if empty
|
|
243
|
+
$(this.options.getActiveElement(ScrollSpy._visibleElements[0].attr('id'))).addClass(
|
|
244
|
+
this.options.activeClass
|
|
245
|
+
);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* @static
|
|
253
|
+
* @memberof ScrollSpy
|
|
254
|
+
* @type {Array.<ScrollSpy>}
|
|
255
|
+
*/
|
|
256
|
+
ScrollSpy._elements = [];
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* @static
|
|
260
|
+
* @memberof ScrollSpy
|
|
261
|
+
* @type {Array.<ScrollSpy>}
|
|
262
|
+
*/
|
|
263
|
+
ScrollSpy._elementsInView = [];
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* @static
|
|
267
|
+
* @memberof ScrollSpy
|
|
268
|
+
* @type {Array.<cash>}
|
|
269
|
+
*/
|
|
270
|
+
ScrollSpy._visibleElements = [];
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* @static
|
|
274
|
+
* @memberof ScrollSpy
|
|
275
|
+
*/
|
|
276
|
+
ScrollSpy._count = 0;
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* @static
|
|
280
|
+
* @memberof ScrollSpy
|
|
281
|
+
*/
|
|
282
|
+
ScrollSpy._increment = 0;
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* @static
|
|
286
|
+
* @memberof ScrollSpy
|
|
287
|
+
*/
|
|
288
|
+
ScrollSpy._ticks = 0;
|
|
289
|
+
|
|
290
|
+
M.ScrollSpy = ScrollSpy;
|
|
291
|
+
|
|
292
|
+
if (M.jQueryLoaded) {
|
|
293
|
+
M.initializeJqueryWrapper(ScrollSpy, 'scrollSpy', 'M_ScrollSpy');
|
|
294
|
+
}
|
|
295
|
+
})(cash, M.anime);
|