document.addEventListener('DOMContentLoaded', function() { const listBody = document.getElementById('bo_list_body'); const toggleBtn = document.getElementById('view-toggle-btn1'); const chkAll = document.getElementById('chkall'); const loadMoreBtn = document.getElementById('btn-load-more'); // ๐Ÿ’ก [์ถ”๊ฐ€] ๋”๋ณด๊ธฐ ๋ฒ„ํŠผ const pagination = document.querySelector('.bo-pagination'); // ๐Ÿ’ก [์ถ”๊ฐ€] ํŽ˜์ด์ง€๋„ค์ด์…˜ if (!listBody || !toggleBtn) { return; // ํ•„์ˆ˜ ์š”์†Œ๊ฐ€ ์—†์œผ๋ฉด ์Šคํฌ๋ฆฝํŠธ ์ค‘๋‹จ } const toggleIcon = toggleBtn.querySelector('i'); // ์ดˆ๊ธฐ ๋ทฐ ๋ชจ๋“œ๋Š” HTML์˜ data-view-mode ์†์„ฑ์—์„œ ๊ฐ€์ ธ์˜ด (PHP์—์„œ ์„ค์ •๋จ) let currentViewMode = listBody.dataset.viewMode || 'card'; // ๋ทฐ ๋ชจ๋“œ๋ฅผ ์„ค์ •ํ•˜๊ณ  ๋ฒ„ํŠผ์˜ ์•„์ด์ฝ˜๊ณผ ํˆดํŒ์„ ์—…๋ฐ์ดํŠธํ•˜๋Š” ํ•จ์ˆ˜ function setViewMode(mode) { // data-view-mode ์†์„ฑ ๋ณ€๊ฒฝ listBody.dataset.viewMode = mode; if (mode === 'card') { // ํ˜„์žฌ ์นด๋“œ๋ทฐ -> ๋‹ค์Œ ํ–‰๋™์€ '๋ชฉ๋กํ˜• ๋ณด๊ธฐ' toggleIcon.className = 'fa fa-bars'; // ๋ชฉ๋ก ์•„์ด์ฝ˜ toggleBtn.title = '๋ชฉ๋กํ˜•์œผ๋กœ ๋ณด๊ธฐ'; // ๐Ÿ’ก [์ถ”๊ฐ€] ๋”๋ณด๊ธฐ ๋ฒ„ํŠผ ๋ณด์ด๊ธฐ, ํŽ˜์ด์ง€๋„ค์ด์…˜ ์ˆจ๊ธฐ๊ธฐ if (loadMoreBtn) loadMoreBtn.parentElement.style.display = 'block'; if (pagination) pagination.style.display = 'none'; } else { // 'list' // ํ˜„์žฌ ๋ชฉ๋ก๋ทฐ -> ๋‹ค์Œ ํ–‰๋™์€ '์นด๋“œํ˜• ๋ณด๊ธฐ' toggleIcon.className = 'fa fa-th-large'; // ์นด๋“œ ์•„์ด์ฝ˜ toggleBtn.title = '์นด๋“œํ˜•์œผ๋กœ ๋ณด๊ธฐ'; // ๐Ÿ’ก [์ถ”๊ฐ€] ๋”๋ณด๊ธฐ ๋ฒ„ํŠผ ์ˆจ๊ธฐ๊ธฐ, ํŽ˜์ด์ง€๋„ค์ด์…˜ ๋ณด์ด๊ธฐ if (loadMoreBtn) loadMoreBtn.parentElement.style.display = 'none'; if (pagination) pagination.style.display = 'flex'; } // ์ฟ ํ‚ค์— ์ €์žฅ (PHP์™€ ์—ฐ๋™) set_cookie('board_' + g5_bo_table + '_view_mode', mode, 365); } // ํ† ๊ธ€ ๋ฒ„ํŠผ ํด๋ฆญ ์ด๋ฒคํŠธ toggleBtn.addEventListener('click', function() { // ํ˜„์žฌ ๋ทฐ ๋ชจ๋“œ๋ฅผ ํ™•์ธํ•˜๊ณ  ๋ฐ˜๋Œ€ ๋ชจ๋“œ๋กœ ์ „ํ™˜ const newMode = (listBody.dataset.viewMode === 'card') ? 'list' : 'card'; setViewMode(newMode); }); // ํŽ˜์ด์ง€ ๋กœ๋“œ ์‹œ ์ดˆ๊ธฐ ์ƒํƒœ ์„ค์ • setViewMode(currentViewMode); // ์ฒดํฌ๋ฐ•์Šค ๋™๊ธฐํ™” ๋ฐ ์ „์ฒด ์„ ํƒ ์ƒํƒœ ์—…๋ฐ์ดํŠธ const listCheckboxes = document.querySelectorAll('input[name="chk_wr_id[]"]'); const cardCheckboxes = document.querySelectorAll('input[name="chk_wr_id_card[]"]'); function updateCheckAllState() { if (!chkAll) return; const total = listCheckboxes.length; let checkedCount = 0; listCheckboxes.forEach(chk => { if (chk.checked) checkedCount++; }); chkAll.checked = (total > 0 && total === checkedCount); } // ๋ฆฌ์ŠคํŠธํ˜• ์ฒดํฌ๋ฐ•์Šค ๋ณ€๊ฒฝ ์‹œ listCheckboxes.forEach((listChk, index) => { listChk.addEventListener('change', function() { if (cardCheckboxes[index]) { cardCheckboxes[index].checked = this.checked; } updateCheckAllState(); }); }); // ์นด๋“œํ˜• ์ฒดํฌ๋ฐ•์Šค ๋ณ€๊ฒฝ ์‹œ cardCheckboxes.forEach((cardChk, index) => { cardChk.addEventListener('change', function() { const listChk = document.getElementById('chk_wr_id_' + index); if (listChk) { listChk.checked = this.checked; } updateCheckAllState(); }); }); // ์ „์ฒด ์„ ํƒ ์ฒดํฌ๋ฐ•์Šค ํด๋ฆญ ์‹œ if (chkAll) { chkAll.addEventListener('change', function() { const isChecked = this.checked; listCheckboxes.forEach(chk => chk.checked = isChecked); cardCheckboxes.forEach(chk => chk.checked = isChecked); }); } // โ–ผโ–ผโ–ผ [์ถ”๊ฐ€] ๋”๋ณด๊ธฐ ๋ฒ„ํŠผ ๊ธฐ๋Šฅ ๊ตฌํ˜„ โ–ผโ–ผโ–ผ if (loadMoreBtn) { loadMoreBtn.addEventListener('click', function() { const nextPage = parseInt(this.dataset.page); const originalText = this.textContent; this.disabled = true; this.textContent = '๋กœ๋”ฉ ์ค‘...'; // ํ˜„์žฌ URL์—์„œ ํŽ˜์ด์ง€ ํŒŒ๋ผ๋ฏธํ„ฐ๋งŒ ๋ณ€๊ฒฝ const url = new URL(window.location.href); url.searchParams.set('page', nextPage); fetch(url) .then(response => response.text()) .then(html => { const parser = new DOMParser(); const doc = parser.parseFromString(html, 'text/html'); // ๋‹ค์Œ ํŽ˜์ด์ง€์˜ ์นด๋“œ ์•„์ดํ…œ๋“ค ๊ฐ€์ ธ์˜ค๊ธฐ const newItems = doc.querySelectorAll('#bo_list_body .bo-card-item'); if (newItems.length > 0) { newItems.forEach(item => { // ๐Ÿ’ก [์ค‘์š”] ์ƒˆ๋กœ ๊ฐ€์ ธ์˜จ ์•„์ดํ…œ์˜ ์ฒดํฌ๋ฐ•์Šค ID ์ถฉ๋Œ ๋ฐฉ์ง€ ๋ฐ ์ด๋ฒคํŠธ ์—ฐ๊ฒฐ ํ•„์š” // ํ•˜์ง€๋งŒ ์—ฌ๊ธฐ์„œ๋Š” ๋‹จ์ˆœ ์ถ”๊ฐ€๋งŒ ํ•˜๊ณ , ์ฒดํฌ๋ฐ•์Šค ๊ธฐ๋Šฅ์€ ๋ณต์žกํ•ด์ง€๋ฏ€๋กœ ์ƒ๋žตํ•˜๊ฑฐ๋‚˜ // ํ•„์š”ํ•˜๋‹ค๋ฉด ์ถ”๊ฐ€ ๋กœ์ง ๊ตฌํ˜„ํ•ด์•ผ ํ•จ. (์ผ๋‹จ์€ ์ถ”๊ฐ€๋งŒ) listBody.appendChild(item); }); // ๋‹ค์Œ ํŽ˜์ด์ง€ ๋ฒˆํ˜ธ ์—…๋ฐ์ดํŠธ this.dataset.page = nextPage + 1; this.disabled = false; this.textContent = originalText; // ๋‹ค์Œ ํŽ˜์ด์ง€์— ๋”๋ณด๊ธฐ ๋ฒ„ํŠผ์ด ์—†์œผ๋ฉด ํ˜„์žฌ ๋ฒ„ํŠผ ์ˆจ๊น€ const nextLoadMoreBtn = doc.getElementById('btn-load-more'); if (!nextLoadMoreBtn) { this.parentElement.style.display = 'none'; } } else { this.parentElement.style.display = 'none'; } }) .catch(error => { console.error('Error:', error); this.disabled = false; this.textContent = originalText; alert('๊ฒŒ์‹œ๋ฌผ์„ ๋ถˆ๋Ÿฌ์˜ค๋Š” ์ค‘ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค.'); }); }); } // โ–ฒโ–ฒโ–ฒ ์—ฌ๊ธฐ๊นŒ์ง€ โ–ฒโ–ฒโ–ฒ // ๋…ธ์ถœ ์ƒํƒœ ํ† ๊ธ€ ๊ธฐ๋Šฅ $('#bo_list_body').on('click', '.btn-status-toggle', function(e) { e.preventDefault(); const button = $(this); const wr_id = button.data('wr-id'); const is_on = button.hasClass('status-on'); const new_status = is_on ? 'hide' : 'show'; const bo_table = $('input[name="bo_table"]').val(); button.find('i').removeClass('fa-toggle-on fa-toggle-off').addClass('fa-spinner fa-spin'); $.ajax({ url: board_skin_url + '/ajax.status_update.php', type: 'POST', data: { bo_table: bo_table, wr_id: wr_id, status: new_status }, dataType: 'json', success: function(data) { if (data.success) { button.removeClass('status-on status-off'); button.find('i').removeClass('fa-spinner fa-spin'); if (data.new_status === 'hidden') { button.addClass('status-off').attr('title', '๋…ธ์ถœ ์ƒํƒœ๋กœ ๋ณ€๊ฒฝ'); button.find('i').addClass('fa-toggle-off'); } else { button.addClass('status-on').attr('title', '์ˆจ๊น€ ์ƒํƒœ๋กœ ๋ณ€๊ฒฝ'); button.find('i').addClass('fa-toggle-on'); } location.reload(); } else { alert(data.error || '์ƒํƒœ ๋ณ€๊ฒฝ์— ์‹คํŒจํ–ˆ์Šต๋‹ˆ๋‹ค.'); button.find('i').removeClass('fa-spinner fa-spin').addClass(is_on ? 'fa-toggle-on' : 'fa-toggle-off'); } }, error: function() { alert('์„œ๋ฒ„์™€ ํ†ต์‹  ์ค‘ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค.'); button.find('i').removeClass('fa-spinner fa-spin').addClass(is_on ? 'fa-toggle-on' : 'fa-toggle-off'); } }); }); });