(() => { const { EventManager } = ShopbySkin; const { deleteArticle, checkIsArticleEditable } = ShopbySkin.pageHelper.articleViewHelper(); const url = new URL(window.location.href); const searchParams = new URLSearchParams(url.search); const boardId = searchParams.get('boardId'); const boardNo = searchParams.get('boardNo'); const categoryNo = searchParams.get('categoryNo'); const articleNo = Number(searchParams.get('articleNo')); const moveToList = () => { let queryString = ''; if (boardId) { queryString += `boardId=${boardId}&categoryNo=${categoryNo}`; } else if (boardNo) { queryString += `boardNo=${boardNo}&categoryNo=${categoryNo}`; } location.href = `/en/pages/board/post-list.html${queryString && `?${queryString}`}`; }; const openPasswordFormModal = (nextAction) => { EventManager.fire('OPEN_LAYER_MODAL', { name: 'check-post-password-form', label: 'Confirm', title: 'Password authentication', isFull: false, onClose: ({ reason, state = {} }) => { if (reason === 'DID_SUBMIT' && nextAction) { nextAction(state); } }, }); }; const openPostFormModal = ({ boardName, password = '' }) => { EventManager.fire('OPEN_LAYER_MODAL', { title: boardName, name: 'article-write-form', isFull: false, data: { boardId, boardNo, articleNo, password, isModify: true, }, onClose: ({ reason }) => { if (reason === 'DID_SUBMIT') { location.reload(); } }, }); }; const postFormModal = ({ registerType, boardName }) => { if (registerType === 'GUEST') { openPasswordFormModal((state) => { const { password } = state; if (password) { openPostFormModal({ boardName, password }); } }); } else { openPostFormModal({ boardName }); } }; const deleteAction = async (state) => { const { password = '' } = state ?? {}; const param = { boardNo: boardId || boardNo, articleNo, }; if (password) { param.password = password; } await deleteArticle(param); EventManager.fire('MODAL_ALERT_OPEN', { noticeType: 'SUCCESS', label: 'Confirm', message: 'Deletion has been completed', onClose: () => { moveToList(); }, }); }; const moduleActionHandler = { LIST: moveToList, MODIFY: async ({ target }) => { const boardName = document.querySelector('[shopby-board-name]')?.getAttribute('shopby-board-name'); const registerType = target.closest('[shopby-register-type]')?.getAttribute('shopby-register-type'); if (registerType !== 'GUEST') { const isArticleEditable = await checkIsArticleEditable({ boardNo: boardId || boardNo, articleNo, }); if (!isArticleEditable) { EventManager.fire('MODAL_ALERT_OPEN', { label: 'Confirm', message: 'You do not have permission.', }); return; } } postFormModal({ registerType, boardName }); }, DELETE: ({ target }) => { const registerType = target.closest('[shopby-register-type]')?.getAttribute('shopby-register-type'); EventManager.fire('MODAL_CONFIRM_OPEN', { noticeType: 'WARNING', label: 'Confirm', message: 'Do you want to delete the post?', onConfirm: () => { if (registerType === 'GUEST') { openPasswordFormModal((state) => { deleteAction(state); }); } else { deleteAction(); } }, }); }, MOVE_TO_PARENT_POST: ({ target }) => { const parentArticleNo = target.closest('[shopby-parent-article-no]')?.getAttribute('shopby-parent-article-no'); searchParams.set('articleNo', parentArticleNo); location.href = `/en/pages/board/post-detail.html?${searchParams.toString()}`; }, DOWNLOAD_FILE: async ({ target }) => { const fileName = target.getAttribute('shopby-file-name'); const originFileName = target.getAttribute('shopby-origin-file-name'); const blob = await ShopbySkin.utils.downloadFile(fileName); const a = document.createElement('a'); a.href = URL.createObjectURL(blob); a.download = originFileName; document.body.appendChild(a); a.click(); document.body.removeChild(a); }, }; // 비밀번호 인증이 필요한 경우 EventManager.on('NEED_PASSWORD_FORM', () => { EventManager.fire('OPEN_LAYER_MODAL', { name: 'check-post-password-form', label: 'Confirm', title: 'Password authentication', isFull: false, onClose: ({ reason }) => { if (reason === 'DID_CLOSE') { if (!document.referrer || location.href === document.referrer) { history.back(); return; } location.href = document.referrer; } }, }); }); // 해당 게시글에 접근할 권한이 없는 경우 EventManager.on('FORBIDDEN_ARTICLE', () => { EventManager.fire('MODAL_ALERT_OPEN', { noticeType: 'WARNING', label: 'Confirm', message: 'You do not have permission to view private messages.', onClose: () => { if (!document.referrer || location.href === document.referrer) { history.back(); return; } location.href = document.referrer; }, }); }); document.querySelector('article-view-v2')?.addEventListener('click', ({ target }) => { const action = target.getAttribute('shopby-action'); moduleActionHandler[action]?.({ target }); }); //매거진 게시판 if(boardId == "magazineEn" || boardNo =="285803"){ document.querySelector('.l-page').classList.add("magazine"); } })();