@schukai/monster 3.74.0 → 3.75.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -10,26 +10,19 @@
10
10
  * For more information about purchasing a commercial license, please contact schukai GmbH.
11
11
  */
12
12
 
13
- import {instanceSymbol} from "../../constants.mjs";
14
- import {addAttributeToken} from "../../dom/attributes.mjs";
13
+ import { instanceSymbol } from "../../constants.mjs";
14
+ import { ATTRIBUTE_PREFIX, ATTRIBUTE_ROLE } from "../../dom/constants.mjs";
15
+ import { CustomElement, getSlottedElements } from "../../dom/customelement.mjs";
15
16
  import {
16
- ATTRIBUTE_ERRORMESSAGE, ATTRIBUTE_PREFIX,
17
- ATTRIBUTE_ROLE,
18
- } from "../../dom/constants.mjs";
19
- import {CustomControl} from "../../dom/customcontrol.mjs";
20
- import {CustomElement, getSlottedElements} from "../../dom/customelement.mjs";
21
- import {
22
- assembleMethodSymbol,
23
- registerCustomElement,
17
+ assembleMethodSymbol,
18
+ registerCustomElement,
24
19
  } from "../../dom/customelement.mjs";
25
- import {findTargetElementFromEvent} from "../../dom/events.mjs";
26
- import {isFunction} from "../../types/is.mjs";
27
- import {SliderStyleSheet} from "./stylesheet/slider.mjs";
28
- import {fireCustomEvent} from "../../dom/events.mjs";
20
+ import { SliderStyleSheet } from "./stylesheet/slider.mjs";
21
+ import { fireCustomEvent } from "../../dom/events.mjs";
29
22
 
30
- import {getWindow} from "../../dom/util.mjs";
23
+ import { getWindow } from "../../dom/util.mjs";
31
24
 
32
- export {Slider};
25
+ export { Slider };
33
26
 
34
27
  /**
35
28
  * @private
@@ -65,7 +58,7 @@ const configSymbol = Symbol("config");
65
58
  * @private
66
59
  * @type {string}
67
60
  */
68
- const ATTRIBUTE_CLON_FROM = ATTRIBUTE_PREFIX + "clone-from"
61
+ const ATTRIBUTE_CLON_FROM = ATTRIBUTE_PREFIX + "clone-from";
69
62
 
70
63
  /**
71
64
  * A Slider
@@ -79,152 +72,147 @@ const ATTRIBUTE_CLON_FROM = ATTRIBUTE_PREFIX + "clone-from"
79
72
  * @summary A beautiful Slider that can make your life easier and also looks good.
80
73
  */
81
74
  class Slider extends CustomElement {
82
- /**
83
- * This method is called by the `instanceof` operator.
84
- * @returns {symbol}
85
- */
86
- static get [instanceSymbol]() {
87
- return Symbol.for("@schukai/monster/components/layout/slider@@instance");
88
- }
89
-
90
- /**
91
- *
92
- * @return {Components.Layout.Slider
93
- */
94
- [assembleMethodSymbol]() {
95
- super[assembleMethodSymbol]();
96
-
97
- this[configSymbol] = {
98
- currentIndex: 0,
99
-
100
- isDragging: false,
101
- draggingPos: 0,
102
- startPos: 0,
103
- // currentTranslate: 0,
104
- // prevTranslate: 0,
105
- //
106
- // startPositions: null,
107
- // currentPositions: null,
108
-
109
- autoPlayInterval: null,
110
- }
111
-
112
- initControlReferences.call(this);
113
- initEventHandler.call(this);
114
- initStructure.call(this);
115
-
116
- return this;
117
- }
118
-
119
- /**
120
- * To set the options via the html tag the attribute `data-monster-options` must be used.
121
- * @see {@link https://monsterjs.org/en/doc/#configurate-a-monster-control}
122
- *
123
- * The individual configuration values can be found in the table.
124
- *
125
- * @property {Object} templates Template definitions
126
- * @property {string} templates.main Main template
127
- * @property {Object} labels Label definitions
128
- * @property {Object} actions Callbacks
129
- * @property {string} actions.click="throw Error" Callback when clicked
130
- * @property {Object} features Features
131
- * @property {Object} classes CSS classes
132
- * @property {boolean} disabled=false Disabled state
133
- */
134
- get defaults() {
135
- return Object.assign({}, super.defaults, {
136
- templates: {
137
- main: getTemplate(),
138
- },
139
- labels: {},
140
- classes: {},
141
- disabled: false,
142
-
143
- features: {
144
- carousel: false,
145
- autoPlay: true,
146
- thumbnails: true,
147
- },
148
-
149
- autoPlay: {
150
- delay: 1500,
151
- startDelay: 1000,
152
- direction: "next",
153
- mouseOverPause: true,
154
- touchPause: true,
155
- drag: true,
156
- },
157
-
158
- actions: {
159
- click: () => {
160
- throw new Error("the click action is not defined");
161
- },
162
- }
163
- });
164
- }
165
-
166
- /**
167
- * @return {string}
168
- */
169
- static getTag() {
170
- return "monster-slider";
171
- }
172
-
173
- /**
174
- * @return {CSSStyleSheet[]}
175
- */
176
- static getCSSStyleSheet() {
177
- return [SliderStyleSheet];
178
- }
179
-
180
- /**
181
- * moves the slider to the given index
182
- *
183
- * @param index
184
- * @returns {void}
185
- */
186
- moveTo(index) {
187
- return moveTo.call(this, index)
188
- }
189
-
190
- /**
191
- * shows the previous slide
192
- *
193
- * @return {void}
194
- */
195
- previous() {
196
- return prev.call(this);
197
- }
198
-
199
- /**
200
- * shows the next slide
201
- *
202
- * @return {void}
203
- */
204
- next() {
205
- return next.call(this);
206
- }
207
-
208
- /**
209
- * stops the auto play
210
- *
211
- * @return {void}
212
- */
213
- stopAutoPlay() {
214
- if (this[configSymbol].autoPlayInterval) {
215
- clearInterval(this[configSymbol].autoPlayInterval);
216
- }
217
- }
218
-
219
- /**
220
- * starts the auto play
221
- *
222
- * @return {void}
223
- */
224
- startAutoPlay() {
225
- initAutoPlay.call(this);
226
- }
227
-
75
+ /**
76
+ * This method is called by the `instanceof` operator.
77
+ * @returns {symbol}
78
+ */
79
+ static get [instanceSymbol]() {
80
+ return Symbol.for("@schukai/monster/components/layout/slider@@instance");
81
+ }
82
+
83
+ /**
84
+ *
85
+ * @return {Components.Layout.Slider
86
+ */
87
+ [assembleMethodSymbol]() {
88
+ super[assembleMethodSymbol]();
89
+
90
+ this[configSymbol] = {
91
+ currentIndex: 0,
92
+
93
+ isDragging: false,
94
+ draggingPos: 0,
95
+ startPos: 0,
96
+ autoPlayInterval: null,
97
+ };
98
+
99
+ initControlReferences.call(this);
100
+ initEventHandler.call(this);
101
+ initStructure.call(this);
102
+
103
+ return this;
104
+ }
105
+
106
+ /**
107
+ * To set the options via the html tag the attribute `data-monster-options` must be used.
108
+ * @see {@link https://monsterjs.org/en/doc/#configurate-a-monster-control}
109
+ *
110
+ * The individual configuration values can be found in the table.
111
+ *
112
+ * @property {Object} templates Template definitions
113
+ * @property {string} templates.main Main template
114
+ * @property {string} actions.click="throw Error" Callback when clicked
115
+ * @property {Object} features Features
116
+ * @property {boolean} features.carousel=true Carousel feature
117
+ * @property {boolean} features.autoPlay=true Auto play feature
118
+ * @property {boolean} features.thumbnails=true Thumbnails feature
119
+ * @property {boolean} features.drag=true Drag feature
120
+ * @property {Object} autoPlay Auto play configuration
121
+ * @property {number} autoPlay.delay=1500 Delay between slides
122
+ * @property {number} autoPlay.startDelay=1000 Start delay
123
+ * @property {string} autoPlay.direction="next" Direction of the auto play
124
+ * @property {boolean} autoPlay.mouseOverPause=true Pause on mouse over
125
+ * @property {boolean} autoPlay.touchPause=true Pause on touch
126
+ * @property {Object} classes CSS classes
127
+ * @property {boolean} disabled=false Disabled state
128
+ */
129
+ get defaults() {
130
+ return Object.assign({}, super.defaults, {
131
+ templates: {
132
+ main: getTemplate(),
133
+ },
134
+
135
+ classes: {},
136
+ disabled: false,
137
+
138
+ features: {
139
+ carousel: true,
140
+ autoPlay: true,
141
+ thumbnails: true,
142
+ drag: true,
143
+ },
144
+
145
+ autoPlay: {
146
+ delay: 1500,
147
+ startDelay: 1000,
148
+ direction: "next",
149
+ mouseOverPause: true,
150
+ touchPause: true,
151
+ },
152
+ });
153
+ }
154
+
155
+ /**
156
+ * @return {string}
157
+ */
158
+ static getTag() {
159
+ return "monster-slider";
160
+ }
161
+
162
+ /**
163
+ * @return {CSSStyleSheet[]}
164
+ */
165
+ static getCSSStyleSheet() {
166
+ return [SliderStyleSheet];
167
+ }
168
+
169
+ /**
170
+ * moves the slider to the given index
171
+ *
172
+ * @param index
173
+ * @returns {void}
174
+ */
175
+ moveTo(index) {
176
+ return moveTo.call(this, index);
177
+ }
178
+
179
+ /**
180
+ * shows the previous slide
181
+ *
182
+ * @return {void}
183
+ */
184
+ previous() {
185
+ return prev.call(this);
186
+ }
187
+
188
+ /**
189
+ * shows the next slide
190
+ *
191
+ * @return {void}
192
+ */
193
+ next() {
194
+ return next.call(this);
195
+ }
196
+
197
+ /**
198
+ * stops the auto play
199
+ *
200
+ * @return {void}
201
+ */
202
+ stopAutoPlay() {
203
+ if (this[configSymbol].autoPlayInterval) {
204
+ clearInterval(this[configSymbol].autoPlayInterval);
205
+ }
206
+ }
207
+
208
+ /**
209
+ * starts the auto play
210
+ *
211
+ * @return {void}
212
+ */
213
+ startAutoPlay() {
214
+ initAutoPlay.call(this);
215
+ }
228
216
  }
229
217
 
230
218
  /**
@@ -232,151 +220,148 @@ class Slider extends CustomElement {
232
220
  * @param name
233
221
  */
234
222
  function initNavigation(name) {
235
- const element = this.shadowRoot.querySelector("." + name + "");
236
- const elementHeight = element.offsetHeight;
237
- element.style.top = `calc(50% - ${elementHeight / 2}px)`;
223
+ const element = this.shadowRoot.querySelector("." + name + "");
224
+ const elementHeight = element.offsetHeight;
225
+ element.style.top = `calc(50% - ${elementHeight / 2}px)`;
238
226
  }
239
227
 
240
228
  /**
241
229
  * @private
242
230
  */
243
231
  function initStructure() {
244
- initNavigation.call(this, "next");
245
- initNavigation.call(this, "prev");
232
+ initNavigation.call(this, "next");
233
+ initNavigation.call(this, "prev");
246
234
 
247
- if (this.getOption("features.thumbnails")) {
248
- initThumbnails.call(this);
249
- }
235
+ if (this.getOption("features.thumbnails")) {
236
+ initThumbnails.call(this);
237
+ }
250
238
 
251
- if (this.getOption("features.carousel")) {
252
- initCarousel.call(this);
253
- }
239
+ if (this.getOption("features.carousel")) {
240
+ initCarousel.call(this);
241
+ }
254
242
 
255
- if (this.getOption("features.autoPlay")) {
256
- initAutoPlay.call(this);
257
- }
243
+ if (this.getOption("features.autoPlay")) {
244
+ initAutoPlay.call(this);
245
+ }
258
246
  }
259
247
 
260
248
  /**
261
249
  * @private
262
250
  */
263
251
  function initThumbnails() {
264
- const self = this;
265
- const thumbnails = this.shadowRoot.querySelector("[data-monster-role='thumbnails']");
266
- const slides = Array.from(getSlottedElements.call(this, ":scope", null));
267
-
268
- slides.forEach((slide, index) => {
269
- const thumbnail = document.createElement("div");
270
- thumbnail.classList.add("thumbnail");
271
- thumbnail.addEventListener("click", () => {
272
- if (self.getOption("features.carousel")) {
273
- this.moveTo(index + 1);
274
- } else {
275
- this.moveTo(index);
276
- }
277
- });
278
-
279
- thumbnails.appendChild(thumbnail);
280
- })
281
-
282
- this.addEventListener("monster-slider-moved", (e) => {
283
- const index = e.detail.index;
284
- const thumbnail = thumbnails.children[index];
285
-
286
- if (!thumbnail) {
287
- return;
288
- }
289
-
290
- Array.from(thumbnails.children).forEach((thumb) => {
291
- thumb.classList.remove("current");
292
- })
293
-
294
- thumbnail.classList.add("current");
295
- })
252
+ const self = this;
253
+ const thumbnails = this.shadowRoot.querySelector(
254
+ "[data-monster-role='thumbnails']",
255
+ );
256
+ const slides = Array.from(getSlottedElements.call(this, ":scope", null));
257
+
258
+ slides.forEach((slide, index) => {
259
+ const thumbnail = document.createElement("div");
260
+ thumbnail.classList.add("thumbnail");
261
+ thumbnail.addEventListener("click", () => {
262
+ if (self.getOption("features.carousel")) {
263
+ this.moveTo(index + 1);
264
+ } else {
265
+ this.moveTo(index);
266
+ }
267
+ });
268
+
269
+ thumbnails.appendChild(thumbnail);
270
+ });
271
+
272
+ this.addEventListener("monster-slider-moved", (e) => {
273
+ const index = e.detail.index;
274
+ const thumbnail = thumbnails.children[index];
275
+
276
+ if (!thumbnail) {
277
+ return;
278
+ }
279
+
280
+ Array.from(thumbnails.children).forEach((thumb) => {
281
+ thumb.classList.remove("current");
282
+ });
283
+
284
+ thumbnail.classList.add("current");
285
+ });
296
286
  }
297
287
 
298
288
  /**
299
289
  * @private
300
290
  */
301
291
  function initAutoPlay() {
302
- const self = this;
303
- const autoPlay = this.getOption("autoPlay");
304
- const delay = autoPlay.delay;
305
- const startDelay = autoPlay.startDelay;
306
- const direction = autoPlay.direction;
307
-
308
- function start() {
309
-
310
- if (self[configSymbol].autoPlayInterval) {
311
- clearInterval(self[configSymbol].autoPlayInterval);
312
- }
313
-
314
- self[configSymbol].autoPlayInterval = setInterval(() => {
315
- if (direction === "next") {
316
- if(self.next() === -1) {
317
- if (self.getOption("features.carousel")) {
318
- clearInterval(self[configSymbol].autoPlayInterval);
319
- }
320
- }
321
- } else {
322
- if (self.previous() === -1) {
323
- if (self.getOption("features.carousel")) {
324
- clearInterval(self[configSymbol].autoPlayInterval);
325
- }
326
- }
327
- }
328
- }, delay);
329
- }
330
-
331
- setTimeout(() => {
332
- start();
333
- }, startDelay);
334
-
335
- if (autoPlay.mouseOverPause) {
336
- this.addEventListener("mouseover", () => {
337
- clearInterval(this[configSymbol].autoPlayInterval);
338
- });
339
-
340
- this.addEventListener("mouseout", () => {
341
- if (this[configSymbol].isDragging) {
342
- return;
343
- }
344
- start();
345
- });
346
- }
347
-
348
- if (autoPlay.touchPause) {
349
- this.addEventListener("touchstart", () => {
350
- clearInterval(this[configSymbol].autoPlayInterval);
351
- });
352
-
353
- this.addEventListener("touchend", () => {
354
- start();
355
- });
356
- }
357
-
292
+ const self = this;
293
+ const autoPlay = this.getOption("autoPlay");
294
+ const delay = autoPlay.delay;
295
+ const startDelay = autoPlay.startDelay;
296
+ const direction = autoPlay.direction;
297
+
298
+ function start() {
299
+ if (self[configSymbol].autoPlayInterval) {
300
+ clearInterval(self[configSymbol].autoPlayInterval);
301
+ }
302
+
303
+ self[configSymbol].autoPlayInterval = setInterval(() => {
304
+ if (direction === "next") {
305
+ if (self.next() === -1) {
306
+ if (self.getOption("features.carousel")) {
307
+ clearInterval(self[configSymbol].autoPlayInterval);
308
+ }
309
+ }
310
+ } else {
311
+ if (self.previous() === -1) {
312
+ if (self.getOption("features.carousel")) {
313
+ clearInterval(self[configSymbol].autoPlayInterval);
314
+ }
315
+ }
316
+ }
317
+ }, delay);
318
+ }
319
+
320
+ setTimeout(() => {
321
+ start();
322
+ }, startDelay);
323
+
324
+ if (autoPlay.mouseOverPause) {
325
+ this.addEventListener("mouseover", () => {
326
+ clearInterval(this[configSymbol].autoPlayInterval);
327
+ });
328
+
329
+ this.addEventListener("mouseout", () => {
330
+ if (this[configSymbol].isDragging) {
331
+ return;
332
+ }
333
+ start();
334
+ });
335
+ }
336
+
337
+ if (autoPlay.touchPause) {
338
+ this.addEventListener("touchstart", () => {
339
+ clearInterval(this[configSymbol].autoPlayInterval);
340
+ });
341
+
342
+ this.addEventListener("touchend", () => {
343
+ start();
344
+ });
345
+ }
358
346
  }
359
347
 
360
348
  /**
361
349
  * @private
362
350
  */
363
351
  function initCarousel() {
352
+ const { slides, totalSlides } = getSlidesAndTotal.call(this);
353
+ if (this.getOption("features.carousel") && totalSlides > 2) {
354
+ const firstElement = slides[0].cloneNode(true);
355
+ firstElement.setAttribute(ATTRIBUTE_CLON_FROM, 1);
364
356
 
365
- const {slides, totalSlides} = getSlidesAndTotal.call(this);
366
- if (this.getOption("features.carousel") && totalSlides > 2) {
367
-
368
- const firstElement = slides[0].cloneNode(true);
369
- firstElement.setAttribute(ATTRIBUTE_CLON_FROM, 1);
370
-
371
- const lastElement = slides[totalSlides - 1].cloneNode(true);
372
- lastElement.setAttribute(ATTRIBUTE_CLON_FROM, totalSlides);
373
- slides[totalSlides - 1].insertAdjacentElement("afterend", firstElement);
357
+ const lastElement = slides[totalSlides - 1].cloneNode(true);
358
+ lastElement.setAttribute(ATTRIBUTE_CLON_FROM, totalSlides);
359
+ slides[totalSlides - 1].insertAdjacentElement("afterend", firstElement);
374
360
 
375
- slides[0].insertAdjacentElement("beforebegin", lastElement);
361
+ slides[0].insertAdjacentElement("beforebegin", lastElement);
376
362
 
377
- moveTo.call(this, 1);
378
-
379
- }
363
+ moveTo.call(this, 1);
364
+ }
380
365
  }
381
366
 
382
367
  /**
@@ -384,9 +369,9 @@ function initCarousel() {
384
369
  * @returns {{slides: unknown[], totalSlides: number}}
385
370
  */
386
371
  function getSlidesAndTotal() {
387
- const slides = Array.from(getSlottedElements.call(this, ":scope", null));
388
- const totalSlides = slides.length;
389
- return {slides, totalSlides};
372
+ const slides = Array.from(getSlottedElements.call(this, ":scope", null));
373
+ const totalSlides = slides.length;
374
+ return { slides, totalSlides };
390
375
  }
391
376
 
392
377
  /**
@@ -394,23 +379,22 @@ function getSlidesAndTotal() {
394
379
  * @returns {number}
395
380
  */
396
381
  function next() {
397
-
398
- const {slides, totalSlides} = getSlidesAndTotal.call(this);
399
- const nextIndex = this[configSymbol].currentIndex + 1;
400
-
401
- if (nextIndex >= totalSlides) {
402
- return -1;
403
- }
404
-
405
- queueMicrotask(() => {
406
- getWindow().requestAnimationFrame(() => {
407
- getWindow().requestAnimationFrame(() => {
408
- moveTo.call(this, nextIndex);
409
- });
410
- });
411
- });
412
-
413
- return 0;
382
+ const { slides, totalSlides } = getSlidesAndTotal.call(this);
383
+ const nextIndex = this[configSymbol].currentIndex + 1;
384
+
385
+ if (nextIndex >= totalSlides) {
386
+ return -1;
387
+ }
388
+
389
+ queueMicrotask(() => {
390
+ getWindow().requestAnimationFrame(() => {
391
+ getWindow().requestAnimationFrame(() => {
392
+ moveTo.call(this, nextIndex);
393
+ });
394
+ });
395
+ });
396
+
397
+ return 0;
414
398
  }
415
399
 
416
400
  /**
@@ -418,15 +402,14 @@ function next() {
418
402
  * @returns {number}
419
403
  */
420
404
  function prev() {
405
+ const prevIndex = this[configSymbol].currentIndex - 1;
421
406
 
422
- const prevIndex = this[configSymbol].currentIndex - 1;
423
-
424
- if (prevIndex < 0) {
425
- return -1;
426
- }
407
+ if (prevIndex < 0) {
408
+ return -1;
409
+ }
427
410
 
428
- moveTo.call(this, prevIndex);
429
- return 0;
411
+ moveTo.call(this, prevIndex);
412
+ return 0;
430
413
  }
431
414
 
432
415
  /**
@@ -435,21 +418,20 @@ function prev() {
435
418
  * @param index
436
419
  */
437
420
  function setMoveProperties(slides, index) {
421
+ this[configSymbol].currentIndex = index;
438
422
 
439
- this[configSymbol].currentIndex = index
440
-
441
- slides.forEach((slide) => {
442
- slide.classList.remove("current");
443
- })
444
-
445
- let offset = -(index * 100);
446
- if (offset !== 0) {
447
- offset += "%";
448
- }
423
+ slides.forEach((slide) => {
424
+ slide.classList.remove("current");
425
+ });
449
426
 
450
- this[sliderElementSymbol].style.transform = `translateX(calc(${offset} + ${this[configSymbol].draggingPos}px))`;
451
- slides[index].classList.add("current");
427
+ let offset = -(index * 100);
428
+ if (offset !== 0) {
429
+ offset += "%";
430
+ }
452
431
 
432
+ this[sliderElementSymbol].style.transform =
433
+ `translateX(calc(${offset} + ${this[configSymbol].draggingPos}px))`;
434
+ slides[index].classList.add("current");
453
435
  }
454
436
 
455
437
  /**
@@ -458,93 +440,97 @@ function setMoveProperties(slides, index) {
458
440
  * @fires monster-slider-moved
459
441
  */
460
442
  function moveTo(index) {
443
+ const { slides, totalSlides } = getSlidesAndTotal.call(this);
461
444
 
462
- const {slides, totalSlides} = getSlidesAndTotal.call(this);
445
+ if (index < 0) {
446
+ index = totalSlides - 1;
447
+ } else if (index >= totalSlides) {
448
+ index = 0;
449
+ }
463
450
 
464
- if (index < 0) {
465
- index = totalSlides - 1
466
- } else if (index >= totalSlides) {
467
- index = 0
468
- }
451
+ const slider = this[sliderElementSymbol];
469
452
 
470
- const slider = this[sliderElementSymbol];
453
+ setMoveProperties.call(this, slides, index);
471
454
 
472
- setMoveProperties.call(this, slides, index);
455
+ const style = getComputedStyle(this[sliderElementSymbol]);
456
+ const duration = style.transitionDuration;
457
+ const durationMilis = parseFloat(duration) * 1000;
473
458
 
474
- const style = getComputedStyle(this[sliderElementSymbol]);
475
- const duration = style.transitionDuration;
476
- const durationMilis = parseFloat(duration) * 1000;
459
+ let slideIndex = index;
460
+ let eventFired = false;
477
461
 
478
- let slideIndex = index;
479
- let eventFired = false;
462
+ if (this.getOption("features.carousel")) {
463
+ slideIndex = index - 1;
480
464
 
481
- if (this.getOption("features.carousel")) {
482
- slideIndex = index - 1;
465
+ if (slides[index].hasAttribute(ATTRIBUTE_CLON_FROM)) {
466
+ const from = parseInt(slides[index].getAttribute(ATTRIBUTE_CLON_FROM));
483
467
 
484
- if (slides[index].hasAttribute(ATTRIBUTE_CLON_FROM)) {
485
- const from = parseInt(slides[index].getAttribute(ATTRIBUTE_CLON_FROM));
468
+ getWindow().requestAnimationFrame(() => {
469
+ getWindow().requestAnimationFrame(() => {
470
+ setTimeout(() => {
471
+ slider.style.transitionProperty = "none";
486
472
 
487
- getWindow().requestAnimationFrame(() => {
488
- getWindow().requestAnimationFrame(() => {
489
- setTimeout(() => {
490
- slider.style.transitionProperty = "none";
473
+ setMoveProperties.call(this, slides, from);
474
+ slideIndex = from - 1;
491
475
 
492
- setMoveProperties.call(this, slides, from);
493
- slideIndex = from - 1;
476
+ getWindow().requestAnimationFrame(() => {
477
+ getWindow().requestAnimationFrame(() => {
478
+ slider.style.transitionProperty = "";
494
479
 
495
- getWindow().requestAnimationFrame(() => {
496
- getWindow().requestAnimationFrame(() => {
497
- slider.style.transitionProperty = "";
480
+ fireCustomEvent(this, "monster-slider-moved", {
481
+ index: slideIndex,
482
+ });
498
483
 
499
- fireCustomEvent(this, "monster-slider-moved", {
500
- index: slideIndex,
501
- })
484
+ eventFired = true;
485
+ });
486
+ });
487
+ }, durationMilis);
488
+ });
489
+ });
490
+ }
491
+ }
502
492
 
503
- eventFired = true;
504
- });
505
- });
506
- }, durationMilis);
507
- });
508
- });
509
- }
510
- }
511
-
512
- if (!eventFired) {
513
- fireCustomEvent(this, "monster-slider-moved", {
514
- index: slideIndex,
515
- })
516
- }
493
+ if (!eventFired) {
494
+ fireCustomEvent(this, "monster-slider-moved", {
495
+ index: slideIndex,
496
+ });
497
+ }
517
498
  }
518
499
 
519
-
520
500
  /**
521
501
  * @private
522
502
  * @return {initEventHandler}
523
503
  */
524
504
  function initEventHandler() {
525
- const self = this;
505
+ const self = this;
506
+
507
+ const nextElements = this[nextElementSymbol];
526
508
 
527
- const nextElements = this[nextElementSymbol];
509
+ if (nextElements) {
510
+ nextElements.addEventListener("click", () => {
511
+ self.next();
512
+ });
513
+ }
528
514
 
529
- if (nextElements) {
530
- nextElements.addEventListener("click", () => {
531
- self.next();
532
- });
533
- }
515
+ const prevElements = this[prevElementSymbol];
534
516
 
535
- const prevElements = this[prevElementSymbol];
517
+ if (prevElements) {
518
+ prevElements.addEventListener("click", () => {
519
+ self.previous();
520
+ });
521
+ }
536
522
 
537
- if (prevElements) {
538
- prevElements.addEventListener("click", () => {
539
- self.previous();
540
- });
541
- }
523
+ if (this.getOption("features.drag")) {
524
+ this[sliderElementSymbol].addEventListener("mousedown", (e) =>
525
+ startDragging.call(this, e, "mouse"),
526
+ );
542
527
 
543
- this[sliderElementSymbol].addEventListener('mousedown', (e) => startDragging.call(this, e, 'mouse'));
544
- this[sliderElementSymbol].addEventListener('touchstart', (e) => startDragging.call(this, e, 'touch'));
545
- // this[sliderElementSymbol].addEventListener('touchend', () => stopDragging.call(this, 'touch'));
546
- // this[sliderElementSymbol].addEventListener('touchmove', (e) => dragging.call(this, e, 'touch'));
547
- return this;
528
+ this[sliderElementSymbol].addEventListener("touchstart", (e) =>
529
+ startDragging.call(this, e, "touch"),
530
+ );
531
+ }
532
+
533
+ return this;
548
534
  }
549
535
 
550
536
  /**
@@ -553,49 +539,45 @@ function initEventHandler() {
553
539
  * @param type
554
540
  */
555
541
  function startDragging(e, type) {
542
+ this[configSymbol].isDragging = true;
543
+ this[configSymbol].startPos = getPositionX(e, type);
544
+ this[sliderElementSymbol].classList.add("grabbing");
545
+ this[sliderElementSymbol].style.transitionProperty = "none";
556
546
 
557
- this[configSymbol].isDragging = true;
558
- this[configSymbol].startPos = getPositionX(e, type);
559
- this[sliderElementSymbol].classList.add('grabbing');
560
- this[sliderElementSymbol].style.transitionProperty = "none";
561
-
562
- const callbackMousemove = (x) => {
563
- dragging.call(this, x, type);
564
- }
547
+ const callbackMousemove = (x) => {
548
+ dragging.call(this, x, type);
549
+ };
565
550
 
566
- const callbackMouseUp = () => {
567
-
568
- const endEvent = type === 'mouse' ? 'mouseup' : 'touchend';
569
- const moveEvent = type === 'mouse' ? 'mousemove' : 'touchmove';
551
+ const callbackMouseUp = () => {
552
+ const endEvent = type === "mouse" ? "mouseup" : "touchend";
553
+ const moveEvent = type === "mouse" ? "mousemove" : "touchmove";
570
554
 
571
- document.body.removeEventListener(endEvent, callbackMouseUp);
572
- document.body.removeEventListener(moveEvent, callbackMousemove);
555
+ document.body.removeEventListener(endEvent, callbackMouseUp);
556
+ document.body.removeEventListener(moveEvent, callbackMousemove);
573
557
 
574
- this[configSymbol].isDragging = false;
575
- this[configSymbol].startPos = 0;
576
- this[sliderElementSymbol].classList.remove('grabbing');
577
- this[sliderElementSymbol].style.transitionProperty = "";
558
+ this[configSymbol].isDragging = false;
559
+ this[configSymbol].startPos = 0;
560
+ this[sliderElementSymbol].classList.remove("grabbing");
561
+ this[sliderElementSymbol].style.transitionProperty = "";
578
562
 
579
- const lastPos = this[configSymbol].draggingPos;
580
- const widthOfSlider = this[sliderElementSymbol].offsetWidth;
581
- this[configSymbol].draggingPos = 0;
563
+ const lastPos = this[configSymbol].draggingPos;
564
+ const widthOfSlider = this[sliderElementSymbol].offsetWidth;
565
+ this[configSymbol].draggingPos = 0;
582
566
 
583
- let newIndex = this[configSymbol].currentIndex;
567
+ let newIndex = this[configSymbol].currentIndex;
584
568
 
585
- const x = lastPos / widthOfSlider;
586
- if (x > 0.5) {
587
- newIndex--;
588
- } else if (x < -0.5) {
589
- newIndex++;
590
- }
569
+ const x = lastPos / widthOfSlider;
570
+ if (x > 0.5) {
571
+ newIndex--;
572
+ } else if (x < -0.5) {
573
+ newIndex++;
574
+ }
591
575
 
592
- this.moveTo(newIndex);
593
-
594
- }
595
-
596
- document.body.addEventListener('mouseup', callbackMouseUp);
597
- document.body.addEventListener('mousemove', callbackMousemove);
576
+ this.moveTo(newIndex);
577
+ };
598
578
 
579
+ document.body.addEventListener("mouseup", callbackMouseUp);
580
+ document.body.addEventListener("mousemove", callbackMousemove);
599
581
  }
600
582
 
601
583
  /**
@@ -605,7 +587,7 @@ function startDragging(e, type) {
605
587
  * @returns {*|number|number}
606
588
  */
607
589
  function getPositionX(e, type) {
608
- return type === 'mouse' ? e.pageX : e.touches[0].clientX;
590
+ return type === "mouse" ? e.pageX : e.touches[0].clientX;
609
591
  }
610
592
 
611
593
  /**
@@ -614,10 +596,11 @@ function getPositionX(e, type) {
614
596
  * @param type
615
597
  */
616
598
  function dragging(e, type) {
617
- if (!this[configSymbol].isDragging) return;
618
- this[configSymbol].draggingPos = getPositionX(e, type) - this[configSymbol].startPos;
619
- const {slides, totalSlides} = getSlidesAndTotal.call(this);
620
- setMoveProperties.call(this, slides, this[configSymbol].currentIndex);
599
+ if (!this[configSymbol].isDragging) return;
600
+ this[configSymbol].draggingPos =
601
+ getPositionX(e, type) - this[configSymbol].startPos;
602
+ const { slides, totalSlides } = getSlidesAndTotal.call(this);
603
+ setMoveProperties.call(this, slides, this[configSymbol].currentIndex);
621
604
  }
622
605
 
623
606
  /**
@@ -625,22 +608,21 @@ function dragging(e, type) {
625
608
  * @return {void}
626
609
  */
627
610
  function initControlReferences() {
611
+ this[controlElementSymbol] = this.shadowRoot.querySelector(
612
+ `[${ATTRIBUTE_ROLE}="control"]`,
613
+ );
628
614
 
629
- this[controlElementSymbol] = this.shadowRoot.querySelector(
630
- `[${ATTRIBUTE_ROLE}="control"]`,
631
- );
615
+ this[sliderElementSymbol] = this.shadowRoot.querySelector(
616
+ `[${ATTRIBUTE_ROLE}="slider"]`,
617
+ );
632
618
 
633
- this[sliderElementSymbol] = this.shadowRoot.querySelector(
634
- `[${ATTRIBUTE_ROLE}="slider"]`,
635
- );
619
+ this[prevElementSymbol] = this.shadowRoot.querySelector(
620
+ `[${ATTRIBUTE_ROLE}="prev"]`,
621
+ );
636
622
 
637
- this[prevElementSymbol] = this.shadowRoot.querySelector(
638
- `[${ATTRIBUTE_ROLE}="prev"]`,
639
- );
640
-
641
- this[nextElementSymbol] = this.shadowRoot.querySelector(
642
- `[${ATTRIBUTE_ROLE}="next"]`,
643
- );
623
+ this[nextElementSymbol] = this.shadowRoot.querySelector(
624
+ `[${ATTRIBUTE_ROLE}="next"]`,
625
+ );
644
626
  }
645
627
 
646
628
  /**
@@ -648,8 +630,8 @@ function initControlReferences() {
648
630
  * @return {string}
649
631
  */
650
632
  function getTemplate() {
651
- // language=HTML
652
- return `
633
+ // language=HTML
634
+ return `
653
635
  <div data-monster-role="control" part="control">
654
636
  <div class="prev" data-monster-role="prev" part="prev">
655
637
  <slot name="prev"></slot>
@@ -664,5 +646,4 @@ function getTemplate() {
664
646
  </div>`;
665
647
  }
666
648
 
667
-
668
649
  registerCustomElement(Slider);