Skip to content

Commit

Permalink
Fix listeners leak in autoplay mode
Browse files Browse the repository at this point in the history
  • Loading branch information
nolimits4web committed Apr 20, 2018
1 parent 0fc00de commit 6832cea
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 13 deletions.
24 changes: 15 additions & 9 deletions src/components/autoplay/autoplay.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint no-underscore-dangle: "off" */
import Utils from '../../utils/utils';

const Autoplay = {
Expand Down Expand Up @@ -70,15 +71,8 @@ const Autoplay = {
swiper.autoplay.paused = false;
swiper.autoplay.run();
} else {
swiper.$wrapperEl.transitionEnd(() => {
if (!swiper || swiper.destroyed) return;
swiper.autoplay.paused = false;
if (!swiper.autoplay.running) {
swiper.autoplay.stop();
} else {
swiper.autoplay.run();
}
});
swiper.$wrapperEl[0].addEventListener('transitionend', swiper.autoplay.onTransitionEnd);
swiper.$wrapperEl[0].addEventListener('webkitTransitionEnd', swiper.autoplay.onTransitionEnd);
}
},
};
Expand All @@ -105,6 +99,18 @@ export default {
start: Autoplay.start.bind(swiper),
stop: Autoplay.stop.bind(swiper),
pause: Autoplay.pause.bind(swiper),
onTransitionEnd(e) {
if (!swiper || swiper.destroyed || !swiper.$wrapperEl) return;
if (e.target !== this) return;
swiper.$wrapperEl[0].removeEventListener('transitionend', swiper.autoplay.onTransitionEnd);
swiper.$wrapperEl[0].removeEventListener('webkitTransitionEnd', swiper.autoplay.onTransitionEnd);
swiper.autoplay.paused = false;
if (!swiper.autoplay.running) {
swiper.autoplay.stop();
} else {
swiper.autoplay.run();
}
},
},
});
},
Expand Down
15 changes: 11 additions & 4 deletions src/components/core/slide/slideTo.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,17 @@ export default function (index = 0, speed = this.params.speed, runCallbacks = tr
swiper.transitionStart(runCallbacks, direction);
if (!swiper.animating) {
swiper.animating = true;
$wrapperEl.transitionEnd(() => {
if (!swiper || swiper.destroyed) return;
swiper.transitionEnd(runCallbacks, direction);
});
if (!swiper.onSlideToWrapperTransitionEnd) {
swiper.onSlideToWrapperTransitionEnd = function transitionEnd(e) {
if (!swiper || swiper.destroyed) return;
if (e.target !== this) return;
swiper.$wrapperEl[0].removeEventListener('transitionend', swiper.onSlideToWrapperTransitionEnd);
swiper.$wrapperEl[0].removeEventListener('webkitTransitionEnd', swiper.onSlideToWrapperTransitionEnd);
swiper.transitionEnd(runCallbacks, direction);
};
}
swiper.$wrapperEl[0].addEventListener('transitionend', swiper.onSlideToWrapperTransitionEnd);
swiper.$wrapperEl[0].addEventListener('webkitTransitionEnd', swiper.onSlideToWrapperTransitionEnd);
}
}

Expand Down

0 comments on commit 6832cea

Please sign in to comment.