@materializecss/materialize 1.2.2 → 2.0.1-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 (90) hide show
  1. package/Gruntfile.js +68 -313
  2. package/README.md +26 -14
  3. package/dist/css/materialize.css +1009 -1822
  4. package/dist/css/materialize.min.css +2 -8
  5. package/dist/js/materialize.js +8414 -12299
  6. package/dist/js/materialize.min.js +8968 -2
  7. package/dist/js/materialize.min.js.map +1 -0
  8. package/package.json +13 -9
  9. package/sass/components/_badges.scss +12 -2
  10. package/sass/components/_buttons.scss +16 -11
  11. package/sass/components/_cards.scss +14 -9
  12. package/sass/components/_carousel.scss +5 -2
  13. package/sass/components/_chips.scss +3 -3
  14. package/sass/components/_collapsible.scss +22 -8
  15. package/sass/components/_collection.scss +14 -6
  16. package/sass/components/_datepicker.scss +30 -11
  17. package/sass/components/_dropdown.scss +6 -4
  18. package/sass/components/_global.scss +132 -111
  19. package/sass/components/_grid.scss +119 -98
  20. package/sass/components/_modal.scss +3 -3
  21. package/sass/components/_navbar.scss +31 -17
  22. package/sass/components/_normalize.scss +26 -124
  23. package/sass/components/_sidenav.scss +21 -20
  24. package/sass/components/_slider.scss +27 -7
  25. package/sass/components/_table_of_contents.scss +12 -12
  26. package/sass/components/_tabs.scss +47 -16
  27. package/sass/components/_tapTarget.scss +6 -6
  28. package/sass/components/_theme_variables.scss +98 -0
  29. package/sass/components/_timepicker.scss +54 -46
  30. package/sass/components/_toast.scss +3 -3
  31. package/sass/components/_tooltip.scss +4 -5
  32. package/sass/components/_typography.scss +1 -1
  33. package/sass/components/_variables.scss +185 -120
  34. package/sass/components/forms/_checkboxes.scss +9 -9
  35. package/sass/components/forms/_file-input.scss +9 -7
  36. package/sass/components/forms/_input-fields.scss +173 -234
  37. package/sass/components/forms/_radio-buttons.scss +1 -1
  38. package/sass/components/forms/_range.scss +11 -11
  39. package/sass/components/forms/_select.scss +29 -19
  40. package/sass/components/forms/_switches.scss +22 -18
  41. package/sass/materialize.scss +1 -1
  42. package/src/autocomplete.ts +459 -0
  43. package/src/bounding.ts +6 -0
  44. package/{js/buttons.js → src/buttons.ts} +103 -162
  45. package/src/cards.ts +54 -0
  46. package/{js/carousel.js → src/carousel.ts} +137 -262
  47. package/src/characterCounter.ts +88 -0
  48. package/src/chips.ts +350 -0
  49. package/src/collapsible.ts +184 -0
  50. package/{js/component.js → src/component.ts} +6 -19
  51. package/{js/datepicker.js → src/datepicker.ts} +213 -299
  52. package/{js/dropdown.js → src/dropdown.ts} +140 -254
  53. package/src/edges.ts +6 -0
  54. package/src/forms.ts +120 -0
  55. package/src/global.ts +385 -0
  56. package/src/materialbox.ts +348 -0
  57. package/src/modal.ts +256 -0
  58. package/{js/parallax.js → src/parallax.ts} +47 -60
  59. package/{js/pushpin.js → src/pushpin.ts} +19 -47
  60. package/{js/range.js → src/range.ts} +58 -139
  61. package/{js/scrollspy.js → src/scrollspy.ts} +81 -153
  62. package/src/select.ts +448 -0
  63. package/{js/sidenav.js → src/sidenav.ts} +96 -202
  64. package/src/slider.ts +415 -0
  65. package/src/tabs.ts +293 -0
  66. package/src/tapTarget.ts +240 -0
  67. package/{js/timepicker.js → src/timepicker.ts} +268 -272
  68. package/{js/toasts.js → src/toasts.ts} +75 -134
  69. package/{js/tooltip.js → src/tooltip.ts} +59 -96
  70. package/src/waves.ts +70 -0
  71. package/extras/noUiSlider/nouislider.css +0 -404
  72. package/extras/noUiSlider/nouislider.js +0 -2147
  73. package/extras/noUiSlider/nouislider.min.js +0 -1
  74. package/js/anime.min.js +0 -34
  75. package/js/autocomplete.js +0 -479
  76. package/js/cards.js +0 -40
  77. package/js/cash.js +0 -960
  78. package/js/characterCounter.js +0 -136
  79. package/js/chips.js +0 -486
  80. package/js/collapsible.js +0 -275
  81. package/js/forms.js +0 -285
  82. package/js/global.js +0 -428
  83. package/js/materialbox.js +0 -453
  84. package/js/modal.js +0 -382
  85. package/js/select.js +0 -391
  86. package/js/slider.js +0 -497
  87. package/js/tabs.js +0 -402
  88. package/js/tapTarget.js +0 -315
  89. package/js/waves.js +0 -615
  90. package/sass/components/_waves.scss +0 -187
@@ -1,5 +1,5 @@
1
- (function($) {
2
- 'use strict';
1
+ import { Component } from "./component";
2
+ import { M } from "./global";
3
3
 
4
4
  let _defaults = {
5
5
  duration: 200, // ms
@@ -13,53 +13,58 @@
13
13
  onCycleTo: null // Callback for when a new slide is cycled to.
14
14
  };
15
15
 
16
- /**
17
- * @class
18
- *
19
- */
20
- class Carousel extends Component {
21
- /**
22
- * Construct Carousel instance
23
- * @constructor
24
- * @param {Element} el
25
- * @param {Object} options
26
- */
27
- constructor(el, options) {
16
+ export class Carousel extends Component {
17
+ el: HTMLElement;
18
+ hasMultipleSlides: boolean;
19
+ showIndicators: boolean;
20
+ noWrap: any;
21
+ pressed: boolean;
22
+ dragged: boolean;
23
+ offset: number;
24
+ target: number;
25
+ images: HTMLElement[];
26
+ itemWidth: any;
27
+ itemHeight: any;
28
+ dim: number;
29
+ _autoScrollBound: any;
30
+ _trackBound: any;
31
+ _indicators: any;
32
+ count: number;
33
+ xform: string;
34
+ private _handleCarouselTapBound: any;
35
+ private _handleCarouselDragBound: any;
36
+ private _handleCarouselReleaseBound: any;
37
+ private _handleCarouselClickBound: any;
38
+ _handleIndicatorClickBound: any;
39
+ _handleThrottledResizeBound: any;
40
+ verticalDragged: boolean;
41
+ reference: any;
42
+ referenceY: any;
43
+ velocity: number;
44
+ frame: number;
45
+ timestamp: number;
46
+ ticker: NodeJS.Timer;
47
+ amplitude: number;
48
+ center: number = 0;
49
+ imageHeight: any;
50
+ scrollingTimeout: any;
51
+ oneTimeCallback: any;
52
+
53
+ constructor(el: Element, options: Object) {
28
54
  super(Carousel, el, options);
29
-
30
- this.el.M_Carousel = this;
31
-
32
- /**
33
- * Options for the carousel
34
- * @member Carousel#options
35
- * @prop {Number} duration
36
- * @prop {Number} dist
37
- * @prop {Number} shift
38
- * @prop {Number} padding
39
- * @prop {Number} numVisible
40
- * @prop {Boolean} fullWidth
41
- * @prop {Boolean} indicators
42
- * @prop {Boolean} noWrap
43
- * @prop {Function} onCycleTo
44
- */
45
- this.options = $.extend({}, Carousel.defaults, options);
55
+ (this.el as any).M_Carousel = this;
56
+ this.options = {...Carousel.defaults, ...options};
46
57
 
47
58
  // Setup
48
- this.hasMultipleSlides = this.$el.find('.carousel-item').length > 1;
59
+ this.hasMultipleSlides = this.el.querySelectorAll('.carousel-item').length > 1;
49
60
  this.showIndicators = this.options.indicators && this.hasMultipleSlides;
50
61
  this.noWrap = this.options.noWrap || !this.hasMultipleSlides;
51
62
  this.pressed = false;
52
63
  this.dragged = false;
53
64
  this.offset = this.target = 0;
54
65
  this.images = [];
55
- this.itemWidth = this.$el
56
- .find('.carousel-item')
57
- .first()
58
- .innerWidth();
59
- this.itemHeight = this.$el
60
- .find('.carousel-item')
61
- .first()
62
- .innerHeight();
66
+ this.itemWidth = this.el.querySelector('.carousel-item').clientWidth;
67
+ this.itemHeight = this.el.querySelector('.carousel-item').clientHeight;
63
68
  this.dim = this.itemWidth * 2 + this.options.padding || 1; // Make sure dim is non zero for divisions.
64
69
  this._autoScrollBound = this._autoScroll.bind(this);
65
70
  this._trackBound = this._track.bind(this);
@@ -71,28 +76,29 @@
71
76
 
72
77
  // Offset fixed items when indicators.
73
78
  if (this.showIndicators) {
74
- this.$el.find('.carousel-fixed-item').addClass('with-indicators');
79
+ this.el.querySelector('.carousel-fixed-item')?.classList.add('with-indicators');
75
80
  }
76
81
  }
77
82
 
78
83
  // Iterate through slides
79
- this.$indicators = $('<ul class="indicators"></ul>');
80
- this.$el.find('.carousel-item').each((el, i) => {
81
- this.images.push(el);
82
- if (this.showIndicators) {
83
- let $indicator = $('<li class="indicator-item"></li>');
84
+ this._indicators = document.createElement('ul');
85
+ this._indicators.classList.add('indicators');
84
86
 
85
- // Add active to first by default.
87
+ this.el.querySelectorAll('.carousel-item').forEach((item: HTMLElement, i) => {
88
+ this.images.push(item);
89
+ if (this.showIndicators) {
90
+ const indicator = document.createElement('li');
91
+ indicator.classList.add('indicator-item');
86
92
  if (i === 0) {
87
- $indicator[0].classList.add('active');
93
+ indicator.classList.add('active');
88
94
  }
89
-
90
- this.$indicators.append($indicator);
95
+ this._indicators.appendChild(indicator);
91
96
  }
92
97
  });
93
- if (this.showIndicators) {
94
- this.$el.append(this.$indicators);
95
- }
98
+
99
+ if (this.showIndicators)
100
+ this.el.appendChild(this._indicators);
101
+
96
102
  this.count = this.images.length;
97
103
 
98
104
  // Cap numVisible at count
@@ -121,60 +127,43 @@
121
127
  return super.init(this, els, options);
122
128
  }
123
129
 
124
- /**
125
- * Get Instance
126
- */
127
130
  static getInstance(el) {
128
131
  let domElem = !!el.jquery ? el[0] : el;
129
132
  return domElem.M_Carousel;
130
133
  }
131
134
 
132
- /**
133
- * Teardown component
134
- */
135
135
  destroy() {
136
136
  this._removeEventHandlers();
137
- this.el.M_Carousel = undefined;
137
+ (this.el as any).M_Carousel = undefined;
138
138
  }
139
139
 
140
- /**
141
- * Setup Event Handlers
142
- */
143
140
  _setupEventHandlers() {
144
141
  this._handleCarouselTapBound = this._handleCarouselTap.bind(this);
145
142
  this._handleCarouselDragBound = this._handleCarouselDrag.bind(this);
146
143
  this._handleCarouselReleaseBound = this._handleCarouselRelease.bind(this);
147
144
  this._handleCarouselClickBound = this._handleCarouselClick.bind(this);
148
-
149
145
  if (typeof window.ontouchstart !== 'undefined') {
150
146
  this.el.addEventListener('touchstart', this._handleCarouselTapBound);
151
147
  this.el.addEventListener('touchmove', this._handleCarouselDragBound);
152
148
  this.el.addEventListener('touchend', this._handleCarouselReleaseBound);
153
149
  }
154
-
155
150
  this.el.addEventListener('mousedown', this._handleCarouselTapBound);
156
151
  this.el.addEventListener('mousemove', this._handleCarouselDragBound);
157
152
  this.el.addEventListener('mouseup', this._handleCarouselReleaseBound);
158
153
  this.el.addEventListener('mouseleave', this._handleCarouselReleaseBound);
159
154
  this.el.addEventListener('click', this._handleCarouselClickBound);
160
-
161
- if (this.showIndicators && this.$indicators) {
155
+ if (this.showIndicators && this._indicators) {
162
156
  this._handleIndicatorClickBound = this._handleIndicatorClick.bind(this);
163
- this.$indicators.find('.indicator-item').each((el, i) => {
157
+ this._indicators.querySelectorAll('.indicator-item').forEach((el) => {
164
158
  el.addEventListener('click', this._handleIndicatorClickBound);
165
159
  });
166
160
  }
167
-
168
161
  // Resize
169
- let throttledResize = M.throttle(this._handleResize, 200);
162
+ let throttledResize = M.throttle(this._handleResize, 200, null);
170
163
  this._handleThrottledResizeBound = throttledResize.bind(this);
171
-
172
164
  window.addEventListener('resize', this._handleThrottledResizeBound);
173
165
  }
174
166
 
175
- /**
176
- * Remove Event Handlers
177
- */
178
167
  _removeEventHandlers() {
179
168
  if (typeof window.ontouchstart !== 'undefined') {
180
169
  this.el.removeEventListener('touchstart', this._handleCarouselTapBound);
@@ -186,23 +175,17 @@
186
175
  this.el.removeEventListener('mouseup', this._handleCarouselReleaseBound);
187
176
  this.el.removeEventListener('mouseleave', this._handleCarouselReleaseBound);
188
177
  this.el.removeEventListener('click', this._handleCarouselClickBound);
189
-
190
- if (this.showIndicators && this.$indicators) {
191
- this.$indicators.find('.indicator-item').each((el, i) => {
178
+ if (this.showIndicators && this._indicators) {
179
+ this._indicators.querySelectorAll('.indicator-item').forEach((el) => {
192
180
  el.removeEventListener('click', this._handleIndicatorClickBound);
193
181
  });
194
182
  }
195
-
196
183
  window.removeEventListener('resize', this._handleThrottledResizeBound);
197
184
  }
198
185
 
199
- /**
200
- * Handle Carousel Tap
201
- * @param {Event} e
202
- */
203
186
  _handleCarouselTap(e) {
204
187
  // Fixes firefox draggable image bug
205
- if (e.type === 'mousedown' && $(e.target).is('img')) {
188
+ if (e.type === 'mousedown' && (<HTMLElement>e.target).tagName === 'IMG') {
206
189
  e.preventDefault();
207
190
  }
208
191
  this.pressed = true;
@@ -218,10 +201,6 @@
218
201
  this.ticker = setInterval(this._trackBound, 100);
219
202
  }
220
203
 
221
- /**
222
- * Handle Carousel Drag
223
- * @param {Event} e
224
- */
225
204
  _handleCarouselDrag(e) {
226
205
  let x, y, delta, deltaY;
227
206
  if (this.pressed) {
@@ -246,7 +225,6 @@
246
225
  this.verticalDragged = true;
247
226
  }
248
227
  }
249
-
250
228
  if (this.dragged) {
251
229
  // If dragging don't allow vertical scroll.
252
230
  e.preventDefault();
@@ -255,17 +233,12 @@
255
233
  }
256
234
  }
257
235
 
258
- /**
259
- * Handle Carousel Release
260
- * @param {Event} e
261
- */
262
236
  _handleCarouselRelease(e) {
263
237
  if (this.pressed) {
264
238
  this.pressed = false;
265
239
  } else {
266
240
  return;
267
241
  }
268
-
269
242
  clearInterval(this.ticker);
270
243
  this.target = this.offset;
271
244
  if (this.velocity > 10 || this.velocity < -10) {
@@ -273,7 +246,6 @@
273
246
  this.target = this.offset + this.amplitude;
274
247
  }
275
248
  this.target = Math.round(this.target / this.dim) * this.dim;
276
-
277
249
  // No wrap of items.
278
250
  if (this.noWrap) {
279
251
  if (this.target >= this.dim * (this.count - 1)) {
@@ -285,7 +257,6 @@
285
257
  this.amplitude = this.target - this.offset;
286
258
  this.timestamp = Date.now();
287
259
  requestAnimationFrame(this._autoScrollBound);
288
-
289
260
  if (this.dragged) {
290
261
  e.preventDefault();
291
262
  e.stopPropagation();
@@ -293,28 +264,22 @@
293
264
  return false;
294
265
  }
295
266
 
296
- /**
297
- * Handle Carousel Click
298
- * @param {Event} e
299
- */
300
267
  _handleCarouselClick(e) {
301
268
  // Disable clicks if carousel was dragged.
302
269
  if (this.dragged) {
303
270
  e.preventDefault();
304
271
  e.stopPropagation();
305
272
  return false;
306
- } else if (!this.options.fullWidth) {
307
- let clickedIndex = $(e.target)
308
- .closest('.carousel-item')
309
- .index();
310
- let diff = this._wrap(this.center) - clickedIndex;
311
-
273
+ }
274
+ else if (!this.options.fullWidth) {
275
+ const clickedElem = (<HTMLElement>e.target).closest('.carousel-item');
276
+ const clickedIndex = [...clickedElem.parentNode.children].indexOf(clickedElem);
277
+ const diff = this._wrap(this.center) - clickedIndex;
312
278
  // Disable clicks if carousel was shifted by click
313
279
  if (diff !== 0) {
314
280
  e.preventDefault();
315
281
  e.stopPropagation();
316
282
  }
317
-
318
283
  // fixes https://github.com/materializecss/materialize/issues/180
319
284
  if (clickedIndex < 0) {
320
285
  // relative X position > center of carousel = clicked at the right part of the carousel
@@ -329,106 +294,81 @@
329
294
  }
330
295
  }
331
296
 
332
- /**
333
- * Handle Indicator CLick
334
- * @param {Event} e
335
- */
336
- _handleIndicatorClick(e) {
297
+ _handleIndicatorClick(e: Event) {
337
298
  e.stopPropagation();
338
-
339
- let indicator = $(e.target).closest('.indicator-item');
340
- if (indicator.length) {
341
- this._cycleTo(indicator.index());
299
+ const indicator = (<HTMLElement>e.target).closest('.indicator-item');
300
+ if (indicator) {
301
+ const index = [...indicator.parentNode.children].indexOf(indicator);
302
+ this._cycleTo(index);
342
303
  }
343
304
  }
344
305
 
345
- /**
346
- * Handle Throttle Resize
347
- * @param {Event} e
348
- */
349
306
  _handleResize(e) {
350
307
  if (this.options.fullWidth) {
351
- this.itemWidth = this.$el
352
- .find('.carousel-item')
353
- .first()
354
- .innerWidth();
355
- this.imageHeight = this.$el.find('.carousel-item.active').height();
308
+ this.itemWidth = this.el.querySelector('.carousel-item').clientWidth;
309
+ this.imageHeight = this.el.querySelector('.carousel-item.active').clientHeight;
356
310
  this.dim = this.itemWidth * 2 + this.options.padding;
357
311
  this.offset = this.center * 2 * this.itemWidth;
358
312
  this.target = this.offset;
359
313
  this._setCarouselHeight(true);
360
- } else {
314
+ }
315
+ else {
361
316
  this._scroll();
362
317
  }
363
318
  }
364
319
 
365
- /**
366
- * Set carousel height based on first slide
367
- * @param {Booleam} imageOnly - true for image slides
368
- */
369
- _setCarouselHeight(imageOnly) {
370
- let firstSlide = this.$el.find('.carousel-item.active').length
371
- ? this.$el.find('.carousel-item.active').first()
372
- : this.$el.find('.carousel-item').first();
373
- let firstImage = firstSlide.find('img').first();
374
- if (firstImage.length) {
375
- if (firstImage[0].complete) {
320
+ _setCarouselHeight(imageOnly: boolean = false) {
321
+ const firstSlide = this.el.querySelector('.carousel-item.active')
322
+ ? this.el.querySelector('.carousel-item.active')
323
+ : this.el.querySelector('.carousel-item');
324
+
325
+ const firstImage = firstSlide.querySelector('img');
326
+ if (firstImage) {
327
+ if (firstImage.complete) {
376
328
  // If image won't trigger the load event
377
- let imageHeight = firstImage.height();
329
+ const imageHeight = firstImage.clientHeight;
378
330
  if (imageHeight > 0) {
379
- this.$el.css('height', imageHeight + 'px');
380
- } else {
331
+ this.el.style.height = imageHeight+'px';
332
+ }
333
+ else {
381
334
  // If image still has no height, use the natural dimensions to calculate
382
- let naturalWidth = firstImage[0].naturalWidth;
383
- let naturalHeight = firstImage[0].naturalHeight;
384
- let adjustedHeight = (this.$el.width() / naturalWidth) * naturalHeight;
385
- this.$el.css('height', adjustedHeight + 'px');
335
+ const naturalWidth = firstImage.naturalWidth;
336
+ const naturalHeight = firstImage.naturalHeight;
337
+ const adjustedHeight = (this.el.clientWidth / naturalWidth) * naturalHeight;
338
+ this.el.style.height = adjustedHeight+'px';
386
339
  }
387
340
  } else {
388
341
  // Get height when image is loaded normally
389
- firstImage.one('load', (el, i) => {
390
- this.$el.css('height', el.offsetHeight + 'px');
342
+ firstImage.addEventListener('load', () => {
343
+ this.el.style.height = firstImage.offsetHeight+'px';
391
344
  });
392
345
  }
393
- } else if (!imageOnly) {
394
- let slideHeight = firstSlide.height();
395
- this.$el.css('height', slideHeight + 'px');
346
+ }
347
+ else if (!imageOnly) {
348
+ const slideHeight = firstSlide.clientHeight;
349
+ this.el.style.height = slideHeight+'px';
396
350
  }
397
351
  }
398
352
 
399
- /**
400
- * Get x position from event
401
- * @param {Event} e
402
- */
403
353
  _xpos(e) {
404
354
  // touch event
405
355
  if (e.targetTouches && e.targetTouches.length >= 1) {
406
356
  return e.targetTouches[0].clientX;
407
357
  }
408
-
409
358
  // mouse event
410
359
  return e.clientX;
411
360
  }
412
361
 
413
- /**
414
- * Get y position from event
415
- * @param {Event} e
416
- */
417
362
  _ypos(e) {
418
363
  // touch event
419
364
  if (e.targetTouches && e.targetTouches.length >= 1) {
420
365
  return e.targetTouches[0].clientY;
421
366
  }
422
-
423
367
  // mouse event
424
368
  return e.clientY;
425
369
  }
426
370
 
427
- /**
428
- * Wrap index
429
- * @param {Number} x
430
- */
431
- _wrap(x) {
371
+ _wrap(x: number) {
432
372
  return x >= this.count
433
373
  ? x % this.count
434
374
  : x < 0
@@ -436,28 +376,19 @@
436
376
  : x;
437
377
  }
438
378
 
439
- /**
440
- * Tracks scrolling information
441
- */
442
379
  _track() {
443
380
  let now, elapsed, delta, v;
444
-
445
381
  now = Date.now();
446
382
  elapsed = now - this.timestamp;
447
383
  this.timestamp = now;
448
384
  delta = this.offset - this.frame;
449
385
  this.frame = this.offset;
450
-
451
386
  v = (1000 * delta) / (1 + elapsed);
452
387
  this.velocity = 0.8 * v + 0.2 * this.velocity;
453
388
  }
454
389
 
455
- /**
456
- * Auto scrolls to nearest carousel item.
457
- */
458
390
  _autoScroll() {
459
391
  let elapsed, delta;
460
-
461
392
  if (this.amplitude) {
462
393
  elapsed = Date.now() - this.timestamp;
463
394
  delta = this.amplitude * Math.exp(-elapsed / this.options.duration);
@@ -470,20 +401,16 @@
470
401
  }
471
402
  }
472
403
 
473
- /**
474
- * Scroll to target
475
- * @param {Number} x
476
- */
477
- _scroll(x) {
404
+ _scroll(x: number = 0) {
478
405
  // Track scrolling state
479
- if (!this.$el.hasClass('scrolling')) {
406
+ if (!this.el.classList.contains('scrolling')) {
480
407
  this.el.classList.add('scrolling');
481
408
  }
482
409
  if (this.scrollingTimeout != null) {
483
410
  window.clearTimeout(this.scrollingTimeout);
484
411
  }
485
412
  this.scrollingTimeout = window.setTimeout(() => {
486
- this.$el.removeClass('scrolling');
413
+ this.el.classList.remove('scrolling');
487
414
  }, this.options.duration);
488
415
 
489
416
  // Start actual scroll
@@ -502,6 +429,7 @@
502
429
 
503
430
  this.offset = typeof x === 'number' ? x : this.offset;
504
431
  this.center = Math.floor((this.offset + this.dim / 2) / this.dim);
432
+
505
433
  delta = this.offset - this.center * this.dim;
506
434
  dir = delta < 0 ? 1 : -1;
507
435
  tween = (-dir * delta * 2) / this.dim;
@@ -510,7 +438,8 @@
510
438
  if (this.options.fullWidth) {
511
439
  alignment = 'translateX(0)';
512
440
  centerTweenedOpacity = 1;
513
- } else {
441
+ }
442
+ else {
514
443
  alignment = 'translateX(' + (this.el.clientWidth - this.itemWidth) / 2 + 'px) ';
515
444
  alignment += 'translateY(' + (this.el.clientHeight - this.itemHeight) / 2 + 'px)';
516
445
  centerTweenedOpacity = 1 - numVisibleOffset * tween;
@@ -518,14 +447,13 @@
518
447
 
519
448
  // Set indicator active
520
449
  if (this.showIndicators) {
521
- let diff = this.center % this.count;
522
- let activeIndicator = this.$indicators.find('.indicator-item.active');
523
- if (activeIndicator.index() !== diff) {
524
- activeIndicator.removeClass('active');
525
- this.$indicators
526
- .find('.indicator-item')
527
- .eq(diff)[0]
528
- .classList.add('active');
450
+ const diff = this.center % this.count;
451
+ const activeIndicator = this._indicators.querySelector('.indicator-item.active');
452
+ const activeIndicatorIndex = [...activeIndicator.parentNode.children].indexOf(activeIndicator);
453
+ if (activeIndicatorIndex !== diff) {
454
+ activeIndicator.classList.remove('active');
455
+ const pos = diff < 0 ? this.count + diff : diff;
456
+ this._indicators.querySelectorAll('.indicator-item')[pos].classList.add('active');
529
457
  }
530
458
  }
531
459
 
@@ -535,10 +463,11 @@
535
463
  el = this.images[this._wrap(this.center)];
536
464
 
537
465
  // Add active class to center item.
538
- if (!$(el).hasClass('active')) {
539
- this.$el.find('.carousel-item').removeClass('active');
466
+ if (!el.classList.contains('active')) {
467
+ this.el.querySelector('.carousel-item').classList.remove('active');
540
468
  el.classList.add('active');
541
469
  }
470
+
542
471
  let transformString = `${alignment} translateX(${-delta / 2}px) translateX(${dir *
543
472
  this.options.shift *
544
473
  tween *
@@ -562,7 +491,6 @@
562
491
  (this.dim * i - delta) / 2}px) translateZ(${zTranslation}px)`;
563
492
  this._updateItemStyle(el, tweenedOpacity, -i, transformString);
564
493
  }
565
-
566
494
  // left side
567
495
  if (this.options.fullWidth) {
568
496
  zTranslation = this.options.dist;
@@ -579,7 +507,6 @@
579
507
  this._updateItemStyle(el, tweenedOpacity, -i, transformString);
580
508
  }
581
509
  }
582
-
583
510
  // center
584
511
  // Don't show wrapped items.
585
512
  if (!this.noWrap || (this.center >= 0 && this.center < this.count)) {
@@ -589,42 +516,28 @@
589
516
  tween}px) translateZ(${this.options.dist * tween}px)`;
590
517
  this._updateItemStyle(el, centerTweenedOpacity, 0, transformString);
591
518
  }
592
-
593
519
  // onCycleTo callback
594
- let $currItem = this.$el.find('.carousel-item').eq(this._wrap(this.center));
520
+ const _currItem = this.el.querySelectorAll('.carousel-item')[this._wrap(this.center)];
521
+
595
522
  if (lastCenter !== this.center && typeof this.options.onCycleTo === 'function') {
596
- this.options.onCycleTo.call(this, $currItem[0], this.dragged);
523
+ this.options.onCycleTo.call(this, _currItem, this.dragged);
597
524
  }
598
-
599
525
  // One time callback
600
526
  if (typeof this.oneTimeCallback === 'function') {
601
- this.oneTimeCallback.call(this, $currItem[0], this.dragged);
527
+ this.oneTimeCallback.call(this, _currItem, this.dragged);
602
528
  this.oneTimeCallback = null;
603
529
  }
604
530
  }
605
531
 
606
- /**
607
- * Cycle to target
608
- * @param {Element} el
609
- * @param {Number} opacity
610
- * @param {Number} zIndex
611
- * @param {String} transform
612
- */
613
- _updateItemStyle(el, opacity, zIndex, transform) {
532
+ _updateItemStyle(el: HTMLElement, opacity: number, zIndex: number, transform: string) {
614
533
  el.style[this.xform] = transform;
615
- el.style.zIndex = zIndex;
616
- el.style.opacity = opacity;
534
+ el.style.zIndex = zIndex.toString();
535
+ el.style.opacity = opacity.toString();
617
536
  el.style.visibility = 'visible';
618
537
  }
619
538
 
620
- /**
621
- * Cycle to target
622
- * @param {Number} n
623
- * @param {Function} callback
624
- */
625
- _cycleTo(n, callback) {
539
+ _cycleTo(n: number, callback: Function = null) {
626
540
  let diff = (this.center % this.count) - n;
627
-
628
541
  // Account for wraparound.
629
542
  if (!this.noWrap) {
630
543
  if (diff < 0) {
@@ -637,22 +550,18 @@
637
550
  }
638
551
  }
639
552
  }
640
-
641
553
  this.target = this.dim * Math.round(this.offset / this.dim);
642
554
  // Next
643
555
  if (diff < 0) {
644
- this.target += this.dim * Math.abs(diff);
645
-
646
- // Prev
647
- } else if (diff > 0) {
556
+ this.target += this.dim * Math.abs(diff);
557
+ } // Prev
558
+ else if (diff > 0) {
648
559
  this.target -= this.dim * diff;
649
560
  }
650
-
651
561
  // Set one time callback
652
562
  if (typeof callback === 'function') {
653
563
  this.oneTimeCallback = callback;
654
564
  }
655
-
656
565
  // Scroll
657
566
  if (this.offset !== this.target) {
658
567
  this.amplitude = this.target - this.offset;
@@ -661,72 +570,38 @@
661
570
  }
662
571
  }
663
572
 
664
- /**
665
- * Cycle to next item
666
- * @param {Number} [n]
667
- */
668
- next(n) {
573
+ next(n: number = 1) {
669
574
  if (n === undefined || isNaN(n)) {
670
575
  n = 1;
671
576
  }
672
-
673
577
  let index = this.center + n;
674
578
  if (index >= this.count || index < 0) {
675
- if (this.noWrap) {
676
- return;
677
- }
678
-
579
+ if (this.noWrap) return;
679
580
  index = this._wrap(index);
680
581
  }
681
582
  this._cycleTo(index);
682
583
  }
683
584
 
684
- /**
685
- * Cycle to previous item
686
- * @param {Number} [n]
687
- */
688
- prev(n) {
585
+ prev(n: number = 1) {
689
586
  if (n === undefined || isNaN(n)) {
690
587
  n = 1;
691
588
  }
692
-
693
589
  let index = this.center - n;
694
590
  if (index >= this.count || index < 0) {
695
- if (this.noWrap) {
696
- return;
697
- }
698
-
591
+ if (this.noWrap) return;
699
592
  index = this._wrap(index);
700
593
  }
701
-
702
594
  this._cycleTo(index);
703
595
  }
704
596
 
705
- /**
706
- * Cycle to nth item
707
- * @param {Number} [n]
708
- * @param {Function} callback
709
- */
710
- set(n, callback) {
597
+ set(n: number, callback: Function) {
711
598
  if (n === undefined || isNaN(n)) {
712
599
  n = 0;
713
600
  }
714
-
715
601
  if (n > this.count || n < 0) {
716
- if (this.noWrap) {
717
- return;
718
- }
719
-
602
+ if (this.noWrap) return;
720
603
  n = this._wrap(n);
721
604
  }
722
-
723
605
  this._cycleTo(n, callback);
724
606
  }
725
- }
726
-
727
- M.Carousel = Carousel;
728
-
729
- if (M.jQueryLoaded) {
730
- M.initializeJqueryWrapper(Carousel, 'carousel', 'M_Carousel');
731
- }
732
- })(cash);
607
+ }