//////////////////////////////////////////////////////////////////////////////////////// //Document Ready //////////////////////////////////////////////////////////////////////////////////////// function execDocReady() { var pluginGroups = [ ["../reference/light-blue/lib/vendor/jquery.ui.widget.js", "../reference/lightblue4/docs/lib/widgster/widgster.js"], [ "../reference/lightblue4/docs/lib/parsleyjs/dist/parsley.min.js", "../reference/lightblue4/docs/lib/parsleyjs/dist/i18n/ko.js" ] // 추가적인 플러그인 그룹들을 이곳에 추가하면 됩니다. ]; loadPluginGroupsParallelAndSequential(pluginGroups) .then(function () { console.log("모든 플러그인 로드 완료"); $(".widget").widgster(); var urlParams = new URL(location.href).searchParams; var id = urlParams.get("id"); var path; var editor; var waitCKEDITOR = setInterval(function () { try { if (window.CKEDITOR) { if (window.CKEDITOR.status === "loaded") { editor = CKEDITOR.replace("editor", { contentsCss: "./css/contents.css" }); clearInterval(waitCKEDITOR); } } } catch (err) { console.log("CKEDITOR 로드가 완료되지 않아서 초기화 재시도 중..."); } }, 313 /*milli*/); var postComponents = (function () { return { loading: function () { return $( `

` ); }, main: function (post) { return $( `
${post.userName} ${post.viewCount || 0} ${new Date(post.createdDate).toLocaleString()}

${post.subjectName}

${post.contents}
` ); } }; })(); var replyComponents = (function () { return { loading: function () { return $( `

` ); }, main: function (reply) { return $( `
${reply.userName} ${new Date(reply.createdDate).toLocaleString()}
${reply.contents}
` ); }, noData: function () { return $( `

등록된 댓글이 없습니다.

` ); } }; })(); var drawBoard = function (id) { var $postDetail = $("#post_detail"); var $replyList = $("#reply_list"); $.ajax({ url: "/bbs/find-path/find-id/" + id, type: "GET", beforeSend: function () { $postDetail.html(postComponents.loading()); $replyList.html(replyComponents.loading()); }, success: function (data) { path = data.response[0].path; var board = data.response.reduce( function (_boardList, _board) { if (_board.postType === "POST") { _boardList.detail = _board; return _boardList; } _boardList.reply = _boardList.reply.concat(_board); return _boardList; }, { detail: {}, reply: [] } ); $postDetail.html(postComponents.main(board.detail)); if (board.reply.length <= 0) { $replyList.html(replyComponents.noData()); return; } $replyList.empty(); board.reply.forEach(function (_reply) { $replyList.append(replyComponents.main(_reply)); }); } }); }; drawBoard(id); $("#reply_form").on("submit", function (event) { event.preventDefault(); $.ajax({ url: "/bbs/verify/captcha", type: "POST", contentType: "application/json;charset=utf-8", data: JSON.stringify({ captcha: $("#input_captcha").val() }), success: function () { var formData = Object.fromEntries(new FormData(event.target)); formData.contents = editor.getData(); formData.path = path; formData.boardType = "LANDING"; $.ajax({ url: "/bbs/reply-message", type: "POST", contentType: "application/json;charset=utf-8", data: JSON.stringify(formData), success: function () { $(event.target).trigger("reset"); $("#board_list").empty(); editor.setData(""); drawBoard(id); } }); }, error: function (xhr) { jError("캡차 인증에 실패했습니다. 다시 시도해주세요.: " + (xhr.responseJSON?.error || "알 수 없는 오류")); } }); return false; }); $("#btn_refresh_captcha").on("click", function () { $("#captcha").attr("src", "/bbs/verify/image?_t=" + new Date().getTime()); }); (function () { var $modalDeleteBoard = $("#modal_delete_board"); var $formDeleteBoard = $("#form_delete_board"); var targetId = ""; var postType = ""; $modalDeleteBoard .on("shown.bs.modal", function (event) { var $relatedTarget = $(event.relatedTarget); targetId = $relatedTarget.data("board-id"); postType = $relatedTarget.data("post-type"); }) .on("hidden.bs.modal", function () { $formDeleteBoard.trigger("reset"); }); $formDeleteBoard.on("submit", function (event) { event.preventDefault(); var formData = Object.fromEntries(new FormData(event.target)); formData.id = targetId; $.ajax({ url: "/bbs/check-password", type: "POST", contentType: "application/json;charset=utf-8", data: JSON.stringify(formData), success: function () { $modalDeleteBoard.modal("hide"); $.ajax({ url: "/bbs/delete-id/" + targetId, type: "DELETE", beforeSend: function () { if (postType === "POST") { $("#post_detail").html(postComponents.loading()); } else { $("#reply_list").html(replyComponents.loading()); } }, success: function () { if (postType === "POST") { location.replace("/cover/template.html?page=board"); } else { drawBoard(id); } } }); }, error: function (error) { jError(error.responseJSON.error.message); } }); return false; }); })(); (function () { var $modalUpdateBoard = $("#modal_update_board"); var $formUpdateBoard = $("#form_update_board"); var targetId = ""; $modalUpdateBoard .on("shown.bs.modal", function (event) { targetId = $(event.relatedTarget).data("board-id"); }) .on("hidden.bs.modal", function () { $formUpdateBoard.trigger("reset"); }); $formUpdateBoard.on("submit", function (event) { event.preventDefault(); var formData = Object.fromEntries(new FormData(event.target)); formData.id = targetId; $.ajax({ url: "/bbs/check-password", type: "POST", contentType: "application/json;charset=utf-8", data: JSON.stringify(formData), success: function () { $modalUpdateBoard.modal("hide"); location.href = "/cover/template.html?page=question&id=" + targetId; }, error: function (error) { jError(error.responseJSON.error.message); } }); return false; }); })(); }) .catch(function (error) { console.error("플러그인 로드 중 오류 발생"); console.error(error); }); }