diff --git a/ui/_shared.css b/ui/_shared.css index d83ce71..e8764a7 100644 --- a/ui/_shared.css +++ b/ui/_shared.css @@ -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; } +} diff --git a/ui/index.html b/ui/index.html index 4ed88da..38a7960 100644 --- a/ui/index.html +++ b/ui/index.html @@ -19,16 +19,16 @@ หน้าแรก | Atroute (mockup) - + - - - - - - + + + + + + diff --git a/ui/partials/home.init.js b/ui/partials/home.init.js index 03a95ad..eb28541 100644 --- a/ui/partials/home.init.js +++ b/ui/partials/home.init.js @@ -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) { diff --git a/ui/share.js b/ui/share.js new file mode 100644 index 0000000..e834dc1 --- /dev/null +++ b/ui/share.js @@ -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) + + ' ' + esc(url) + ' ' + + '' + + esc(t('share.line', 'แชร์ผ่าน LINE')) + ''; + } + + 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(); + }); +})(); diff --git a/ui/sw.js b/ui/sw.js index 5b04714..e15a72f 100644 --- a/ui/sw.js +++ b/ui/sw.js @@ -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", diff --git a/ui/version.json b/ui/version.json index 203e69c..c6a5533 100644 --- a/ui/version.json +++ b/ui/version.json @@ -1 +1 @@ -{"version": "2026.09.27.123"} +{"version": "2026.09.27.124"}