From 750b4a2ea809dbdf952547d166ac2671a68764c7 Mon Sep 17 00:00:00 2001 From: Bkk1234 Date: Sat, 24 Oct 2026 00:11:56 +0700 Subject: [PATCH] mock: three search tabs - stop code, place name, near me - busStop.html: added the third tab (data-mode=near) and its own panel with the location button, hint and result area; removed the near button from the toolbar and deleted the old on-screen numpad markup - busStop.search.js: MODE_NEAR in setMode, disables the other panels, hides the stop list while ranked results are shown, skips filtering in that mode, and removed the dead initNumpad code - security gate: the tab is revealed only when isSecureContext and navigator.geolocation exist; otherwise it stays hidden and the mode is refused - map.js: re-enable the button after a successful lookup - i18n: stops.modeNear / nearCta / nearHint - bump SW version to 2026.09.27.98 Verified on localhost:8090 - three tabs, near mode shows a map with 8 ranked stops, button re-enables and works again, switching back restores the list; with isSecureContext forced false the tab is hidden and unselectable. --- resource/data/provinces.json | 54 +++++++++++++++--- ui/i18n.js | 19 ++++++- ui/index.html | 22 ++++---- ui/locales/en.json | 91 ++++++++++++++++++++++++++++++- ui/locales/th.json | 91 ++++++++++++++++++++++++++++++- ui/map.js | 14 +++-- ui/partials/blog.html | 2 +- ui/partials/busDetail.html | 20 +++---- ui/partials/busDetail.init.js | 11 ++-- ui/partials/busStop.html | 66 +++++++++++++--------- ui/partials/busStop.init.js | 2 +- ui/partials/busStop.search.js | 76 ++++++++++---------------- ui/partials/checkSchedule.html | 4 +- ui/partials/checkSchedule.init.js | 12 ++-- ui/partials/credits.html | 36 ++++++------ ui/partials/home.html | 4 +- ui/partials/home.init.js | 8 ++- ui/partials/schedules.js | 9 ++- ui/partials/stopDetail.html | 6 +- ui/partials/stopDetail.init.js | 4 +- ui/popular.js | 2 +- ui/pwa.js | 11 +++- ui/router.js | 20 +++---- ui/sw.js | 2 +- ui/visitors.js | 20 ++++--- 25 files changed, 426 insertions(+), 180 deletions(-) diff --git a/resource/data/provinces.json b/resource/data/provinces.json index 673d4d2..332c60c 100644 --- a/resource/data/provinces.json +++ b/resource/data/provinces.json @@ -1,13 +1,49 @@ { "provinces": [ - { "province_id": 1, "province_name_th": "อ่างทอง" }, - { "province_id": 2, "province_name_th": "อยุธยา" }, - { "province_id": 3, "province_name_th": "ปทุมธานี" }, - { "province_id": 4, "province_name_th": "กรุงเทพมหานคร" }, - { "province_id": 5, "province_name_th": "สุพรรณบุรี" }, - { "province_id": 6, "province_name_th": "สระบุรี" }, - { "province_id": 7, "province_name_th": "ลพบุรี" }, - { "province_id": 8, "province_name_th": "สิงห์บุรี" }, - { "province_id": 9, "province_name_th": "ชัยนาท" } + { + "province_id": 1, + "province_name_th": "อ่างทอง", + "province_name_en": "Ang Thong" + }, + { + "province_id": 2, + "province_name_th": "อยุธยา", + "province_name_en": "Ayutthaya" + }, + { + "province_id": 3, + "province_name_th": "ปทุมธานี", + "province_name_en": "Pathum Thani" + }, + { + "province_id": 4, + "province_name_th": "กรุงเทพมหานคร", + "province_name_en": "Bangkok" + }, + { + "province_id": 5, + "province_name_th": "สุพรรณบุรี", + "province_name_en": "Suphan Buri" + }, + { + "province_id": 6, + "province_name_th": "สระบุรี", + "province_name_en": "Saraburi" + }, + { + "province_id": 7, + "province_name_th": "ลพบุรี", + "province_name_en": "Lopburi" + }, + { + "province_id": 8, + "province_name_th": "สิงห์บุรี", + "province_name_en": "Sing Buri" + }, + { + "province_id": 9, + "province_name_th": "ชัยนาท", + "province_name_en": "Chai Nat" + } ] } diff --git a/ui/i18n.js b/ui/i18n.js index 2a0b479..bf85972 100644 --- a/ui/i18n.js +++ b/ui/i18n.js @@ -75,15 +75,18 @@ el.textContent = t(el.getAttribute('data-i18n'), vars); }); scope.querySelectorAll('[data-i18n-attr]').forEach(function (el) { + var avars = null; + var an = el.getAttribute('data-i18n-n'); + if (an !== null) avars = { n: an }; el.getAttribute('data-i18n-attr').split(',').forEach(function (pair) { var parts = pair.split(':'); if (parts.length === 2) { var attr = parts[0].trim(); var key = parts[1].trim(); if (attr === 'html') { - el.innerHTML = t(key); + el.innerHTML = t(key, avars); } else { - el.setAttribute(attr, t(key)); + el.setAttribute(attr, t(key, avars)); } } }); @@ -109,8 +112,20 @@ }); } + /* เลือกชื่อเฉพาะตามภาษา: ชื่อฟิลด์ฐาน เช่น 'province_name' → province_name_en / province_name_th + ไม่มีคำแปล = ถอยไปใช้ภาษาไทย (ชื่อเฉพาะไม่บังคับต้องแปล) */ + function name(obj, base) { + if (!obj) return ''; + var v = obj[base + '_' + current]; + if (v != null && v !== '') return v; + var b = obj[base + '_' + BASE]; + if (b != null && b !== '') return b; + return obj[base] != null ? obj[base] : ''; + } + window.I18N = { t: t, + name: name, apply: apply, setLang: setLang, getLang: function () { return current; }, diff --git a/ui/index.html b/ui/index.html index b119671..fcdb118 100644 --- a/ui/index.html +++ b/ui/index.html @@ -12,8 +12,8 @@ - - + +