From 411aa23d84c9743875b2fe0944f742ff22a04a67 Mon Sep 17 00:00:00 2001 From: takky94 Date: Wed, 12 Apr 2023 21:25:26 +0900 Subject: [PATCH] Bug that autoplay stops when a click or drag event occurs while autoplay is enabled. ( #117 ) --- src/js/components/Autoplay/Autoplay.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/js/components/Autoplay/Autoplay.ts b/src/js/components/Autoplay/Autoplay.ts index 87cedb6f..e4d39d0a 100644 --- a/src/js/components/Autoplay/Autoplay.ts +++ b/src/js/components/Autoplay/Autoplay.ts @@ -5,13 +5,14 @@ import { EVENT_AUTOPLAY_PLAY, EVENT_AUTOPLAY_PLAYING, EVENT_MOVE, + EVENT_MOVED, EVENT_REFRESH, EVENT_SCROLL, } from '../../constants/events'; import { EventInterface, RequestInterval } from '../../constructors'; import { Splide } from '../../core/Splide/Splide'; import { BaseComponent, Components, Options } from '../../types'; -import { getAttribute, setAttribute, style, toggleClass } from '../../utils'; +import { apply, getAttribute, setAttribute, style, toggleClass } from '../../utils'; import { INTERVAL_DATA_ATTRIBUTE } from './constants'; @@ -98,13 +99,15 @@ export function Autoplay( Splide: Splide, Components: Components, options: Optio on( [ EVENT_MOVE, EVENT_SCROLL, EVENT_REFRESH ], interval.rewind ); on( EVENT_MOVE, onMove ); + on( EVENT_MOVED, apply( play, false ) ); } /** * Starts autoplay and clears all flags. + * @param isRestart - Determines whether to restart autoplay or not. */ - function play(): void { - if ( isPaused() && Components.Slides.isEnough() ) { + function play(isRestart = true): void { + if ( ( isRestart && isPaused() && Components.Slides.isEnough() ) || ( ! isRestart && ! stopped && Components.Slides.isEnough() ) ) { interval.start( ! options.resetProgress ); focused = hovered = stopped = false; update();