add
This commit is contained in:
1 parent
bea0fff388
commit
4ac51969e2
37 files changed
+1270
-166
No files matched your search
@@ -0,0 +1,72 @@
|
||||
<style>
|
||||
/* ===== หน้าเกี่ยวกับเรา — เนื้อหาจาก partials/about-data/ (textN.json + picN) ===== */
|
||||
.mu-hero-lead {
|
||||
margin: 14px auto 0;
|
||||
max-width: 640px;
|
||||
color: #5b3b71;
|
||||
font-size: .95rem;
|
||||
}
|
||||
|
||||
.mu-about-wrap { padding: 30px 0 52px; }
|
||||
#about-blocks { display: flex; flex-direction: column; gap: 26px; }
|
||||
|
||||
.mu-about-block {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr;
|
||||
gap: 16px;
|
||||
align-items: center;
|
||||
background: #fff;
|
||||
border: 1px solid #ebe8f4;
|
||||
border-radius: 18px;
|
||||
padding: 16px;
|
||||
box-shadow: 0 10px 26px rgba(63, 43, 94, .07);
|
||||
}
|
||||
.mu-about-block .mu-about-media { order: 2; }
|
||||
.mu-about-block .mu-about-media img {
|
||||
width: 100%;
|
||||
height: auto;
|
||||
max-height: 420px;
|
||||
object-fit: cover;
|
||||
border-radius: 14px;
|
||||
display: block;
|
||||
box-shadow: 0 10px 24px rgba(63, 43, 94, .14);
|
||||
}
|
||||
.mu-about-block h2 { margin: 0 0 10px; font-size: 1.2rem; color: #1f2a44; font-weight: 800; line-height: 1.35; }
|
||||
.mu-about-block p { margin: 0 0 10px; color: #4a5568; font-size: .95rem; line-height: 1.8; }
|
||||
.mu-about-block p:last-child { margin-bottom: 0; }
|
||||
|
||||
.mu-about-skeleton { color: #6f7b95; font-size: .9rem; text-align: center; padding: 18px 0; }
|
||||
.mu-about-skel-card { height: 180px; border-radius: 18px; background: linear-gradient(90deg, #f4f2fa 25%, #ece8f6 37%, #f4f2fa 63%); background-size: 400% 100%; animation: muSkel 1.4s ease infinite; }
|
||||
@keyframes muSkel { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }
|
||||
|
||||
/* แท็บเล็ต/เดสก์ท็อป: 2 คอลัมน์ + สลับข้าง (คี่ = ข้อความซ้าย, คู่ = รูปซ้าย) */
|
||||
@media (min-width: 768px) {
|
||||
.mu-about-block { grid-template-columns: 1.05fr .95fr; gap: 28px; padding: 24px 26px; }
|
||||
.mu-about-block .mu-about-media { order: 0; }
|
||||
.mu-about-block:nth-child(even) .mu-about-media { order: -1; }
|
||||
}
|
||||
</style>
|
||||
|
||||
<!-- ============ HERO (ภาษาเดียวกับหน้าแรก) ============ -->
|
||||
<section class="mu-hero">
|
||||
<img class="mu-hero-map" src="../.image/network/overview-map.png" alt="" aria-hidden="true" decoding="async">
|
||||
<div class="mu-blob one"></div>
|
||||
<div class="mu-blob two"></div>
|
||||
<div class="mu-blob three"></div>
|
||||
<div class="mu-container mu-hero-content">
|
||||
<span class="mu-badge"><svg class="ic" aria-hidden="true"><use href="#ic-map-pin"/></svg> <span data-i18n="nav.about">เกี่ยวกับเรา</span></span>
|
||||
<h1><span data-i18n="about.title">เกี่ยวกับเรา</span><br><span class="mu-gradient-text" data-i18n="about.brand">เมื่อไหร่รถจะมา</span></h1>
|
||||
<p class="mu-hero-lead" data-i18n="about.lead">เรื่องราวและที่มาของเว็บนี้ — อ่านเรียงตามบล็อกด้านล่างได้เลย</p>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- ============ เนื้อหา (โหลดจาก about-data: text1.json + pic1, text2.json + pic2 ...) ============ -->
|
||||
<section class="mu-about-wrap">
|
||||
<div class="mu-container">
|
||||
<div id="about-blocks" aria-live="polite">
|
||||
<div class="mu-about-skeleton"><div class="mu-about-skel-card"></div></div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<script src="./partials/about.init.js"></script>
|
||||
@@ -0,0 +1,105 @@
|
||||
/* ============================================================
|
||||
หน้าเกี่ยวกับเรา — loader
|
||||
------------------------------------------------------------
|
||||
อ่านเนื้อหาจาก partials/about-data/ เรียงสลับกันไปเรื่อย ๆ:
|
||||
text1.json + pic1.<ext> , text2.json + pic2.<ext> , ...
|
||||
- textN.json: { "th": { "title": "...", "body": ["...", "..."] },
|
||||
"en": { "title": "...", "body": [...] } }
|
||||
(ไม่เขียน en → โหมด EN ใช้ th แทน)
|
||||
- picN รองรับ .jpg .jpeg .png .webp
|
||||
- หยุดเองเมื่อหา textN.json ถัดไปไม่เจอ
|
||||
============================================================ */
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
var DATA_DIR = './partials/about-data/';
|
||||
var IMG_EXTS = ['jpg', 'jpeg', 'png', 'webp'];
|
||||
var MAX_BLOCKS = 30;
|
||||
|
||||
function lang() {
|
||||
return (window.I18N && I18N.getLang()) || 'th';
|
||||
}
|
||||
|
||||
function pick(data, l) {
|
||||
if (!data) return null;
|
||||
if (l !== 'th' && data[l]) return data[l];
|
||||
return data.th || data[l] || data[Object.keys(data)[0]] || data;
|
||||
}
|
||||
|
||||
function fetchJSON(n) {
|
||||
return fetch(DATA_DIR + 'text' + n + '.json', { cache: 'no-store' })
|
||||
.then(function (r) { return r.ok ? r.json() : null; })
|
||||
.catch(function () { return null; });
|
||||
}
|
||||
|
||||
function findImage(n) {
|
||||
var i = 0;
|
||||
function tryNext() {
|
||||
if (i >= IMG_EXTS.length) return Promise.resolve(null);
|
||||
var url = DATA_DIR + 'pic' + n + '.' + IMG_EXTS[i++];
|
||||
return fetch(url, { method: 'HEAD', cache: 'no-store' })
|
||||
.then(function (r) { return r.ok ? url : tryNext(); })
|
||||
.catch(tryNext);
|
||||
}
|
||||
return tryNext();
|
||||
}
|
||||
|
||||
function renderBlock(host, data, imgUrl) {
|
||||
var c = pick(data, lang());
|
||||
if (!c) return;
|
||||
var art = document.createElement('article');
|
||||
art.className = 'mu-about-block';
|
||||
|
||||
var text = document.createElement('div');
|
||||
text.className = 'mu-about-text';
|
||||
var h2 = document.createElement('h2');
|
||||
h2.textContent = c.title || '';
|
||||
text.appendChild(h2);
|
||||
(c.body || c.paragraphs || []).forEach(function (p) {
|
||||
var el = document.createElement('p');
|
||||
el.textContent = p;
|
||||
text.appendChild(el);
|
||||
});
|
||||
art.appendChild(text);
|
||||
|
||||
if (imgUrl) {
|
||||
var media = document.createElement('div');
|
||||
media.className = 'mu-about-media';
|
||||
var img = document.createElement('img');
|
||||
img.src = imgUrl;
|
||||
img.alt = c.imgAlt || c.title || '';
|
||||
img.loading = 'lazy';
|
||||
img.decoding = 'async';
|
||||
media.appendChild(img);
|
||||
art.appendChild(media);
|
||||
}
|
||||
host.appendChild(art);
|
||||
}
|
||||
|
||||
function init() {
|
||||
var host = document.getElementById('about-blocks');
|
||||
if (!host) return;
|
||||
var cleared = false;
|
||||
|
||||
var n = 1;
|
||||
function next() {
|
||||
if (n > MAX_BLOCKS) return;
|
||||
var current = n++;
|
||||
fetchJSON(current).then(function (data) {
|
||||
if (!data) return; // ไม่มี textN ถัดไป → จบ
|
||||
if (!cleared) { host.innerHTML = ''; cleared = true; }
|
||||
findImage(current).then(function (imgUrl) {
|
||||
renderBlock(host, data, imgUrl);
|
||||
next();
|
||||
});
|
||||
});
|
||||
}
|
||||
next();
|
||||
}
|
||||
|
||||
if (document.readyState === 'loading') {
|
||||
document.addEventListener('DOMContentLoaded', init);
|
||||
} else {
|
||||
init();
|
||||
}
|
||||
})();
|
||||
@@ -0,0 +1,37 @@
|
||||
# 📁 blog-data — เนื้อหาหน้า "บทความ" (#/blog)
|
||||
|
||||
ระบบเดียวกับ `about-data/` — **แต่ละบทความ = textN.json + picN.\*** จับคู่กันตามเลข
|
||||
(`text1.json`+`pic1.jpg`, `text2.json`+`pic2.jpg`, ...) ระบบไล่เลขไปเรื่อย ๆ จนหาไม่เจอแล้วหยุดเอง
|
||||
|
||||
## รูปแบบ textN.json
|
||||
|
||||
```json
|
||||
{
|
||||
"date": "2026-09-14",
|
||||
"th": { "title": "หัวข้อบทความ", "tag": "ข่าว", "body": ["ย่อหน้าที่ 1", "ย่อหน้าที่ 2"] },
|
||||
"en": { "title": "Post title", "tag": "News", "body": ["Paragraph 1", "Paragraph 2"] }
|
||||
}
|
||||
```
|
||||
|
||||
| ฟิลด์ | จำเป็น? | หมายเหตุ |
|
||||
|---|---|---|
|
||||
| `th.title` / `th.body` | ✅ | เนื้อหาไทย (โหมด EN ถ้าไม่เขียน en จะใช้ th แทน) |
|
||||
| `th.tag` | – | ป้ายมุมการ์ด (เช่น ข่าว / วิธีใช้ / อัปเดต) |
|
||||
| `en.*` | – | คำแปลอังกฤษ (ไม่ใส่ = ใช้ th) |
|
||||
| `date` | – | ISO `YYYY-MM-DD` แสดงบนการ์ด (ไม่ใส่ก็ได้) |
|
||||
|
||||
## รูป
|
||||
|
||||
- วางชื่อ `picN.jpg` (หรือ `.jpeg` / `.png` / `.webp`) — แนะนำ 1200×675 (16:9)
|
||||
- ไม่มีรูปก็ได้ — การ์ดจะใช้พื้น gradient แทน
|
||||
|
||||
## มุมมอง
|
||||
|
||||
- หน้า `#/blog` มีปุ่มสลับ **ตาราง (grid)** / **รายการ (list)** — จำค่าที่เลือกไว้
|
||||
- คลิกการ์ด → เปิดอ่านบทความเต็มที่ `#/blog/N` (มีปุ่มย้อนกลับไปรายการ)
|
||||
|
||||
## เพิ่มบทความใหม่
|
||||
|
||||
สร้าง `text5.json` + `pic5.jpg` — จบ (ไม่ต้องแก้โค้ด)
|
||||
|
||||
> แก้ไฟล์แล้วกด F5 เห็นผลทันที (โหลดแบบ network-first)
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 13 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 13 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 13 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 13 KiB |
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"date": "2026-09-14",
|
||||
"th": {
|
||||
"title": "เปิดเพิ่ม 3 เส้นทางช่วงปลายฝน",
|
||||
"tag": "ข่าว",
|
||||
"body": [
|
||||
"ช่วงปลายฝนนี้มีเส้นทางใหม่เปิดให้บริการเพิ่ม 3 เส้นทาง เชื่อมต่ออ่างทองกับจังหวัดใกล้เคียง เริ่มตั้งแต่ต้นเดือนตุลาคมเป็นต้นไป",
|
||||
"ตารางเดินรถของเส้นทางใหม่จะอัปเดตในหน้า “เช็กเวลาเดินรถ” ทันทีที่ผู้ประกอบการยืนยันรอบวิ่ง — ฝากติดตามไว้ด้วยครับ"
|
||||
]
|
||||
},
|
||||
"en": {
|
||||
"title": "Three new routes open this rainy season",
|
||||
"tag": "News",
|
||||
"body": [
|
||||
"Three new routes connecting Ang Thong with nearby provinces will start service in early October.",
|
||||
"Their schedules will appear on the Check Schedules page as soon as operators confirm the trips — stay tuned."
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"date": "2026-09-10",
|
||||
"th": {
|
||||
"title": "วิธีดูว่ารถสาย 101 ผ่านป้ายเรากี่โมง",
|
||||
"tag": "วิธีใช้",
|
||||
"body": [
|
||||
"เปิดหน้าป้ายหยุดรถ เลือกป้ายที่ต้องการ แล้วดูรายการ “สายรถที่ผ่านจุดนี้” — ระบบจะไฮไลต์เที่ยวถัดไปให้อัตโนมัติ",
|
||||
"ถ้าต้องการดูทุกจุดจอดของสาย เข้าเมนูรายละเอียดสายรถ หรือกดปุ่มเช็กเวลาเดินรถเพื่อดูตารางแบบเต็มในหน้าเดียว"
|
||||
]
|
||||
},
|
||||
"en": {
|
||||
"title": "How to see when route 101 passes your stop",
|
||||
"tag": "How-to",
|
||||
"body": [
|
||||
"Open Bus Stops, pick your stop, then check the routes serving it — the next departure is highlighted automatically.",
|
||||
"For every stop along a route, open Route Details or hit Check Schedules for the full table in one page."
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"date": "2026-09-05",
|
||||
"th": {
|
||||
"title": "อัปเดตตารางเดินรถสาย 902",
|
||||
"tag": "อัปเดต",
|
||||
"body": [
|
||||
"สาย 902 (กรุงเทพ–อ่างทอง สายเอเซีย) ปรับรอบวิ่งช่วงเย็นจากเดิมออกทุก 50 นาที เป็นทุก 40 นาที ตั้งแต่วันที่ 1 กันยายน",
|
||||
"รอบเช้าและรอบกลางวันยังคงเดิม หากมีเปลี่ยนแปลงเพิ่มเติมจะแจ้งผ่าน LINE Official ของสายโดยตรง"
|
||||
]
|
||||
},
|
||||
"en": {
|
||||
"title": "Route 902 timetable update",
|
||||
"tag": "Update",
|
||||
"body": [
|
||||
"Route 902 (Bangkok–Ang Thong, Asia line) now departs every 40 minutes in the evening instead of 50, effective 1 September.",
|
||||
"Morning and midday trips are unchanged. Further changes will be announced via the line's LINE Official."
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"date": "2026-08-28",
|
||||
"th": {
|
||||
"title": "ทำไมตารางรถถึงเปลี่ยนบ่อย",
|
||||
"tag": "ความรู้",
|
||||
"body": [
|
||||
"ตารางเดินรถของรถโดยสารประจำทางเปลี่ยนได้ตามสภาพการจราจร จำนวนผู้โดยสาร และช่วงเทศกาล — บางสายปรับตามวันหยุดอีกด้วย",
|
||||
"เราจึงแสดงเวลาดิบจากผู้ประกอบการเสมอ และมีหมายเหตุเตือนให้เช็กเวลากับทางสายโดยตรงก่อนเดินทางในวันที่ฝนตกหรือวันหยุดยาว"
|
||||
]
|
||||
},
|
||||
"en": {
|
||||
"title": "Why bus timetables change so often",
|
||||
"tag": "Explainer",
|
||||
"body": [
|
||||
"Bus schedules shift with traffic, passenger demand and seasonal peaks — some lines even differ on holidays.",
|
||||
"That's why we show operators' raw times and remind you to double-check with the operator before travelling in heavy rain or long holidays."
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,168 @@
|
||||
<style>
|
||||
/* ===== หน้าบทความ — ข้อมูลจาก partials/blog-data/ (ระบบเดียวกับ about) ===== */
|
||||
.mu-hero-lead {
|
||||
margin: 14px auto 0;
|
||||
max-width: 640px;
|
||||
color: #5b3b71;
|
||||
font-size: .95rem;
|
||||
}
|
||||
|
||||
.mu-blog-wrap { padding: 26px 0 52px; }
|
||||
|
||||
/* --- แถบสลับมุมมอง (ตาราง / รายการ) --- */
|
||||
.mu-blog-bar {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
margin-bottom: 18px;
|
||||
}
|
||||
.mu-blog-count { margin: 0; color: #6f7b95; font-size: .88rem; }
|
||||
.mu-view-switch {
|
||||
margin-left: auto;
|
||||
display: inline-flex;
|
||||
gap: 2px;
|
||||
background: #f0edf7;
|
||||
border: 1px solid #e4dcf2;
|
||||
border-radius: 999px;
|
||||
padding: 3px;
|
||||
}
|
||||
.mu-view-btn {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
border: 0;
|
||||
background: transparent;
|
||||
color: #6d28d9;
|
||||
font-family: inherit;
|
||||
font-weight: 700;
|
||||
font-size: .8rem;
|
||||
min-height: 36px;
|
||||
padding: 6px 14px;
|
||||
border-radius: 999px;
|
||||
cursor: pointer;
|
||||
transition: background .15s ease, color .15s ease;
|
||||
}
|
||||
.mu-view-btn .ic { width: 15px; height: 15px; }
|
||||
.mu-view-btn.active { background: #fff; color: #7a4cc0; box-shadow: 0 1px 4px rgba(63, 43, 94, .18); }
|
||||
.mu-view-btn:focus-visible { outline: 2px solid #7a4cc0; outline-offset: 2px; }
|
||||
|
||||
/* --- โหมดตาราง (grid) --- */
|
||||
#blog-list.mode-grid {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr;
|
||||
gap: 18px;
|
||||
}
|
||||
.mu-blog-card {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
background: #fff;
|
||||
border: 1px solid #ebe8f4;
|
||||
border-radius: 18px;
|
||||
overflow: hidden;
|
||||
box-shadow: 0 10px 26px rgba(63, 43, 94, .07);
|
||||
text-decoration: none;
|
||||
color: inherit;
|
||||
transition: transform .18s ease, box-shadow .18s ease;
|
||||
}
|
||||
.mu-blog-card:hover { transform: translateY(-3px); box-shadow: 0 16px 34px rgba(63, 43, 94, .14); }
|
||||
.mu-blog-card .mu-cover { aspect-ratio: 16 / 9; }
|
||||
.mu-blog-card .mu-cover.no-img { background: linear-gradient(135deg, #7a4cc0, #3071b8); }
|
||||
.mu-blog-card .mu-cover.no-img::after { background: linear-gradient(180deg, rgba(15,23,42,0) 40%, rgba(15,23,42,.4) 100%); }
|
||||
.mu-blog-body { padding: 14px 16px 16px; display: flex; flex-direction: column; gap: 8px; flex: 1; }
|
||||
.mu-blog-meta { display: flex; align-items: center; gap: 8px; color: #6f7b95; font-size: .78rem; }
|
||||
.mu-blog-meta time { font-variant-numeric: tabular-nums; }
|
||||
.mu-blog-card h2 { margin: 0; font-size: 1.02rem; color: #1f2a44; font-weight: 800; line-height: 1.4; }
|
||||
.mu-blog-excerpt { margin: 0; color: #4a5568; font-size: .88rem; line-height: 1.7; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
|
||||
.mu-blog-more { margin-top: auto; padding-top: 6px; color: #7a4cc0; font-weight: 700; font-size: .85rem; }
|
||||
|
||||
/* --- โหมดรายการ (list) --- */
|
||||
#blog-list.mode-list { display: flex; flex-direction: column; gap: 14px; }
|
||||
.mu-blog-row {
|
||||
display: grid;
|
||||
grid-template-columns: 108px 1fr;
|
||||
gap: 14px;
|
||||
align-items: center;
|
||||
background: #fff;
|
||||
border: 1px solid #ebe8f4;
|
||||
border-radius: 16px;
|
||||
padding: 12px;
|
||||
box-shadow: 0 8px 20px rgba(63, 43, 94, .06);
|
||||
text-decoration: none;
|
||||
color: inherit;
|
||||
transition: border-color .15s ease, box-shadow .15s ease;
|
||||
}
|
||||
.mu-blog-row:hover { border-color: #d8c9f2; box-shadow: 0 12px 26px rgba(63, 43, 94, .12); }
|
||||
.mu-blog-row .thumb {
|
||||
width: 108px; height: 84px;
|
||||
border-radius: 12px;
|
||||
object-fit: cover;
|
||||
display: block;
|
||||
background: linear-gradient(135deg, #7a4cc0, #3071b8);
|
||||
}
|
||||
.mu-blog-row h2 { margin: 4px 0 6px; font-size: .98rem; color: #1f2a44; font-weight: 800; line-height: 1.4; }
|
||||
.mu-blog-row .mu-blog-excerpt { -webkit-line-clamp: 2; }
|
||||
.mu-blog-empty { color: #6f7b95; text-align: center; padding: 34px 0; }
|
||||
.mu-blog-skel { height: 220px; border-radius: 18px; background: linear-gradient(90deg, #f4f2fa 25%, #ece8f6 37%, #f4f2fa 63%); background-size: 400% 100%; animation: muSkelB 1.4s ease infinite; }
|
||||
@keyframes muSkelB { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }
|
||||
|
||||
/* --- หน้าอ่านบทความ --- */
|
||||
.mu-post { background: #fff; border: 1px solid #ebe8f4; border-radius: 20px; overflow: hidden; box-shadow: 0 12px 30px rgba(63, 43, 94, .08); }
|
||||
.mu-post .mu-cover { aspect-ratio: 16 / 8; }
|
||||
.mu-post-body { padding: 20px 18px 26px; }
|
||||
.mu-post-body h1 { margin: 6px 0 12px; font-size: 1.35rem; color: #1f2a44; font-weight: 800; line-height: 1.4; }
|
||||
.mu-post-body p { margin: 0 0 14px; color: #4a5568; font-size: .96rem; line-height: 1.9; }
|
||||
.mu-post-body p:last-child { margin-bottom: 0; }
|
||||
.mu-post-back {
|
||||
display: inline-flex; align-items: center; gap: 6px;
|
||||
margin-bottom: 16px; color: #7a4cc0; font-weight: 700;
|
||||
text-decoration: none; font-size: .9rem;
|
||||
}
|
||||
.mu-post-back:hover { text-decoration: underline; }
|
||||
|
||||
/* แท็บเล็ตขึ้นไป: การ์ด 2 คอลัมน์ → 3 คอลัมน์ */
|
||||
@media (min-width: 640px) {
|
||||
#blog-list.mode-grid { grid-template-columns: repeat(2, 1fr); }
|
||||
}
|
||||
@media (min-width: 1024px) {
|
||||
#blog-list.mode-grid { grid-template-columns: repeat(3, 1fr); }
|
||||
.mu-post-body { padding: 26px 30px 34px; }
|
||||
}
|
||||
</style>
|
||||
|
||||
<!-- ============ HERO ============ -->
|
||||
<section class="mu-hero">
|
||||
<img class="mu-hero-map" src="../.image/network/overview-map.png" alt="" aria-hidden="true" decoding="async">
|
||||
<div class="mu-blob one"></div>
|
||||
<div class="mu-blob two"></div>
|
||||
<div class="mu-blob three"></div>
|
||||
<div class="mu-container mu-hero-content">
|
||||
<span class="mu-badge"><svg class="ic" aria-hidden="true"><use href="#ic-message-circle"/></svg> <span data-i18n="nav.blog">บ่นไปเรื่อย</span></span>
|
||||
<h1><span data-i18n="blog.title">บ่นไปเรื่อย</span><br><span class="mu-gradient-text" data-i18n="blog.subtitle">หน้านี้ก็เหมือนไดอารี่ของเรา อยากบ่นอะไรก็บ่น</span></h1>
|
||||
<p class="mu-hero-lead" data-i18n="blog.lead">ขอบคุณที่เข้ามาอ่านบางบทความก็มีสาระบางบทความก็ไม่มีสาระ </p>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- ============ รายการบทความ (โหลดจาก blog-data: text1.json + pic1, ...) ============ -->
|
||||
<section class="mu-blog-wrap">
|
||||
<div class="mu-container">
|
||||
<div class="mu-blog-bar" id="blog-bar" hidden>
|
||||
<p class="mu-blog-count" id="blog-count"></p>
|
||||
<div class="mu-view-switch" role="group" aria-label="มุมมอง">
|
||||
<button type="button" class="mu-view-btn" data-view="grid">
|
||||
<svg class="ic" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect width="7" height="7" x="3" y="3" rx="1"/><rect width="7" height="7" x="14" y="3" rx="1"/><rect width="7" height="7" x="14" y="14" rx="1"/><rect width="7" height="7" x="3" y="14" rx="1"/></svg>
|
||||
<span data-i18n="blog.viewGrid">ตาราง</span>
|
||||
</button>
|
||||
<button type="button" class="mu-view-btn" data-view="list">
|
||||
<svg class="ic" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><line x1="8" x2="21" y1="6" y2="6"/><line x1="8" x2="21" y1="12" y2="12"/><line x1="8" x2="21" y1="18" y2="18"/><line x1="3" x2="3.01" y1="6" y2="6"/><line x1="3" x2="3.01" y1="12" y2="12"/><line x1="3" x2="3.01" y1="18" y2="18"/></svg>
|
||||
<span data-i18n="blog.viewList">รายการ</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div id="blog-list" aria-live="polite">
|
||||
<div class="mu-blog-skel"></div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<script src="./partials/blog.init.js"></script>
|
||||
@@ -0,0 +1,264 @@
|
||||
/* ============================================================
|
||||
หน้าบทความ — loader + สลับมุมมอง ตาราง/รายการ + หน้าอ่านบทความ
|
||||
------------------------------------------------------------
|
||||
ข้อมูล: partials/blog-data/ (ระบบเดียวกับ about us)
|
||||
text1.json + pic1.<ext> , text2.json + pic2.<ext> , ...
|
||||
{ "th": { "title","body":["..."],"tag" }, "en": {...}, "date": "2026-09-01" }
|
||||
|
||||
route:
|
||||
#/blog → รายการบทความ (มุมมอง grid/list — จำค่าใน localStorage)
|
||||
#/blog/:n → อ่านบทความที่ n
|
||||
============================================================ */
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
var DATA_DIR = './partials/blog-data/';
|
||||
var IMG_EXTS = ['jpg', 'jpeg', 'png', 'webp'];
|
||||
var MAX_POSTS = 50;
|
||||
var LS_VIEW = 'at_blog_view';
|
||||
var EXCERPT_LEN = 150;
|
||||
|
||||
function lang() { return (window.I18N && I18N.getLang()) || 'th'; }
|
||||
function t(key) { return window.I18N ? I18N.t(key) : key; }
|
||||
|
||||
function pick(data, l) {
|
||||
if (!data) return null;
|
||||
if (l !== 'th' && data[l]) return data[l];
|
||||
return data.th || data[l] || data[Object.keys(data)[0]] || data;
|
||||
}
|
||||
|
||||
function fetchJSON(n) {
|
||||
return fetch(DATA_DIR + 'text' + n + '.json', { cache: 'no-store' })
|
||||
.then(function (r) { return r.ok ? r.json() : null; })
|
||||
.catch(function () { return null; });
|
||||
}
|
||||
|
||||
function findImage(n) {
|
||||
var i = 0;
|
||||
function tryNext() {
|
||||
if (i >= IMG_EXTS.length) return Promise.resolve(null);
|
||||
var url = DATA_DIR + 'pic' + n + '.' + IMG_EXTS[i++];
|
||||
return fetch(url, { method: 'HEAD', cache: 'no-store' })
|
||||
.then(function (r) { return r.ok ? url : tryNext(); })
|
||||
.catch(tryNext);
|
||||
}
|
||||
return tryNext();
|
||||
}
|
||||
|
||||
function loadPosts() {
|
||||
var posts = [];
|
||||
var n = 1;
|
||||
function next() {
|
||||
if (n > MAX_POSTS) return Promise.resolve(posts);
|
||||
var current = n++;
|
||||
return fetchJSON(current).then(function (data) {
|
||||
if (!data) return posts;
|
||||
return findImage(current).then(function (imgUrl) {
|
||||
posts.push({ n: current, data: data, img: imgUrl });
|
||||
return next();
|
||||
});
|
||||
});
|
||||
}
|
||||
return next();
|
||||
}
|
||||
|
||||
function getView() {
|
||||
try {
|
||||
var v = localStorage.getItem(LS_VIEW);
|
||||
return v === 'list' ? 'list' : 'grid';
|
||||
} catch (e) { return 'grid'; }
|
||||
}
|
||||
|
||||
function setView(v) {
|
||||
try { localStorage.setItem(LS_VIEW, v); } catch (e) {}
|
||||
}
|
||||
|
||||
function readTime(body) {
|
||||
var words = (body || []).join(' ').length;
|
||||
return Math.max(1, Math.round(words / 350)); // ~350 ตัวอักษร/นาที
|
||||
}
|
||||
|
||||
function renderGrid(posts, host) {
|
||||
posts.forEach(function (p) {
|
||||
var c = pick(p.data, lang());
|
||||
var a = document.createElement('a');
|
||||
a.className = 'mu-blog-card';
|
||||
a.href = '#/blog/' + p.n;
|
||||
|
||||
var cover = document.createElement('div');
|
||||
cover.className = 'mu-cover' + (p.img ? '' : ' no-img');
|
||||
if (p.img) {
|
||||
var im = document.createElement('img');
|
||||
im.src = p.img; im.alt = ''; im.loading = 'lazy'; im.decoding = 'async';
|
||||
cover.appendChild(im);
|
||||
}
|
||||
if (c.tag) {
|
||||
var tag = document.createElement('span');
|
||||
tag.className = 'mu-cover-tag';
|
||||
tag.textContent = c.tag;
|
||||
cover.appendChild(tag);
|
||||
}
|
||||
var ct = document.createElement('p');
|
||||
ct.className = 'mu-cover-title';
|
||||
ct.textContent = c.title || '';
|
||||
cover.appendChild(ct);
|
||||
a.appendChild(cover);
|
||||
|
||||
var body = document.createElement('div');
|
||||
body.className = 'mu-blog-body';
|
||||
body.innerHTML = '<div class="mu-blog-meta"></div><h2></h2><p class="mu-blog-excerpt"></p><span class="mu-blog-more"></span>';
|
||||
body.querySelector('h2').textContent = c.title || '';
|
||||
body.querySelector('.mu-blog-excerpt').textContent = (c.body || []).join(' ').slice(0, EXCERPT_LEN) + '…';
|
||||
body.querySelector('.mu-blog-more').textContent = t('blog.readMore') + ' →';
|
||||
var meta = body.querySelector('.mu-blog-meta');
|
||||
if (p.data.date) {
|
||||
var tm = document.createElement('time');
|
||||
tm.dateTime = p.data.date;
|
||||
tm.textContent = p.data.date;
|
||||
meta.appendChild(tm);
|
||||
var dot = document.createElement('span'); dot.textContent = '·'; meta.appendChild(dot);
|
||||
}
|
||||
var rt = document.createElement('span');
|
||||
rt.textContent = readTime(c.body) + ' ' + t('blog.minRead');
|
||||
meta.appendChild(rt);
|
||||
a.appendChild(body);
|
||||
host.appendChild(a);
|
||||
});
|
||||
}
|
||||
|
||||
function renderList(posts, host) {
|
||||
posts.forEach(function (p) {
|
||||
var c = pick(p.data, lang());
|
||||
var a = document.createElement('a');
|
||||
a.className = 'mu-blog-row';
|
||||
a.href = '#/blog/' + p.n;
|
||||
if (p.img) {
|
||||
var im = document.createElement('img');
|
||||
im.className = 'thumb'; im.src = p.img; im.alt = ''; im.loading = 'lazy'; im.decoding = 'async';
|
||||
a.appendChild(im);
|
||||
}
|
||||
var box = document.createElement('div');
|
||||
box.innerHTML = '<div class="mu-blog-meta"></div><h2></h2><p class="mu-blog-excerpt"></p>';
|
||||
box.querySelector('h2').textContent = c.title || '';
|
||||
box.querySelector('.mu-blog-excerpt').textContent = (c.body || []).join(' ').slice(0, 110) + '…';
|
||||
var meta = box.querySelector('.mu-blog-meta');
|
||||
var bits = [];
|
||||
if (p.data.date) bits.push(p.data.date);
|
||||
if (c.tag) bits.push(c.tag);
|
||||
bits.push(readTime(c.body) + ' ' + t('blog.minRead'));
|
||||
meta.textContent = bits.join(' · ');
|
||||
a.appendChild(box);
|
||||
host.appendChild(a);
|
||||
});
|
||||
}
|
||||
|
||||
function renderPost(post, host) {
|
||||
var c = pick(post.data, lang());
|
||||
var art = document.createElement('article');
|
||||
art.className = 'mu-post';
|
||||
|
||||
if (post.img) {
|
||||
var cover = document.createElement('div');
|
||||
cover.className = 'mu-cover';
|
||||
var im = document.createElement('img');
|
||||
im.src = post.img; im.alt = c.title || ''; im.decoding = 'async';
|
||||
cover.appendChild(im);
|
||||
if (c.tag) {
|
||||
var tag = document.createElement('span');
|
||||
tag.className = 'mu-cover-tag';
|
||||
tag.textContent = c.tag;
|
||||
cover.appendChild(tag);
|
||||
}
|
||||
art.appendChild(cover);
|
||||
}
|
||||
|
||||
var body = document.createElement('div');
|
||||
body.className = 'mu-post-body';
|
||||
var back = document.createElement('a');
|
||||
back.className = 'mu-post-back';
|
||||
back.href = '#/blog';
|
||||
back.textContent = '← ' + t('blog.backList');
|
||||
body.appendChild(back);
|
||||
|
||||
var meta = document.createElement('div');
|
||||
meta.className = 'mu-blog-meta';
|
||||
var bits = [];
|
||||
if (post.data.date) bits.push(post.data.date);
|
||||
bits.push(readTime(c.body) + ' ' + t('blog.minRead'));
|
||||
meta.textContent = bits.join(' · ');
|
||||
body.appendChild(meta);
|
||||
|
||||
var h1 = document.createElement('h1');
|
||||
h1.textContent = c.title || '';
|
||||
body.appendChild(h1);
|
||||
|
||||
(c.body || []).forEach(function (pText) {
|
||||
var p = document.createElement('p');
|
||||
p.textContent = pText;
|
||||
body.appendChild(p);
|
||||
});
|
||||
|
||||
art.appendChild(body);
|
||||
host.appendChild(art);
|
||||
}
|
||||
|
||||
function init() {
|
||||
var host = document.getElementById('blog-list');
|
||||
if (!host) return;
|
||||
|
||||
var route = window.__route || { params: {} };
|
||||
var postId = route.params && route.params.postId;
|
||||
|
||||
loadPosts().then(function (posts) {
|
||||
host.innerHTML = '';
|
||||
|
||||
if (postId) {
|
||||
var post = posts.filter(function (p) { return String(p.n) === String(postId); })[0];
|
||||
var bar = document.getElementById('blog-bar');
|
||||
if (bar) bar.hidden = true;
|
||||
if (post) {
|
||||
renderPost(post, host);
|
||||
} else {
|
||||
host.innerHTML = '<p class="mu-blog-empty">' + t('blog.notFound') + '</p>';
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (!posts.length) {
|
||||
host.innerHTML = '<p class="mu-blog-empty">' + t('blog.empty') + '</p>';
|
||||
return;
|
||||
}
|
||||
|
||||
var bar = document.getElementById('blog-bar');
|
||||
var count = document.getElementById('blog-count');
|
||||
if (count) count.textContent = t('blog.count') + ' ' + posts.length + ' ' + t('blog.items');
|
||||
if (bar) bar.hidden = false;
|
||||
|
||||
var mode = getView();
|
||||
function paint() {
|
||||
host.className = mode === 'list' ? 'mode-list' : 'mode-grid';
|
||||
host.innerHTML = '';
|
||||
(mode === 'list' ? renderList : renderGrid)(posts, host);
|
||||
document.querySelectorAll('.mu-view-btn').forEach(function (b) {
|
||||
b.classList.toggle('active', b.getAttribute('data-view') === mode);
|
||||
b.setAttribute('aria-pressed', String(b.getAttribute('data-view') === mode));
|
||||
});
|
||||
}
|
||||
paint();
|
||||
|
||||
document.querySelectorAll('.mu-view-btn').forEach(function (b) {
|
||||
b.addEventListener('click', function () {
|
||||
mode = b.getAttribute('data-view');
|
||||
setView(mode);
|
||||
paint();
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
if (document.readyState === 'loading') {
|
||||
document.addEventListener('DOMContentLoaded', init);
|
||||
} else {
|
||||
init();
|
||||
}
|
||||
})();
|
||||
@@ -96,25 +96,6 @@
|
||||
border-color: #c8b4ec;
|
||||
}
|
||||
|
||||
.mu-province-strip {
|
||||
display:flex;
|
||||
flex-wrap:wrap;
|
||||
gap:8px;
|
||||
margin: 14px 0 18px;
|
||||
}
|
||||
.mu-province-strip a {
|
||||
background: linear-gradient(135deg, #ffffff, #f6f8ff);
|
||||
border: 1px solid #e7e3f7;
|
||||
padding: 8px 14px;
|
||||
border-radius: 999px;
|
||||
color: #5b3b71;
|
||||
text-decoration:none;
|
||||
font-size:.84rem;
|
||||
font-weight:700;
|
||||
box-shadow: 0 6px 14px rgba(63,43,94,.05);
|
||||
}
|
||||
.mu-province-strip a.active { background: linear-gradient(135deg, #7a4cc0, #8b5cf6); color:#fff; border-color: transparent; }
|
||||
|
||||
.mu-stop-grid {
|
||||
display:grid;
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
@@ -258,7 +239,7 @@
|
||||
<p class="mu-breadcrumb"><a href="#/">หน้าแรก</a>/ ป้ายหยุดรถ</p>
|
||||
<section class="mu-hero-panel">
|
||||
<div>
|
||||
<h1 class="mu-hero-title"><span data-i18n="stops.title">ค้นหาป้ายหยุดรถแบบรวดเร็วและอ่านง่าย</span></h1>
|
||||
<h1 class="mu-hero-title"><span data-i18n="stops.title">ค้นหาป้ายหยุดรถแบบรวดเร็ว</span></h1>
|
||||
<p class="mu-hero-subtitle"><span data-i18n="stops.subtitle">รวมสถานีขนส่งหลัก จุดจอดท้องถิ่น สถานีรถตู้ และจุดเอกชนในโทน soft gradient ที่ดูสะอาดตา ใช้งานได้ทั้งบนมือถือและเดสก์ท็อป</span></p>
|
||||
<div class="mu-kpi-grid" aria-label="summary metrics">
|
||||
<div class="mu-kpi">
|
||||
@@ -281,7 +262,7 @@
|
||||
</div>
|
||||
<div class="mu-hero-map">
|
||||
<p class="mu-hero-map-title"><span data-i18n="stops.mapTitle">แผนที่ย่อของเครือข่ายป้าย</span></p>
|
||||
<img class="mu-hero-map-photo" src="../.image/network/overview-map.png" alt="แผนที่เครือข่ายป้าย AT Transit" loading="lazy" decoding="async">
|
||||
<img class="mu-hero-map-photo" src="../.image/network/overview-map.png" alt="แผนที่เครือข่ายป้าย Atroute" loading="lazy" decoding="async">
|
||||
</div>
|
||||
</section>
|
||||
|
||||
@@ -290,30 +271,16 @@
|
||||
<svg class="ic" aria-hidden="true"><use href="#ic-search"/></svg>
|
||||
<input type="search" placeholder="ค้นหาชื่อสถานที่ เช่น บขส.อ่างทอง" data-i18n-attr="placeholder:stops.searchPh,aria-label:stops.searchPh">
|
||||
</div>
|
||||
<select aria-label="ประเภทสถานี">
|
||||
<select aria-label="ประเภทป้ายหยุดรถ">
|
||||
<option><span data-i18n="stops.allTypes">ทุกประเภท</span></option>
|
||||
<option><span data-i18n="type.terminal">สถานีขนส่งหลัก</span></option>
|
||||
<option><span data-i18n="type.van">สถานีรถตู้</span></option>
|
||||
<option><span data-i18n="type.local">จุดจอดท้องถิ่น</span></option>
|
||||
<option><span data-i18n="type.marketOpt">ตลาด/จุดเอกชน</span></option>
|
||||
<option><span data-i18n="type.terminal">สถานีขนส่งผู้โดยสาร</span></option>
|
||||
<option><span data-i18n="type.busstop">ศาลารอรถ หรือป้ายหยุดรถ</span></option>
|
||||
<option><span data-i18n="type.startlocalpoint">ต้นทางรถสายท้องถิ่น</span></option>
|
||||
</select>
|
||||
<button type="button" class="mu-btn primary"><span data-i18n="common.search">ค้นหา</span></button>
|
||||
<a class="mu-btn ghost" href="#/"><span data-i18n="common.back">ย้อนกลับ</span></a>
|
||||
</form>
|
||||
|
||||
<div class="mu-province-strip" aria-label="กรองตามจังหวัด">
|
||||
<a class="active" href="#"><span data-i18n="stops.allProvinces">ทุกจังหวัด</span></a>
|
||||
<a href="#">อ่างทอง</a>
|
||||
<a href="#">อยุธยา</a>
|
||||
<a href="#">ปทุมธานี</a>
|
||||
<a href="#">กรุงเทพมหานคร</a>
|
||||
<a href="#">สุพรรณบุรี</a>
|
||||
<a href="#">สระบุรี</a>
|
||||
<a href="#">ลพบุรี</a>
|
||||
<a href="#">สิงห์บุรี</a>
|
||||
<a href="#">ชัยนาท</a>
|
||||
</div>
|
||||
|
||||
<ul class="mu-stop-grid">
|
||||
<li><img class="mu-stop-thumb" src="../.image/stops/54950.jpg" alt="" loading="lazy" decoding="async"><div class="mu-stop-card main"><div class="mu-stop-top"><div><span class="mu-type-pill main"><span data-i18n="type.terminal">สถานีขนส่งหลัก</span></span><h2 class="mu-stop-title">บขส.อ่างทอง</h2><p class="mu-loc">เมืองอ่างทอง · อ่างทอง</p></div><span class="mu-chip count">8 สาย</span></div><div class="mu-chip-row"><span class="mu-chip route">สายหลัก</span><span class="mu-chip">เปิดบริการ</span></div><div class="mu-stop-action"><p class="mu-stop-note">ศูนย์กลางเส้นทางหลักของจังหวัด</p><a class="mu-row-link" href="#/stops/at_main_terminal?route=101"><span data-i18n="common.details">ดูรายละเอียด</span></a></div></div></li>
|
||||
<li><img class="mu-stop-thumb" src="../.image/stops/36020.jpg" alt="" loading="lazy" decoding="async"><div class="mu-stop-card main"><div class="mu-stop-top"><div><span class="mu-type-pill main"><span data-i18n="type.terminal">สถานีขนส่งหลัก</span></span><h2 class="mu-stop-title">สถานีขนส่งป่าโมก</h2><p class="mu-loc">ป่าโมก · อ่างทอง</p></div><span class="mu-chip count">2 สาย</span></div><div class="mu-chip-row"><span class="mu-chip route">จุดต่อรถ</span><span class="mu-chip">Hub ย่อย</span></div><div class="mu-stop-action"><p class="mu-stop-note">เหมาะสำหรับต่อรถไปอยุธยา</p><a class="mu-row-link" href="#/stops/pa_mok_terminal?route=101"><span data-i18n="common.details">ดูรายละเอียด</span></a></div></div></li>
|
||||
|
||||
@@ -88,7 +88,7 @@
|
||||
|
||||
<section class="mu-credit-section">
|
||||
<h2><span data-i18n="credits.pwa">โหมดออฟไลน์ (PWA / Service Worker)</span></h2>
|
||||
<p class="src">พัฒนาโดยทีม AT Transit — ไม่ใช้ไลบรารีภายนอก</p>
|
||||
<p class="src">พัฒนาโดยทีม Atroute — ไม่ใช้ไลบรารีภายนอก</p>
|
||||
<ul>
|
||||
<li>เว็บนี้เป็น Progressive Web App — ติดตั้งได้ (Add to Home Screen) และเปิดใช้งานได้เมื่อไม่มีอินเทอร์เน็ต</li>
|
||||
<li>อัปเดตเนื้อหาอัตโนมัติ: เมื่อเปิดเว็บ ระบบจะตรวจสอบเวอร์ชันใหม่และโหลดให้เอง — ผู้ใช้ไม่ต้องล้างแคช</li>
|
||||
|
||||
+80
-76
@@ -1,50 +1,21 @@
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
var PROVINCES = [
|
||||
'กรุงเทพมหานคร', 'กระบี่', 'กาญจนบุรี', 'กาฬสินธุ์', 'กำแพงเพชร', 'ขอนแก่น',
|
||||
'จันทบุรี', 'ฉะเชิงเทรา', 'ชลบุรี', 'ชัยนาท', 'ชัยภูมิ', 'ชุมพร', 'เชียงราย', 'เชียงใหม่',
|
||||
'ตรัง', 'ตราด', 'ตาก', 'นครนายก', 'นครปฐม', 'นครพนม', 'นครราชสีมา', 'นครศรีธรรมราช',
|
||||
'นครสวรรค์', 'นนทบุรี', 'นราธิวาส', 'น่าน', 'บึงกาฬ', 'บุรีรัมย์', 'ปทุมธานี',
|
||||
'ประจวบคีรีขันธ์', 'ปราจีนบุรี', 'ปัตตานี', 'พระนครศรีอยุธยา', 'พะเยา', 'พังงา', 'พัทลุง',
|
||||
'พิจิตร', 'พิษณุโลก', 'เพชรบุรี', 'เพชรบูรณ์', 'แพร่', 'ภูเก็ต', 'มหาสารคาม', 'มุกดาหาร',
|
||||
'แม่ฮ่องสอน', 'ยโสธร', 'ยะลา', 'ร้อยเอ็ด', 'ระนอง', 'ระยอง', 'ราชบุรี', 'ลพบุรี',
|
||||
'ลำปาง', 'ลำพูน', 'เลย', 'ศรีสะเกษ', 'สกลนคร', 'สงขลา', 'สตูล', 'สมุทรปราการ',
|
||||
'สมุทรสงคราม', 'สมุทรสาคร', 'สระแก้ว', 'สระบุรี', 'สิงห์บุรี', 'สุโขทัย', 'สุพรรณบุรี',
|
||||
'สุราษฎร์ธานี', 'สุรินทร์', 'หนองคาย', 'หนองบัวลำภู', 'อ่างทอง', 'อำนาจเจริญ', 'อุดรธานี',
|
||||
'อุตรดิตถ์', 'อุทัยธานี', 'อุบลราชธานี'
|
||||
];
|
||||
|
||||
var STATIONS_BY_PROVINCE = {
|
||||
'อ่างทอง': [
|
||||
'บขส.อ่างทอง',
|
||||
'สถานีขนส่งป่าโมก',
|
||||
'สถานีขนส่งวิเศษชัยชาญ',
|
||||
'สถานีขนส่งไชโย',
|
||||
'สถานีขนส่งโพธิ์ทอง',
|
||||
'สถานีขนส่งแสวงหา',
|
||||
'สถานีขนส่งสามโก้',
|
||||
'นะโมซุปเปอร์มาร์ท',
|
||||
'บขส.999 อ่างทอง สายเอเชีย-เหนือ (ไม่เข้าเมือง)',
|
||||
'จุดขึ้นรถประจำทางอื่นๆ'
|
||||
],
|
||||
'พระนครศรีอยุธยา': [
|
||||
'จุดขึ้นลงรถสองแถว 101 อยุธยา-ป่าโมก-อ่างทอง',
|
||||
'ตลาดเจ้าพรหม'
|
||||
],
|
||||
'ปทุมธานี': ['ท่ารถตู้ต่างจังหวัด รังสิต'],
|
||||
'กรุงเทพมหานคร': [
|
||||
'สถานีเดินรถโดยสารขนาดเล็ก (จตุจักร) รถตู้/มินิบัส',
|
||||
'สายใต้เก่า ปิ่นเกล้า จุดจอดรถตู้'
|
||||
],
|
||||
'ลพบุรี': ['บขส.ลพบุรี'],
|
||||
'สุพรรณบุรี': ['บขส.สุพรรณบุรี'],
|
||||
'สระบุรี': ['บขส.สระบุรี'],
|
||||
'ชัยนาท': ['บขส.ชัยนาท']
|
||||
// แหล่งข้อมูลเดียว (source of truth) — อย่า hardcode รายชื่อจังหวัด/สถานีไว้ในไฟล์นี้
|
||||
var DATA_URL = {
|
||||
provinces: '../resource/data/provinces.json',
|
||||
stations: '../resource/data/stations.json'
|
||||
};
|
||||
|
||||
// จังหวัดเริ่มต้น (home province ของเว็บนี้) — ใช้เป็นค่า default ของ hero + ตัวเลือก
|
||||
var DEFAULT_PROVINCE = 'อ่างทอง';
|
||||
|
||||
function fetchJSON(url) {
|
||||
return fetch(url, { cache: 'no-store' })
|
||||
.then(function (r) { return r.ok ? r.json() : null; })
|
||||
.catch(function () { return null; });
|
||||
}
|
||||
|
||||
function initHomeSelectors() {
|
||||
var provinceSelect = document.getElementById('province-select');
|
||||
var stationSelect = document.getElementById('station-select');
|
||||
@@ -52,45 +23,78 @@
|
||||
var heroProvince = document.getElementById('hero-province');
|
||||
if (!provinceSelect || !stationSelect) return;
|
||||
|
||||
provinceSelect.innerHTML = '';
|
||||
PROVINCES.forEach(function (name) {
|
||||
var opt = document.createElement('option');
|
||||
opt.value = name;
|
||||
opt.textContent = name;
|
||||
if (name === DEFAULT_PROVINCE) opt.selected = true;
|
||||
provinceSelect.appendChild(opt);
|
||||
});
|
||||
var tr = window.I18N ? window.I18N.t : function (k) { return k; };
|
||||
|
||||
function populateStations(province) {
|
||||
stationSelect.innerHTML = '';
|
||||
var stations = STATIONS_BY_PROVINCE[province] || [];
|
||||
var tr = window.I18N ? window.I18N.t : function (k) { return k; };
|
||||
if (stations.length === 0) {
|
||||
var empty = document.createElement('option');
|
||||
empty.value = '';
|
||||
empty.textContent = tr('home.stationEmpty');
|
||||
empty.disabled = true;
|
||||
empty.selected = true;
|
||||
stationSelect.appendChild(empty);
|
||||
if (stationHint) stationHint.textContent = tr('home.stationEmptyHint') + ' ' + province;
|
||||
} else {
|
||||
stations.forEach(function (name) {
|
||||
var opt = document.createElement('option');
|
||||
opt.value = name;
|
||||
opt.textContent = name;
|
||||
stationSelect.appendChild(opt);
|
||||
});
|
||||
if (stationHint) stationHint.innerHTML = tr('home.stationCount', { n: stations.length }) + ' ' + province;
|
||||
// โหลดจังหวัด + สถานี จาก resource/data/*.json (โหลดพร้อมกันรอบเดียว)
|
||||
Promise.all([
|
||||
fetchJSON(DATA_URL.provinces),
|
||||
fetchJSON(DATA_URL.stations)
|
||||
]).then(function (results) {
|
||||
var provincesData = results[0];
|
||||
var stationsData = results[1];
|
||||
|
||||
var provinces = ((provincesData && provincesData.provinces) || [])
|
||||
.map(function (p) { return p.province_name_th; })
|
||||
.filter(Boolean);
|
||||
|
||||
var stations = (stationsData && stationsData.stations) || [];
|
||||
|
||||
if (!provinces.length) return; // โหลดข้อมูลไม่สำเร็จ → ปล่อย select ว่างไว้
|
||||
|
||||
var selectedProvince = provinces.indexOf(DEFAULT_PROVINCE) !== -1
|
||||
? DEFAULT_PROVINCE
|
||||
: provinces[0];
|
||||
|
||||
provinceSelect.innerHTML = '';
|
||||
provinces.forEach(function (name) {
|
||||
var opt = document.createElement('option');
|
||||
opt.value = name;
|
||||
opt.textContent = name;
|
||||
if (name === selectedProvince) opt.selected = true;
|
||||
provinceSelect.appendChild(opt);
|
||||
});
|
||||
|
||||
function stationsFor(province) {
|
||||
return stations
|
||||
.filter(function (s) {
|
||||
// สถานีที่ไม่มี province (เช่น "จุดขึ้นรถประจำทางอื่นๆ") ให้ถือว่าอยู่ในจังหวัดหลัก
|
||||
var p = s.province_th || DEFAULT_PROVINCE;
|
||||
return p === province;
|
||||
})
|
||||
.map(function (s) { return s.station_name_th; })
|
||||
.filter(Boolean);
|
||||
}
|
||||
var prefix = tr('home.provincePrefix');
|
||||
if (heroProvince) heroProvince.textContent = (prefix ? prefix + ' ' : '') + province;
|
||||
}
|
||||
|
||||
provinceSelect.addEventListener('change', function () {
|
||||
populateStations(provinceSelect.value);
|
||||
function populateStations(province) {
|
||||
stationSelect.innerHTML = '';
|
||||
var list = stationsFor(province);
|
||||
if (list.length === 0) {
|
||||
var empty = document.createElement('option');
|
||||
empty.value = '';
|
||||
empty.textContent = tr('home.stationEmpty');
|
||||
empty.disabled = true;
|
||||
empty.selected = true;
|
||||
stationSelect.appendChild(empty);
|
||||
if (stationHint) stationHint.textContent = tr('home.stationEmptyHint') + ' ' + province;
|
||||
} else {
|
||||
list.forEach(function (name) {
|
||||
var opt = document.createElement('option');
|
||||
opt.value = name;
|
||||
opt.textContent = name;
|
||||
stationSelect.appendChild(opt);
|
||||
});
|
||||
if (stationHint) stationHint.innerHTML = tr('home.stationCount', { n: list.length }) + ' ' + province;
|
||||
}
|
||||
var prefix = tr('home.provincePrefix');
|
||||
if (heroProvince) heroProvince.textContent = (prefix ? prefix + ' ' : '') + province;
|
||||
}
|
||||
|
||||
provinceSelect.addEventListener('change', function () {
|
||||
populateStations(provinceSelect.value);
|
||||
});
|
||||
|
||||
populateStations(selectedProvince);
|
||||
});
|
||||
|
||||
populateStations(DEFAULT_PROVINCE);
|
||||
}
|
||||
|
||||
function initMarquee() {
|
||||
@@ -105,4 +109,4 @@
|
||||
|
||||
initHomeSelectors();
|
||||
initMarquee();
|
||||
})();
|
||||
})();
|
||||
@@ -83,4 +83,15 @@
|
||||
<rect width="20" height="16" x="2" y="4" rx="2" />
|
||||
<path d="m22 7-8.97 5.7a1.94 1.94 0 0 1-2.06 0L2 7" />
|
||||
</symbol>
|
||||
|
||||
<symbol id="ic-accessibility" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="16" cy="4" r="1" /> <path d="m18 19 1-7-6 1" /> <path d="m5 8 3-3 5.5 3-2.36 3.5" /> <path d="M4.24 14.5a5 5 0 0 0 6.88 6" /> <path d="M13.76 17.5a5 5 0 0 0-6.88-6" /></symbol>
|
||||
<symbol id="ic-banknote" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect width="20" height="12" x="2" y="6" rx="2" /> <circle cx="12" cy="12" r="2" /> <path d="M6 12h.01M18 12h.01" /></symbol>
|
||||
<symbol id="ic-coffee" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10 2v2" /> <path d="M14 2v2" /> <path d="M16 8a1 1 0 0 1 1 1v8a4 4 0 0 1-4 4H7a4 4 0 0 1-4-4V9a1 1 0 0 1 1-1h14a4 4 0 1 1 0 8h-1" /> <path d="M6 2v2" /></symbol>
|
||||
<symbol id="ic-image" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect width="18" height="18" x="3" y="3" rx="2" ry="2" /> <circle cx="9" cy="9" r="2" /> <path d="m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21" /></symbol>
|
||||
<symbol id="ic-landmark" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10 18v-7" /> <path d="M11.119 2.205a2 2 0 0 1 1.762 0l7.84 3.846A.5.5 0 0 1 20.5 7h-17a.5.5 0 0 1-.22-.949z" /> <path d="M14 18v-7" /> <path d="M18 18v-7" /> <path d="M3 22h18" /> <path d="M6 18v-7" /></symbol>
|
||||
<symbol id="ic-navigation" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polygon points="3 11 22 2 13 21 11 13 3 11" /></symbol>
|
||||
<symbol id="ic-route" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="6" cy="19" r="3" /> <path d="M9 19h8.5a3.5 3.5 0 0 0 0-7h-11a3.5 3.5 0 0 1 0-7H15" /> <circle cx="18" cy="5" r="3" /></symbol>
|
||||
<symbol id="ic-shopping-bag" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M16 10a4 4 0 0 1-8 0" /> <path d="M3.103 6.034h17.794" /> <path d="M3.4 5.467a2 2 0 0 0-.4 1.2V20a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V6.667a2 2 0 0 0-.4-1.2l-2-2.667A2 2 0 0 0 17 2H7a2 2 0 0 0-1.6.8z" /></symbol>
|
||||
<symbol id="ic-store" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M15 21v-5a1 1 0 0 0-1-1h-4a1 1 0 0 0-1 1v5" /> <path d="M17.774 10.31a1.12 1.12 0 0 0-1.549 0 2.5 2.5 0 0 1-3.451 0 1.12 1.12 0 0 0-1.548 0 2.5 2.5 0 0 1-3.452 0 1.12 1.12 0 0 0-1.549 0 2.5 2.5 0 0 1-3.77-3.248l2.889-4.184A2 2 0 0 1 7 2h10a2 2 0 0 1 1.653.873l2.895 4.192a2.5 2.5 0 0 1-3.774 3.244" /> <path d="M4 10.95V19a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-8.05" /></symbol>
|
||||
<symbol id="ic-utensils" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 2v7c0 1.1.9 2 2 2h4a2 2 0 0 0 2-2V2" /> <path d="M7 2v20" /> <path d="M21 15V2a5 5 0 0 0-5 5v6c0 1.1.9 2 2 2h3Zm0 0v7" /></symbol>
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 5.0 KiB After Width: | Height: | Size: 8.2 KiB |
Reference in new issue
Block a user