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:
59
public/js/ui.js
Normal file
59
public/js/ui.js
Normal file
@@ -0,0 +1,59 @@
|
||||
// 헤더 UI — 테마 토글 · 사용자 메뉴 · 로고 이스터에그.
|
||||
import { $, toast, burstThumbs } from "./util.js";
|
||||
|
||||
function applyTheme(t) { document.documentElement.setAttribute("data-aidev-theme", t); }
|
||||
|
||||
export function initTheme() {
|
||||
const btn = $("#themeToggle");
|
||||
if (!btn) return;
|
||||
btn.addEventListener("click", () => {
|
||||
const cur = document.documentElement.getAttribute("data-aidev-theme") === "dark" ? "dark" : "light";
|
||||
const next = cur === "dark" ? "light" : "dark";
|
||||
applyTheme(next);
|
||||
try { localStorage.setItem("aidev-theme", next); } catch (e) {}
|
||||
});
|
||||
}
|
||||
|
||||
export function initUserMenu() {
|
||||
const btn = $("#userMenuBtn"), pop = $("#userMenuPop");
|
||||
if (!btn || !pop) return;
|
||||
btn.addEventListener("click", (e) => {
|
||||
e.stopPropagation();
|
||||
const open = pop.hidden;
|
||||
pop.hidden = !open;
|
||||
btn.setAttribute("aria-expanded", open ? "true" : "false");
|
||||
});
|
||||
document.addEventListener("click", (e) => {
|
||||
if (!pop.hidden && !pop.contains(e.target) && !btn.contains(e.target)) {
|
||||
pop.hidden = true; btn.setAttribute("aria-expanded", "false");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 로고를 4번 빠르게 클릭하면 흔들림 + 👍 (단일 클릭은 잠시 뒤 홈 이동)
|
||||
export function initLogoEgg() {
|
||||
const logo = $("#brandLink");
|
||||
if (!logo) return;
|
||||
let clicks = 0, timer = null, navTimer = null;
|
||||
const mark = $(".brand-mark", logo);
|
||||
logo.addEventListener("click", (e) => {
|
||||
e.preventDefault();
|
||||
clicks++;
|
||||
clearTimeout(timer);
|
||||
timer = setTimeout(() => { clicks = 0; }, 700);
|
||||
if (navTimer) clearTimeout(navTimer);
|
||||
if (clicks >= 4) {
|
||||
clicks = 0;
|
||||
if (mark) {
|
||||
mark.style.animation = "aidev-shake .5s ease";
|
||||
const old = mark.style.filter;
|
||||
mark.style.filter = "hue-rotate(180deg) saturate(1.5)";
|
||||
setTimeout(() => { mark.style.animation = ""; mark.style.filter = old; }, 520);
|
||||
}
|
||||
burstThumbs();
|
||||
toast('🌈 git commit -m "found an easter egg"');
|
||||
return;
|
||||
}
|
||||
navTimer = setTimeout(() => { window.location.href = logo.getAttribute("href") || "/"; }, 320);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user