check page: add share button (parity with Next) + shared share row styles
- ui/share.js: one handler for all pages (id=share-btn / id=share-status), short link = origin+path+hash, navigator.share + clipboard, LINE link, re-binds after router swaps the view (MutationObserver), skips buttons that a page already bound itself - checkSchedule.html: share row inside .mu-container (same position as Next) - _shared.css: .mu-share-* moved here from home.html, values copied from Next (ghost button, radius 8, 44px, tokens) so light/dark match - home.init.js marks its own binding so the shared handler does not double-bind - index.html + sw PRECACHE: share.js · VERSION 2026.09.27.124
This commit is contained in:
1 parent
1adc2a6cd0
commit
b6ccb66ce2
8 files changed
+189
-39
No files matched your search
@@ -681,3 +681,66 @@ body:has(.mu-site-footer) .mu-footer { display: none; }
|
||||
.mu-loadbar { display: none; }
|
||||
}
|
||||
|
||||
/* ============================================================
|
||||
ปุ่ม "แชร์หน้านี้" — พอร์ตจาก web-at-transit (variant ghost)
|
||||
ใช้ได้ทุกหน้า: ปุ่ม id="share-btn" + ข้อความ id="share-status"
|
||||
============================================================ */
|
||||
.mu-share-row {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: flex-end;
|
||||
gap: 8px;
|
||||
margin: 22px 0 44px;
|
||||
}
|
||||
.mu-share-btn {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 6px;
|
||||
min-height: 44px;
|
||||
padding: 10px 18px;
|
||||
border: 1px solid var(--c-border);
|
||||
border-radius: var(--radius);
|
||||
background: var(--c-surface);
|
||||
color: var(--c-brand-ink);
|
||||
font-family: inherit;
|
||||
font-size: .85rem;
|
||||
font-weight: 700;
|
||||
line-height: 1;
|
||||
cursor: pointer;
|
||||
transition: border-color .15s ease, background .15s ease, transform .1s ease;
|
||||
}
|
||||
.mu-share-btn:hover { border-color: #d8c9f2; background: var(--c-surface-2); }
|
||||
.mu-share-btn:active { transform: translateY(1px); }
|
||||
.mu-share-btn:focus-visible { outline: 2px solid var(--c-focus); outline-offset: 2px; }
|
||||
.mu-share-btn .ic { width: 16px; height: 16px; }
|
||||
.mu-share-status {
|
||||
margin: 0;
|
||||
font-size: .85rem;
|
||||
line-height: 1.7;
|
||||
color: var(--c-ink-2);
|
||||
text-align: right;
|
||||
}
|
||||
.mu-share-status:empty { display: none; }
|
||||
.mu-share-url {
|
||||
display: inline-block;
|
||||
padding: 2px 8px;
|
||||
border: 1px solid var(--c-border);
|
||||
border-radius: 8px;
|
||||
background: var(--c-surface-2);
|
||||
font-family: ui-monospace, "IBM Plex Mono", monospace;
|
||||
font-size: .8rem;
|
||||
}
|
||||
.mu-share-line {
|
||||
display: inline-block;
|
||||
margin-left: 6px;
|
||||
font-weight: 700;
|
||||
color: #06c755;
|
||||
text-decoration: none;
|
||||
}
|
||||
.mu-share-line:hover { text-decoration: underline; }
|
||||
@media (max-width: 560px) {
|
||||
.mu-share-row { align-items: stretch; }
|
||||
.mu-share-btn { justify-content: center; }
|
||||
.mu-share-status { text-align: left; }
|
||||
}
|
||||
+24
-23
@@ -19,16 +19,16 @@
|
||||
</script>
|
||||
<title>หน้าแรก | Atroute (mockup)</title>
|
||||
<!-- ฟอนต์หลัก K2D: ไฟล์ในโปรเจกต์ (ui/vendor/fonts/) — ทำงานออฟไลน์ได้ -->
|
||||
<link href="./vendor/fonts/k2d.css?v=2026.09.27.123" rel="stylesheet">
|
||||
<link href="./vendor/fonts/k2d.css?v=2026.09.27.124" 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="./theme.css?v=2026.09.27.123" rel="stylesheet">
|
||||
<link href="./_shared.css?v=2026.09.27.123" rel="stylesheet">
|
||||
<link href="./vendor/leaflet/leaflet.css?v=2026.09.27.123" rel="stylesheet">
|
||||
<link href="./map.css?v=2026.09.27.123" rel="stylesheet">
|
||||
<meta name="app-version" content="2026.09.27.123">
|
||||
<link rel="icon" type="image/png" href="../.image/icons/minibus-512x512.png?v=2026.09.27.123">
|
||||
<link href="./theme.css?v=2026.09.27.124" rel="stylesheet">
|
||||
<link href="./_shared.css?v=2026.09.27.124" rel="stylesheet">
|
||||
<link href="./vendor/leaflet/leaflet.css?v=2026.09.27.124" rel="stylesheet">
|
||||
<link href="./map.css?v=2026.09.27.124" rel="stylesheet">
|
||||
<meta name="app-version" content="2026.09.27.124">
|
||||
<link rel="icon" type="image/png" href="../.image/icons/minibus-512x512.png?v=2026.09.27.124">
|
||||
<style>
|
||||
.mu-card.empty { width: 100%; padding: 16px; text-align: center; color: var(--c-ink-2); background: #fff7fb; border: 1px dashed #f4c7df; }
|
||||
a.mu-card { text-decoration: none; color: inherit; display: block; }
|
||||
@@ -320,20 +320,21 @@
|
||||
</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.123">
|
||||
<script src="./imageurl.js?v=2026.09.27.123" defer></script>
|
||||
<script src="./pwa.js?v=2026.09.27.123" defer></script>
|
||||
<script src="./i18n.js?v=2026.09.27.123" defer></script>
|
||||
<script src="./theme.js?v=2026.09.27.123" defer></script>
|
||||
<script src="./analytics.js?v=2026.09.27.123" defer></script>
|
||||
<script src="./popular.js?v=2026.09.27.123" defer></script>
|
||||
<script src="./vendor/leaflet/leaflet.js?v=2026.09.27.123" defer></script>
|
||||
<script src="./map.js?v=2026.09.27.123" defer></script>
|
||||
<script src="./partials/schedules.js?v=2026.09.27.123" defer></script>
|
||||
<script src="./partials/otherStop.js?v=2026.09.27.123" defer></script>
|
||||
<script src="./motion.js?v=2026.09.27.123" defer></script>
|
||||
<script src="./router.js?v=2026.09.27.123" defer></script>
|
||||
<link rel="stylesheet" href="./responsive.css?v=2026.09.27.123">
|
||||
<link rel="apple-touch-icon" href="../.image/icons/minibus-192x192.png?v=2026.09.27.124">
|
||||
<script src="./imageurl.js?v=2026.09.27.124" defer></script>
|
||||
<script src="./pwa.js?v=2026.09.27.124" defer></script>
|
||||
<script src="./i18n.js?v=2026.09.27.124" defer></script>
|
||||
<script src="./theme.js?v=2026.09.27.124" defer></script>
|
||||
<script src="./share.js?v=2026.09.27.124" defer></script>
|
||||
<script src="./analytics.js?v=2026.09.27.124" defer></script>
|
||||
<script src="./popular.js?v=2026.09.27.124" defer></script>
|
||||
<script src="./vendor/leaflet/leaflet.js?v=2026.09.27.124" defer></script>
|
||||
<script src="./map.js?v=2026.09.27.124" defer></script>
|
||||
<script src="./partials/schedules.js?v=2026.09.27.124" defer></script>
|
||||
<script src="./partials/otherStop.js?v=2026.09.27.124" defer></script>
|
||||
<script src="./motion.js?v=2026.09.27.124" defer></script>
|
||||
<script src="./router.js?v=2026.09.27.124" defer></script>
|
||||
<link rel="stylesheet" href="./responsive.css?v=2026.09.27.124">
|
||||
</head>
|
||||
<body class="main-theme-page">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" style="display:none" aria-hidden="true">
|
||||
@@ -427,7 +428,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.123" alt="Atroute logo" width="44" height="44" decoding="async">
|
||||
<img class="mu-logo-img" src="../.image/icons/minibus-512x512.png?v=2026.09.27.124" 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>
|
||||
@@ -503,7 +504,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.123" alt="Atroute">
|
||||
<img src="../.image/icons/minibus-512x512.png?v=2026.09.27.124" alt="Atroute">
|
||||
<div>
|
||||
<strong>Atroute</strong>
|
||||
<span data-i18n="brand.subtitle">สถานีขนส่งผู้โดยสารจังหวัดอ่างทอง</span>
|
||||
|
||||
@@ -172,6 +172,15 @@
|
||||
<!-- การ์ดจุดจอด + ชิปเวลา: สร้างจาก resource/data/schedules.json (checkSchedule.init.js) -->
|
||||
<ul class="mu-schedule-list" id="check-schedule-list"></ul>
|
||||
</div>
|
||||
|
||||
<!-- ปุ่มแชร์หน้านี้ (ใช้ ui/share.js ร่วมกับหน้าอื่น) -->
|
||||
<div class="mu-share-row">
|
||||
<button type="button" class="mu-share-btn" id="share-btn">
|
||||
<svg class="ic" aria-hidden="true"><use href="#ic-navigation"/></svg>
|
||||
<span data-i18n="share.label">แชร์หน้านี้</span>
|
||||
</button>
|
||||
<p class="mu-share-status" id="share-status" aria-live="polite"></p>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
|
||||
+1
-14
@@ -1,23 +1,10 @@
|
||||
<style>
|
||||
/* ปุ่มแชร์ลิงก์สั้น — มุมล่างขวา ต่อจากการ์ดหมวดเส้นทาง */
|
||||
.mu-share-row { display: flex; flex-direction: column; align-items: flex-end; gap: 8px; margin: 22px 0 44px; }
|
||||
.mu-share-btn {
|
||||
/* ปุ่มแชร์ลิงก์สั้น — มุมล่างขวา ต่อจากการ์ดหมวดเส้นทาง */
|
||||
display: inline-flex; align-items: center; gap: 8px;
|
||||
padding: 10px 16px; border: 1px solid #7a4cc0; border-radius: 8px;
|
||||
background: var(--c-brand); color: #fff; font: inherit; font-size: .9rem; font-weight: 700; cursor: pointer;
|
||||
}
|
||||
.mu-share-btn:hover { background: #6a3cae; }
|
||||
.mu-share-btn:focus-visible { outline: 2px solid #2b2f42; outline-offset: 2px; }
|
||||
.mu-share-btn .ic { width: 18px; height: 18px; }
|
||||
.mu-share-status { margin: 0; font-size: .82rem; line-height: 1.7; color: #4b5570; text-align: right; }
|
||||
.mu-share-status:empty { display: none; }
|
||||
.mu-share-url { display: inline-block; padding: 2px 6px; border: 1px solid var(--c-border); border-radius: 8px; background: #faf9ff; font-size: .8rem; }
|
||||
.mu-share-line { display: inline-block; margin-left: 6px; font-weight: 700; color: #06c755; text-decoration: none; }
|
||||
.mu-share-line:hover { text-decoration: underline; }
|
||||
@media (max-width: 560px) {
|
||||
.mu-share-row { align-items: stretch; }
|
||||
.mu-share-btn { justify-content: center; }
|
||||
.mu-share-status { text-align: left; }
|
||||
}
|
||||
</style>
|
||||
|
||||
|
||||
@@ -419,6 +419,7 @@
|
||||
var btn = document.getElementById('share-btn');
|
||||
var status = document.getElementById('share-status');
|
||||
if (!btn) return;
|
||||
btn.dataset.bound = '1'; /* หน้าแรกมี logic ลิงก์สั้นของตัวเอง */
|
||||
var tr = window.I18N ? window.I18N.t : function (k) { return k; };
|
||||
|
||||
function paint(msg) {
|
||||
|
||||
+88
@@ -0,0 +1,88 @@
|
||||
/* ============================================================
|
||||
share.js — ปุ่ม "แชร์หน้านี้" ใช้ร่วมทุกหน้า (mock)
|
||||
------------------------------------------------------------
|
||||
พอร์ตจาก web-at-transit (lib/share.ts + ปุ่มในทุก view)
|
||||
- ปุ่มต้องมี id="share-btn" · ข้อความสถานะ id="share-status"
|
||||
- ลิงก์สั้น = origin + path + hash ของหน้าปัจจุบัน (ไม่ฝังชื่อเว็บ)
|
||||
- มี navigator.share → เปิดแผงแชร์ของระบบ · พร้อมคัดลอกลงคลิปบอร์ด
|
||||
- ไม่มี → คัดลอกอย่างเดียว
|
||||
- ทำงานซ้ำได้หลัง router เปลี่ยนหน้า (ข้ามปุ่มที่ผูกแล้ว)
|
||||
============================================================ */
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
function t(key, fallback) {
|
||||
var v = (window.I18N && I18N.t) ? I18N.t(key) : key;
|
||||
return (!v || v === key) ? fallback : v;
|
||||
}
|
||||
|
||||
function shortUrl() {
|
||||
return location.origin + location.pathname + location.hash;
|
||||
}
|
||||
|
||||
function esc(s) {
|
||||
return String(s == null ? '' : s).replace(/[&<>"']/g, function (c) {
|
||||
return ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' })[c];
|
||||
});
|
||||
}
|
||||
|
||||
function bind() {
|
||||
var btn = document.getElementById('share-btn');
|
||||
var status = document.getElementById('share-status');
|
||||
if (!btn || btn.dataset.bound === '1') return;
|
||||
btn.dataset.bound = '1';
|
||||
|
||||
function paint(msg) {
|
||||
if (!status) return;
|
||||
var url = shortUrl();
|
||||
status.innerHTML = esc(msg) +
|
||||
' <code class="mu-share-url">' + esc(url) + '</code> ' +
|
||||
'<a class="mu-share-line" href="https://social-plugins.line.me/lineit/share?url=' +
|
||||
encodeURIComponent(url) + '" target="_blank" rel="noopener">' +
|
||||
esc(t('share.line', 'แชร์ผ่าน LINE')) + '</a>';
|
||||
}
|
||||
|
||||
btn.addEventListener('click', function () {
|
||||
var url = shortUrl();
|
||||
|
||||
if (navigator.share) {
|
||||
navigator.share({ title: document.title, url: url }).catch(function () {});
|
||||
}
|
||||
|
||||
if (navigator.clipboard && navigator.clipboard.writeText) {
|
||||
navigator.clipboard.writeText(url).then(function () {
|
||||
paint(t('share.copied', 'คัดลอกลิงก์แล้ว'));
|
||||
}).catch(function () {
|
||||
paint(t('share.short', 'ลิงก์สั้น'));
|
||||
});
|
||||
} else {
|
||||
paint(t('share.short', 'ลิงก์สั้น'));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
window.AtShareInit = bind;
|
||||
bind();
|
||||
|
||||
/* router inject partial ใหม่ทุกครั้งที่เปลี่ยนหน้า → ผูกปุ่มให้เอง */
|
||||
(function watch() {
|
||||
var host = document.getElementById('view');
|
||||
if (!host || !window.MutationObserver) return;
|
||||
var queued = 0;
|
||||
new MutationObserver(function (list) {
|
||||
for (var i = 0; i < list.length; i++) {
|
||||
if (list[i].addedNodes && list[i].addedNodes.length) {
|
||||
if (queued) return;
|
||||
queued = 1;
|
||||
setTimeout(function () { queued = 0; bind(); }, 60);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}).observe(host, { childList: true, subtree: true });
|
||||
})();
|
||||
window.addEventListener('langchange', function () {
|
||||
var btn = document.getElementById('share-btn');
|
||||
if (btn) delete btn.dataset.bound;
|
||||
bind();
|
||||
});
|
||||
})();
|
||||
@@ -13,7 +13,7 @@
|
||||
- ขั้นตอนอัปเดต: ดู AGENTS.md หัวข้อ PWA
|
||||
============================================================ */
|
||||
|
||||
const VERSION = "2026.09.27.123"; // ← bump ทุกครั้งที่แก้ SW เอง
|
||||
const VERSION = "2026.09.27.124"; // ← bump ทุกครั้งที่แก้ SW เอง
|
||||
const CACHE = `at-transit-${VERSION}`;
|
||||
|
||||
const PRECACHE = [
|
||||
@@ -33,6 +33,7 @@ const PRECACHE = [
|
||||
"./popular.js",
|
||||
"./analytics.js",
|
||||
"./theme.js",
|
||||
"./share.js",
|
||||
"./theme.css",
|
||||
"./router.js",
|
||||
"./motion.js",
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
{"version": "2026.09.27.123"}
|
||||
{"version": "2026.09.27.124"}
|
||||
Reference in new issue
Block a user