refactor(js): app.js 를 브라우저 네이티브 ESM 모듈로 분할
public/js/{util,ui,reactions,modals,comments,feed,main}.js 로 분리하고
dashboard/project 에서 <script type="module" src="/public/js/main.js"> 로 로드.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
43
public/js/comments.js
Normal file
43
public/js/comments.js
Normal file
@@ -0,0 +1,43 @@
|
||||
// 댓글 — 답글 타깃 설정 · 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();
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user