feat(slides): add timed playback and looping controls

This commit is contained in:
Anya Tokugawa committed 2026-11-30 23:14:09 +09:00
1 parent fdf6dffc84
commit 1fd2de4c6b
7 files changed
+94 -8

No files matched your search

+13 -1
View File
@@ -1,6 +1,9 @@
(() => {
'use strict';
const token=document.body.dataset.token;
let interval=30,loop=false,playing=false,timer;
const state=()=>parent.postMessage({type:'slides-playback',token,playing,seconds:interval,loop},'*');
function schedule(){clearTimeout(timer);if(!playing||document.hidden)return;timer=setTimeout(()=>{if(deck.isLastSlide()){if(loop)deck.slide(0);else{playing=false;state();return;}}else deck.next();schedule();},interval*1000);}
const deck=new Reveal(document.querySelector('.reveal'),{
embedded:true,hash:false,history:false,respondToHashChanges:false,
transition:'none',backgroundTransition:'none',controls:true,progress:true,
@@ -10,6 +13,15 @@
deck.initialize().then(()=>{
deck.slide(Math.min(Number(document.body.dataset.index)||0,deck.getTotalSlides()-1));
parent.postMessage({type:'slides-ready',token,index:deck.getIndices().h},'*');
deck.on('slidechanged',()=>parent.postMessage({type:'slides-index',token,index:deck.getIndices().h},'*'));
deck.on('slidechanged',()=>{parent.postMessage({type:'slides-index',token,index:deck.getIndices().h},'*');schedule();});
window.addEventListener('message',event=>{
const data=event.data;
if(event.source!==parent||!data||data.token!==token||data.type!=='slides-config')return;
if(!Number.isInteger(data.seconds)||data.seconds<1||data.seconds>3600||typeof data.loop!=='boolean'||typeof data.playing!=='boolean')return;
interval=data.seconds;loop=data.loop;playing=data.playing;
if(playing&&deck.isLastSlide()&&!loop)deck.slide(0);
schedule();state();
});
document.addEventListener('visibilitychange',schedule);
});
})();