Fix 'stops near me' button: it was dead code

stops.nearme.ts exported a default mount() but PageRuntime only invokes
the default export of stops.init; this module was imported for its side
effects and never called, so the button did nothing at all.

- self-bind on import with a dataset.nearBound guard against double binding
- retry up to ~2s while ATMap finishes loading
- map.ts: re-enable the button after a successful lookup (it stayed
  disabled forever, so a second press was impossible)

Verified with geolocation override at 14.5880,100.4530: first press
renders the map plus 8 nearest stops with distances, button re-enables,
second press works, and no duplicated network requests (2 per press).
This commit is contained in:
Bkk1234 committed 2026-10-24 00:03:05 +07:00
1 parent 70cc81b923
commit e6cef15dc8
4 files changed
+79 -7

No files matched your search

+4
View File
@@ -602,6 +602,10 @@ window.ATMap = (function () {
items.sort(function (a, b) { return a.d - b.d; });
var near = items.slice(0, opts.limit || 8);
renderNear(resultEl, near, me, opts);
/* ปลดล็อกปุ่มหลังหาป้ายเสร็จ — ผู้ใช้เดินไปที่ใหม่แล้วกดซ้ำได้ */
button.disabled = false;
}).catch(function () {
button.disabled = false;
});
}, function () {
button.disabled = false;
+31 -6
View File
@@ -1,9 +1,34 @@
// @ts-nocheck
/* Ported from the inline <script> in web-at-transit-mock/ui/partials/busStop.html
(ปุ่ม "ใกล้ฉัน" — ผูกกับแผนที่ Leaflet) */
export default function mount(): void {
var btn = document.getElementById("near-me-btn");
var out = document.getElementById("near-me-result");
if (!btn || !out || !window.ATMap) return;
window.ATMap.nearMe(btn, out, { limit: 8 });
}
(function () {
"use strict";
function bind(): boolean {
var btn = document.getElementById("near-me-btn");
var out = document.getElementById("near-me-result");
if (!btn || !out) return false;
if (!window.ATMap || typeof window.ATMap.nearMe !== "function") return false;
/* กันผูกซ้ำเมื่อ mount ใหม่ (React StrictMode / เดินหน้า-ถอยหลังไปมา) */
if (btn.dataset.nearBound === "1") return true;
btn.dataset.nearBound = "1";
window.ATMap.nearMe(btn, out, { limit: 8 });
return true;
}
/* ATMap อาจยังไม่พร้อมตอน import → ลองซ้ำเบา ๆ ไม่เกิน ~2 วินาที */
var tries = 0;
function retry(): void {
if (bind()) return;
if (++tries > 20) return;
setTimeout(retry, 100);
}
if (document.readyState === "loading") {
document.addEventListener("DOMContentLoaded", retry);
} else {
retry();
}
})();
export {};
+43
View File
@@ -288,3 +288,46 @@ main.mu-container { padding-top: 14px; padding-bottom: 14px; }
font-size: .78rem;
color: var(--c-brand-ink);
}
/* ============================================================
Touch target บนมือถือ — WCAG 2.5.8 / Android 48dp
วัดที่ 375px แล้วพบ: ลิงก์ท้ายเว็บ 34px · breadcrumb 21px ·
ปุ่มย้อนกลับ 41px · ปุ่มซูมแผนที่ 30px → เล็กกว่า 44px ทั้งหมด
============================================================ */
@media (max-width: 639px) {
/* ลิงก์ในเนื้อหา/เมนูต้องกดง่าย (selector เจาะจงพอให้ชนะกฎของหน้า) */
.mu-site-footer .mu-footer-col a,
.mu-site-footer .mu-footer-brand a,
.mu-site-footer .mu-footer-bottom a,
.mu-breadcrumb a,
.mu-menu-panel a {
display: inline-flex;
align-items: center;
min-height: 44px;
}
/* โลโก้ = ลิงก์กลับหน้าแรก */
.mu-brand { min-height: 44px; }
/* ปุ่มย้อนกลับ */
/* min-height ไม่มีผลกับ display:inline — ต้องเป็น inline-flex ก่อน */
#view .mu-back-btn {
display: inline-flex;
align-items: center;
justify-content: center;
min-height: 44px;
}
/* ช่องค้นหาสายรถ (ป้ายหยุดรถ) */
#view .mu-route-filter { min-height: 44px; }
/* ปุ่มซูมของ Leaflet — ต้องชนะ leaflet.css ที่โหลดทีหลัง จึงใช้ specificity สูง */
/* leaflet.css ถูกโหลดจาก public หลัง CSS ของแอป จึงต้องใช้ !important */
.leaflet-container .leaflet-control-zoom a,
.leaflet-bar a.leaflet-control-zoom-in,
.leaflet-bar a.leaflet-control-zoom-out {
width: 44px !important;
height: 44px !important;
line-height: 44px !important;
font-size: 20px;
}
/* ปุ่มเครื่องมือใน topbar (สำรองกรณีเบราว์เซอร์ไม่รายงาน pointer: coarse) */
.mu-pop-btn { min-width: 44px; height: 44px; }
.mu-pop-btn-lang { min-width: 60px; }
}