all repos — retro-website @ 04ee841fb60d2d1fb69656ea323abb2568aa63df

res/js/main.js (view raw)

 1const iframe = document.getElementById("mainframe");
 2
 3const loadSpeed = 2;
 4
 5let first = false;
 6let play = false;
 7let controlsEnabled = false;
 8let currentPage = "about";
 9
10function firstPlay(){
11    if(first) return;
12    document.getElementById("music-player").style.bottom = "0";
13    music.volume = 0.1;
14    controlsEnabled = true;
15    playPause(false, page_tracks[currentPage]);
16    first = true;
17}
18
19function loadIFrame(callback){
20    iframe.contentWindow.start_loading(speed=loadSpeed, not_allowed, callback);
21}
22
23function firstClickPlay(element) {
24    const overlay = document.getElementById("overlay");
25    if(overlay) {
26        overlay.remove();
27        // load this window
28        hide_all();
29        start_loading(speed=loadSpeed, not_allowed, () => { loadIFrame(firstPlay) });
30    }
31
32    click1 = clickAudio1 || parent.clickAudio1;
33    click2 = clickAudio2 || parent.clickAudio2;
34
35    playAudio(click1)
36    element.onmousedown = () => playAudio(click1);
37    element.onmouseup = () => playAudio(click2);
38}
39
40function frameLoadedCallback() {
41    controlsEnabled = true;
42    playPause(!play, page_tracks[currentPage]);
43}
44
45function goToPage(page) {
46    if (!controlsEnabled || currentPage == page) return
47
48    music.pause()
49    controlsEnabled = false;
50    iframe.src = "pages/" + page + ".html";
51    iframe.onload = () => { loadIFrame(frameLoadedCallback); };
52    currentPage = page;
53
54}