Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug that autoplay stops when a click or drag event occurs while autoplay is enabled. ( #117 ) #1151

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/js/components/Autoplay/Autoplay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';


Expand Down Expand Up @@ -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();
Expand Down