PageSourceSearch

https://cdn.ccreview.co.kr/comment/comment.js

js ccreview.co.kr collected 2026-10-02 19:10:25 UTC 18,939 bytes, 476 lines download raw bytes

1/**************************************************
2	COMMENT SCRIPT FILE
3
4	AUTHOR	: DOTI
5	FILE	: /fine_home/comment/comment.js
6	NOTE	: 댓글 사용을 위한 기본적인 스크립트 페이지
7
8 **************************************************/
9
10var $comment = {
11
12	member_check		: ''											// 회원여부
13	, service_code		: ''											// 현재 이용 서비스
14	, bbs_table			: ''											// 게시판 이용시 게시판 테이블명
15	, list_exc_idxno	: ''											// BEST 댓글 노출로 댓글에 제외할 idxno 번호 ( 콤마(,) 구분)
16	, best_container	: $('#comment-list .best-content')				// BEST 댓글 리스트 표시 객체
17	, list_container	: $('#comment-list .normal-content')			// 댓글 리스트 표시 객체
18	, list_total_count	: $('#comment .comment-count')					// 댓글 총 갯수 표시 객체
19	, btn_cmt_more		: $('#comment .btn-comment-more')				// 댓글 더보기 버튼 객체
20	, btn_cmt_save		: $('#comment .btn-comment-save')				// 댓글 등록 버튼 객체
21	, reveal_delete		: $('#comment-reveal-delete')					// 댓글 삭제 모달 창 객체
22	, reveal_modify		: $('#comment-reveal-modify')					// 댓글 수정 모달 창 객체
23
24
25	// 댓글 설정 불러오기
26	, commentConfigSet:function(){
27		$.ajax({
28			url:'/comment/commentConfig.ajax.php',
29			method:'GET',
30			data:{service_code:$comment.service_code, bbs_table:$comment.bbs_table},
31			dataType:'JSON',
32			cache: true,
33			success:function(data){
34				// config set
35				for (var key in data) $comment[key] = data[key];
36				//console.log('%cCOMMENT :: %c'+$comment.ver+'', 'background:black; color:yellow', 'background:black; color:white;');
37
38				// Best Comment
39				if($comment.best_comment[0]) $comment.bestComment($comment.best_comment[1], $comment.best_comment[2]);
40
41				// List Comment
42				setTimeout(function(){
43					$comment.commentList('load', 1, $comment.default_order_by);
44				}, ($comment.best_comment[0])?$comment.load_delay_time:0);	// 베스트 댓글 로딩이 필요한 경우 베스트 댓글 idxno 값을 얻기 위해 지연시킴
45			}
46			/*
47			,error : function(request, status, error) {
48				alert("code: "+request.status+"\n"+"message: "+request.responseText+"\n"+"error: "+error);
49			}
50			*/
51		});
52
53		return true;
54	}
55
56
57	// 댓글 갯수 표시
58	, TotalCount:function(str){														// 표시 문자
59		$comment.list_total_count.text(str);
60	}
61
62
63	// 베스트 댓글 불러오기
64	, bestComment:function(num, limit){							// num:답글+추천 숫자 | limit: 1~3 표시
65		$.ajax({
66			url:'/comment/bestComment.ajax.php',
67			method:'GET',
68			data:{member_check:$comment.member_check, service_code:$comment.service_code, bbs_table:$comment.bbs_table, parent_idxno:$comment.parent_idxno, num:num, limit:limit},
69			dataType:'HTML',
70			cache:true,
71			success:function(data){
72				$comment.best_container.prepend(data);
73				$comment.list_exc_idxno = $comment.best_container.find('#list-exc-idxno').val();
74			}
75		});
76	}
77
78
79	// 댓글 목록 불러오기
80	, commentList:function(mode, comment_page, order_by){							// mode:load(갱신) or add(추가) | comment_page:페이징번호 | order_by:I(최신춘) or C(추천순) or R(답글순)
81		$.ajax({
82			url:'/comment/commentList.ajax.php',
83			method:'GET',
84			data:{member_check:$comment.member_check, service_code:$comment.service_code, bbs_table:$comment.bbs_table, parent_idxno:$comment.parent_idxno, comment_page:comment_page, order_by:order_by, list_exc_idxno:$comment.list_exc_idxno, mode:mode},
85			dataType:'HTML',
86			cache:true,
87			success:function(data){
88				if(mode == 'load') $comment.list_container.html(data);
89				else if(mode == 'add') $comment.list_container.append(data);
90
91				$('#comment .btn-comment-orderby').removeClass('secondary').addClass('nd-gray');
92				$('#comment .btn-comment-orderby-'+order_by).toggleClass('secondary nd-gray');
93			}
94		});
95	}
96
97
98	// 답글 목록 불러오기
99	, commentSubList:function(reply_parent_idxno, mode){			// reply_parent_idxno:부모댓글ë²
99ˆí˜¸
100
101		var sub_item = $('#comment #comment-item-'+reply_parent_idxno+'-sub'),
102			sub_page = sub_item.find('.comment-sub-page').val(),
103			order_by = sub_item.find('.comment-sub-orderby').val();
104
105		if(mode == 'add') sub_page++;
106		if(mode == 'input') order_by = 'D';
107
108		$.ajax({
109			url:'/comment/commentSubList.ajax.php',
110			method:'GET',
111			data:{member_check:$comment.member_check, service_code:$comment.service_code, bbs_table:$comment.bbs_table, parent_idxno:$comment.parent_idxno, reply_parent_idxno:reply_parent_idxno, sub_page:sub_page, order_by:order_by, mode:mode},
112			dataType:'HTML',
113			cache:true,
114			success:function(data){
115				
116				if(mode == 'reload'){
117					sub_item.find('.comment-item-sub-body').html(data);
118					sub_item.find('.btn-sub-comment-orderby').removeClass('secondary');
119					sub_item.find('.btn-sub-comment-orderby-'+order_by).addClass('secondary');
120				}
121
122				if(mode == 'input'){
123					sub_item.find('.comment-item-sub-body').html(data);
124					sub_item.find('.btn-sub-comment-orderby').removeClass('secondary');
125					sub_item.find('.btn-sub-comment-orderby-D').addClass('secondary');
126					sub_item.find('.comment-sub-orderby').val('D');
127				}
128
129				if(mode == 'load'){
130					sub_item.find('.comment-item-sub-body').html(data);
131					sub_item.find('.btn-sub-comment-orderby').removeClass('secondary');
132					sub_item.find('.btn-sub-comment-orderby-A').addClass('secondary');
133
134					if(sub_item.is(':visible') == false){
135						if($comment.auto_sub_comment) sub_item.show();
136						else sub_item.slideDown();
137					} else {
138						sub_item.find('.comment-item-sub-body').html('');
139						sub_item.find('.comment-sub-page').val(1);
140						sub_item.find('.comment-sub-orderby').val('A');
141						sub_item.hide();
142					}
143				}
144
145				if(mode == 'add'){
146					sub_item.find('.comment-item-sub-body').append(data);
147					sub_item.find('.comment-sub-page').val(sub_page);
148
149					if($comment.auto_sub_comment) sub_item.show();
150					else sub_item.slideDown();
151				}
152			}
153		});
154	}
155
156
157	// 댓글 / 답글 더보기 버튼
158	, btnMore:function(mode, moreBtn){						// mode:show(보이기) or hide(숨기기) | 더보기 버튼 객체
159		if(!moreBtn) moreBtn = $comment.btn_cmt_more;
160
161		if(mode == 'show') moreBtn.html('<div class="more-info"><span>더보기</span></div>').show();
162		else if(mode == 'none') moreBtn.hide();
163		else if(mode == 'hide') {
164			if($comment.more_btn_slow_hide == true){		// 버튼이 서서히 사라지기를 원하는 경우
165				moreBtn.html('<div class="more-info-text"><i class="icon-error-o"></i> 더이상 댓글이 존재하지 않습니다</div>');
166				setTimeout(function(){
167					moreBtn.fadeOut();
168					moreBtn.hide();
169				}, 2000);				// 디자인 수정 후 오픈
170			} else {										// 버튼이 서서히 사라지기를 원하지 않는 경우
171				moreBtn.hide();		// 디자인 수정 후 오픈
172			}
173		}
174	}
175
176
177	// 댓글 쓰기
178	, commentWrite:function(f){														// f:폼 그룹
179
180		var writeFormErr = false;
181
182		//// 이름 및 댓글 작성 확인
183		if( !f.find('input[name="user_id"]').val() && !f.find('input[name="password"]').val() ){
184			f.find('input[name="password"]').focus()
185			writeFormErr = '비밀번호를';
186		}
187		if( !f.find('input[name="name"]').val() ){
188			f.find('input[name="name"]').focus()
189			writeFormErr = '이름을';
190		}
191		if( !f.find('textarea[name="content"]').val() ){
192			f.find('textarea[name="content"]').focus()
193			writeFormErr = '본문을';
194		}
195
196		if(writeFormErr){
197			$('.recaptcha-view').remove();
198			alert('[Error.8] '+writeFormErr+' 바르게 입력하세요.');
199			return false;
200
201		}
202
203		//// 캡챠 확인
204		if( $comment.captcha_view == 'Y' && $comment.captcha_enable == true && !f.find('input[name="captcha"]').val() ){
205
206			$('.recaptcha-view').remove();
207
208			$.ajax({
209				url:'/comment/recaptcha.ajax.php',
210				dataType:'HTML',
211				cache: false,
212				success:function(data){
213					f.find('.recaptcha-container').append('<div class="recaptcha-view">'+data+'</div>');
214				}
215			});
216
217			return false;
218		}
219
220		//// 저장
221		$.ajax({
222			url:'/comment/commentWrite.ajax.php',
223			method:'POST',
224			data:f.serialize()+'&captcha_view='+$comment.captcha_view,
225			dataType:'JSON',
226			cache: false,
227			success:function(data){
228				
229				if(data['result'] == true){
230					$comment.commentWriteAdd(data['mode'], data['idxno'], data['reply_parent_idxno']);
231					if($comment.member_check == 'GUEST') f.find('.name, .password, .comment-content, .nomember-captcha').val('');
232					else f.find('.password, .comment-content, .nomember-captcha').val('');
233					f.find('.comment-text-cur').text('0');
234					$('.recaptcha-view').remove();
235
236					if(data['mode'] == 'sub_input'){
237						var cmt_sub_count = ($('#comment-item-'+data['reply_parent_idxno']+' .comment-sub-count').text() == "작성")? 1:Number($('#comment-item-'+data['reply_parent_idxno']+' .comment-sub-count').text()) + 1;
238						$('#comment-item-'+data['reply_parent_idxno']+' .comment-sub-count').html('<small>'+cmt_sub_count+'</small>');
239					}
240
241				} else if(data['result'] == false) {
242					alert(data['msg']);
243					f.find('#nomember-captcha').val('');
244					$('.recaptcha-view').remove();
245				}
246			}
247		});
248	}
249
250
251	// 댓글 작성 후 추가
252	, commentWriteAdd:function(mode, idxno, reply_parent_idxno){					// mode:reply or sub_reply | idxno:댓글번호 | reply_parent_idxno:부모댓글ë²
252ˆí˜¸
253		$.ajax({
254			url:'/comment/commentWriteAdd.ajax.php',
255			method:'GET',
256			data:{member_check:$comment.member_check, service_code:$comment.service_code, bbs_table:$comment.bbs_table, parent_idxno:$comment.parent_idxno, mode:mode, idxno:idxno},
257			dataType:'HTML',
258			cache: true,
259			success:function(data){
260				// 댓글 추가
261				if(mode == 'input'){
262//					addElm = $comment.list_container;
263//					addElm.prepend(data);				// 작성 댓글 추가
264					$comment.commentList('load', $comment.comment_page, $comment.comment_orderby='I');	// 댓글 불러오기
265					$comment.moveScroll($comment.list_container);		// 작성 댓글로 이동
266				}
267
268				// 답글 추가
269				if(mode == 'sub_input'){
270					$comment.commentSubList(reply_parent_idxno, 'input');
271					$comment.moveScroll($('#comment #comment-item-'+reply_parent_idxno));		// 작성 댓글로 이동
272				}
273			}
274		});
275	}
276
277
278	// 댓글 수정
279	, commentModify:function(f){													// f:폼 그룹
280		var result = '';
281		$.ajax({
282			url:'/comment/commentOption.ajax.php',
283			method:'POST',
284			data:f.serialize(),
285			dataType:'JSON',
286			cache: false,
287			success:function(data){
288				if(data['result'] == 'OK'){
289					$('#comment-textbox-'+data['idxno']+' .comment-content-view').html(data['modify_content'].replace(/\n/g,'<br>'));
290					$comment.reveal_modify.foundation('close');						// 수정 모달 닫기
291					$('.user-delete').hide();
292				} else {
293					alert(data['msg']);
294				}
295			}
296		});
297	}
298
299
300	// 댓글 삭제
301	, commentDelete:function(f){													// f:폼 그룹
302		$.ajax({
303			url:'/comment/commentOption.ajax.php',
304			method:'POST',
305			data:f.serialize(),
306			dataType:'JSON',
307			cache: false,
308			success:function(data){ //console.log(data);
309				if(data['result'] == true) {
310					if (typeof data['referer']!="undefined" && data['referer']==true) {
311						window.parent.location.reload();
312						return false;
313					}
314
315					if(data['mode'] == 'delete') $('#comment-item-'+data['idxno']).slideUp('slow');
316					else if(data['mode'] == 'sub-delete'){
317						var cmt_sub_count = Number($('#comment-item-'+data['reply_parent_idxno']+' .comment-sub-count').text()) - 1;
318						if(cmt_sub_count > 0) $('#comment-item-'+data['reply_parent_idxno']+' .comment-sub-count').html('<small>'+cmt_sub_count+'</small>');
319						else $('#comment-item-'+data['reply_parent_idxno']+' .comment-sub-count').html('');
320						$('#comment-item-'+data['idxno']).slideUp('slow');
321					}
322
323					if(data['total_count']) $comment.TotalCount(data['total_count']);		// 댓글 총 개수 변경
324
325					$comment.reveal_delete.foundation('close');								// 삭제 모달 닫기
326				} else {
327					alert('비밀번호 확인 후 다시 시도하시기 바랍니다.');
328				}
329			}
330		});
331	}
332	
333
334	// 댓글 추천/반대
335	, commentVote:function(elm, mode, idxno){												// elm:추천/반대 버튼 객체 | mode:vote_up(추천) or vote_down(반대) | idxno:댓글번호
336		var commentVoteCheck = false;
337
338		if($comment.comment_vote_check[0] == 'S'){												// 스토리지 방식
339			var nowTimestamp	= nowTime = Math.floor(+ new Date() / 1000);
340			var voteCheckName	= 'comment_'+$comment.service_code+'_'+idxno;
341			var voteCheckTime	= nowTime + ($comment.comment_vote_check[2] * 3600);
342//			var voteCheckTime	= nowTime + 10;			// test
343			var setCheckData	= [mode,voteCheckTime];
344			var getCheckData	= (localStorage[voteCheckName] !== undefined) ? JSON.parse(localStorage.getItem(voteCheckName)) : [];
345
346			if(getCheckData[1]){																	// 스토리지에 값이 존재하면
347				if(nowTimestamp < getCheckData[1]){														// 체크시간이 지나지 않았으면
348					if($comment.comment_vote_check[1]){														// 추천 해제 활성 시
349						if(getCheckData[0] != mode) commentVoteCheck = 'A';										// 추천 상태에서 반대를 할 경우 >> 재추천 경고 문구 표시
350						else commentVoteCheck = 'U';															// 추천 상태에서 다시 추천을 할 경우 >> 추천 해제 처리
351					} else commentVoteCheck = 'A';															// 추천 해제 비활성 시 >> 재추천 경고 문구 표시
352				} else commentVoteCheck = 'Y';															// 체크시간이 지났으면 >> 재추천 실행
353			} else commentVoteCheck = 'Y';
353															// 스토리지에 값이 존재하지 않으면 >> 추천 실행
354
355			if(!$comment.nd_check && $comment.member_nd) commentVoteCheck = 'Y';					// ND 체크안함 설정상 && ND 이면 추천 체크 안함
356			if(!$comment.admin_check && $comment.member_check == 'ADMIN') commentVoteCheck = 'Y';	// 관리자 체크안함 설정 상태 && 관리자 이면 추천 체크 안함
357
358		} else if($comment.comment_vote_check[0] == 'C'){										// 쿠키방식
359			commentVoteCheck = 'Y';																	// 추천 실행 (PHP에서 체크 처리)
360		}
361
362		if(commentVoteCheck != false){
363			$.ajax({
364				url:'/comment/commentOption.ajax.php',
365				method:'POST',
366				data:{member_check:$comment.member_check, service_code:$comment.service_code, bbs_table:$comment.bbs_table, list_per_page:$comment.list_per_page, parent_idxno:$comment.parent_idxno, mode:mode, idxno:idxno, vote_check_val:commentVoteCheck},
367				dataType:'JSON',
368				cache: false,
369				success:function(data){
370					if(data['result'] == 'OK'){
371						if($comment.comment_vote_check[0] == 'S') localStorage.setItem(voteCheckName, JSON.stringify(setCheckData));	// 체크 데이터를 스토리지에 저장
372						elm.closest('.user-vote').find('.'+mode+'-off').hide();
373						elm.closest('.user-vote').find('.'+mode+'-on .text-vote').text(data['vote_num']);
374						elm.closest('.user-vote').find('.'+mode+'-on').slideDown();
375
376					} else if(data['result'] == 'UNSET'){
377						if($comment.comment_vote_check[0] == 'S') localStorage.removeItem(voteCheckName);		// 스토리지 제거
378	//					alert(data['msg']);
379						elm.closest('.user-vote').find('.'+mode+'-on').hide();
380						elm.closest('.user-vote').find('.'+mode+'-off .text-vote').text(data['vote_num']);
381						elm.closest('.user-vote').find('.'+mode+'-off').slideDown();
382
383					} else if(data['result'] == 'BLOCK') alert(data['msg']);
384				}
385			});
386		}
387	}
388	
389
390	// 글자수 체크
391	, textLength:function(elm){														// elm:글자수 체크할 객체
392		var content = elm.val();
393
394		if (content.length > $comment.max_length){
395			alert('최대 '+$comment.max_length+'자까지 입력 가능합니다.');
396			elm.val(content.substring(0, $comment.max_length));
397			elm.closest('form').find('.comment-text-cur').text($comment.max_length);
398			elm.height(1).height( elm.prop('scrollHeight')+10 )
399
400			return false;
401
402		} else {
403			elm.closest('form').find('.comment-text-cur').text(content.length);
404			elm.height(1).height( elm.prop('scrollHeight')+10 )
405
406			return true;
407		}
408	}
409
410	// 스크롤 이동
411	, moveScroll:function(elm, force = false, sp = 600){								// elm:위치 이동 객체 | force:true(사용) or false(비사용) | sp:이동 속도
412		if (!$comment.auto_scroll && !force) return false;								// $comment.auto_scroll 환경 설정에서 미사용시에도 force가 true 이면 사용
413
414		const isIframe = window.self !== window.top;
415		const isAdmin = document.querySelector("#admin-wrap") || window.parent.document.querySelector("#admin-wrap");
416		let topMargin = 0;
417
418		if ($('#sticky-header .titles').is(':visible')) topMargin += $('#sticky-header .titles').height();
419
420		if (isAdmin) {
421			if (isIframe) {
422				if ($("#article-preview").is(":visible")) topMargin += $("#article-preview").outerHeight();
423			} else {
424				if ($("#admin-header").is(":visible")) topMargin += $("#admin-header").outerHeight();
425			}
426			topMargin += parseInt(elm.closest(".grid-view").css("padding-top"), 10);
427
428			let gridContent = null;
429			let getParentClass = node => {
430				if (typeof node=="undefined") return '';
431				return node.parentNode.classList.value;
432			};
433
434			if (getParentClass(elm.closest(".grid-view")[0]).indexOf('grid-snb')!=-1) {
435				gridContent = elm.closest('.grid-snb');
436			} else {
437				gridContent = elm.closest('.grid-content');
438			}
439
440			const scrollPosition = elm.offset().top - gridContent.offset().top + gridContent.scrollTop() - topMargin;
441
442			gridContent.animate({ scrollTop: scrollPosition }, sp);
443		} else {
444			$('html, body').animate({ scrollTop: parseInt($("#comment-list").offset().top) - topMargin }, sp);
445		}
446	}
447	// 리스트 추천 ON 처리
448	, voteViewCheck:function(idxno){
449		var nowTimestamp	= nowTime = Math.floor(+ new Date() / 1000);
450		var voteCheckTime	= nowTime + ($comment.comment_vote_check[2] * 3600);
451		var voteCheckName	= 'comment_'+$comment.service_code+'_'+idxno;
452		var getCheckData	= (localStorage[voteCheckName] !== undefined) ? JSON.parse(localStorage.getItem(voteCheckName)) : [];
453
454		if(getCheckData[1] && nowTimestamp < getCheckData[1]){
455			$('#comment-item-'+idxno).find('button.'+getCheckData[0]+'-off').hide();
456			$('#comment-item-'+idxno).find('button.'+getCheckData[0]+'-on').show();
457		}
458	}
459
460
461	// 유저 댓글 정보
462	, userCommentInfo:function(user_id){
463		$.ajax({
464			url:'/comment/userCommentInfo.ajax.php',
465			method:'GET',
466			data:{user_id:user_id, service_code:$comment.service_code},
467			dataType:'HTML',
468			cache: true,
469			success:function(data){
470				$('body').append(data);
471				$('#userCommentInfo').show();
472			}
473		});
474	}
475
476}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.