header: language dropdown + Thai as default language
- replace the two inline TH/EN buttons with a single dropdown (icon + label + caret) mirroring the Next app's LangSwitch: aria-haspopup/expanded, menuitemradio + aria-checked, close on Esc/outside, focus management - i18n.js: default language is Thai (no longer guesses from navigator.language); saved choice still wins via at_lang - bump VERSION 2026.09.27.109
This commit is contained in:
1 parent
246b864c06
commit
bea8f0773e
5 files changed
+147
-46
No files matched your search
+60
-16
@@ -406,35 +406,79 @@ body:has(.mu-site-footer) .mu-footer { display: none; }
|
||||
padding: 10px 12px 10px 38px;
|
||||
}
|
||||
|
||||
/* ---------- ปุ่มสลับภาษา (ไทย / EN) ---------- */
|
||||
/* ---------- ปุ่มสลับภาษา (dropdown เดียว — ไทย / English) ---------- */
|
||||
.mu-lang-switch {
|
||||
position: relative;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 2px;
|
||||
background: #f0edf7;
|
||||
border: 1px solid #e4dcf2;
|
||||
border-radius: 999px;
|
||||
padding: 3px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.mu-lang-btn {
|
||||
border: 0;
|
||||
background: transparent;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
min-height: 34px;
|
||||
padding: 6px 12px;
|
||||
border: 1px solid #e4dcf2;
|
||||
border-radius: 999px;
|
||||
background: #f0edf7;
|
||||
color: #6d28d9;
|
||||
font-family: inherit;
|
||||
font-weight: 700;
|
||||
font-size: .72rem;
|
||||
font-size: .76rem;
|
||||
line-height: 1;
|
||||
padding: 6px 10px;
|
||||
border-radius: 999px;
|
||||
cursor: pointer;
|
||||
transition: background .15s ease, color .15s ease;
|
||||
transition: background .15s ease, color .15s ease, border-color .15s ease;
|
||||
}
|
||||
.mu-lang-btn:hover { color: #5b21b6; }
|
||||
.mu-lang-btn.active {
|
||||
.mu-lang-btn:hover { color: #5b21b6; border-color: #d9cdf0; }
|
||||
.mu-lang-btn[aria-expanded="true"] { background: #fff; border-color: #cbb8ea; }
|
||||
.mu-lang-btn .ic { width: 15px; height: 15px; }
|
||||
.mu-lang-caret {
|
||||
width: 0 !important;
|
||||
height: 0 !important;
|
||||
margin-left: 1px;
|
||||
border: 4px solid transparent;
|
||||
border-top-color: currentColor;
|
||||
transition: transform .18s ease;
|
||||
}
|
||||
.mu-lang-btn[aria-expanded="true"] .mu-lang-caret { transform: rotate(180deg); }
|
||||
.mu-lang-menu {
|
||||
position: absolute;
|
||||
top: calc(100% + 6px);
|
||||
right: 0;
|
||||
z-index: 1200;
|
||||
min-width: 168px;
|
||||
padding: 6px;
|
||||
background: #fff;
|
||||
color: #7a4cc0;
|
||||
box-shadow: 0 1px 4px rgba(63, 43, 94, .18);
|
||||
border: 1px solid #e7e0f6;
|
||||
border-radius: 12px;
|
||||
box-shadow: 0 10px 28px rgba(15, 23, 42, .14);
|
||||
}
|
||||
.mu-lang-menu[hidden] { display: none; }
|
||||
.mu-lang-menu button {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
width: 100%;
|
||||
min-height: 38px;
|
||||
padding: 8px 10px;
|
||||
border: 0;
|
||||
border-radius: 8px;
|
||||
background: transparent;
|
||||
color: #2c3550;
|
||||
font-family: inherit;
|
||||
font-size: .84rem;
|
||||
font-weight: 600;
|
||||
text-align: left;
|
||||
cursor: pointer;
|
||||
}
|
||||
.mu-lang-menu button:hover { background: #f6f2ff; }
|
||||
.mu-lang-menu button[aria-checked="true"] { color: #7a4cc0; font-weight: 800; background: #f4f0fb; }
|
||||
.mu-lang-menu button .mu-lang-code {
|
||||
margin-left: auto;
|
||||
font-family: ui-monospace, "IBM Plex Mono", monospace;
|
||||
font-size: .72rem;
|
||||
color: #8a93a8;
|
||||
}
|
||||
|
||||
/* ============================================================
|
||||
|
||||
+49
-4
@@ -35,8 +35,9 @@
|
||||
var saved = localStorage.getItem(LS_KEY);
|
||||
if (saved && SUPPORTED.indexOf(saved) !== -1) return saved;
|
||||
} catch (e) { /* localStorage ไม่พร้อมใช้งาน */ }
|
||||
var nav = (navigator.language || BASE).toLowerCase();
|
||||
return nav.indexOf('en') === 0 ? 'en' : BASE;
|
||||
/* ภาษาเริ่มต้น = ไทยเสมอ (ไม่เดาจาก navigator.language)
|
||||
ผู้ใช้เปลี่ยนเองได้ที่ปุ่ม dropdown แล้วเลือกจำไว้ใน at_lang */
|
||||
return BASE;
|
||||
}
|
||||
|
||||
/* ---------- โหลดไฟล์ภาษา (cache ต่อภาษา · ล้มเหลว = {} ไม่ให้พัง) ---------- */
|
||||
@@ -94,10 +95,14 @@
|
||||
|
||||
document.documentElement.lang = current;
|
||||
|
||||
/* ไฮไลต์ปุ่มภาษาที่ active */
|
||||
/* ปุ่มภาษาแบบ dropdown — ไฮไลต์ตัวที่เลือก + อัปเดตข้อความบนปุ่ม */
|
||||
document.querySelectorAll('[data-i18n-switch]').forEach(function (btn) {
|
||||
btn.classList.toggle('active', btn.getAttribute('data-i18n-switch') === current);
|
||||
var on = btn.getAttribute('data-i18n-switch') === current;
|
||||
btn.classList.toggle('active', on);
|
||||
btn.setAttribute('aria-checked', on ? 'true' : 'false');
|
||||
});
|
||||
var label = document.getElementById('lang-label');
|
||||
if (label) label.textContent = current === 'en' ? 'EN' : 'ไทย';
|
||||
}
|
||||
|
||||
/* ---------- สลับภาษา (โหลดไฟล์ภาษาก่อน แล้วค่อยบอกให้หน้าวาดใหม่) ---------- */
|
||||
@@ -140,6 +145,46 @@
|
||||
if (btn) setLang(btn.getAttribute('data-i18n-switch'));
|
||||
});
|
||||
|
||||
/* ---------- dropdown ภาษา (ปุ่มเดียว + เมนู) ----------
|
||||
โครงเดียวกับ LangSwitch ของแอป Next: aria-expanded, ปิดด้วย Esc/คลิกนอก,
|
||||
ตัวเลือกในเมนูยังใช้ [data-i18n-switch] → กลไกแปลภาษาเดิมไม่ต้องแก้ */
|
||||
(function langMenu() {
|
||||
var wrap = document.getElementById('lang-switch');
|
||||
var btn = document.getElementById('lang-btn');
|
||||
var menu = document.getElementById('lang-menu');
|
||||
if (!wrap || !btn || !menu) return;
|
||||
|
||||
function setOpen(on) {
|
||||
menu.hidden = !on;
|
||||
btn.setAttribute('aria-expanded', on ? 'true' : 'false');
|
||||
if (on) {
|
||||
var first = menu.querySelector('button');
|
||||
if (first) first.focus({ preventScroll: true });
|
||||
}
|
||||
}
|
||||
|
||||
btn.addEventListener('click', function (e) {
|
||||
e.stopPropagation();
|
||||
setOpen(menu.hidden);
|
||||
});
|
||||
|
||||
document.addEventListener('click', function (e) {
|
||||
if (!wrap.contains(e.target)) setOpen(false);
|
||||
});
|
||||
|
||||
document.addEventListener('keydown', function (e) {
|
||||
if (e.key === 'Escape' && !menu.hidden) {
|
||||
setOpen(false);
|
||||
btn.focus();
|
||||
}
|
||||
});
|
||||
|
||||
/* เลือกภาษาแล้วปิดเมนู (ตัวสลับภาษาอยู่ใน listener กลางด้านบน) */
|
||||
menu.addEventListener('click', function (e) {
|
||||
if (e.target.closest('[data-i18n-switch]')) setOpen(false);
|
||||
});
|
||||
})();
|
||||
|
||||
/* โหลดภาษาปัจจุบัน (+ ภาษาตั้งต้นสำหรับ fallback) แล้วจึงพร้อมใช้งาน */
|
||||
Promise.all([dict(BASE), dict(current)]).then(function () {
|
||||
apply();
|
||||
|
||||
+36
-24
@@ -5,15 +5,15 @@
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
|
||||
<title>หน้าแรก | Atroute (mockup)</title>
|
||||
<!-- ฟอนต์หลัก K2D: ไฟล์ในโปรเจกต์ (ui/vendor/fonts/) — ทำงานออฟไลน์ได้ -->
|
||||
<link href="./vendor/fonts/k2d.css?v=2026.09.27.108" rel="stylesheet">
|
||||
<link href="./vendor/fonts/k2d.css?v=2026.09.27.109" rel="stylesheet">
|
||||
<!-- ตัวสำรอง (โหลดจาก CDN เมื่อออนไลน์เท่านั้น · ออฟไลน์ถอยไปใช้ system-ui) -->
|
||||
<link href="https://fonts.googleapis.com/css2?family=Noto+Sans+Thai:wght@400;500;600;700;800&family=Prompt:wght@400;500;600;700&display=swap" rel="stylesheet">
|
||||
<link href="../../frontend-web-transit/web-transit/css/main-theme.css" rel="stylesheet">
|
||||
<link href="./_shared.css?v=2026.09.27.108" rel="stylesheet">
|
||||
<link href="./vendor/leaflet/leaflet.css?v=2026.09.27.108" rel="stylesheet">
|
||||
<link href="./map.css?v=2026.09.27.108" rel="stylesheet">
|
||||
<meta name="app-version" content="2026.09.27.108">
|
||||
<link rel="icon" type="image/png" href="../.image/icons/minibus-512x512.png?v=2026.09.27.108">
|
||||
<link href="./_shared.css?v=2026.09.27.109" rel="stylesheet">
|
||||
<link href="./vendor/leaflet/leaflet.css?v=2026.09.27.109" rel="stylesheet">
|
||||
<link href="./map.css?v=2026.09.27.109" rel="stylesheet">
|
||||
<meta name="app-version" content="2026.09.27.109">
|
||||
<link rel="icon" type="image/png" href="../.image/icons/minibus-512x512.png?v=2026.09.27.109">
|
||||
<style>
|
||||
.mu-card.empty { width: 100%; padding: 16px; text-align: center; color: #6f7b95; background: #fff7fb; border: 1px dashed #f4c7df; }
|
||||
a.mu-card { text-decoration: none; color: inherit; display: block; }
|
||||
@@ -305,19 +305,19 @@
|
||||
</script>
|
||||
<meta name="apple-mobile-web-app-capable" content="yes">
|
||||
<meta name="apple-mobile-web-app-status-bar-style" content="default">
|
||||
<link rel="apple-touch-icon" href="../.image/icons/minibus-192x192.png?v=2026.09.27.108">
|
||||
<script src="./imageurl.js?v=2026.09.27.108" defer></script>
|
||||
<script src="./pwa.js?v=2026.09.27.108" defer></script>
|
||||
<script src="./i18n.js?v=2026.09.27.108" defer></script>
|
||||
<script src="./analytics.js?v=2026.09.27.108" defer></script>
|
||||
<script src="./popular.js?v=2026.09.27.108" defer></script>
|
||||
<script src="./vendor/leaflet/leaflet.js?v=2026.09.27.108" defer></script>
|
||||
<script src="./map.js?v=2026.09.27.108" defer></script>
|
||||
<script src="./partials/schedules.js?v=2026.09.27.108" defer></script>
|
||||
<script src="./partials/otherStop.js?v=2026.09.27.108" defer></script>
|
||||
<script src="./motion.js?v=2026.09.27.108" defer></script>
|
||||
<script src="./router.js?v=2026.09.27.108" defer></script>
|
||||
<link rel="stylesheet" href="./responsive.css?v=2026.09.27.108">
|
||||
<link rel="apple-touch-icon" href="../.image/icons/minibus-192x192.png?v=2026.09.27.109">
|
||||
<script src="./imageurl.js?v=2026.09.27.109" defer></script>
|
||||
<script src="./pwa.js?v=2026.09.27.109" defer></script>
|
||||
<script src="./i18n.js?v=2026.09.27.109" defer></script>
|
||||
<script src="./analytics.js?v=2026.09.27.109" defer></script>
|
||||
<script src="./popular.js?v=2026.09.27.109" defer></script>
|
||||
<script src="./vendor/leaflet/leaflet.js?v=2026.09.27.109" defer></script>
|
||||
<script src="./map.js?v=2026.09.27.109" defer></script>
|
||||
<script src="./partials/schedules.js?v=2026.09.27.109" defer></script>
|
||||
<script src="./partials/otherStop.js?v=2026.09.27.109" defer></script>
|
||||
<script src="./motion.js?v=2026.09.27.109" defer></script>
|
||||
<script src="./router.js?v=2026.09.27.109" defer></script>
|
||||
<link rel="stylesheet" href="./responsive.css?v=2026.09.27.109">
|
||||
</head>
|
||||
<body class="main-theme-page">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" style="display:none" aria-hidden="true">
|
||||
@@ -411,7 +411,7 @@
|
||||
<header class="mu-topbar">
|
||||
<div class="mu-container mu-topbar-inner">
|
||||
<a class="mu-brand" href="#/" aria-label="Atroute — หน้าแรก" data-i18n-attr="aria-label:aria.brandHome">
|
||||
<img class="mu-logo-img" src="../.image/icons/minibus-512x512.png?v=2026.09.27.108" alt="Atroute logo" width="44" height="44" decoding="async">
|
||||
<img class="mu-logo-img" src="../.image/icons/minibus-512x512.png?v=2026.09.27.109" alt="Atroute logo" width="44" height="44" decoding="async">
|
||||
<span>
|
||||
<span class="mu-brand-title">Atroute</span>
|
||||
<span class="mu-brand-subtitle" data-i18n="brand.subtitle">สถานีขนส่งผู้โดยสารจังหวัดอ่างทอง</span>
|
||||
@@ -439,9 +439,21 @@
|
||||
<a href="#/credits" data-i18n="nav.credits" role="menuitem">เครดิต</a>
|
||||
</div>
|
||||
</details>
|
||||
<div class="mu-lang-switch" role="group" aria-label="ภาษา / Language" data-i18n-attr="aria-label:aria.langSwitch">
|
||||
<button type="button" class="mu-lang-btn" data-i18n-switch="th">ไทย</button>
|
||||
<button type="button" class="mu-lang-btn" data-i18n-switch="en">EN</button>
|
||||
<div class="mu-lang-switch" id="lang-switch">
|
||||
<button type="button" class="mu-lang-btn" id="lang-btn" aria-haspopup="menu" aria-expanded="false"
|
||||
aria-label="ภาษา / Language" data-i18n-attr="aria-label:aria.langSwitch">
|
||||
<svg class="ic" aria-hidden="true"><use href="#ic-globe"/></svg>
|
||||
<span id="lang-label">ไทย</span>
|
||||
<span class="mu-lang-caret" aria-hidden="true"></span>
|
||||
</button>
|
||||
<div class="mu-lang-menu" id="lang-menu" role="menu" hidden aria-label="ภาษา / Language">
|
||||
<button type="button" role="menuitemradio" aria-checked="true" data-i18n-switch="th">
|
||||
ภาษาไทย <span class="mu-lang-code">TH</span>
|
||||
</button>
|
||||
<button type="button" role="menuitemradio" aria-checked="false" data-i18n-switch="en">
|
||||
English <span class="mu-lang-code">EN</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<a class="mu-action-btn" href="#/check" data-i18n="cta.check">เช็กเวลาเดินรถ</a>
|
||||
</div>
|
||||
@@ -454,7 +466,7 @@
|
||||
<div class="mu-footer-grid">
|
||||
<div class="mu-footer-brand">
|
||||
<div class="mu-footer-brand-row">
|
||||
<img src="../.image/icons/minibus-512x512.png?v=2026.09.27.108" alt="Atroute">
|
||||
<img src="../.image/icons/minibus-512x512.png?v=2026.09.27.109" alt="Atroute">
|
||||
<div>
|
||||
<strong>Atroute</strong>
|
||||
<span data-i18n="brand.subtitle">สถานีขนส่งผู้โดยสารจังหวัดอ่างทอง</span>
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
- ขั้นตอนอัปเดต: ดู AGENTS.md หัวข้อ PWA
|
||||
============================================================ */
|
||||
|
||||
const VERSION = "2026.09.27.108"; // ← bump ทุกครั้งที่แก้ SW เอง
|
||||
const VERSION = "2026.09.27.109"; // ← bump ทุกครั้งที่แก้ SW เอง
|
||||
const CACHE = `at-transit-${VERSION}`;
|
||||
|
||||
const PRECACHE = [
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
{"version": "2026.09.27.108"}
|
||||
{"version": "2026.09.27.109"}
|
||||
Reference in new issue
Block a user