|
@@ -87,16 +87,11 @@ function toggleClass(elm, classes, force) {
|
|
function addClass(elm, classes) {
|
|
function addClass(elm, classes) {
|
|
toggleClass(elm, classes, true);
|
|
toggleClass(elm, classes, true);
|
|
}
|
|
}
|
|
-function append(parent, children2) {
|
|
|
|
- forEach(children2, parent.appendChild.bind(parent));
|
|
|
|
|
|
+function append(parent, ...children2) {
|
|
|
|
+ parent && parent.append(...children2);
|
|
}
|
|
}
|
|
-function before(nodes, ref) {
|
|
|
|
- forEach(nodes, (node) => {
|
|
|
|
- const parent = (ref || node).parentNode;
|
|
|
|
- if (parent) {
|
|
|
|
- parent.insertBefore(node, ref);
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
|
|
+function before(ref, ...nodes) {
|
|
|
|
+ ref && ref.before(...nodes);
|
|
}
|
|
}
|
|
function matches(elm, selector) {
|
|
function matches(elm, selector) {
|
|
return isHTMLElement(elm) && elm.matches(selector);
|
|
return isHTMLElement(elm) && elm.matches(selector);
|
|
@@ -933,7 +928,7 @@ const Slides = (Splide, Components, options, event) => {
|
|
}
|
|
}
|
|
if (isHTMLElement(slide)) {
|
|
if (isHTMLElement(slide)) {
|
|
const ref = slides[index];
|
|
const ref = slides[index];
|
|
- ref ? before(slide, ref) : append(list, slide);
|
|
|
|
|
|
+ ref ? before(ref, slide) : append(list, slide);
|
|
addClass(slide, options.classes.slide);
|
|
addClass(slide, options.classes.slide);
|
|
observeImages(slide, apply(emit, EVENT_RESIZE));
|
|
observeImages(slide, apply(emit, EVENT_RESIZE));
|
|
}
|
|
}
|
|
@@ -1144,7 +1139,7 @@ const Clones = (Splide, Components, options, event) => {
|
|
push(slides.slice(-count), slides.slice(0, count)).forEach((Slide, index) => {
|
|
push(slides.slice(-count), slides.slice(0, count)).forEach((Slide, index) => {
|
|
const isHead = index < count;
|
|
const isHead = index < count;
|
|
const clone = cloneDeep(Slide.slide, index);
|
|
const clone = cloneDeep(Slide.slide, index);
|
|
- isHead ? before(clone, slides[0].slide) : append(Elements.list, clone);
|
|
|
|
|
|
+ isHead ? before(slides[0].slide, clone) : append(Elements.list, clone);
|
|
push(clones, clone);
|
|
push(clones, clone);
|
|
Slides.register(clone, index - count + (isHead ? 0 : length), Slide.index);
|
|
Slides.register(clone, index - count + (isHead ? 0 : length), Slide.index);
|
|
});
|
|
});
|
|
@@ -1551,8 +1546,8 @@ const Arrows = (Splide, Components, options, event) => {
|
|
prev = createArrow(true);
|
|
prev = createArrow(true);
|
|
next = createArrow(false);
|
|
next = createArrow(false);
|
|
created = true;
|
|
created = true;
|
|
- append(wrapper, [prev, next]);
|
|
|
|
- !placeholder && before(wrapper, track);
|
|
|
|
|
|
+ append(wrapper, prev, next);
|
|
|
|
+ !placeholder && before(track, wrapper);
|
|
}
|
|
}
|
|
function createArrow(prev2) {
|
|
function createArrow(prev2) {
|
|
const arrow = `<button class="${classes.arrow} ${prev2 ? classes.prev : classes.next}" type="button"><svg xmlns="${XML_NAME_SPACE}" viewBox="0 0 ${SIZE} ${SIZE}" width="${SIZE}" height="${SIZE}"><path d="${options.arrowPath || PATH}" />`;
|
|
const arrow = `<button class="${classes.arrow} ${prev2 ? classes.prev : classes.next}" type="button"><svg xmlns="${XML_NAME_SPACE}" viewBox="0 0 ${SIZE} ${SIZE}" width="${SIZE}" height="${SIZE}"><path d="${options.arrowPath || PATH}" />`;
|
|
@@ -1934,38 +1929,22 @@ const Keyboard = (Splide, Components, options, event) => {
|
|
const { on, bind, destroy } = event;
|
|
const { on, bind, destroy } = event;
|
|
const { root } = Splide;
|
|
const { root } = Splide;
|
|
const { resolve } = Components.Direction;
|
|
const { resolve } = Components.Direction;
|
|
- let target;
|
|
|
|
- let disabled;
|
|
|
|
function mount() {
|
|
function mount() {
|
|
- init();
|
|
|
|
- on(EVENT_UPDATED, destroy);
|
|
|
|
- on(EVENT_UPDATED, init);
|
|
|
|
- on(EVENT_MOVE, onMove);
|
|
|
|
- }
|
|
|
|
- function init() {
|
|
|
|
const { keyboard } = options;
|
|
const { keyboard } = options;
|
|
- if (keyboard) {
|
|
|
|
- target = keyboard === "global" ? window : root;
|
|
|
|
- bind(target, KEYBOARD_EVENT, onKeydown);
|
|
|
|
- }
|
|
|
|
|
|
+ destroy();
|
|
|
|
+ keyboard && bind(keyboard === "global" ? window : root, KEYBOARD_EVENT, onKeydown);
|
|
|
|
+ on(EVENT_UPDATED, mount);
|
|
}
|
|
}
|
|
function disable(value) {
|
|
function disable(value) {
|
|
- disabled = value;
|
|
|
|
- }
|
|
|
|
- function onMove() {
|
|
|
|
- const _disabled = disabled;
|
|
|
|
- disabled = true;
|
|
|
|
- nextTick(() => {
|
|
|
|
- disabled = _disabled;
|
|
|
|
- });
|
|
|
|
|
|
+ value ? destroy() : mount();
|
|
}
|
|
}
|
|
function onKeydown(e) {
|
|
function onKeydown(e) {
|
|
- if (!disabled) {
|
|
|
|
- if (e.key === resolve(ARROW_LEFT)) {
|
|
|
|
- Splide.go("<");
|
|
|
|
- } else if (e.key === resolve(ARROW_RIGHT)) {
|
|
|
|
- Splide.go(">");
|
|
|
|
- }
|
|
|
|
|
|
+ if (e.key === resolve(ARROW_LEFT)) {
|
|
|
|
+ Splide.go("<");
|
|
|
|
+ prevent(e, true);
|
|
|
|
+ } else if (e.key === resolve(ARROW_RIGHT)) {
|
|
|
|
+ Splide.go(">");
|
|
|
|
+ prevent(e, true);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return {
|
|
return {
|