@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/slider.js
CHANGED
|
@@ -1,359 +1,359 @@
|
|
|
1
|
-
(function($, anim) {
|
|
2
|
-
'use strict';
|
|
3
|
-
|
|
4
|
-
let _defaults = {
|
|
5
|
-
indicators: true,
|
|
6
|
-
height: 400,
|
|
7
|
-
duration: 500,
|
|
8
|
-
interval: 6000
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* @class
|
|
13
|
-
*
|
|
14
|
-
*/
|
|
15
|
-
class Slider extends Component {
|
|
16
|
-
/**
|
|
17
|
-
* Construct Slider instance and set up overlay
|
|
18
|
-
* @constructor
|
|
19
|
-
* @param {Element} el
|
|
20
|
-
* @param {Object} options
|
|
21
|
-
*/
|
|
22
|
-
constructor(el, options) {
|
|
23
|
-
super(Slider, el, options);
|
|
24
|
-
|
|
25
|
-
this.el.M_Slider = this;
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Options for the modal
|
|
29
|
-
* @member Slider#options
|
|
30
|
-
* @prop {Boolean} [indicators=true] - Show indicators
|
|
31
|
-
* @prop {Number} [height=400] - height of slider
|
|
32
|
-
* @prop {Number} [duration=500] - Length in ms of slide transition
|
|
33
|
-
* @prop {Number} [interval=6000] - Length in ms of slide interval
|
|
34
|
-
*/
|
|
35
|
-
this.options = $.extend({}, Slider.defaults, options);
|
|
36
|
-
|
|
37
|
-
// setup
|
|
38
|
-
this.$slider = this.$el.find('.slides');
|
|
39
|
-
this.$slides = this.$slider.children('li');
|
|
40
|
-
this.activeIndex = this.$slides
|
|
41
|
-
.filter(function(item) {
|
|
42
|
-
return $(item).hasClass('active');
|
|
43
|
-
})
|
|
44
|
-
.first()
|
|
45
|
-
.index();
|
|
46
|
-
if (this.activeIndex != -1) {
|
|
47
|
-
this.$active = this.$slides.eq(this.activeIndex);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
this._setSliderHeight();
|
|
51
|
-
|
|
52
|
-
// Set initial positions of captions
|
|
53
|
-
this.$slides.find('.caption').each((el) => {
|
|
54
|
-
this._animateCaptionIn(el, 0);
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
// Move img src into background-image
|
|
58
|
-
this.$slides.find('img').each((el) => {
|
|
59
|
-
let placeholderBase64 =
|
|
60
|
-
'data:image/gif;base64,R0lGODlhAQABAIABAP///wAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==';
|
|
61
|
-
if ($(el).attr('src') !== placeholderBase64) {
|
|
62
|
-
$(el).css('background-image', 'url("' + $(el).attr('src') + '")');
|
|
63
|
-
$(el).attr('src', placeholderBase64);
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
this._setupIndicators();
|
|
68
|
-
|
|
69
|
-
// Show active slide
|
|
70
|
-
if (this.$active) {
|
|
71
|
-
this.$active.css('display', 'block');
|
|
72
|
-
} else {
|
|
73
|
-
this.$slides.first().addClass('active');
|
|
74
|
-
anim({
|
|
75
|
-
targets: this.$slides.first()[0],
|
|
76
|
-
opacity: 1,
|
|
77
|
-
duration: this.options.duration,
|
|
78
|
-
easing: 'easeOutQuad'
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
this.activeIndex = 0;
|
|
82
|
-
this.$active = this.$slides.eq(this.activeIndex);
|
|
83
|
-
|
|
84
|
-
// Update indicators
|
|
85
|
-
if (this.options.indicators) {
|
|
86
|
-
this.$indicators.eq(this.activeIndex).addClass('active');
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// Adjust height to current slide
|
|
91
|
-
this.$active.find('img').each((el) => {
|
|
92
|
-
anim({
|
|
93
|
-
targets: this.$active.find('.caption')[0],
|
|
94
|
-
opacity: 1,
|
|
95
|
-
translateX: 0,
|
|
96
|
-
translateY: 0,
|
|
97
|
-
duration: this.options.duration,
|
|
98
|
-
easing: 'easeOutQuad'
|
|
99
|
-
});
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
this._setupEventHandlers();
|
|
103
|
-
|
|
104
|
-
// auto scroll
|
|
105
|
-
this.start();
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
static get defaults() {
|
|
109
|
-
return _defaults;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
static init(els, options) {
|
|
113
|
-
return super.init(this, els, options);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* Get Instance
|
|
118
|
-
*/
|
|
119
|
-
static getInstance(el) {
|
|
120
|
-
let domElem = !!el.jquery ? el[0] : el;
|
|
121
|
-
return domElem.M_Slider;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* Teardown component
|
|
126
|
-
*/
|
|
127
|
-
destroy() {
|
|
128
|
-
this.pause();
|
|
129
|
-
this._removeIndicators();
|
|
130
|
-
this._removeEventHandlers();
|
|
131
|
-
this.el.M_Slider = undefined;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
* Setup Event Handlers
|
|
136
|
-
*/
|
|
137
|
-
_setupEventHandlers() {
|
|
138
|
-
this._handleIntervalBound = this._handleInterval.bind(this);
|
|
139
|
-
this._handleIndicatorClickBound = this._handleIndicatorClick.bind(this);
|
|
140
|
-
|
|
141
|
-
if (this.options.indicators) {
|
|
142
|
-
this.$indicators.each((el) => {
|
|
143
|
-
el.addEventListener('click', this._handleIndicatorClickBound);
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
/**
|
|
149
|
-
* Remove Event Handlers
|
|
150
|
-
*/
|
|
151
|
-
_removeEventHandlers() {
|
|
152
|
-
if (this.options.indicators) {
|
|
153
|
-
this.$indicators.each((el) => {
|
|
154
|
-
el.removeEventListener('click', this._handleIndicatorClickBound);
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
/**
|
|
160
|
-
* Handle indicator click
|
|
161
|
-
* @param {Event} e
|
|
162
|
-
*/
|
|
163
|
-
_handleIndicatorClick(e) {
|
|
164
|
-
let currIndex = $(e.target).index();
|
|
165
|
-
this.set(currIndex);
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
/**
|
|
169
|
-
* Handle Interval
|
|
170
|
-
*/
|
|
171
|
-
_handleInterval() {
|
|
172
|
-
let newActiveIndex = this.$slider.find('.active').index();
|
|
173
|
-
if (this.$slides.length === newActiveIndex + 1) newActiveIndex = 0;
|
|
174
|
-
// loop to start
|
|
175
|
-
else newActiveIndex += 1;
|
|
176
|
-
|
|
177
|
-
this.set(newActiveIndex);
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
/**
|
|
181
|
-
* Animate in caption
|
|
182
|
-
* @param {Element} caption
|
|
183
|
-
* @param {Number} duration
|
|
184
|
-
*/
|
|
185
|
-
_animateCaptionIn(caption, duration) {
|
|
186
|
-
let animOptions = {
|
|
187
|
-
targets: caption,
|
|
188
|
-
opacity: 0,
|
|
189
|
-
duration: duration,
|
|
190
|
-
easing: 'easeOutQuad'
|
|
191
|
-
};
|
|
192
|
-
|
|
193
|
-
if ($(caption).hasClass('center-align')) {
|
|
194
|
-
animOptions.translateY = -100;
|
|
195
|
-
} else if ($(caption).hasClass('right-align')) {
|
|
196
|
-
animOptions.translateX = 100;
|
|
197
|
-
} else if ($(caption).hasClass('left-align')) {
|
|
198
|
-
animOptions.translateX = -100;
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
anim(animOptions);
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
/**
|
|
205
|
-
* Set height of slider
|
|
206
|
-
*/
|
|
207
|
-
_setSliderHeight() {
|
|
208
|
-
// If fullscreen, do nothing
|
|
209
|
-
if (!this.$el.hasClass('fullscreen')) {
|
|
210
|
-
if (this.options.indicators) {
|
|
211
|
-
// Add height if indicators are present
|
|
212
|
-
this.$el.css('height', this.options.height + 40 + 'px');
|
|
213
|
-
} else {
|
|
214
|
-
this.$el.css('height', this.options.height + 'px');
|
|
215
|
-
}
|
|
216
|
-
this.$slider.css('height', this.options.height + 'px');
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
/**
|
|
221
|
-
* Setup indicators
|
|
222
|
-
*/
|
|
223
|
-
_setupIndicators() {
|
|
224
|
-
if (this.options.indicators) {
|
|
225
|
-
this.$indicators = $('<ul class="indicators"></ul>');
|
|
226
|
-
this.$slides.each((el, index) => {
|
|
227
|
-
let $indicator = $('<li class="indicator-item"></li>');
|
|
228
|
-
this.$indicators.append($indicator[0]);
|
|
229
|
-
});
|
|
230
|
-
this.$el.append(this.$indicators[0]);
|
|
231
|
-
this.$indicators = this.$indicators.children('li.indicator-item');
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
/**
|
|
236
|
-
* Remove indicators
|
|
237
|
-
*/
|
|
238
|
-
_removeIndicators() {
|
|
239
|
-
this.$el.find('ul.indicators').remove();
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
/**
|
|
243
|
-
* Cycle to nth item
|
|
244
|
-
* @param {Number} index
|
|
245
|
-
*/
|
|
246
|
-
set(index) {
|
|
247
|
-
// Wrap around indices.
|
|
248
|
-
if (index >= this.$slides.length) index = 0;
|
|
249
|
-
else if (index < 0) index = this.$slides.length - 1;
|
|
250
|
-
|
|
251
|
-
// Only do if index changes
|
|
252
|
-
if (this.activeIndex != index) {
|
|
253
|
-
this.$active = this.$slides.eq(this.activeIndex);
|
|
254
|
-
let $caption = this.$active.find('.caption');
|
|
255
|
-
this.$active.removeClass('active');
|
|
256
|
-
|
|
257
|
-
anim({
|
|
258
|
-
targets: this.$active[0],
|
|
259
|
-
opacity: 0,
|
|
260
|
-
duration: this.options.duration,
|
|
261
|
-
easing: 'easeOutQuad',
|
|
262
|
-
complete: () => {
|
|
263
|
-
this.$slides.not('.active').each((el) => {
|
|
264
|
-
anim({
|
|
265
|
-
targets: el,
|
|
266
|
-
opacity: 0,
|
|
267
|
-
translateX: 0,
|
|
268
|
-
translateY: 0,
|
|
269
|
-
duration: 0,
|
|
270
|
-
easing: 'easeOutQuad'
|
|
271
|
-
});
|
|
272
|
-
});
|
|
273
|
-
}
|
|
274
|
-
});
|
|
275
|
-
|
|
276
|
-
this._animateCaptionIn($caption[0], this.options.duration);
|
|
277
|
-
|
|
278
|
-
// Update indicators
|
|
279
|
-
if (this.options.indicators) {
|
|
280
|
-
this.$indicators.eq(this.activeIndex).removeClass('active');
|
|
281
|
-
this.$indicators.eq(index).addClass('active');
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
anim({
|
|
285
|
-
targets: this.$slides.eq(index)[0],
|
|
286
|
-
opacity: 1,
|
|
287
|
-
duration: this.options.duration,
|
|
288
|
-
easing: 'easeOutQuad'
|
|
289
|
-
});
|
|
290
|
-
|
|
291
|
-
anim({
|
|
292
|
-
targets: this.$slides.eq(index).find('.caption')[0],
|
|
293
|
-
opacity: 1,
|
|
294
|
-
translateX: 0,
|
|
295
|
-
translateY: 0,
|
|
296
|
-
duration: this.options.duration,
|
|
297
|
-
delay: this.options.duration,
|
|
298
|
-
easing: 'easeOutQuad'
|
|
299
|
-
});
|
|
300
|
-
|
|
301
|
-
this.$slides.eq(index).addClass('active');
|
|
302
|
-
this.activeIndex = index;
|
|
303
|
-
|
|
304
|
-
// Reset interval
|
|
305
|
-
this.start();
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
/**
|
|
310
|
-
* Pause slider interval
|
|
311
|
-
*/
|
|
312
|
-
pause() {
|
|
313
|
-
clearInterval(this.interval);
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
/**
|
|
317
|
-
* Start slider interval
|
|
318
|
-
*/
|
|
319
|
-
start() {
|
|
320
|
-
clearInterval(this.interval);
|
|
321
|
-
this.interval = setInterval(
|
|
322
|
-
this._handleIntervalBound,
|
|
323
|
-
this.options.duration + this.options.interval
|
|
324
|
-
);
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
/**
|
|
328
|
-
* Move to next slide
|
|
329
|
-
*/
|
|
330
|
-
next() {
|
|
331
|
-
let newIndex = this.activeIndex + 1;
|
|
332
|
-
|
|
333
|
-
// Wrap around indices.
|
|
334
|
-
if (newIndex >= this.$slides.length) newIndex = 0;
|
|
335
|
-
else if (newIndex < 0) newIndex = this.$slides.length - 1;
|
|
336
|
-
|
|
337
|
-
this.set(newIndex);
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
/**
|
|
341
|
-
* Move to previous slide
|
|
342
|
-
*/
|
|
343
|
-
prev() {
|
|
344
|
-
let newIndex = this.activeIndex - 1;
|
|
345
|
-
|
|
346
|
-
// Wrap around indices.
|
|
347
|
-
if (newIndex >= this.$slides.length) newIndex = 0;
|
|
348
|
-
else if (newIndex < 0) newIndex = this.$slides.length - 1;
|
|
349
|
-
|
|
350
|
-
this.set(newIndex);
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
M.Slider = Slider;
|
|
355
|
-
|
|
356
|
-
if (M.jQueryLoaded) {
|
|
357
|
-
M.initializeJqueryWrapper(Slider, 'slider', 'M_Slider');
|
|
358
|
-
}
|
|
359
|
-
})(cash, M.anime);
|
|
1
|
+
(function($, anim) {
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
let _defaults = {
|
|
5
|
+
indicators: true,
|
|
6
|
+
height: 400,
|
|
7
|
+
duration: 500,
|
|
8
|
+
interval: 6000
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @class
|
|
13
|
+
*
|
|
14
|
+
*/
|
|
15
|
+
class Slider extends Component {
|
|
16
|
+
/**
|
|
17
|
+
* Construct Slider instance and set up overlay
|
|
18
|
+
* @constructor
|
|
19
|
+
* @param {Element} el
|
|
20
|
+
* @param {Object} options
|
|
21
|
+
*/
|
|
22
|
+
constructor(el, options) {
|
|
23
|
+
super(Slider, el, options);
|
|
24
|
+
|
|
25
|
+
this.el.M_Slider = this;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Options for the modal
|
|
29
|
+
* @member Slider#options
|
|
30
|
+
* @prop {Boolean} [indicators=true] - Show indicators
|
|
31
|
+
* @prop {Number} [height=400] - height of slider
|
|
32
|
+
* @prop {Number} [duration=500] - Length in ms of slide transition
|
|
33
|
+
* @prop {Number} [interval=6000] - Length in ms of slide interval
|
|
34
|
+
*/
|
|
35
|
+
this.options = $.extend({}, Slider.defaults, options);
|
|
36
|
+
|
|
37
|
+
// setup
|
|
38
|
+
this.$slider = this.$el.find('.slides');
|
|
39
|
+
this.$slides = this.$slider.children('li');
|
|
40
|
+
this.activeIndex = this.$slides
|
|
41
|
+
.filter(function(item) {
|
|
42
|
+
return $(item).hasClass('active');
|
|
43
|
+
})
|
|
44
|
+
.first()
|
|
45
|
+
.index();
|
|
46
|
+
if (this.activeIndex != -1) {
|
|
47
|
+
this.$active = this.$slides.eq(this.activeIndex);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
this._setSliderHeight();
|
|
51
|
+
|
|
52
|
+
// Set initial positions of captions
|
|
53
|
+
this.$slides.find('.caption').each((el) => {
|
|
54
|
+
this._animateCaptionIn(el, 0);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
// Move img src into background-image
|
|
58
|
+
this.$slides.find('img').each((el) => {
|
|
59
|
+
let placeholderBase64 =
|
|
60
|
+
'data:image/gif;base64,R0lGODlhAQABAIABAP///wAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==';
|
|
61
|
+
if ($(el).attr('src') !== placeholderBase64) {
|
|
62
|
+
$(el).css('background-image', 'url("' + $(el).attr('src') + '")');
|
|
63
|
+
$(el).attr('src', placeholderBase64);
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
this._setupIndicators();
|
|
68
|
+
|
|
69
|
+
// Show active slide
|
|
70
|
+
if (this.$active) {
|
|
71
|
+
this.$active.css('display', 'block');
|
|
72
|
+
} else {
|
|
73
|
+
this.$slides.first().addClass('active');
|
|
74
|
+
anim({
|
|
75
|
+
targets: this.$slides.first()[0],
|
|
76
|
+
opacity: 1,
|
|
77
|
+
duration: this.options.duration,
|
|
78
|
+
easing: 'easeOutQuad'
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
this.activeIndex = 0;
|
|
82
|
+
this.$active = this.$slides.eq(this.activeIndex);
|
|
83
|
+
|
|
84
|
+
// Update indicators
|
|
85
|
+
if (this.options.indicators) {
|
|
86
|
+
this.$indicators.eq(this.activeIndex).addClass('active');
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Adjust height to current slide
|
|
91
|
+
this.$active.find('img').each((el) => {
|
|
92
|
+
anim({
|
|
93
|
+
targets: this.$active.find('.caption')[0],
|
|
94
|
+
opacity: 1,
|
|
95
|
+
translateX: 0,
|
|
96
|
+
translateY: 0,
|
|
97
|
+
duration: this.options.duration,
|
|
98
|
+
easing: 'easeOutQuad'
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
this._setupEventHandlers();
|
|
103
|
+
|
|
104
|
+
// auto scroll
|
|
105
|
+
this.start();
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
static get defaults() {
|
|
109
|
+
return _defaults;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
static init(els, options) {
|
|
113
|
+
return super.init(this, els, options);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Get Instance
|
|
118
|
+
*/
|
|
119
|
+
static getInstance(el) {
|
|
120
|
+
let domElem = !!el.jquery ? el[0] : el;
|
|
121
|
+
return domElem.M_Slider;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Teardown component
|
|
126
|
+
*/
|
|
127
|
+
destroy() {
|
|
128
|
+
this.pause();
|
|
129
|
+
this._removeIndicators();
|
|
130
|
+
this._removeEventHandlers();
|
|
131
|
+
this.el.M_Slider = undefined;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Setup Event Handlers
|
|
136
|
+
*/
|
|
137
|
+
_setupEventHandlers() {
|
|
138
|
+
this._handleIntervalBound = this._handleInterval.bind(this);
|
|
139
|
+
this._handleIndicatorClickBound = this._handleIndicatorClick.bind(this);
|
|
140
|
+
|
|
141
|
+
if (this.options.indicators) {
|
|
142
|
+
this.$indicators.each((el) => {
|
|
143
|
+
el.addEventListener('click', this._handleIndicatorClickBound);
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Remove Event Handlers
|
|
150
|
+
*/
|
|
151
|
+
_removeEventHandlers() {
|
|
152
|
+
if (this.options.indicators) {
|
|
153
|
+
this.$indicators.each((el) => {
|
|
154
|
+
el.removeEventListener('click', this._handleIndicatorClickBound);
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Handle indicator click
|
|
161
|
+
* @param {Event} e
|
|
162
|
+
*/
|
|
163
|
+
_handleIndicatorClick(e) {
|
|
164
|
+
let currIndex = $(e.target).index();
|
|
165
|
+
this.set(currIndex);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Handle Interval
|
|
170
|
+
*/
|
|
171
|
+
_handleInterval() {
|
|
172
|
+
let newActiveIndex = this.$slider.find('.active').index();
|
|
173
|
+
if (this.$slides.length === newActiveIndex + 1) newActiveIndex = 0;
|
|
174
|
+
// loop to start
|
|
175
|
+
else newActiveIndex += 1;
|
|
176
|
+
|
|
177
|
+
this.set(newActiveIndex);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Animate in caption
|
|
182
|
+
* @param {Element} caption
|
|
183
|
+
* @param {Number} duration
|
|
184
|
+
*/
|
|
185
|
+
_animateCaptionIn(caption, duration) {
|
|
186
|
+
let animOptions = {
|
|
187
|
+
targets: caption,
|
|
188
|
+
opacity: 0,
|
|
189
|
+
duration: duration,
|
|
190
|
+
easing: 'easeOutQuad'
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
if ($(caption).hasClass('center-align')) {
|
|
194
|
+
animOptions.translateY = -100;
|
|
195
|
+
} else if ($(caption).hasClass('right-align')) {
|
|
196
|
+
animOptions.translateX = 100;
|
|
197
|
+
} else if ($(caption).hasClass('left-align')) {
|
|
198
|
+
animOptions.translateX = -100;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
anim(animOptions);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Set height of slider
|
|
206
|
+
*/
|
|
207
|
+
_setSliderHeight() {
|
|
208
|
+
// If fullscreen, do nothing
|
|
209
|
+
if (!this.$el.hasClass('fullscreen')) {
|
|
210
|
+
if (this.options.indicators) {
|
|
211
|
+
// Add height if indicators are present
|
|
212
|
+
this.$el.css('height', this.options.height + 40 + 'px');
|
|
213
|
+
} else {
|
|
214
|
+
this.$el.css('height', this.options.height + 'px');
|
|
215
|
+
}
|
|
216
|
+
this.$slider.css('height', this.options.height + 'px');
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Setup indicators
|
|
222
|
+
*/
|
|
223
|
+
_setupIndicators() {
|
|
224
|
+
if (this.options.indicators) {
|
|
225
|
+
this.$indicators = $('<ul class="indicators"></ul>');
|
|
226
|
+
this.$slides.each((el, index) => {
|
|
227
|
+
let $indicator = $('<li class="indicator-item"></li>');
|
|
228
|
+
this.$indicators.append($indicator[0]);
|
|
229
|
+
});
|
|
230
|
+
this.$el.append(this.$indicators[0]);
|
|
231
|
+
this.$indicators = this.$indicators.children('li.indicator-item');
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* Remove indicators
|
|
237
|
+
*/
|
|
238
|
+
_removeIndicators() {
|
|
239
|
+
this.$el.find('ul.indicators').remove();
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* Cycle to nth item
|
|
244
|
+
* @param {Number} index
|
|
245
|
+
*/
|
|
246
|
+
set(index) {
|
|
247
|
+
// Wrap around indices.
|
|
248
|
+
if (index >= this.$slides.length) index = 0;
|
|
249
|
+
else if (index < 0) index = this.$slides.length - 1;
|
|
250
|
+
|
|
251
|
+
// Only do if index changes
|
|
252
|
+
if (this.activeIndex != index) {
|
|
253
|
+
this.$active = this.$slides.eq(this.activeIndex);
|
|
254
|
+
let $caption = this.$active.find('.caption');
|
|
255
|
+
this.$active.removeClass('active');
|
|
256
|
+
|
|
257
|
+
anim({
|
|
258
|
+
targets: this.$active[0],
|
|
259
|
+
opacity: 0,
|
|
260
|
+
duration: this.options.duration,
|
|
261
|
+
easing: 'easeOutQuad',
|
|
262
|
+
complete: () => {
|
|
263
|
+
this.$slides.not('.active').each((el) => {
|
|
264
|
+
anim({
|
|
265
|
+
targets: el,
|
|
266
|
+
opacity: 0,
|
|
267
|
+
translateX: 0,
|
|
268
|
+
translateY: 0,
|
|
269
|
+
duration: 0,
|
|
270
|
+
easing: 'easeOutQuad'
|
|
271
|
+
});
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
this._animateCaptionIn($caption[0], this.options.duration);
|
|
277
|
+
|
|
278
|
+
// Update indicators
|
|
279
|
+
if (this.options.indicators) {
|
|
280
|
+
this.$indicators.eq(this.activeIndex).removeClass('active');
|
|
281
|
+
this.$indicators.eq(index).addClass('active');
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
anim({
|
|
285
|
+
targets: this.$slides.eq(index)[0],
|
|
286
|
+
opacity: 1,
|
|
287
|
+
duration: this.options.duration,
|
|
288
|
+
easing: 'easeOutQuad'
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
anim({
|
|
292
|
+
targets: this.$slides.eq(index).find('.caption')[0],
|
|
293
|
+
opacity: 1,
|
|
294
|
+
translateX: 0,
|
|
295
|
+
translateY: 0,
|
|
296
|
+
duration: this.options.duration,
|
|
297
|
+
delay: this.options.duration,
|
|
298
|
+
easing: 'easeOutQuad'
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
this.$slides.eq(index).addClass('active');
|
|
302
|
+
this.activeIndex = index;
|
|
303
|
+
|
|
304
|
+
// Reset interval
|
|
305
|
+
this.start();
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
/**
|
|
310
|
+
* Pause slider interval
|
|
311
|
+
*/
|
|
312
|
+
pause() {
|
|
313
|
+
clearInterval(this.interval);
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* Start slider interval
|
|
318
|
+
*/
|
|
319
|
+
start() {
|
|
320
|
+
clearInterval(this.interval);
|
|
321
|
+
this.interval = setInterval(
|
|
322
|
+
this._handleIntervalBound,
|
|
323
|
+
this.options.duration + this.options.interval
|
|
324
|
+
);
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
/**
|
|
328
|
+
* Move to next slide
|
|
329
|
+
*/
|
|
330
|
+
next() {
|
|
331
|
+
let newIndex = this.activeIndex + 1;
|
|
332
|
+
|
|
333
|
+
// Wrap around indices.
|
|
334
|
+
if (newIndex >= this.$slides.length) newIndex = 0;
|
|
335
|
+
else if (newIndex < 0) newIndex = this.$slides.length - 1;
|
|
336
|
+
|
|
337
|
+
this.set(newIndex);
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
/**
|
|
341
|
+
* Move to previous slide
|
|
342
|
+
*/
|
|
343
|
+
prev() {
|
|
344
|
+
let newIndex = this.activeIndex - 1;
|
|
345
|
+
|
|
346
|
+
// Wrap around indices.
|
|
347
|
+
if (newIndex >= this.$slides.length) newIndex = 0;
|
|
348
|
+
else if (newIndex < 0) newIndex = this.$slides.length - 1;
|
|
349
|
+
|
|
350
|
+
this.set(newIndex);
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
M.Slider = Slider;
|
|
355
|
+
|
|
356
|
+
if (M.jQueryLoaded) {
|
|
357
|
+
M.initializeJqueryWrapper(Slider, 'slider', 'M_Slider');
|
|
358
|
+
}
|
|
359
|
+
})(cash, M.anime);
|