feat(cards): คลิกการ์ดโรงหนังได้ทั้งใบ (ไม่ใช่แค่ "ดูรายละเอียด")
- assets/card-click.v1.js: event delegation บน <article> → location.assign(a[href^="/cinema/"]) · ยกเว้นปุ่ม/ลิงก์ภายในใบ (ปุ่มแชร์ยังทำงานเอง) และตอนลากเลือกข้อความ · cursor pointer + focus ring ที่ลิงก์ "ดูรายละเอียด" - scripts/apply-card-click.mjs: เติม <script defer> ให้ทุก .html (64 ไฟล์) + โหมด --check - sw.js: precache card-click + VERSION v2.1.3 - docs/card-clickable.md: กติกา ผลทดสอบ และขั้นตอนหลัง re-export
This commit is contained in:
1 parent
3ebfcfea75
commit
c2506b8ed4
68 files changed
+212
-65
No files matched your search
@@ -0,0 +1,56 @@
|
||||
/*!
|
||||
* card-click v1 — ทำให้การ์ดโรงหนัง "ทั้งใบ" กดเปิดหน้าโรงหนังได้
|
||||
*
|
||||
* บริบท: เว็บนี้เป็น static export (HTML + JS ที่ build มาแล้ว ไม่มี React source ในรีโป)
|
||||
* จึงเสริมพฤติกรรมด้วย event delegation แทนการแก้ component
|
||||
*
|
||||
* กติกา
|
||||
* - คลิกที่ว่างของการ์ด = ไปหน้า /cinema/<slug> ของการ์ดนั้น
|
||||
* - คลิกที่ปุ่ม/ลิงก์/ช่องกรอกในใบ (เช่น ปุ่มแชร์, "ดูรายละเอียด") = ปล่อยให้ของเดิมทำงาน
|
||||
* - ไม่ทำงานเมื่อ: กดปุ่มกลาง/ขวา, มี modifier (ctrl/cmd/shift/alt), หรือกำลังลากเลือกข้อความ
|
||||
* - คีย์บอร์ดยังใช้ลิงก์ "ดูรายละเอียด" (Tab + Enter) ได้ตามเดิม
|
||||
*/
|
||||
(() => {
|
||||
const CARD = "article";
|
||||
const CARD_LINK = 'a[href^="/cinema/"]';
|
||||
const INTERACTIVE =
|
||||
'a,button,input,select,textarea,label,summary,[role="button"],[contenteditable="true"]';
|
||||
|
||||
function cardClick(event) {
|
||||
if (event.defaultPrevented || event.button !== 0) return;
|
||||
if (event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) return;
|
||||
|
||||
const target = event.target instanceof Element ? event.target : null;
|
||||
if (!target) return;
|
||||
|
||||
const card = target.closest(CARD);
|
||||
if (!card) return;
|
||||
|
||||
// ปล่อยให้ปุ่ม/ลิงก์ภายในใบทำงานของตัวเอง (เช่น ปุ่มแชร์)
|
||||
const own = target.closest(INTERACTIVE);
|
||||
if (own && card.contains(own)) return;
|
||||
|
||||
// อย่าแย่งคลิกตอนผู้ใช้ลากเลือกข้อความ
|
||||
const selection = window.getSelection();
|
||||
if (selection && selection.toString().trim() !== "") return;
|
||||
|
||||
const link = card.querySelector(CARD_LINK);
|
||||
if (!link) return;
|
||||
|
||||
event.preventDefault();
|
||||
location.assign(link.getAttribute("href"));
|
||||
}
|
||||
|
||||
document.addEventListener("click", cardClick);
|
||||
|
||||
// ลูกศรชี้ + วงโฟกัทให้เห็นว่าใบนี้กดได้ (ใช้ selector เดียวกับการ์ดจริง)
|
||||
const style = document.createElement("style");
|
||||
style.textContent =
|
||||
'article:has(' +
|
||||
CARD_LINK +
|
||||
"){cursor:pointer}" +
|
||||
"article " +
|
||||
CARD_LINK +
|
||||
":focus-visible{outline:2px solid #A92626;outline-offset:4px;border-radius:16px}";
|
||||
document.head.appendChild(style);
|
||||
})();
|
||||
Reference in new issue
Block a user