comment.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719
  1. $(function() {
  2. Comment.init();
  3. Comment.list();
  4. // 댓글입력 창 높이 자동조정
  5. $.each($('textarea[data-autoresize]'), function () {
  6. $(this).on('keyup input', function () {
  7. Comment.resizeTextarea(this);
  8. }).removeAttr('data-autoresize');
  9. });
  10. });
  11. const Comment =
  12. {
  13. callback: "",
  14. listID: "commentList",
  15. writeID: "commentWrite",
  16. method: {write: "store", modify: "update", reply: "reply"},
  17. mode: "", // write, modify, reply
  18. code: "",
  19. bid: 0,
  20. pid: 0,
  21. cid: 0,
  22. total: 0,
  23. page: 0,
  24. perPage: 0,
  25. minLength: 0,
  26. maxLength: 0,
  27. listForm: null,
  28. writeForm: null,
  29. saveHtml: null,
  30. saveBefore: null,
  31. useEditor: false,
  32. // 댓글 기본설정
  33. init: function()
  34. {
  35. this.listForm = document.getElementById(this.listID);
  36. // 댓글 목록
  37. if(this.listForm !== null) {
  38. this.code = document.getElementById("code").value;
  39. this.bid = document.getElementById("bid").value;
  40. this.pid = document.getElementById("pid").value;
  41. this.callback = (BASE_URL + "/board/" + String(this.code) + "/" + String(this.pid) + "/comment");
  42. }
  43. this.writeForm = document.getElementById(this.writeID);
  44. // 댓글 입력창
  45. if(IS_USER && this.writeForm !== null) {
  46. let form = this.writeForm.getElementsByTagName("form")[0];
  47. this.minLength = Number(form.elements["min_length"].value);
  48. this.maxLength = Number(form.elements["max_length"].value);
  49. this.saveHtml = this.writeForm.innerHTML; // 댓글 입력 창 저장
  50. this.reset(form);
  51. }
  52. },
  53. // 초기화
  54. reset: function(form)
  55. {
  56. this.mode = "write";
  57. this.cid = 0;
  58. this.saveBefore = null;
  59. if (typeof form !== "undefined") {
  60. form.elements["mode"].value = "write";
  61. form.elements["cid"].value = "";
  62. form.elements["length"].value = "0";
  63. form.elements["content"].value = "";
  64. if (typeof form.elements["is_secret"] !== "undefined") {
  65. form.elements["is_secret"].checked = false;
  66. }
  67. let $length = form.getElementsByClassName("comment-length");
  68. if ($length.length > 0) {
  69. $length[0].innerText = "0";
  70. }
  71. form.elements["btn_comment_submit"].disabled = false;
  72. form.elements["btn_comment_cancel"].disabled = false;
  73. this.resizeTextarea(form.elements["content"]);
  74. }
  75. if (this.useEditor) {
  76. tinyMCE.activeEditor.setContent("");
  77. }
  78. },
  79. // 댓글 목록 새로고침
  80. refresh: function() {
  81. this.list(this.page);
  82. },
  83. // textarea 높이 조절
  84. resizeTextarea: function(e)
  85. {
  86. $(e).css('height', 'auto').css('height', e.scrollHeight + (e.offsetHeight - e.clientHeight));
  87. },
  88. // 댓글 영역으로 스크롤 이동
  89. scrollReplyNow: function(cid)
  90. {
  91. if (typeof cid != "undefined" && cid) {
  92. let offset = $('#comment_' + cid).offset();
  93. if(typeof offset != "undefined"){
  94. window.document.body.scrollTop = offset.top;
  95. }
  96. }
  97. },
  98. // 댓글 영역 강조
  99. focusCommentBox: function(cid)
  100. {
  101. if (typeof cid != "undefined" && cid) {
  102. $('#comment_' + cid).effect('highlight', {
  103. 'color': '#FFFFC6'
  104. }, 1500);
  105. }
  106. },
  107. // 금지 단어 확인
  108. filterSpamKeyword: function (content)
  109. {
  110. let ret = "";
  111. $.ajax({
  112. headers: {'X-CSRF-TOKEN': CSRF},
  113. url: (BASE_URL + '/api/filterSpamKeyword'),
  114. type: 'POST',
  115. dataType: 'JSON',
  116. async: false,
  117. cache: false,
  118. data: {subject: "", content: content},
  119. success: function (res) {
  120. ret = res.content;
  121. },
  122. error: function (xhr, status, err) {
  123. procErrorEvent(xhr, status, err);
  124. }
  125. });
  126. return ret;
  127. },
  128. // 글자수 확인
  129. checkByte: function(e)
  130. {
  131. let form = e.form;
  132. if (typeof form !== "undefined") {
  133. let hiddenInputLength = form.elements["length"];
  134. let spanInputLength = form.getElementsByClassName("comment-length")[0];
  135. let textarea = form.elements["content"];
  136. let length = textarea.value.length;
  137. let tinymce = form.getElementsByTagName("iframe");
  138. if (this.useEditor) {
  139. let editor = tinymce[0].contentDocument.body;
  140. length = editor.innerText.trim().length;
  141. if (this.maxLength > 0 && length > this.maxLength) {
  142. editor.innerHTML = editor.innerHTML.substr(0, this.maxLength);
  143. length = editor.innerHTML.length;
  144. }
  145. } else {
  146. if (this.maxLength > 0 && length > this.maxLength) {
  147. textarea.value = textarea.value.substr(0, this.maxLength);
  148. length = textarea.value.length;
  149. }
  150. }
  151. // 글자 수 저장
  152. hiddenInputLength.value = length;
  153. // 글자 수 출력
  154. if (typeof spanInputLength !== "undefined") {
  155. spanInputLength.innerText = length;
  156. }
  157. }
  158. },
  159. // 목록
  160. list: function(page, cid, message, sort) {
  161. if (!page || page < 1 || page === Number.POSITIVE_INFINITY) {
  162. page = 1;
  163. }
  164. let listURL = (this.callback + "?page=" + page);
  165. if (sort) {
  166. listURL += "&sort=" + sort;
  167. }
  168. $('#' + this.listID).load(listURL, function (response, status, xhr) { // HTML 형식으로 뎃글목록 출력
  169. let total = this.children.total.value;
  170. let page = this.children.page.value;
  171. let perPage = this.children.per_page.value;
  172. if (total) { // 댓글 수 표시
  173. document.getElementById("txtCommentRows").innerText = total;
  174. document.getElementById("txtPostCommentCnt").innerText = total;
  175. }
  176. if (message) { // 알림이 있을 경우 alert
  177. alert(message);
  178. }
  179. Comment.page = page;
  180. Comment.perPage = perPage;
  181. Comment.total = total;
  182. Comment.focusCommentBox(cid);
  183. Comment.scrollReplyNow(cid);
  184. });
  185. return false;
  186. },
  187. // 댓글 등록/수정
  188. submit: function(e)
  189. {
  190. e.blur();
  191. e.disabled = true;
  192. $(e.form).validate({
  193. onkeyup: false,
  194. onclick: false,
  195. onfocusout: false,
  196. rules: {
  197. mode: {required: true, contains: ["write", "modify", "reply"]},
  198. content: {
  199. required: true,
  200. normalizer: function (value) {
  201. if(Comment.useEditor) {
  202. return tinyMCE.activeEditor.getContent({format: "text"}).trim();
  203. }else{
  204. return value.trim();
  205. }
  206. },
  207. minlength: Comment.minLength,
  208. maxlength: Comment.maxLength
  209. },
  210. is_secret: {number: true}
  211. },
  212. messages: {
  213. mode: {required: "댓글 처리중 오류가 발생하였습니다.", contains: "잘못된 요청입니다."},
  214. content: {required: "댓글을 입력해주세요."},
  215. is_secret: {number: true}
  216. },
  217. showErrors: function (errorMap, errorList) {
  218. if (this.numberOfInvalids()) {
  219. setTimeout(function() {
  220. alert(errorList[0].message);
  221. errorList[0].element.focus();
  222. if(Comment.useEditor) {
  223. tinyMCE.activeEditor.getBody().scrollIntoView();
  224. }else{
  225. window.scrollTo({top: errorList[0].element.offsetTop});
  226. }
  227. }, 100);
  228. e.disabled = false;
  229. }
  230. },
  231. submitHandler: function (form)
  232. {
  233. let mode = form.elements["mode"].value;
  234. let content = form.elements["content"].value;
  235. let spamKeyword = Comment.filterSpamKeyword(content); // 금지 단어 검사
  236. if (spamKeyword) {
  237. alert("내용에 금지어 ('" + spamKeyword + "')가 포함 되어있습니다.");
  238. form.elements["content"].focus();
  239. return false;
  240. }
  241. // 댓글 등록
  242. let formData = $(form).serializeArray();
  243. formData.push({name: "bid", value: Comment.bid});
  244. formData.push({name: "pid", value: Comment.pid});
  245. // 버튼 비활성화
  246. form.elements["btn_comment_submit"].disabled = true;
  247. form.elements["btn_comment_cancel"].disabled = true;
  248. $.ajax({
  249. headers: {'X-CSRF-TOKEN': CSRF},
  250. url: (Comment.callback + "/" + Comment.method[mode]),
  251. type: 'post',
  252. cache: false,
  253. async: true,
  254. data: formData,
  255. dataType: 'json',
  256. beforeSend: function (xhr) {
  257. if (!loginCheck()) {
  258. xhr.abort();
  259. }
  260. showLoading();
  261. },
  262. success: function (res) {
  263. if (res.success) {
  264. let page = (mode === "write" ? Math.ceil((Number(Comment.total) + 1) / Comment.perPage) : Comment.page);
  265. Comment.list(page, res.commentID);
  266. }else{
  267. alert(res.message);
  268. }
  269. Comment.reset(form);
  270. },
  271. error: function (xhr, status, err) {
  272. procErrorEvent(xhr, status, err);
  273. },
  274. complete: function() {
  275. hideLoading();
  276. }
  277. });
  278. }
  279. });
  280. $(e.form).submit();
  281. },
  282. // 수정, 답글
  283. write: function(e, mode)
  284. {
  285. if(!loginCheck()) {
  286. return false;
  287. }
  288. if(typeof e === "undefined") {
  289. return false;
  290. }
  291. if(typeof mode == "undefined" || mode == null || !mode) {
  292. return false;
  293. }
  294. if($.inArray(mode, ["write", "modify", "reply"]) < 0) {
  295. return false;
  296. }
  297. let listForm = e.form; // 댓글 영역
  298. let writeForm = null;
  299. let cid = (listForm.elements["cid"].value || 0);
  300. let mediaFormID = ("#fCommentWrite_" + cid);
  301. let $saveBefore = $(this.saveBefore); // 이전 답글
  302. let $target = $(mediaFormID); // 현재 답글
  303. // 답글
  304. if(mode === "reply") {
  305. if(this.cid === cid && this.saveBefore === mediaFormID && this.mode === mode) {
  306. $saveBefore.toggle(); // 기존 댓글 창 보기/숨김
  307. }else{
  308. $saveBefore.html("");
  309. $target.show();
  310. writeForm = $target.html(this.saveHtml).get(0).firstElementChild;
  311. writeForm.elements["mode"].value = mode;
  312. writeForm.elements["cid"].value = cid;
  313. }
  314. }
  315. // 수정
  316. if(mode === "modify") {
  317. $saveBefore.html("");
  318. $target.show();
  319. writeForm = $target.html(this.saveHtml).get(0).firstElementChild;
  320. writeForm.elements["content"].value = listForm.content.value; // 내용 대입
  321. if(typeof writeForm.elements["is_secret"] !== "undefined") {
  322. writeForm.elements["is_secret"].checked = Boolean(listForm.is_secret.value === '1'); // 비밀글 체크
  323. }
  324. writeForm.elements["mode"].value = mode;
  325. writeForm.elements["cid"].value = cid;
  326. // 입력창 높이 조절
  327. this.resizeTextarea(writeForm.elements["content"]);
  328. }
  329. // textarea ID 할당
  330. if(writeForm) {
  331. writeForm.elements["content"].setAttribute("id", writeForm.elements["content"].name + "_" + cid);
  332. // 1:1 문의 게시판은 에디터를 사용
  333. if(this.useEditor) {
  334. tinyMCE.init(tinyMCE.activeEditor.settings);
  335. tinyMCE.EditorManager.execCommand('mceAddEditor', true, writeForm.elements["content"]);
  336. }
  337. // 글자 수 확인
  338. this.checkByte(writeForm.elements["content"]);
  339. }
  340. this.mode = mode;
  341. this.cid = cid;
  342. this.saveBefore = mediaFormID; // 현재 영역
  343. },
  344. // 댓글 삭제
  345. delete: function(e)
  346. {
  347. e.blur();
  348. if (confirm("정말 삭제 하시겠습니까?")) {
  349. let bid = e.form.bid.value;
  350. let pid = e.form.pid.value;
  351. let cid = e.form.cid.value;
  352. $.ajax({
  353. url: (this.callback + "/delete"),
  354. type: 'delete',
  355. cache: false,
  356. async: false,
  357. data: {bid: bid, pid: pid, cid: cid, _method: "delete"},
  358. dataType: 'json',
  359. beforeSend: function(xhr) {
  360. if(!loginCheck()) {
  361. xhr.abort();
  362. }
  363. },
  364. success: function (res) {
  365. if (res.success) {
  366. alert("댓글이 삭제되었습니다.");
  367. Comment.refresh();
  368. }else{
  369. alert(res.message || "처리 중 오류가 발생하였습니다. 관리자에게 문의하십시오.");
  370. }
  371. Comment.reset();
  372. },
  373. error: function (xhr, status, err) {
  374. procErrorEvent(xhr, status, err);
  375. }
  376. });
  377. }
  378. return false;
  379. },
  380. // 댓글 신고
  381. blame: function(e)
  382. {
  383. e.blur();
  384. if(!loginCheck()) {
  385. return false;
  386. }
  387. let bid = e.form.bid.value;
  388. let pid = e.form.pid.value;
  389. let cid = e.form.cid.value;
  390. // 신고 접수 유효성
  391. $("#fCommentBlame").validate({
  392. onkeyup: false,
  393. onclick: false,
  394. onfocusout: false,
  395. rules: {
  396. blame_type: {required: true, contains: ['1', '2', '3', '4', '5', '6', '7', '8', '9']},
  397. blame_reason: {required: true, normalizer: function (value) {return $.trim(value);}, maxlength: 1000}
  398. },
  399. messages: {
  400. blame_type: {required: "신고 유형을 선택해주세요.", contains: "잘못된 요청입니다."},
  401. blame_reason: {required: "신고 내용을 입력해주세요.", maxlength: "신고 내용은 {0}자까지 입력 가능합니다."}
  402. },
  403. showErrors: function (errorMap, errorList) {
  404. if (this.numberOfInvalids()) {
  405. alert(errorList[0].message);
  406. errorList[0].element.focus();
  407. }
  408. },
  409. submitHandler: function(form) {
  410. if (confirm("신고를 접수하시겠습니까?")) {
  411. $.ajax({
  412. url: (this.callback + "/blame"),
  413. type: 'post',
  414. cache: false,
  415. async: false,
  416. data: {bid: bid, pid: pid, cid: cid, type: form.blame_type.value, reason: form.blame_reason.value},
  417. dataType: 'json',
  418. beforeSend: function (xhr) {
  419. if(!loginCheck()) {
  420. xhr.abort();
  421. }
  422. },
  423. success: function (res) {
  424. form.blame_type.value = "";
  425. form.blame_reason.value = "";
  426. if (res.success) {
  427. alert("감사합니다. 신고가 접수되었습니다. 이용 규칙을 위반한 것으로 확인되면 댓글이 삭제됩니다.");
  428. }else{
  429. alert(res.message || "처리 중 오류가 발생하였습니다. 관리자에게 문의하십시오.");
  430. }
  431. $('div.modal').modal('hide');
  432. },
  433. error: function (xhr, status, err) {
  434. procErrorEvent(xhr, status, err);
  435. }
  436. });
  437. }
  438. }
  439. });
  440. },
  441. // 추천
  442. like: function (e) {
  443. let bid = e.form.bid.value;
  444. let pid = e.form.pid.value;
  445. let cid = e.form.cid.value;
  446. let type = e.value;
  447. let active = Number(e.dataset.active);
  448. $.ajax({
  449. url: (this.callback + "/like"),
  450. type: 'post',
  451. cache: false,
  452. async: false,
  453. data: {bid: bid, pid: pid, cid: cid, type: type},
  454. dataType: 'json',
  455. beforeSend: function (xhr) {
  456. if (!loginCheck()) {
  457. xhr.abort();
  458. }
  459. },
  460. success: function (res) {
  461. if (res.success) {
  462. Comment.toggleLike(cid, 1, !active);
  463. } else {
  464. alert(res.message || "처리 중 오류가 발생하였습니다. 관리자에게 문의하십시오.");
  465. }
  466. },
  467. error: function (xhr, status, err) {
  468. procErrorEvent(xhr, status, err);
  469. }
  470. });
  471. },
  472. // 비추천
  473. dislike: function (e) {
  474. let bid = e.form.bid.value;
  475. let pid = e.form.pid.value;
  476. let cid = e.form.cid.value;
  477. let type = e.value;
  478. let active = Number(e.dataset.active);
  479. $.ajax({
  480. url: (this.callback + "/dislike"),
  481. type: 'post',
  482. cache: false,
  483. async: false,
  484. data: {bid: bid, pid: pid, cid: cid, type: type},
  485. dataType: 'json',
  486. beforeSend: function (xhr) {
  487. if (!loginCheck()) {
  488. xhr.abort();
  489. }
  490. },
  491. success: function (res) {
  492. if (res.success) {
  493. Comment.toggleLike(cid, 2, !active);
  494. } else {
  495. alert(res.message || "처리 중 오류가 발생하였습니다. 관리자에게 문의하십시오.");
  496. }
  497. },
  498. error: function (xhr, status, err) {
  499. procErrorEvent(xhr, status, err);
  500. }
  501. });
  502. },
  503. // 댓글 입력 취소
  504. cancel: function ($this) {
  505. if ($this.form.mode.value === "write") {
  506. $this.form.elements["mode"].value = "write";
  507. $this.form.elements["cid"].value = "";
  508. $this.form.elements["length"].value = "0";
  509. $this.form.elements["content"].value = "";
  510. if (typeof $this.form.elements["is_secret"] !== "undefined") {
  511. $this.form.elements["is_secret"].checked = false;
  512. }
  513. let $length = $this.form.getElementsByClassName("comment-length");
  514. if ($length.length > 0) {
  515. $length[0].innerText = "0";
  516. }
  517. } else {
  518. $this.form.parentNode.style.display = "none";
  519. $this.form.parentNode.innerHTML = "";
  520. }
  521. this.reset($this.form);
  522. },
  523. /*
  524. * 댓글 에디터 옵션 변경
  525. * 1:1 게시판에서 댓글을 작성하면 실행
  526. */
  527. setInitEditor: function () {
  528. let tinyMCEExtendSetting = {
  529. min_height: 210,
  530. max_height: 310,
  531. init_instance_callback: function (editor) {
  532. editor.on('SetContent', function (e) {
  533. let iframeRows = e.target.contentDocument.body.getElementsByTagName("iframe");
  534. if (iframeRows > 0) {
  535. $(e.content).filter("iframe").attr("src", ""); // iframe src 주소
  536. }
  537. });
  538. editor.on('keyup', function () {
  539. Comment.checkByte(editor.targetElm);
  540. });
  541. editor.on('keypress', function () {
  542. Comment.checkByte(editor.targetElm);
  543. // document.getElementById(e.target.dataset.id).value = e.currentTarget.textContent;
  544. });
  545. }
  546. };
  547. tinymce.init(Object.assign(tinyMCE.activeEditor.settings, tinyMCEExtendSetting));
  548. this.useEditor = true;
  549. },
  550. // 좋아요/싫어요 처리
  551. toggleLike: function (cid, type, active) {
  552. let btnCommentLike = document.getElementById("comment_" + cid).getElementsByClassName("btn-comment-like")[0];
  553. let btnCommentDisLike = document.getElementById("comment_" + cid).getElementsByClassName("btn-comment-dislike")[0];
  554. if (type === 1) {
  555. this.setLike(cid, active);
  556. if (Number(btnCommentDisLike.dataset.active)) {
  557. this.setDislike(cid, false);
  558. }
  559. } else if (type === 2) {
  560. this.setDislike(cid, active);
  561. if (Number(btnCommentLike.dataset.active)) {
  562. this.setLike(cid, false);
  563. }
  564. }
  565. },
  566. // 좋아요 갱신
  567. setLike: function (cid, active) {
  568. let button = document.getElementById("comment_" + cid).getElementsByClassName("btn-comment-like")[0];
  569. let rows = Number(button.dataset.rows);
  570. if (active) {
  571. rows = (rows + 1);
  572. button.innerHTML = '<i class="fas fa-thumbs-up"></i><span> ' + String(rows) + '</span>';
  573. button.dataset.active = "1";
  574. } else {
  575. rows = (rows > 0 ? rows - 1 : rows);
  576. button.innerHTML = '<i class="far fa-thumbs-up"></i><span> ' + String(rows) + '</span>';
  577. button.dataset.active = "0";
  578. }
  579. button.dataset.rows = rows;
  580. },
  581. // 싫어요 갱신
  582. setDislike: function (cid, active) {
  583. let button = document.getElementById("comment_" + cid).getElementsByClassName("btn-comment-dislike")[0];
  584. let rows = Number(button.dataset.rows);
  585. if (active) {
  586. rows = (rows + 1);
  587. button.innerHTML = '<i class="fas fa-thumbs-down"></i><span> ' + String(rows) + '</span>';
  588. button.dataset.active = "1";
  589. } else {
  590. rows = (rows > 0 ? rows - 1 : rows);
  591. button.innerHTML = '<i class="far fa-thumbs-down"></i><span> ' + String(rows) + '</span>';
  592. button.dataset.active = "0";
  593. }
  594. button.dataset.rows = rows;
  595. }
  596. };
  597. // 댓글 입력하면 창 크기 조절
  598. $(document).on("keyup input", "textarea[data-autoresize]", function() {
  599. Comment.resizeTextarea(this);
  600. });
  601. // 댓글 글자수 확인
  602. $(document).on('keydown keyup', "textarea.comment-content", function (e) {
  603. Comment.checkByte(this);
  604. });
  605. // 댓글 등록
  606. $(document).on("click", "button.btn-comment-submit", function () {
  607. Comment.submit(this);
  608. });
  609. // 댓글 답글
  610. $(document).on("click", "button.btn-comment-reply", function() {
  611. Comment.write(this, "reply");
  612. });
  613. // 댓글 수정
  614. $(document).on("click", "button.btn-comment-modify", function () {
  615. Comment.write(this, "modify");
  616. });
  617. // 댓글 취소
  618. $(document).on("click", "button.btn-comment-cancel", function () {
  619. Comment.cancel(this);
  620. });
  621. // 댓글 삭제
  622. $(document).on("click", "button.btn-comment-delete", function () {
  623. Comment.delete(this);
  624. });
  625. // 댓글 신고
  626. $(document).on("click", "button.btn-comment-blame", function() {
  627. Comment.blame(this);
  628. });
  629. // 댓글 추천하기
  630. $(document).on("click", "button.btn-comment-like", function () {
  631. Comment.like(this);
  632. });
  633. // 댓글 비추천하기
  634. $(document).on("click", "button.btn-comment-dislike", function () {
  635. Comment.dislike(this);
  636. });
  637. // 댓글 페이징 처리
  638. $(document).on("click", "#commentList > nav > ul > li > a", function () {
  639. let page = Number(params('page', this.href));
  640. return Comment.list(page);
  641. });
  642. // 댓글 정렬
  643. $(document).on("change", "select#commentSort", function () {
  644. Comment.list(null, null, null, this.value);
  645. });
  646. // 댓글 신고 모달 열리면 초기화
  647. $(document).on("show.bs.modal", "#commentBlameModal", function(e) {
  648. let form = e.currentTarget.getElementsByTagName("form")[0];
  649. form.elements["blame_type"].selectedIndex = 0;
  650. form.elements["blame_reason"].value = "";
  651. });