document.addEventListener('DOMContentLoaded', function() { const journalBoard = document.getElementById('journal-board'); if (!journalBoard) return; // ๐Ÿ’ก [์ตœ์ข… ์ˆ˜์ •] data-view-mode ์†์„ฑ์ด ์žˆ๋Š” ์‹ค์ œ ์š”์†Œ์ธ .board-list-wrapper๋ฅผ ์„ ํƒํ•ฉ๋‹ˆ๋‹ค. const boardListWrapper = journalBoard.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์˜ data-view-mode ์†์„ฑ์„ ๋ณ€๊ฒฝํ•ฉ๋‹ˆ๋‹ค. boardListWrapper.dataset.viewMode = mode; // PHP์—์„œ ์ „๋‹ฌ๋ฐ›์€ JavaScript ์ „์—ญ ๋ณ€์ˆ˜๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. if (typeof journal_skin_options !== 'undefined') { set_cookie('board_' + journal_skin_options.bo_table + '_view_mode', mode, 365, journal_skin_options.cookie_domain, journal_skin_options.cookie_path); } // ๋ทฐ ๋ชจ๋“œ์— ๋”ฐ๋ผ ํŽ˜์ด์ง€๋„ค์ด์…˜/๋”๋ณด๊ธฐ ๋ฒ„ํŠผ ๋ณด์ด๊ธฐ/์ˆจ๊ธฐ๊ธฐ 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('#board-list-wrapper .card-list'); // boardListWrapper ์•ˆ์—์„œ ์ฐพ์Œ 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; } });