]> littlesong.place Git - littlesongplace.git/commitdiff
Fix back bug and more work on navigation
authorChris Fulljames <christianfulljames@gmail.com>
Sat, 21 Jun 2025 18:59:41 +0000 (14:59 -0400)
committerChris Fulljames <christianfulljames@gmail.com>
Sat, 21 Jun 2025 18:59:41 +0000 (14:59 -0400)
src/littlesongplace/static/nav.js
src/littlesongplace/static/player.js
src/littlesongplace/static/styles.css
src/littlesongplace/templates/base.html

index aa8c2b54901961024e92d89383c61e8a706caadf..51421d39a3dbe9250fb9b49f190312a5a8141e90 100644 (file)
@@ -1,4 +1,9 @@
+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) => {
@@ -31,6 +36,11 @@ document.addEventListener("DOMContentLoaded", async (e) => {
         document.getElementById("my-profile").href = `/users/${username}`;
     }
 
+    // Add event handler to navbar links to hide menu on mobile
+    document.querySelectorAll("#navbar a, #page-header div a").forEach((link) => {
+        link.addEventListener("click", (e) => {hideNavMenu(e)});
+    });
+
     // Update activity indicator status
     checkForNewActivity();
 
@@ -135,6 +145,7 @@ async function handleAjaxResponse(response) {
 
         // Get page content from response
         var text = await response.text();
+        console.log("PUSH", url);
         window.history.pushState(text, "", url);
 
         updatePageState(text);
@@ -251,3 +262,24 @@ function updateImageColors() {
     });
 }
 
+// Navigation menu visibility
+const sizeQuery = window.matchMedia('(min-width: 480px)');
+function showNavMenu() {
+    document.getElementById('page-header').style['display'] = 'block';
+}
+
+function hideNavMenu() {
+    if (!sizeQuery.matches) {
+        document.getElementById('page-header').style['display'] = 'none';
+    }
+}
+
+sizeQuery.addListener((e) => {
+    if (e.matches) { // Switch from small to big, show menu
+        showNavMenu();
+    }
+    else {
+        hideNavMenu();
+    }
+});
+
index e48fe811fce5acbf875ffafa899737ddaee6589f..9338e3e4c4c2da400d9e1904400034dfb7dec235 100644 (file)
@@ -177,14 +177,14 @@ function songUpdate() {
 }
 
 // Add event listeners
-var m_firstLoad = true;
+var m_firstLoadPlayer = true;
 document.addEventListener("DOMContentLoaded", (event) => {
 
     // 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");
index ed13756888fdc949be95c086498890c96b722260..930362dbc78140ca087a097a5366aa5bd268b7b2 100644 (file)
@@ -254,13 +254,14 @@ input[type=range]::-moz-range-thumb {
 #page-header {
     display: none;
     position: fixed;
-    box-shadow: 5px 5px 0px 0px var(--black);
-    border: 1px solid var(--black);
-    border-radius: var(--radius);
     background-color: var(--yellow);
-    margin: 10px;
+    margin: 0px;
     padding: 5px;
-    width: calc(100% - 30px);
+    box-sizing: border-box;
+    width: 100%;
+    height: 100%;
+    top: 0px;
+    left: 0px;
 }
 
 #navbar {
@@ -278,6 +279,10 @@ input[type=range]::-moz-range-thumb {
         width: auto;
         display: block;
         position: static;
+        margin: 10px;
+        box-shadow: 5px 5px 0px 0px var(--black);
+        border: 1px solid var(--black);
+        border-radius: var(--radius);
     }
     #navbar {
         flex-direction: row;
@@ -339,6 +344,7 @@ input[type=range]::-moz-range-thumb {
     background: none;
     border: none;
     padding: 10px;
+    padding-bottom: 0px;
     /* margin-left: 10px; */
     /* margin-top: 10px; */
     /* left: 10px; */
index ae16c0566f85212f72b8912c180b9617db96a67e..5436c236aeabb8ac6bcb6d9e2cfe75975cff9a3a 100644 (file)
         <button id="mobile-menu-btn" onclick="showNavMenu()">
             <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><g fill="none"><path d="m12.593 23.258l-.011.002l-.071.035l-.02.004l-.014-.004l-.071-.035q-.016-.005-.024.005l-.004.01l-.017.428l.005.02l.01.013l.104.074l.015.004l.012-.004l.104-.074l.012-.016l.004-.017l-.017-.427q-.004-.016-.017-.018m.265-.113l-.013.002l-.185.093l-.01.01l-.003.011l.018.43l.005.012l.008.007l.201.093q.019.005.029-.008l.004-.014l-.034-.614q-.005-.018-.02-.022m-.715.002a.02.02 0 0 0-.027.006l-.006.014l-.034.614q.001.018.017.024l.015-.002l.201-.093l.01-.008l.004-.011l.017-.43l-.003-.012l-.01-.01z"/><path fill="currentColor" d="M20 17.5a1.5 1.5 0 0 1 .144 2.993L20 20.5H4a1.5 1.5 0 0 1-.144-2.993L4 17.5zm0-7a1.5 1.5 0 0 1 0 3H4a1.5 1.5 0 0 1 0-3zm0-7a1.5 1.5 0 0 1 0 3H4a1.5 1.5 0 1 1 0-3z"/></g></svg>
         </button>
-        <script>
-            function showNavMenu() {
-                document.getElementById('page-header').style['display'] = 'block';
-            }
-            function hideNavMenu() {
-                document.getElementById('page-header').style['display'] = 'none';
-            }
-        </script>
 
         <div id="page-header">
             <button id="mobile-hide-header-btn" onclick="hideNavMenu()">