ZENLLC commited on
Commit
9aa3085
·
verified ·
1 Parent(s): 0e489cc

Create script.js

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