97 lines
2.7 KiB
JavaScript

/**
* 밍글 스튜디오 메인 팝업 관리
*/
// 쿠키 관련 함수
function setCookie(name, value, days) {
const date = new Date();
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
const expires = "expires=" + date.toUTCString();
document.cookie = name + "=" + value + ";" + expires + ";path=/";
}
function getCookie(name) {
const nameEQ = name + "=";
const ca = document.cookie.split(';');
for(let i = 0; i < ca.length; i++) {
let c = ca[i];
while (c.charAt(0) == ' ') c = c.substring(1, c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
}
return null;
}
// 팝업 표시 함수
function showPopup() {
const popup = document.getElementById('mainPopup');
if (popup) {
popup.classList.add('active');
document.body.style.overflow = 'hidden'; // 스크롤 방지
}
}
// 팝업 닫기 함수
function closePopup() {
const popup = document.getElementById('mainPopup');
const dontShowToday = document.getElementById('dontShowToday');
if (popup) {
popup.classList.remove('active');
document.body.style.overflow = ''; // 스크롤 복원
// "하루동안 보지 않기" 체크된 경우
if (dontShowToday && dontShowToday.checked) {
setCookie('hideMainPopup', 'true', 1); // 1일간 쿠키 저장
}
}
}
// 페이지 로드 시 실행
document.addEventListener('DOMContentLoaded', function() {
// 쿠키 확인
const hidePopup = getCookie('hideMainPopup');
// 쿠키가 없으면 팝업 표시 (1초 후)
if (!hidePopup) {
setTimeout(showPopup, 1000);
}
// 닫기 버튼 이벤트
const closeBtn = document.getElementById('popupCloseBtn');
if (closeBtn) {
closeBtn.addEventListener('click', closePopup);
}
// X 버튼 이벤트
const closeX = document.getElementById('popupCloseX');
if (closeX) {
closeX.addEventListener('click', closePopup);
}
// 오버레이 클릭 시 닫기
const overlay = document.getElementById('mainPopup');
if (overlay) {
overlay.addEventListener('click', function(e) {
if (e.target === overlay) {
closePopup();
}
});
}
// ESC 키로 닫기
document.addEventListener('keydown', function(e) {
if (e.key === 'Escape') {
closePopup();
}
});
// CTA 버튼 클릭 시 연락처 페이지로 이동
const ctaBtn = document.getElementById('popupCtaBtn');
if (ctaBtn) {
ctaBtn.addEventListener('click', function() {
closePopup();
window.location.href = '/contact';
});
}
});