mirror of
https://github.com/alexhopeoconnor/bom-local-service.git
synced 2026-10-03 21:21:59 +10:00
68 lines
1.5 KiB
JavaScript
68 lines
1.5 KiB
JavaScript
// Slideshow controls (play/pause)
|
|
import { state } from './state.js';
|
|
import { showFrame } from './frame-navigation.js';
|
|
|
|
/**
|
|
* Play slideshow
|
|
*/
|
|
export function play() {
|
|
if (state.frames.length === 0) return;
|
|
|
|
state.isPlaying = true;
|
|
const playBtn = document.getElementById('play-btn');
|
|
if (playBtn) playBtn.textContent = '⏸ Pause';
|
|
|
|
if (state.playInterval) {
|
|
clearInterval(state.playInterval);
|
|
}
|
|
|
|
state.playInterval = setInterval(() => {
|
|
state.currentFrameIndex = (state.currentFrameIndex + 1) % state.frames.length;
|
|
showFrame(state.currentFrameIndex);
|
|
}, state.settings.frameInterval * 1000);
|
|
}
|
|
|
|
/**
|
|
* Pause slideshow
|
|
*/
|
|
export function pause() {
|
|
state.isPlaying = false;
|
|
const playBtn = document.getElementById('play-btn');
|
|
if (playBtn) playBtn.textContent = '▶ Play';
|
|
|
|
if (state.playInterval) {
|
|
clearInterval(state.playInterval);
|
|
state.playInterval = null;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Toggle play/pause
|
|
*/
|
|
export function togglePlay() {
|
|
if (state.isPlaying) {
|
|
pause();
|
|
} else {
|
|
play();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Go to previous frame
|
|
*/
|
|
export function previousFrame() {
|
|
pause();
|
|
const newIndex = state.currentFrameIndex > 0 ? state.currentFrameIndex - 1 : state.frames.length - 1;
|
|
showFrame(newIndex);
|
|
}
|
|
|
|
/**
|
|
* Go to next frame
|
|
*/
|
|
export function nextFrame() {
|
|
pause();
|
|
const newIndex = (state.currentFrameIndex + 1) % state.frames.length;
|
|
showFrame(newIndex);
|
|
}
|
|
|