From ab9392d212727592c38af3378dedbde91ccd9fe6 Mon Sep 17 00:00:00 2001 From: Chris Fulljames Date: Thu, 26 Jun 2025 07:15:59 -0400 Subject: [PATCH] Fix bugs with refreshing the page --- src/littlesongplace/static/nav.js | 7 ++++++- src/littlesongplace/static/player.js | 12 ++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/littlesongplace/static/nav.js b/src/littlesongplace/static/nav.js index b369974..8a03c74 100644 --- a/src/littlesongplace/static/nav.js +++ b/src/littlesongplace/static/nav.js @@ -1,4 +1,9 @@ -document.addEventListener("DOMContentLoaded", (e) => { +var m_firstLoadNav = true; +document.addEventListener("DOMContentLoaded", async (e) => { + if (m_firstLoadNav) { + m_firstLoadNav = false; + window.history.replaceState(document.documentElement.outerHTML, ""); + } // Handle link clicks with AJAX document.querySelectorAll("a").forEach((anchor) => { diff --git a/src/littlesongplace/static/player.js b/src/littlesongplace/static/player.js index e48fe81..b14d598 100644 --- a/src/littlesongplace/static/player.js +++ b/src/littlesongplace/static/player.js @@ -177,17 +177,21 @@ function songUpdate() { } // Add event listeners -var m_firstLoad = true; +var m_firstLoadPlayer = true; document.addEventListener("DOMContentLoaded", (event) => { + // Sync volume with current slider position (may be reset after refresh) + var audio = document.getElementById("player-audio"); + const slider = document.getElementById("volume-slider"); + audio.volume = slider.value; + // The player never gets rebuilt, so we only need to set it up the first time - if (!m_firstLoad) { + if (!m_firstLoadPlayer) { return; } - m_firstLoad = false; + m_firstLoadPlayer = false; // Audio playback position while playing - var audio = document.getElementById("player-audio"); audio.addEventListener("timeupdate", songUpdate); // Next song on audio playback end -- 2.39.5