|
@@ -1170,13 +1170,14 @@ const Clones = (Splide, Components, options, event) => {
|
|
|
|
|
|
const Move = (Splide, Components, options, event) => {
|
|
const Move = (Splide, Components, options, event) => {
|
|
const { on, emit } = event;
|
|
const { on, emit } = event;
|
|
- const { set } = Splide.state;
|
|
|
|
|
|
+ const { set, is } = Splide.state;
|
|
const { Slides } = Components;
|
|
const { Slides } = Components;
|
|
const { slideSize, getPadding, listSize, sliderSize, totalSize, trackSize } = Components.Layout;
|
|
const { slideSize, getPadding, listSize, sliderSize, totalSize, trackSize } = Components.Layout;
|
|
const { resolve, orient } = Components.Direction;
|
|
const { resolve, orient } = Components.Direction;
|
|
const { list, track } = Components.Elements;
|
|
const { list, track } = Components.Elements;
|
|
let Transition;
|
|
let Transition;
|
|
let indices;
|
|
let indices;
|
|
|
|
+ let callback;
|
|
function mount() {
|
|
function mount() {
|
|
Transition = Components.Transition;
|
|
Transition = Components.Transition;
|
|
on([EVENT_MOUNTED, EVENT_RESIZED, EVENT_UPDATED, EVENT_REFRESH], reposition);
|
|
on([EVENT_MOUNTED, EVENT_RESIZED, EVENT_UPDATED, EVENT_REFRESH], reposition);
|
|
@@ -1188,29 +1189,27 @@ const Move = (Splide, Components, options, event) => {
|
|
Slides.update();
|
|
Slides.update();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- function move(dest, index, prev, callback) {
|
|
|
|
- const forwards = dest > prev;
|
|
|
|
- const closest = toIndex(getPosition());
|
|
|
|
- const detouring = exceededLimit(forwards) && abs(dest - closest) > abs(dest - prev);
|
|
|
|
|
|
+ function move(dest, index, prev, forwards, onMoved) {
|
|
cancel();
|
|
cancel();
|
|
- if ((dest !== index || detouring) && canShift(forwards)) {
|
|
|
|
- translate(shift(getPosition(), forwards), true);
|
|
|
|
- }
|
|
|
|
|
|
+ const shiftBackwards = dest !== index ? dest > index : forwards;
|
|
|
|
+ const shouldShift = (dest !== index || exceededLimit(forwards)) && canShift(shiftBackwards);
|
|
|
|
+ shouldShift && translate(shift(getPosition(), shiftBackwards), true);
|
|
indices = [index, prev, dest];
|
|
indices = [index, prev, dest];
|
|
|
|
+ callback = onMoved;
|
|
set(MOVING);
|
|
set(MOVING);
|
|
emit(EVENT_MOVE, index, prev, dest);
|
|
emit(EVENT_MOVE, index, prev, dest);
|
|
- Transition.start(index, () => {
|
|
|
|
- set(IDLE);
|
|
|
|
- emit(EVENT_MOVED, index, prev, dest);
|
|
|
|
- callback && callback();
|
|
|
|
- });
|
|
|
|
|
|
+ Transition.start(index, onTransitionEnd);
|
|
|
|
+ }
|
|
|
|
+ function onTransitionEnd() {
|
|
|
|
+ set(IDLE);
|
|
|
|
+ emit(EVENT_MOVED, ...indices);
|
|
|
|
+ callback && callback();
|
|
}
|
|
}
|
|
function cancel() {
|
|
function cancel() {
|
|
- if (Splide.state.is(MOVING) && indices) {
|
|
|
|
|
|
+ if (is(MOVING) && indices) {
|
|
translate(getPosition(), true);
|
|
translate(getPosition(), true);
|
|
Transition.cancel();
|
|
Transition.cancel();
|
|
- set(IDLE);
|
|
|
|
- emit(EVENT_MOVED, ...indices);
|
|
|
|
|
|
+ onTransitionEnd();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
function jump(index) {
|
|
function jump(index) {
|
|
@@ -1361,19 +1360,16 @@ const Controller = (Splide, Components, options, event) => {
|
|
}
|
|
}
|
|
function go(control, callback) {
|
|
function go(control, callback) {
|
|
if (!isBusy()) {
|
|
if (!isBusy()) {
|
|
- const dest = parse(control);
|
|
|
|
|
|
+ const [dest, forwards] = parse(control);
|
|
const index = loop(dest);
|
|
const index = loop(dest);
|
|
- if (canGo(dest, index)) {
|
|
|
|
|
|
+ const canGo = dest === index || Move.exceededLimit(!forwards) || Move.canShift(forwards);
|
|
|
|
+ if (index > -1 && canGo) {
|
|
Scroll.cancel();
|
|
Scroll.cancel();
|
|
setIndex(index);
|
|
setIndex(index);
|
|
- Move.move(dest, index, prevIndex, callback);
|
|
|
|
|
|
+ Move.move(dest, index, prevIndex, forwards, callback);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- function canGo(dest, index) {
|
|
|
|
- const forward = dest > prevIndex;
|
|
|
|
- return index > -1 && (index !== currIndex || !isMoving()) && (dest === index || Move.exceededLimit(!forward) || Move.canShift(forward));
|
|
|
|
- }
|
|
|
|
function jump(control) {
|
|
function jump(control) {
|
|
const { set } = Components.Breakpoints;
|
|
const { set } = Components.Breakpoints;
|
|
const { speed } = options;
|
|
const { speed } = options;
|
|
@@ -1389,22 +1385,23 @@ const Controller = (Splide, Components, options, event) => {
|
|
});
|
|
});
|
|
}
|
|
}
|
|
function parse(control) {
|
|
function parse(control) {
|
|
- let index = currIndex;
|
|
|
|
|
|
+ let dest = currIndex;
|
|
|
|
+ let forwards = true;
|
|
if (isString(control)) {
|
|
if (isString(control)) {
|
|
- const [, indicator, number] = control.match(/([+\-<>]\|?)(\d+)?/) || [];
|
|
|
|
- if (indicator === "+" || indicator === "-") {
|
|
|
|
- index = computeDestIndex(currIndex + +`${indicator}${+number || 1}`, currIndex);
|
|
|
|
- } else if (indicator === ">") {
|
|
|
|
- index = number ? toIndex(+number) : getNext(true);
|
|
|
|
- } else if (indicator === "<") {
|
|
|
|
- index = getPrev(true);
|
|
|
|
- } else if (indicator === ">|") {
|
|
|
|
- index = endIndex;
|
|
|
|
|
|
+ const [, indicator, number] = control.match(/([+-]|>>?|<<?)(-?\d+)?/) || [];
|
|
|
|
+ const oneOf = (...indicators) => includes(indicators, indicator);
|
|
|
|
+ forwards = oneOf("+", ">", ">>");
|
|
|
|
+ if (oneOf("+", "-")) {
|
|
|
|
+ dest = computeDestIndex(currIndex + +`${indicator}${+number || 1}`, currIndex);
|
|
|
|
+ } else if (oneOf(">", "<")) {
|
|
|
|
+ dest = number ? toIndex(+number) : getAdjacent(!forwards, true);
|
|
|
|
+ } else if (oneOf(">>", "<<")) {
|
|
|
|
+ dest = number ? +number || 0 : forwards ? endIndex : 0;
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
- index = isLoop ? control : clamp(control, 0, endIndex);
|
|
|
|
|
|
+ dest = isLoop ? control : clamp(control, 0, endIndex);
|
|
}
|
|
}
|
|
- return index;
|
|
|
|
|
|
+ return [dest, forwards];
|
|
}
|
|
}
|
|
function getAdjacent(prev, destination) {
|
|
function getAdjacent(prev, destination) {
|
|
const number = perMove || (hasFocus() ? 1 : perPage);
|
|
const number = perMove || (hasFocus() ? 1 : perPage);
|
|
@@ -1782,6 +1779,7 @@ const Drag = (Splide, Components, options, event) => {
|
|
const { Move, Scroll, Controller, Elements: { track }, Breakpoints: { reduce } } = Components;
|
|
const { Move, Scroll, Controller, Elements: { track }, Breakpoints: { reduce } } = Components;
|
|
const { resolve, orient } = Components.Direction;
|
|
const { resolve, orient } = Components.Direction;
|
|
const { getPosition, exceededLimit } = Move;
|
|
const { getPosition, exceededLimit } = Move;
|
|
|
|
+ let startCoord;
|
|
let basePosition;
|
|
let basePosition;
|
|
let baseEvent;
|
|
let baseEvent;
|
|
let prevBaseEvent;
|
|
let prevBaseEvent;
|
|
@@ -1813,6 +1811,7 @@ const Drag = (Splide, Components, options, event) => {
|
|
target = isTouch ? track : window;
|
|
target = isTouch ? track : window;
|
|
dragging = state.is([MOVING, SCROLLING]);
|
|
dragging = state.is([MOVING, SCROLLING]);
|
|
prevBaseEvent = null;
|
|
prevBaseEvent = null;
|
|
|
|
+ startCoord = coordOf(e);
|
|
binder.bind(target, POINTER_MOVE_EVENTS, onPointerMove, SCROLL_LISTENER_OPTIONS);
|
|
binder.bind(target, POINTER_MOVE_EVENTS, onPointerMove, SCROLL_LISTENER_OPTIONS);
|
|
binder.bind(target, POINTER_UP_EVENTS, onPointerUp, SCROLL_LISTENER_OPTIONS);
|
|
binder.bind(target, POINTER_UP_EVENTS, onPointerUp, SCROLL_LISTENER_OPTIONS);
|
|
Move.cancel();
|
|
Move.cancel();
|
|
@@ -1873,20 +1872,22 @@ const Drag = (Splide, Components, options, event) => {
|
|
basePosition = getPosition();
|
|
basePosition = getPosition();
|
|
}
|
|
}
|
|
function move(e) {
|
|
function move(e) {
|
|
|
|
+ const { go } = Controller;
|
|
const { updateOnDragged = true } = options;
|
|
const { updateOnDragged = true } = options;
|
|
const velocity = computeVelocity(e);
|
|
const velocity = computeVelocity(e);
|
|
const destination = computeDestination(velocity);
|
|
const destination = computeDestination(velocity);
|
|
|
|
+ const forwards = orient(coordOf(e) - startCoord) > 0;
|
|
const rewind = options.rewind && options.rewindByDrag;
|
|
const rewind = options.rewind && options.rewindByDrag;
|
|
const scroll = updateOnDragged ? Controller.scroll : Scroll.scroll;
|
|
const scroll = updateOnDragged ? Controller.scroll : Scroll.scroll;
|
|
reduce(false);
|
|
reduce(false);
|
|
if (isFree) {
|
|
if (isFree) {
|
|
scroll(destination, void 0, options.snap);
|
|
scroll(destination, void 0, options.snap);
|
|
} else if (Splide.is(FADE)) {
|
|
} else if (Splide.is(FADE)) {
|
|
- Controller.go(orient(sign(velocity)) < 0 ? rewind ? "<" : "-" : rewind ? ">" : "+");
|
|
|
|
|
|
+ go(forwards ? rewind ? ">" : "+" : rewind ? "<" : "-");
|
|
} else if (Splide.is(SLIDE) && exceeded && rewind) {
|
|
} else if (Splide.is(SLIDE) && exceeded && rewind) {
|
|
- Controller.go(exceededLimit(true) ? ">" : "<");
|
|
|
|
|
|
+ go(exceededLimit(true) ? ">" : "<");
|
|
} else {
|
|
} else {
|
|
- Controller.go(Controller.toDest(destination));
|
|
|
|
|
|
+ go(`${forwards ? ">>" : "<<"}${Controller.toDest(destination)}`);
|
|
}
|
|
}
|
|
reduce(true);
|
|
reduce(true);
|
|
}
|
|
}
|
|
@@ -2205,7 +2206,7 @@ const Sync = (Splide2, Components, options, event) => {
|
|
function sync(splide, target) {
|
|
function sync(splide, target) {
|
|
const event2 = splide.event.create();
|
|
const event2 = splide.event.create();
|
|
event2.on(EVENT_MOVE, (index, prev, dest) => {
|
|
event2.on(EVENT_MOVE, (index, prev, dest) => {
|
|
- target.go(target.is(LOOP) ? dest : index);
|
|
|
|
|
|
+ target.index !== index && target.go(target.is(LOOP) ? dest : index);
|
|
});
|
|
});
|
|
events.push(event2);
|
|
events.push(event2);
|
|
}
|
|
}
|