Files
2026-06-11 18:47:38 +09:00

97 lines
4.4 KiB
JavaScript

// 📌 [핵심] 스크립트가 여러 번 로드되어도 단 한 번만 실행되도록 하는 '실행 가드'입니다.
if (typeof window.myThemeScriptLoaded === 'undefined') {
// 스크립트가 실행되었음을 전역 변수에 표시합니다.
window.myThemeScriptLoaded = true;
document.addEventListener('DOMContentLoaded', () => {
// 💡 [핵심 추가] 헤더 높이를 계산하여 메인 콘텐츠의 padding-top을 설정하는 함수
function adjustMainContentPadding() {
const header = document.getElementById('header');
const footer = document.querySelector('.main-footer'); // 푸터 클래스 확인 필요
const mainContent = document.querySelector('main.layout-main-content, div.layout-main-content');
if (header && mainContent) {
// 1. 헤더 높이만큼 padding-top 적용 (겹침 방지)
const headerHeight = header.offsetHeight;
mainContent.style.paddingTop = headerHeight + 'px';
// 2. 푸터가 중간에 뜨지 않도록 min-height 계산
// 화면 전체 높이(window.innerHeight)에서 헤더 높이와 푸터 높이를 뺍니다.
let footerHeight = 0;
if (footer) {
footerHeight = footer.offsetHeight;
}
// 최소 높이 = 화면 높이 - 헤더 높이 - 푸터 높이
// 이렇게 하면 내용이 적어도 푸터는 항상 화면 맨 아래에 위치하게 됩니다.
const minHeight = window.innerHeight - headerHeight - footerHeight;
if (minHeight > 0) {
mainContent.style.minHeight = minHeight + 'px';
}
}
}
// 페이지 로드 시 즉시 실행
adjustMainContentPadding();
// 브라우저 창 크기가 변경될 때마다 다시 실행 (반응형 대응)
window.addEventListener('resize', adjustMainContentPadding);
// 이미지 로드 등으로 높이가 변할 수 있으므로, 잠시 후 한 번 더 실행
setTimeout(adjustMainContentPadding, 500);
// 💡 [기존] 모바일 메뉴 제어 로직
const mobileMenuToggle = document.querySelector('.mobile-menu-toggle');
const mobileNavPanel = document.querySelector('.mobile-nav-panel');
const mobileNavOverlay = document.querySelector('.mobile-nav-overlay');
const mobileMenuClose = document.querySelector('.mobile-menu-close');
const mainNavigation = document.querySelector('.main-navigation');
const mobileNavigation = document.querySelector('.mobile-navigation');
if (mobileMenuToggle && mobileNavPanel && mobileNavOverlay && mobileMenuClose && mainNavigation && mobileNavigation) {
mobileNavigation.innerHTML = mainNavigation.innerHTML;
const openMobileMenu = () => {
mobileNavPanel.classList.add('active');
mobileNavOverlay.classList.add('active');
document.body.style.overflow = 'hidden';
};
const closeMobileMenu = () => {
mobileNavPanel.classList.remove('active');
mobileNavOverlay.classList.remove('active');
document.body.style.overflow = '';
};
mobileMenuToggle.addEventListener('click', openMobileMenu);
mobileMenuClose.addEventListener('click', closeMobileMenu);
mobileNavOverlay.addEventListener('click', closeMobileMenu);
}
}); // <-- DOMContentLoaded 이벤트 리스너 종료
// 💡 배너 클릭 카운트 함수는 전역 범위에 있어야 onclick에서 호출할 수 있습니다.
window.banner_click_count = function(element) {
try {
const bn_id = element.getAttribute('data-banner-id');
if (!bn_id) return;
const url = (typeof g5_url !== 'undefined' ? g5_url : '') + '/rb/rb.mod/banner/bannerhit.php?bn_id=' + bn_id;
if (navigator.sendBeacon) {
navigator.sendBeacon(url);
} else {
const xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.send(null);
}
} catch (e) {
console.error("배너 클릭 카운트 오류:", e);
}
}
}