// 댓글 — 답글 타깃 설정 · Enter 등록 · 삭제 확인. (모달/단독 페이지 공용) import { $ } from "./util.js"; export function initComments() { document.addEventListener("click", (e) => { const rb = e.target.closest("[data-reply-to]"); if (rb) { e.preventDefault(); const scope = rb.closest(".modal") || document; const parentInput = $('input[name="parent_id"]', scope); const banner = $(".reply-banner", scope); const ta = $(".comment-input", scope); if (parentInput) parentInput.value = rb.getAttribute("data-reply-to"); if (banner) { banner.hidden = false; const who = $(".reply-banner-name", banner); if (who) who.textContent = rb.getAttribute("data-reply-name") || ""; } if (ta) { ta.placeholder = "답글을 입력하세요…"; ta.focus(); } return; } if (e.target.closest("[data-cancel-reply]")) { e.preventDefault(); const scope = e.target.closest(".modal") || document; const pi = $('input[name="parent_id"]', scope); if (pi) pi.value = ""; const bn = $(".reply-banner", scope); if (bn) bn.hidden = true; const ta = $(".comment-input", scope); if (ta) ta.placeholder = "댓글을 입력하세요…"; return; } const del = e.target.closest("[data-confirm]"); if (del && !window.confirm(del.getAttribute("data-confirm"))) e.preventDefault(); }); // Enter 등록 / Shift+Enter 줄바꿈 document.addEventListener("keydown", (e) => { const ta = e.target; if (ta && ta.classList && ta.classList.contains("comment-input") && e.key === "Enter" && !e.shiftKey) { e.preventDefault(); const form = ta.closest("form"); if (form && ta.value.trim()) form.submit(); } }); }