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