@schukai/monster 3.74.0 → 3.76.0
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 +35 -6
- package/package.json +1 -1
- package/source/components/datatable/datasource/rest.mjs +0 -1
- package/source/components/form/api-button.mjs +0 -1
- package/source/components/form/context-error.mjs +0 -1
- package/source/components/form/context-help.mjs +0 -1
- package/source/components/form/message-state-button.mjs +0 -1
- package/source/components/form/popper-button.mjs +0 -1
- package/source/components/form/select.mjs +16 -5
- package/source/components/form/toggle-switch.mjs +0 -3
- package/source/components/form/tree-select.mjs +0 -1
- package/source/components/layout/collapse.mjs +361 -395
- package/source/components/layout/details.mjs +10 -40
- package/source/components/layout/iframe.mjs +358 -0
- package/source/components/layout/panel.mjs +10 -25
- package/source/components/layout/slider.mjs +420 -439
- package/source/components/layout/split-panel.mjs +7 -39
- package/source/components/layout/style/iframe.pcss +39 -0
- package/source/components/layout/style/panel.pcss +10 -3
- package/source/components/layout/style/split-panel.pcss +2 -0
- package/source/components/layout/stylesheet/iframe.mjs +38 -0
- package/source/components/layout/stylesheet/panel.mjs +1 -1
- package/source/components/layout/stylesheet/slider.mjs +13 -6
- package/source/components/layout/tabs.mjs +6 -35
- package/source/components/layout/width-toggle.mjs +10 -31
- package/source/components/navigation/table-of-content.mjs +0 -1
- package/source/components/tree-menu/dragable-tree-menu.mjs +4 -4
- package/source/components/tree-menu/tree-menu.mjs +16 -12
- package/source/data/datasource/server/restapi.mjs +1 -1
- package/source/dom/updater.mjs +767 -771
- package/source/math/random.mjs +2 -3
- package/source/monster.mjs +12 -3
- package/source/types/version.mjs +1 -1
- package/test/cases/components/form/button.mjs +2 -1
- package/test/cases/components/form/confirm-button.mjs +1 -1
- package/test/cases/components/form/form.mjs +1 -1
- package/test/cases/components/form/reload.mjs +1 -1
- package/test/cases/components/form/select.mjs +1 -1
- package/test/cases/components/form/state-button.mjs +1 -1
- package/test/cases/components/form/template.mjs +1 -1
- package/test/cases/components/form/toggle-switch.mjs +1 -1
- package/test/cases/components/form/tree-select.mjs +1 -1
- package/test/cases/components/host/details.mjs +1 -1
- package/test/cases/components/host/host.mjs +1 -1
- package/test/cases/components/host/overlay.mjs +1 -1
- package/test/cases/components/layout/panel.mjs +1 -1
- package/test/cases/components/layout/slit-panel.mjs +1 -1
- package/test/cases/components/layout/tabs.mjs +1 -1
- package/test/cases/components/notify/message.mjs +1 -1
- package/test/cases/components/notify/notify.mjs +1 -1
- package/test/cases/dom/customcontrol.mjs +1 -1
- package/test/cases/dom/customelement-initfromscripthost.mjs +1 -1
- package/test/cases/dom/customelement.mjs +1 -1
- package/test/cases/dom/resource/data.mjs +1 -1
- package/test/cases/dom/resource/link/stylesheet.mjs +1 -1
- package/test/cases/dom/resource/link.mjs +1 -1
- package/test/cases/dom/resource/script.mjs +1 -1
- package/test/cases/dom/updater.mjs +1 -1
- package/test/cases/monster.mjs +1 -1
- package/test/web/test.html +2 -2
- package/test/web/tests.js +6 -15
|
@@ -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 {
|
|
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
|
-
|
|
17
|
-
|
|
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 {
|
|
26
|
-
import {
|
|
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,166 +58,161 @@ const configSymbol = Symbol("config");
|
|
|
65
58
|
* @private
|
|
66
59
|
* @type {string}
|
|
67
60
|
*/
|
|
68
|
-
const
|
|
61
|
+
const ATTRIBUTE_CLONE_FROM = ATTRIBUTE_PREFIX + "clone-from";
|
|
69
62
|
|
|
70
63
|
/**
|
|
71
64
|
* A Slider
|
|
72
65
|
*
|
|
73
|
-
* @fragments /fragments/components/
|
|
66
|
+
* @fragments /fragments/components/layout/slider/
|
|
74
67
|
*
|
|
75
|
-
* @example /examples/components/
|
|
68
|
+
* @example /examples/components/layout/slider-simple
|
|
76
69
|
*
|
|
77
70
|
* @since 3.74.0
|
|
78
71
|
* @copyright schukai GmbH
|
|
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
|
-
|
|
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
|
-
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 autoplay
|
|
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
|
-
|
|
236
|
-
|
|
237
|
-
|
|
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
|
-
|
|
245
|
-
|
|
232
|
+
initNavigation.call(this, "next");
|
|
233
|
+
initNavigation.call(this, "prev");
|
|
246
234
|
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
235
|
+
if (this.getOption("features.thumbnails")) {
|
|
236
|
+
initThumbnails.call(this);
|
|
237
|
+
}
|
|
250
238
|
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
239
|
+
if (this.getOption("features.carousel")) {
|
|
240
|
+
initCarousel.call(this);
|
|
241
|
+
}
|
|
254
242
|
|
|
255
|
-
|
|
256
|
-
|
|
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
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
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
|
-
|
|
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
|
-
}
|
|
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_CLONE_FROM, 1);
|
|
364
356
|
|
|
365
|
-
|
|
366
|
-
|
|
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_CLONE_FROM, totalSlides);
|
|
359
|
+
slides[totalSlides - 1].insertAdjacentElement("afterend", firstElement);
|
|
374
360
|
|
|
375
|
-
|
|
361
|
+
slides[0].insertAdjacentElement("beforebegin", lastElement);
|
|
376
362
|
|
|
377
|
-
|
|
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
|
-
|
|
388
|
-
|
|
389
|
-
|
|
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
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
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
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
return -1;
|
|
426
|
-
}
|
|
407
|
+
if (prevIndex < 0) {
|
|
408
|
+
return -1;
|
|
409
|
+
}
|
|
427
410
|
|
|
428
|
-
|
|
429
|
-
|
|
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
|
-
|
|
440
|
-
|
|
441
|
-
|
|
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
|
-
|
|
451
|
-
|
|
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
|
-
|
|
445
|
+
if (index < 0) {
|
|
446
|
+
index = totalSlides - 1;
|
|
447
|
+
} else if (index >= totalSlides) {
|
|
448
|
+
index = 0;
|
|
449
|
+
}
|
|
463
450
|
|
|
464
|
-
|
|
465
|
-
index = totalSlides - 1
|
|
466
|
-
} else if (index >= totalSlides) {
|
|
467
|
-
index = 0
|
|
468
|
-
}
|
|
451
|
+
const slider = this[sliderElementSymbol];
|
|
469
452
|
|
|
470
|
-
|
|
453
|
+
setMoveProperties.call(this, slides, index);
|
|
471
454
|
|
|
472
|
-
|
|
455
|
+
const style = getComputedStyle(this[sliderElementSymbol]);
|
|
456
|
+
const duration = style.transitionDuration;
|
|
457
|
+
const durationMilis = parseFloat(duration) * 1000;
|
|
473
458
|
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
const durationMilis = parseFloat(duration) * 1000;
|
|
459
|
+
let slideIndex = index;
|
|
460
|
+
let eventFired = false;
|
|
477
461
|
|
|
478
|
-
|
|
479
|
-
|
|
462
|
+
if (this.getOption("features.carousel")) {
|
|
463
|
+
slideIndex = index - 1;
|
|
480
464
|
|
|
481
|
-
|
|
482
|
-
|
|
465
|
+
if (slides[index].hasAttribute(ATTRIBUTE_CLONE_FROM)) {
|
|
466
|
+
const from = parseInt(slides[index].getAttribute(ATTRIBUTE_CLONE_FROM));
|
|
483
467
|
|
|
484
|
-
|
|
485
|
-
|
|
468
|
+
getWindow().requestAnimationFrame(() => {
|
|
469
|
+
getWindow().requestAnimationFrame(() => {
|
|
470
|
+
setTimeout(() => {
|
|
471
|
+
slider.style.transitionProperty = "none";
|
|
486
472
|
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
setTimeout(() => {
|
|
490
|
-
slider.style.transitionProperty = "none";
|
|
473
|
+
setMoveProperties.call(this, slides, from);
|
|
474
|
+
slideIndex = from - 1;
|
|
491
475
|
|
|
492
|
-
|
|
493
|
-
|
|
476
|
+
getWindow().requestAnimationFrame(() => {
|
|
477
|
+
getWindow().requestAnimationFrame(() => {
|
|
478
|
+
slider.style.transitionProperty = "";
|
|
494
479
|
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
480
|
+
fireCustomEvent(this, "monster-slider-moved", {
|
|
481
|
+
index: slideIndex,
|
|
482
|
+
});
|
|
498
483
|
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
484
|
+
eventFired = true;
|
|
485
|
+
});
|
|
486
|
+
});
|
|
487
|
+
}, durationMilis);
|
|
488
|
+
});
|
|
489
|
+
});
|
|
490
|
+
}
|
|
491
|
+
}
|
|
502
492
|
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
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
|
-
|
|
505
|
+
const self = this;
|
|
506
|
+
|
|
507
|
+
const nextElements = this[nextElementSymbol];
|
|
526
508
|
|
|
527
|
-
|
|
509
|
+
if (nextElements) {
|
|
510
|
+
nextElements.addEventListener("click", () => {
|
|
511
|
+
self.next();
|
|
512
|
+
});
|
|
513
|
+
}
|
|
528
514
|
|
|
529
|
-
|
|
530
|
-
nextElements.addEventListener("click", () => {
|
|
531
|
-
self.next();
|
|
532
|
-
});
|
|
533
|
-
}
|
|
515
|
+
const prevElements = this[prevElementSymbol];
|
|
534
516
|
|
|
535
|
-
|
|
517
|
+
if (prevElements) {
|
|
518
|
+
prevElements.addEventListener("click", () => {
|
|
519
|
+
self.previous();
|
|
520
|
+
});
|
|
521
|
+
}
|
|
536
522
|
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
}
|
|
523
|
+
if (this.getOption("features.drag")) {
|
|
524
|
+
this[sliderElementSymbol].addEventListener("mousedown", (e) =>
|
|
525
|
+
startDragging.call(this, e, "mouse"),
|
|
526
|
+
);
|
|
542
527
|
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
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
|
-
|
|
558
|
-
|
|
559
|
-
|
|
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
|
-
|
|
567
|
-
|
|
568
|
-
|
|
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
|
-
|
|
572
|
-
|
|
555
|
+
document.body.removeEventListener(endEvent, callbackMouseUp);
|
|
556
|
+
document.body.removeEventListener(moveEvent, callbackMousemove);
|
|
573
557
|
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
558
|
+
this[configSymbol].isDragging = false;
|
|
559
|
+
this[configSymbol].startPos = 0;
|
|
560
|
+
this[sliderElementSymbol].classList.remove("grabbing");
|
|
561
|
+
this[sliderElementSymbol].style.transitionProperty = "";
|
|
578
562
|
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
563
|
+
const lastPos = this[configSymbol].draggingPos;
|
|
564
|
+
const widthOfSlider = this[sliderElementSymbol].offsetWidth;
|
|
565
|
+
this[configSymbol].draggingPos = 0;
|
|
582
566
|
|
|
583
|
-
|
|
567
|
+
let newIndex = this[configSymbol].currentIndex;
|
|
584
568
|
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
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
|
-
|
|
630
|
-
|
|
631
|
-
|
|
615
|
+
this[sliderElementSymbol] = this.shadowRoot.querySelector(
|
|
616
|
+
`[${ATTRIBUTE_ROLE}="slider"]`,
|
|
617
|
+
);
|
|
632
618
|
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
619
|
+
this[prevElementSymbol] = this.shadowRoot.querySelector(
|
|
620
|
+
`[${ATTRIBUTE_ROLE}="prev"]`,
|
|
621
|
+
);
|
|
636
622
|
|
|
637
|
-
|
|
638
|
-
|
|
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,21 +630,20 @@ function initControlReferences() {
|
|
|
648
630
|
* @return {string}
|
|
649
631
|
*/
|
|
650
632
|
function getTemplate() {
|
|
651
|
-
|
|
652
|
-
|
|
633
|
+
// language=HTML
|
|
634
|
+
return `
|
|
653
635
|
<div data-monster-role="control" part="control">
|
|
654
|
-
<div class="prev" data-monster-role="prev" part="prev">
|
|
636
|
+
<div class="prev" data-monster-role="prev" part="prev" part="prev">
|
|
655
637
|
<slot name="prev"></slot>
|
|
656
638
|
</div>
|
|
657
|
-
<div data-monster-role="slider">
|
|
639
|
+
<div data-monster-role="slider" part="slides">
|
|
658
640
|
<slot></slot>
|
|
659
641
|
</div>
|
|
660
642
|
<div data-monster-role="thumbnails"></div>
|
|
661
|
-
<div class="next" data-monster-role="next" part="next">
|
|
643
|
+
<div class="next" data-monster-role="next" part="next" part="next">
|
|
662
644
|
<slot name="next"></slot>
|
|
663
645
|
</div>
|
|
664
646
|
</div>`;
|
|
665
647
|
}
|
|
666
648
|
|
|
667
|
-
|
|
668
649
|
registerCustomElement(Slider);
|