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

82 lines
3.3 KiB
JavaScript

document.addEventListener('DOMContentLoaded', function() {
const boardWrapper = document.getElementById('photonews-board');
if (!boardWrapper) return;
const boardListWrapper = boardWrapper.querySelector('.board-list-wrapper');
if (!boardListWrapper) return;
const viewModeButtons = document.querySelectorAll('.btn-view-mode');
const paginationWrapper = document.querySelector('.pagination-wrapper');
const loadMoreWrapper = document.querySelector('.load-more-wrapper');
viewModeButtons.forEach(button => {
button.addEventListener('click', function() {
const mode = this.dataset.mode;
viewModeButtons.forEach(btn => btn.classList.remove('active'));
this.classList.add('active');
boardListWrapper.dataset.viewMode = mode;
set_cookie('board_photonews_view_mode', mode, 365, '/', '');
if (paginationWrapper) paginationWrapper.style.display = (mode === 'list') ? 'block' : 'none';
if (loadMoreWrapper) loadMoreWrapper.style.display = (mode === 'card') ? 'block' : 'none';
});
});
const loadMoreButton = document.getElementById('btn-load-more');
if (loadMoreButton) {
loadMoreButton.addEventListener('click', function() {
let currentPage = parseInt(this.dataset.page, 10);
this.textContent = '로딩 중...';
this.disabled = true;
const url = new URL(window.location.href);
url.searchParams.set('page', currentPage);
fetch(url)
.then(response => response.text())
.then(html => {
const parser = new DOMParser();
const doc = parser.parseFromString(html, 'text/html');
const newItems = doc.querySelectorAll('.board-list-wrapper .card-item');
const cardList = boardListWrapper.querySelector('.card-list');
if (newItems.length > 0 && cardList) {
newItems.forEach(item => {
cardList.appendChild(item);
});
currentPage++;
this.dataset.page = currentPage;
this.textContent = '더보기';
this.disabled = false;
const nextLoadMoreButton = doc.getElementById('btn-load-more');
if (!nextLoadMoreButton) {
this.style.display = 'none';
}
} else {
this.textContent = '마지막 페이지입니다.';
this.disabled = true;
}
})
.catch(error => {
console.error('Error loading more items:', error);
this.textContent = '오류 발생';
});
});
}
function set_cookie(name, value, time, domain, path) {
let expires = "";
if (time) {
const date = new Date();
date.setTime(date.getTime() + (time * 24 * 60 * 60 * 1000));
expires = "; expires=" + date.toUTCString();
}
document.cookie = name + "=" + (value || "") + expires + "; path=" + path + "; domain=" + domain;
}
});