Skip to content
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