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 @@
-
+