]> littlesong.place Git - littlesongplace.git/commitdiff
Handle all links, not just navbar
authorChris Fulljames <christianfulljames@gmail.com>
Tue, 18 Feb 2025 23:57:38 +0000 (18:57 -0500)
committerChris Fulljames <christianfulljames@gmail.com>
Tue, 18 Feb 2025 23:57:38 +0000 (18:57 -0500)
templates/base.html
todo.txt

index f14ef47868b136dfdb6dcdd08e08b3cbf38ef60f..69b1a9ddaf31529be5bb3510691e25cfb530c731 100644 (file)
         {% endblock %}
         <script>
             document.addEventListener("click", (event) => {
-                // TODO - what links do we actually want to match?  Use URL?
-                if (!event.target.matches(".navbar a")) {
+                // Handle all clicks on links
+                if (!event.target.matches("a")) {
                     return;
                 }
+
+                // Only intercept links to other pages on the site
+                var targetUrl = new URL(event.target.href);
+                var currentUrl = new URL(window.location.href);
+                if (targetUrl.origin !== currentUrl.origin) {
+                    return;  // Link to external site
+                }
+
                 event.preventDefault();
 
                 // Add AJAX type specifier to URL params
-                var url = new URL(event.target.href);
-                url.searchParams.set("request-type", "ajax")
+                targetUrl.searchParams.set("request-type", "ajax")
 
                 // Update HTML
-                getPageAjax(url);
+                getPageAjax(targetUrl);
             });
             async function getPageAjax(url) {
                 fetch(url, {redirect: "follow"}).then(async (response) => {
index e93e8834410abd683eff09b6b3b3c52618dfb3e1..a6b7902beba09dc74f72659cd45964c7eeef5c22 100644 (file)
--- a/todo.txt
+++ b/todo.txt
@@ -2,7 +2,6 @@ NOW
 - AJAX pages so songs can play during navigation
     - Forms
     - Back (history stack)
-    - Other on-site links (songs, profiles, tags, etc.)
     - Update page colors
 - Break up main.py, test_offline.py
 - Pinned profile playlists