simo 1 mese fa
parent
commit
8d727b41d3
3 ha cambiato i file con 40 aggiunte e 14 eliminazioni
  1. 6 0
      static/main.css
  2. 7 13
      templates/home.html
  3. 27 1
      templates/results.html

+ 6 - 0
static/main.css

@@ -259,6 +259,12 @@ h1 span {
     background: var(--w98-teal); /* desktop-like backdrop */
 }
 
+/* Embed mode: when URL fragment contains #embed, the homepage toggles this on <body> */
+body.embed .view-home {
+    min-height: auto;
+    padding: 0;
+}
+
 .view-home .container {
     width: 100%;
     max-width: 560px;

+ 7 - 13
templates/home.html

@@ -17,30 +17,24 @@
         />
         <script>
             (function () {
-                function applyEmbedModeFromHash() {
-                    var isEmbed =
+                function syncEmbedClassFromHash() {
+                    const isEmbed =
                         (window.location.hash || "").indexOf("#embed") !== -1;
-                    if (!isEmbed) return;
 
-                    var container = document.querySelector(
-                        ".view-home .container",
-                    );
-                    if (!container) return;
-
-                    document.body.innerHTML = "";
-                    document.body.appendChild(container);
+                    // Toggle a class on <body>. CSS handles the layout changes.
+                    document.body.classList.toggle("embed", isEmbed);
                 }
 
                 if (document.readyState === "loading") {
                     document.addEventListener(
                         "DOMContentLoaded",
-                        applyEmbedModeFromHash,
+                        syncEmbedClassFromHash,
                     );
                 } else {
-                    applyEmbedModeFromHash();
+                    syncEmbedClassFromHash();
                 }
 
-                window.addEventListener("hashchange", applyEmbedModeFromHash);
+                window.addEventListener("hashchange", syncEmbedClassFromHash);
             })();
         </script>
     </head>

+ 27 - 1
templates/results.html

@@ -19,7 +19,7 @@
 
     <body class="results-view">
         <header>
-            <a onclick="window.location = '/'"
+            <a style="text-decoration: none" onclick="window.location = '/'"
                 ><h1>Simo<span>Search</span></h1></a
             >
             <form action="/search" method="GET" class="search-form">
@@ -32,6 +32,32 @@
                     value="{{query}}"
                 />
             </form>
+
+            <script>
+                (function () {
+                    const isEmbed =
+                        (window.location.hash || "").indexOf("#embed") !== -1;
+                    if (!isEmbed) return;
+
+                    function persistEmbedHash(ev) {
+                        const a =
+                            ev.target && ev.target.closest
+                                ? ev.target.closest("a[href]")
+                                : null;
+                        if (!a) return;
+
+                        const href = a.getAttribute("href");
+                        if (!href) return;
+
+                        if (href[0] === "#" || href.indexOf("#embed") !== -1)
+                            return;
+
+                        a.setAttribute("href", href + "#embed");
+                    }
+
+                    document.addEventListener("click", persistEmbedHash, true);
+                })();
+            </script>
         </header>
         <nav class="nav-tabs">
             <div class="nav-container">