File size: 2,610 Bytes
9aa3085 3637792 9aa3085 3637792 9aa3085 3637792 9aa3085 3637792 9aa3085 3637792 9aa3085 3637792 9aa3085 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
// ------- Simple marquee for ticker -------
(function(){
function initTicker(){
const el = document.getElementById("zenTicker");
if(!el) return;
let speed = parseFloat(el.dataset.speed || "38"); // px/sec
let x = el.offsetWidth;
const step = () => {
const dt = 1/60; // 60fps
x -= speed*dt;
if(x < -el.scrollWidth) x = el.offsetWidth;
el.style.transform = `translateX(${x}px)`;
requestAnimationFrame(step);
};
step();
}
setTimeout(initTicker, 100);
})();
// ------- Teleprompter controls -------
(function(){
let raf = null;
let y = 0;
function elScroll(){ return document.getElementById("prompterScroll"); }
function elSpeed(){ return document.getElementById("pSpeed"); }
function loop(){
const el = elScroll();
if(!el) return;
const playing = (el.dataset.playing === "true");
const speed = parseFloat(el.dataset.speed || "40"); // px/s
const dt = 1/60;
if(playing){
y -= speed*dt; // scroll up
el.style.transform = `translateY(${y}px)`;
}
raf = requestAnimationFrame(loop);
}
function togglePlay(){
const el = elScroll(); if(!el) return;
const playing = (el.dataset.playing === "true");
el.dataset.playing = (!playing).toString();
}
function speedDelta(d){
const el = elScroll(); if(!el) return;
let s = parseFloat(el.dataset.speed || "40");
s = Math.max(5, Math.min(200, s + d));
el.dataset.speed = String(s);
const sp = elSpeed(); if(sp) sp.textContent = `${Math.round(s)}px/s`;
}
function fullScreen(){
const vp = document.querySelector(".prompter__viewport");
if(!vp) return;
if(!document.fullscreenElement){
vp.requestFullscreen().catch(()=>{});
}else{
document.exitFullscreen().catch(()=>{});
}
}
function keyHandler(e){
if(e.key === " "){ e.preventDefault(); togglePlay(); }
if(e.key === "ArrowUp"){ e.preventDefault(); speedDelta(+5); }
if(e.key === "ArrowDown"){ e.preventDefault(); speedDelta(-5); }
}
function clickBind(){
const play = document.getElementById("pPlayPause");
const slow = document.getElementById("pSlower");
const fast = document.getElementById("pFaster");
const full = document.getElementById("pFullscreen");
if(play) play.onclick = togglePlay;
if(slow) slow.onclick = ()=>speedDelta(-5);
if(fast) fast.onclick = ()=>speedDelta(+5);
if(full) full.onclick = fullScreen;
document.addEventListener("keydown", keyHandler);
}
setTimeout(()=>{
clickBind();
if(!raf) raf = requestAnimationFrame(loop);
}, 120);
})();
|