Skip to content

Commit

Permalink
fix(core): fixed thrown error on calling slideTo methods on destroyed…
Browse files Browse the repository at this point in the history
… swiper

fixes #7416
  • Loading branch information
nolimits4web committed Mar 28, 2024
1 parent aac2dcf commit 8c6a3c6
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 24 deletions.
5 changes: 4 additions & 1 deletion src/core/slide/slideNext.mjs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
/* eslint no-unused-vars: "off" */
export default function slideNext(speed = this.params.speed, runCallbacks = true, internal) {
export default function slideNext(speed, runCallbacks = true, internal) {
const swiper = this;
const { enabled, params, animating } = swiper;
if (!enabled || swiper.destroyed) return swiper;
if (typeof speed === 'undefined') {
speed = swiper.params.speed;
}
let perGroup = params.slidesPerGroup;
if (params.slidesPerView === 'auto' && params.slidesPerGroup === 1 && params.slidesPerGroupAuto) {
perGroup = Math.max(swiper.slidesPerViewDynamic('current', true), 1);
Expand Down
6 changes: 5 additions & 1 deletion src/core/slide/slidePrev.mjs
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
/* eslint no-unused-vars: "off" */
export default function slidePrev(speed = this.params.speed, runCallbacks = true, internal) {
export default function slidePrev(speed, runCallbacks = true, internal) {
const swiper = this;
const { params, snapGrid, slidesGrid, rtlTranslate, enabled, animating } = swiper;
if (!enabled || swiper.destroyed) return swiper;
if (typeof speed === 'undefined') {
speed = swiper.params.speed;
}

const isVirtual = swiper.virtual && params.virtual.enabled;

if (params.loop) {
Expand Down
5 changes: 4 additions & 1 deletion src/core/slide/slideReset.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
/* eslint no-unused-vars: "off" */
export default function slideReset(speed = this.params.speed, runCallbacks = true, internal) {
export default function slideReset(speed, runCallbacks = true, internal) {
const swiper = this;
if (swiper.destroyed) return;
if (typeof speed === 'undefined') {
speed = swiper.params.speed;
}
return swiper.slideTo(swiper.activeIndex, speed, runCallbacks, internal);
}
15 changes: 6 additions & 9 deletions src/core/slide/slideTo.mjs
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
import { animateCSSModeScroll } from '../../shared/utils.mjs';

export default function slideTo(
index = 0,
speed = this.params.speed,
runCallbacks = true,
internal,
initial,
) {
export default function slideTo(index = 0, speed, runCallbacks = true, internal, initial) {
if (typeof index === 'string') {
index = parseInt(index, 10);
}
Expand All @@ -28,12 +22,15 @@ export default function slideTo(
} = swiper;

if (
(swiper.animating && params.preventInteractionOnTransition) ||
(!enabled && !internal && !initial) ||
swiper.destroyed
swiper.destroyed ||
(swiper.animating && params.preventInteractionOnTransition)
) {
return false;
}
if (typeof speed === 'undefined') {
speed = swiper.params.speed;
}

const skip = Math.min(swiper.params.slidesPerGroupSkip, slideIndex);
let snapIndex = skip + Math.floor((slideIndex - skip) / swiper.params.slidesPerGroup);
Expand Down
12 changes: 6 additions & 6 deletions src/core/slide/slideToClosest.mjs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/* eslint no-unused-vars: "off" */
export default function slideToClosest(
speed = this.params.speed,
runCallbacks = true,
internal,
threshold = 0.5,
) {
export default function slideToClosest(speed, runCallbacks = true, internal, threshold = 0.5) {
const swiper = this;
if (swiper.destroyed) return;

if (typeof speed === 'undefined') {
speed = swiper.params.speed;
}

let index = swiper.activeIndex;
const skip = Math.min(swiper.params.slidesPerGroupSkip, index);
const snapIndex = skip + Math.floor((index - skip) / swiper.params.slidesPerGroup);
Expand Down
12 changes: 6 additions & 6 deletions src/core/slide/slideToLoop.mjs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
export default function slideToLoop(
index = 0,
speed = this.params.speed,
runCallbacks = true,
internal,
) {
export default function slideToLoop(index = 0, speed, runCallbacks = true, internal) {
if (typeof index === 'string') {
const indexAsNumber = parseInt(index, 10);

index = indexAsNumber;
}
const swiper = this;
if (swiper.destroyed) return;

if (typeof speed === 'undefined') {
speed = swiper.params.speed;
}

const gridEnabled = swiper.grid && swiper.params.grid && swiper.params.grid.rows > 1;
let newIndex = index;
if (swiper.params.loop) {
Expand Down

0 comments on commit 8c6a3c6

Please sign in to comment.