From 3dcbdb88e72bc12438adf970ed847fe6bb967183 Mon Sep 17 00:00:00 2001 From: BANK Date: Fri, 20 Nov 2026 03:02:48 +0700 Subject: [PATCH] =?UTF-8?q?fix(js):=20boot=20guard=20+=20cache-busted=20sc?= =?UTF-8?q?ript,=20=E0=A4=A8av=20breakpoint,=20docs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - wrap init ใน boot() พร้อม retry จนกว่า #progress จะมีใน DOM - กันแคชสคริปต์ด้วย ?v=7 + defer - ปรับ breakpoint เมนูเป็น 960px และแก้สีหัวข้อ dorm บนพื้นขาว - DESIGN.md: motion tokens, กติกา section #why, reduced-motion - README: แหล่งอ้างอิง NYT/Verge และ Microsoft Q&A --- assets/js/main.js | 27 +++++++++++++++++++++++++++ index.html | 2 +- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/assets/js/main.js b/assets/js/main.js index 81ad1ca..1d5fedf 100644 --- a/assets/js/main.js +++ b/assets/js/main.js @@ -8,6 +8,14 @@ (function () { "use strict"; + /* รอให้ DOM พร้อมก่อนเสมอ — กันกรณีสคริปต์ถูกเรียกก่อน element ถูก parse */ + var booted = false; + + function boot() { + if (booted) return true; + if (!document.getElementById("progress")) return false; + booted = true; + var ORDER_EMAIL = "order@sff-pc.example"; // TODO: เปลี่ยนเป็นอีเมลร้านจริง var reduceMotion = window.matchMedia("(prefers-reduced-motion: reduce)").matches; @@ -307,4 +315,23 @@ } }); } + } + + function tryBoot() { + if (boot()) return; + document.addEventListener("DOMContentLoaded", tryBoot, { once: true }); + window.addEventListener("load", tryBoot, { once: true }); + var tries = 0; + (function retry() { + if (boot() || ++tries > 30) return; + setTimeout(retry, 100); + })(); + } + + if (document.readyState === "loading") { + document.addEventListener("DOMContentLoaded", tryBoot, { once: true }); + } else { + tryBoot(); + } + window.addEventListener("load", tryBoot); })(); diff --git a/index.html b/index.html index 29c4775..da9fba9 100644 --- a/index.html +++ b/index.html @@ -871,6 +871,6 @@ - +