// ============================================================================================================ // πŸ“Œ Feather μ•„μ΄μ½˜ μ΄ˆκΈ°ν™” (function () { const replace = () => window.feather?.replace?.(); document.addEventListener("DOMContentLoaded", replace); // 동적 DOM μ‚½μž… λŒ€μ‘ new MutationObserver(replace).observe(document.body, { childList: true, subtree: true, }); })(); // ============================================================================================================ // πŸ“Œ λͺ¨λ°”일 헀더 μ½”λ“œ (function () { const MOBILE_BREAK = 990; const onReady = (fn) => { if (document.readyState === "loading") document.addEventListener("DOMContentLoaded", fn, { once: true }); else fn(); }; const findHeaderEl = () => document.querySelector("site-header .site-header") || document.querySelector(".site-header"); function bindHeader(headerEl) { if (!headerEl || headerEl.__hdrBound) return; headerEl.__hdrBound = true; const isMobile = () => window.innerWidth <= MOBILE_BREAK; // ------- PC: hover open/close + focusout μ ‘κ·Όμ„± ------- headerEl.addEventListener("mouseenter", () => headerEl.setAttribute("data-open", "true"), ); headerEl.addEventListener("mouseleave", () => headerEl.removeAttribute("data-open"), ); headerEl.addEventListener("focusout", () => { setTimeout(() => { if (!headerEl.contains(document.activeElement)) headerEl.removeAttribute("data-open"); }, 0); }); // ------- 단일 클릭 μœ„μž„μœΌλ‘œ MO 햄버거 & .col λ™μž‘ 처리 ------- headerEl.addEventListener("click", (ev) => { // 햄버거 ν† κΈ€ (λ²„νŠΌ λ‚΄λΆ€/μžμ‹ 클릭 λͺ¨λ‘ 처리) if (ev.target.closest(".menu_btn")) { if (!isMobile()) return; ev.preventDefault(); headerEl.classList.toggle("open"); return; } // mega 컬럼 κ΄€λ ¨: h4 > a λŠ” λͺ¨λ°”μΌμ—μ„œ 이동 막고 컬럼 ν† κΈ€ const h4Link = ev.target.closest(".mega .col h4 > a"); if (h4Link) { if (!isMobile()) return; // PCλŠ” κΈ°λ³Έ λ™μž‘ ev.preventDefault(); ev.stopPropagation(); const col = h4Link.closest(".mega .col"); // λ‹«κΈ° λ‹€λ₯Έ 컬럼 headerEl.querySelectorAll(".mega .col").forEach((c) => { if (c !== col) c.classList.remove("mo-open"); }); col.classList.toggle("mo-open"); return; } // 컬럼 λ‚΄λΆ€ λΉˆμ˜μ—­ 클릭 -> ν† κΈ€ (단, depth2 링크 클릭은 λ¬΄μ‹œ) const col = ev.target.closest(".mega .col"); if (col) { if (!isMobile()) return; if (ev.target.closest(".depth2 a")) return; // 2뎁슀 λ§ν¬λŠ” 이동 if (ev.target.closest("h4")) return; // h4λŠ” μœ„μ—μ„œ 처리 headerEl.querySelectorAll(".mega .col").forEach((c) => { if (c !== col) c.classList.remove("mo-open"); }); col.classList.toggle("mo-open"); } }); // ------- 단일 resize 처리: λͺ¨λ°”일->λ°μŠ€ν¬νƒ‘ μ „ν™˜μ—μ„œ μ΄ˆκΈ°ν™” ------- const onResize = () => { if (!isMobile()) { headerEl.classList.remove("open"); headerEl .querySelectorAll(".mega .col.mo-open") .forEach((c) => c.classList.remove("mo-open")); } }; window.addEventListener("resize", onResize); } // Try immediate bind, otherwise observe for 동적 λ Œλ”λ§ (μ›Ήμ»΄ν¬λ„ŒνŠΈ λ“±) onReady(() => { const h = findHeaderEl(); if (h) { bindHeader(h); return; } const mo = new MutationObserver((_, obs) => { const h2 = findHeaderEl(); if (h2) { obs.disconnect(); bindHeader(h2); } }); mo.observe(document.body, { childList: true, subtree: true }); }); })(); // ============================================================================ // πŸ“ŒνŒμ—… λ‹«κΈ° document.addEventListener("DOMContentLoaded", () => { const wrap = document.querySelector(".popup_wrap"); if (!wrap) return; const popup = wrap.querySelector(".popup"); const ul = popup?.querySelector("ul"); // λ°°κ²½ 클릭 β†’ νŒμ—…λž© 전체 μˆ¨κΉ€ wrap.addEventListener("click", (e) => { if (e.target === wrap) wrap.style.display = "none"; }); // νŒμ—… λ‚΄λΆ€ 클릭 μ „νŒŒ 차단 popup?.addEventListener("click", (e) => e.stopPropagation()); // li λ‹«κΈ° λ²„νŠΌ: ν•΄λ‹Ή li μˆ¨κΉ€ β†’ 남은 li μ—†μœΌλ©΄ νŒμ—…λž© μˆ¨κΉ€ popup?.querySelectorAll(".popup_close").forEach((btn) => { btn.addEventListener("click", (e) => { e.preventDefault(); e.stopPropagation(); const li = btn.closest("li"); if (!li) return; li.style.display = "none"; const anyVisible = ul && Array.from(ul.children).some( (c) => c.offsetParent !== null && getComputedStyle(c).display !== "none", ); if (!anyVisible) wrap.style.display = "none"; }); }); // "1일 λ™μ•ˆ 보지 μ•ŠμŒ" β€” μžμ • κΈ°μ€€(λ‹€μŒ μžμ •κΉŒμ§€) const skip = popup?.querySelector(".popup_skip_oneday"); if (skip) { const until = Number(localStorage.getItem("popup_hide_until") || 0); if (until > Date.now()) { wrap.style.display = "none"; return; } skip.addEventListener("click", (e) => { e.preventDefault(); e.stopPropagation(); const now = new Date(); const nextMidnight = new Date( now.getFullYear(), now.getMonth(), now.getDate() + 1, ); // λ‹€μŒ μžμ • 00:00 localStorage.setItem("popup_hide_until", String(nextMidnight.getTime())); wrap.style.display = "none"; }); } }); // ============================================================================================================ // πŸ” 맨 μœ„λ‘œ κ°€κΈ° λ²„νŠΌ (#scrollTopBtn) (function () { document.addEventListener("click", (e) => { const btn = e.target.closest?.("#scrollTopBtn"); if (!btn) return; window.scrollTo({ top: 0, behavior: "smooth" }); }); })(); // ============================================================================================================ // πŸ“Œ κ°œμΈμ •λ³΄μ·¨κΈ‰λ°©μΉ¨ λͺ¨λ‹¬ (function () { function bindPrivacyModal(root) { const wrap = root.querySelector("#privacyModal"); if (!wrap || wrap.__privacyBound) return; wrap.__privacyBound = true; const closeModal = () => { wrap.classList.remove("open"); document.body.style.overflow = ""; }; const openModal = () => { wrap.classList.add("open"); document.body.style.overflow = "hidden"; }; root.addEventListener("click", (e) => { if (e.target.closest(".privacy-link")) { e.preventDefault(); openModal(); } if (e.target.closest(".privacy-modal-close")) { closeModal(); } if (e.target === wrap) { closeModal(); } }); document.addEventListener("keydown", (e) => { if (e.key === "Escape" && wrap.classList.contains("open")) { closeModal(); } }); } const mo = new MutationObserver(() => { document.querySelectorAll("#privacyModal").forEach((el) => { bindPrivacyModal( el.closest("lead-form, section, main, .pv-wrap, body") || document.body, ); }); }); mo.observe(document.body, { childList: true, subtree: true }); document.addEventListener("DOMContentLoaded", () => { document.querySelectorAll("#privacyModal").forEach((el) => { bindPrivacyModal( el.closest("lead-form, section, main, .pv-wrap, body") || document.body, ); }); }); })(); // ============================================================================================================ // πŸ“Œ 곡개 문의 API 제좜 (function () { function closeModal(modal) { modal?.classList.remove("open"); document.body.style.overflow = ""; } function openSuccessModal(formEl) { const modal = formEl .closest("lead-form, #form_box, .contents-box") ?.querySelector("#submitSuccessModal") || document.querySelector("#submitSuccessModal"); if (!modal) return; modal.classList.add("open"); document.body.style.overflow = "hidden"; const closeBtn = modal.querySelector(".submit-success-modal__close"); closeBtn?.addEventListener("click", () => closeModal(modal), { once: true, }); modal.addEventListener( "click", (ev) => { if (ev.target === modal) closeModal(modal); }, { once: true }, ); } function setFeedback(formEl, message = "", type = "error") { const feedback = formEl.querySelector(".form-feedback"); if (!feedback) return; if (!message) { feedback.hidden = true; feedback.textContent = ""; feedback.dataset.state = ""; return; } feedback.hidden = false; feedback.dataset.state = type; feedback.textContent = message; } function normalizePhone(value) { return String(value || "").replace(/\D/g, ""); } async function submitLead(formEl) { const name = formEl.querySelector("#inq-name"); const phone = formEl.querySelector("#inq-phone"); const visitDate = formEl.querySelector("#inq-visit-date"); const visitTime = formEl.querySelector("#inq-visit-time"); const memo = formEl.querySelector("#inq-memo"); const agree = formEl.querySelector("#inq-agree"); const honeypot = formEl.querySelector("#inq-company"); const submitButton = formEl.querySelector(".form-submit"); if (!name?.value.trim()) { name?.focus(); return; } if (!phone?.value.trim()) { phone?.focus(); return; } if (!visitDate?.value.trim()) { visitDate?.focus(); return; } if (!agree?.checked) { agree?.focus(); setFeedback(formEl, "κ°œμΈμ •λ³΄ μˆ˜μ§‘ 및 μ΄μš©λ™μ˜κ°€ ν•„μš”ν•©λ‹ˆλ‹€."); return; } const leadConfig = await (window.VendingRuntime?.getLeadConfig?.() || Promise.resolve({})); if (!leadConfig.apiUrl || !leadConfig.publicFormKey) { setFeedback( formEl, "문의 섀정이 μ™„λ£Œλ˜μ§€ μ•Šμ•˜μŠ΅λ‹ˆλ‹€. κ΄€λ¦¬μžμ—κ²Œ 확인해 μ£Όμ„Έμš”.", ); return; } if (formEl.__submitting) return; formEl.__submitting = true; setFeedback(formEl); const originalLabel = submitButton?.textContent || "상담 μ‹ μ²­"; if (submitButton) { submitButton.textContent = "μ ‘μˆ˜ 쀑..."; submitButton.setAttribute("aria-busy", "true"); submitButton.style.pointerEvents = "none"; submitButton.style.opacity = "0.7"; } try { const response = await fetch(leadConfig.apiUrl, { method: "POST", headers: { "Content-Type": "application/json", Accept: "application/json", }, body: JSON.stringify({ publicFormKey: leadConfig.publicFormKey, name: name.value.trim(), phone: phone.value.trim(), visitDate: visitDate?.value || "", visitTime: visitTime?.value || "", privacyAgreed: agree?.checked === true, note: [ memo?.value?.trim() || "", formEl.dataset.source ? `μœ μž…μœ„μΉ˜: ${formEl.dataset.source}` : "", ] .filter(Boolean) .join("\n"), homepageUrl: window.location.href, honeypot: honeypot?.value || "", }), }); let payload = null; try { payload = await response.json(); } catch (error) { payload = null; } if (!response.ok || payload?.success === false) { throw new Error("submit failed"); } formEl.reset(); setFeedback(formEl); openSuccessModal(formEl); } catch (error) { console.error("[VendingLead] 문의 μ ‘μˆ˜ μ‹€νŒ¨", error); setFeedback( formEl, leadConfig.failureMessage || "문의 μ ‘μˆ˜μ— μ‹€νŒ¨ν–ˆμŠ΅λ‹ˆλ‹€. μž μ‹œ ν›„ λ‹€μ‹œ μ‹œλ„ν•΄ μ£Όμ„Έμš”.", ); } finally { formEl.__submitting = false; if (submitButton) { submitButton.textContent = originalLabel; submitButton.removeAttribute("aria-busy"); submitButton.style.pointerEvents = ""; submitButton.style.opacity = ""; } } } function bindSubmitModal(formEl) { if (!formEl || formEl.__submitBound) return; formEl.__submitBound = true; formEl.addEventListener("submit", async (e) => { e.preventDefault(); await submitLead(formEl); }); } const obs = new MutationObserver(() => { document.querySelectorAll(".inquiry-form").forEach(bindSubmitModal); }); obs.observe(document.body, { childList: true, subtree: true }); document.addEventListener("DOMContentLoaded", () => { document.querySelectorAll(".inquiry-form").forEach(bindSubmitModal); }); })(); // ============================================================================================================ // πŸ“Œ μ „ν™”λ²ˆν˜Έ μžλ™ ν•˜μ΄ν”ˆ + ν˜•μ‹ 검증 (function () { const PHONE_RE = /^(01[0-9])-?([0-9]{3,4})-?([0-9]{4})$/; const MSG = "μ˜¬λ°”λ₯Έ μ „ν™”λ²ˆν˜Έ ν˜•μ‹μœΌλ‘œ μž…λ ₯ν•΄μ£Όμ„Έμš”. (예: 010-1234-5678)"; const isPhone = (el) => el?.matches?.("#inq-phone"); const isValid = (v) => PHONE_RE.test(String(v || "").replace(/\s/g, "")); function formatPhone(v) { const d = String(v || "") .replace(/\D/g, "") .slice(0, 11); if (d.length < 4) return d; if (d.length < 8) return d.slice(0, 3) + "-" + d.slice(3); return d.slice(0, 3) + "-" + d.slice(3, 7) + "-" + d.slice(7); } function setError(input, on) { input.style.borderColor = on ? "#e53e3e" : ""; input.style.boxShadow = on ? "0 0 0 3px rgba(229,62,62,0.15)" : ""; const sib = input.nextElementSibling; const hasErr = sib?.classList.contains("phone-error"); if (on && !hasErr) { const msg = document.createElement("span"); msg.className = "phone-error"; msg.style.cssText = "color:#e53e3e;font-size:.78rem;margin-top:4px;display:block;white-space:normal;"; msg.textContent = MSG; input.insertAdjacentElement("afterend", msg); } else if (!on && hasErr) { sib.remove(); } } document.addEventListener("input", (e) => { if (!isPhone(e.target)) return; const input = e.target; const pos = input.selectionStart; const prev = input.value; input.value = formatPhone(prev); const diff = input.value.length - prev.length; input.setSelectionRange(pos + diff, pos + diff); }); document.addEventListener("focusout", (e) => { if (isPhone(e.target)) { setError(e.target, !!e.target.value && !isValid(e.target.value)); } }); document.addEventListener("focusin", (e) => { if (isPhone(e.target)) { setError(e.target, false); } }); document.addEventListener( "submit", (e) => { const form = e.target.closest?.(".inquiry-form"); const phone = form?.querySelector("#inq-phone"); if (phone && !isValid(phone.value)) { e.preventDefault(); e.stopImmediatePropagation(); setError(phone, true); phone.focus(); } }, true, ); })();