(function ($, window, document) { document.domain = 'joins.com'; var noImage = utils.config('imagePath') + '/pc/article/v_noimg_60x60.png'; var reporterDataUrl = utils.config('staticPath') + '/scripts/data/reporter.info.js'; $.fn.comment = function (options) { //set css var comment_cssUrl = ['https://static.joins.com/joongang_15re/styles/pc/article_cmt.css']; var joinsLogin_url = { pc: 'https://my.joins.com/login/login.asp', mobile: 'https://my.joins.com/login/login_mobile_web_type2.asp' }; var snsLogin_url = { Facebook: '/sns/login?snstype=facebook', Twitter: '/sns/login?snstype=twitter' }; var SNSPOST_URL = { facebook: '/sns/share?snstype=facebook', twitter: '/sns/share?snstype=twitter' }; var web_paths = { pc: utils.config('webPcPath'), mobile: utils.config('webMobilePath') }; var reffer_url = { article: 'joongang.joins.com/article', reporter: 'joongang.joins.com/reporter', jtbc: 'joongang.joins.com/jtbc', jpod: 'joongang.joins.com/jpod' }; var isShare = false, // sns 공유 선택 여부 isLogin = false, // 로그인 상태 여부 isWrite = true; // 글을 등록할 수 있는지 여부 var apiPath = utils.config('apiPath'), webPath = ''; var per_page = 10; var totalId = utils.getTotalId(); var defaults = { id: '', language: 'ko', page: 'article', user: {}, currentPage: 1, perPage: per_page, enabledPaste: false, enabledCopy: false, enabledDrag: false, enabledSort: true, sortType: 'new', //new, good, bad referUrl: '' }, snsList = [{ id: '1', url: web_paths.pc + '/comment/', cls: 'i_js', code: 'joins', name: '조인스', nameEN: 'Joins', target: '_self', loginUrl: '' }, { id: '2', url: 'https://www.facebook.com/app_scoped_user_id/', cls: 'i_fb', code: 'facebook', name: '페이스북', nameEN: 'Facebook', target: '_self', loginUrl: snsLogin_url.Facebook }, { id: '3', url: 'https://twitter.com/intent/user?user_id=', cls: 'i_tw', code: 'twitter', name: '트위터', nameEN: 'Twitter', target: '_self', loginUrl: snsLogin_url.Twitter }, { id: '4', url: web_paths.pc + '/comment/', cls: 'i_kk', code: 'kakao', name: '카카오', nameEN: 'KaKao', target: '_self', loginUrl: '' }, { id: '5', url: web_paths.pc + '/comment/', cls: 'i_ap', code: 'apple', name: '애플', nameEN: 'Apple', target: '_self', loginUrl: '' }], config = $.extend(true, defaults, options), userInfo = null, $container = this, commentLanguage = window.commentLanguage[config.language], commentHtml = window.commentHtml(config.lang), commentDatas = { displayCount : 0, Count : 0, List: [] }, reporterCookieName = 'reporterInfo'; var $head = null, $body = null, $foot = null; var listDirective = { //'nick_img': { // userSnsLink: { // href: function () { // var url = '', // id = this.userSnsLink.UserId; // for (var i = 0, // len = snsList.length; i < len; i++) { // if (snsList[i].nameEN === this.userSnsLink.UserLoginType) { // url = snsList[i].url; // } // } // return url !== '' ? url + id : ''; // } // }, // profile: { // src: function () { // var src = ''; // if (this.profile.IsReporter === true || this.profile.IsJplusJouralist === true) { // if (this.profile.ReporterProfile === undefined) { // src = noImage; // } else { // src = this.profile.ReporterProfile; // } // } else if (this.profile.UserImage !== '') { // src = this.profile.UserImage//.replace('http:', 'https:'); // } else { // src = noImage; // } // return src; // }, // alt: function () { // return this.profile.UserId; // } // } //}, 'cmt_area': { 'cmt_info': { mg: { html: function () { var $ele = $(arguments[0].element), cls = '', commentListUrl = '', target = '_self', userName = ''; if (this.mg.UserLoginType === 'Joins' && this.mg.IsReporter === true) { userName = this.mg.UserName + ' ' + commentLanguage.isReporter; } else if (this.mg.UserLoginType === 'Joins' && this.mg.IsJplusJouralist === true) { userName = this.mg.UserName; } else { userName = this.mg.UserId; } if (this.mg.UserLoginType !== 'Joins' && this.mg.IsReporter !== true) { userName = this.mg.UserName; } if (this.mg.IsReporter !== true) { if (userName.length > 4) { userName = userName.substring(0, 4) + "****"; } else { var len = userName.length / 2; userName = userName.substring(0, len) + "****"; } } for (var i = 0, len = snsList.length; i < len; i++) { if (snsList[i].nameEN === this.mg.UserLoginType) { cls = snsList[i].cls; target = snsList[i].target; if (this.mg.UserLoginType === 'Joins' && this.mg.IsReporter) { commentListUrl = '/reporter/' + this.mg.ReporterId; } else { commentListUrl = snsList[i].url + this.mg.UserId; } } } if (cls !== '') { $ele.addClass(cls); } //return '' + userName + ''; return userName; } }, 'btn_report': { html: function () { var $ele = $(arguments[0].element); if (isLogin === true && userInfo.id === this.mg.UserId || this.mg.IsDelete === 'D' || this.mg.IsDelete === 'N') { $ele.hide(); } $ele.attr('data-reportid', this.btn_report.Id); } }, 'btn_reply': { html : function() { var $ele = $(arguments[0].element); if (this.mg.IsDelete === 'D' || this.mg.IsDelete === 'N') { $ele.hide(); } } }, date: { html: function () { return this.mg.RegistedDateTime && this.mg.RegistedDateTime.toDateISO8061().format('yyyy-MM-dd HH:mm:ss'); } }, content: { html: function () { var $ele = $(arguments[0].element), content = this.mg.Content, deletButton = ' 삭제'; content = utils.strip(content) || ''; if (isLogin === true && userInfo.id === this.mg.UserId) { content = content + deletButton; } if (this.mg.IsDelete === 'D' || this.mg.IsDelete === 'N') { $ele.addClass('del'); content = content = this.mg.IsDelete === 'D' ? commentLanguage.removeMessageUser : commentLanguage.removeMessageAdmin; } else { $ele.removeClass('del'); } return content + ' '; } } }, 'btn_recomm': { good: { text: function () { var $ele = $(arguments[0].element); if (isLogin === true && userInfo.id === this.good.UserId || this.good.IsDelete === 'D' || this.good.IsDelete === 'N') { $ele.parent().addClass('not disable'); } $ele.parent().attr('data-voiteid', this.good.Id); return this.good.GoodCount; } }, bad: { text: function () { var $ele = $(arguments[0].element); if (isLogin === true && userInfo.id === this.bad.UserId || this.bad.IsDelete === 'D' || this.bad.IsDelete === 'N') { $ele.parent().addClass('not disable'); } $ele.parent().attr('data-voiteid', this.bad.Id); return this.bad.BadCount; } } } } }; //load css (function () { $.when.apply($, $.map(comment_cssUrl, function (url) { url += '?' + new Date().getTime(); return $('', { rel: 'stylesheet', type: 'text/css', 'href': url }).appendTo('head'); }) ).then(function () { var reporterInfo = utils.getCookie(reporterCookieName), rInfos = {}; userInfo = commentUserInfo.getInfo(); isLogin = commentUserInfo.isLogin(); webPath = web_paths.pc; if (reporterInfo !== null) { reporterInfo = reporterInfo.split('&'); for (var i = 0,len = reporterInfo.length; i < len; i++) { var minfo = reporterInfo[i].split('='), key = minfo[0], value = minfo[1]; if (key === 'REP_NAME') { value = decodeURIComponent(value); } if (key === 'REP_VIEW_IMG') { value = decodeURIComponent(value); } rInfos[key] = value; } if (rInfos.JOINS_ID === userInfo.id) { //기자이다! userInfo.profileImage = rInfos.REP_VIEW_IMG; userInfo.reporterSEQ = rInfos.REP_SEQ; } else { //remove cookie utils.removeCookie(reporterCookieName, COOKIE_CONDITION.path, COOKIE_CONDITION.domain); } } else { if (isLogin === true) { getReporterList(function () { //기자정보 서치 rInfos = fnGetRepoterInfoByJoinsId(userInfo.id); //rInfos = fnGetRepoterInfoByJoinsId('choyg94');//test if (rInfos !== null) { userInfo.profileImage = rInfos.REP_VIEW_IMG; userInfo.reporterSEQ = rInfos.REP_SEQ; utils.setCookie('reporterInfo', $.param(rInfos), 1, COOKIE_CONDITION.path, COOKIE_CONDITION.domain); } }); } } //선거 //$("#comment").addClass("election_comment"); init(); }); })(); function userLogin(type, device) { var url = '', currentUrl = location.href, returnPath = utils.config('webPcPath'); if (type === 'joins' || type === 'kakao' || type === 'facebook' || type === 'twitter' || type === 'apple') { url = joinsLogin_url[device] + '?targeturl=' + encodeURIComponent(location.href); location.href = url; } else { //선거 //url = joinsLogin_url[device] + '?targeturl=' + encodeURIComponent(location.href); //location.href = url; url = returnPath + '/sns/login?snstype=' + type; window.open(url, '_blank'); } } function loginFirst() { $container.find('.comment_form').find('.select_sns').find('a:first').focus(); if (confirm(commentLanguage.errorLoginCmt)) { userLogin('joins', 'pc'); } return false; } function emptyComment($t) { alert(commentLanguage.errorEmptyContent); $t.focus(); } function commentVotePost(obj) { utils.ajaxPost({ url: apiPath + '/comment/' + obj.id + '/' + obj.type + '/' + utils.getCookie('PCID'), success: function (res) { obj.callback && obj.callback(res); } }); } function commentReportPost(obj) { utils.ajaxPost({ url: apiPath + '/comment/' + obj.id + '/report', success: function (res) { if (res.IsSuccess) { alert(commentLanguage.reportTrue); obj.callback && obj.callback(); } else { alert(commentLanguage.reportFail); } } }); } function commentDeletePost(obj) { var params = {}; if (config.page === 'article') { params.TotalId = obj.totalid; } if (config.page === 'reporter') { params.ReporterId = obj.reporterid; } if (config.page === 'jpod') { params.TotalId = obj.id; } params.Id = obj.id; utils.ajaxPost({ url: apiPath + '/comment/' + obj.id + '/delete', data: params, success: function (resData) { obj.callback && obj.callback(resData); } }); } function sendSNS(obj) { var type = userInfo.type.toLowerCase(), loc = location.href, url = webPath + SNSPOST_URL[type]; if (type === 'facebook') { url = url + '&msg=' + obj.message + '&url=' + loc; window.open(encodeURI(url), 'share_facebook', 'directories=no,location=no,menubar=no,status=no,toolbar=no,scrollbars=no,resizable=no,width=640,height=440'); } else if (type === 'twitter') { url = url + '&msg=' + obj.message + ' ' + loc; window.open(encodeURI(url), 'share_twitter', 'width=640, height=440'); } } function moreList() { getCommentList({ currentPage: config.currentPage, perPage: config.perPage, callback: function (datas) { updateCommentDatas(datas, false); renderHeader($head, commentDatas); renderList($body, commentDatas); renderFoot($foot, commentDatas); $(window).trigger('resize_layout'); } }); } function reRenderAll() { // data 없을 시 renderHeader($head, commentDatas); renderForm($body); renderSort($body, commentDatas); renderList($body); renderFoot($foot, commentDatas); getCommentList({ currentPage: config.currentPage, perPage: config.perPage, callback: function (datas) { updateCommentDatas(datas, true); renderHeader($head, commentDatas); renderForm($body); renderSort($body, commentDatas); renderList($body, commentDatas); renderFoot($foot, commentDatas); if ($('.share_article').length > 0 && $('.share_article').find('.text_comment').length > 0) { $('.share_article').find('.text_comment').find('.mg').html(commentDatas.displayCount); } } }); } function submitComment(obj) { var params = { ParentId: obj.seq, Content: obj.content.replace(/<[^>]*>/g, ' '), UserId: userInfo.id, UserName: userInfo.name, UserImage: userInfo.profileImage, UserLoginType: userInfo.type, GroupId: 0, UsedCache: false, ReferUrl: config.referUrl }; if (config.page === 'article') { params.TotalId = config.id; } if (config.page === 'reporter') { params.ReporterId = config.id; } if (config.page === 'jpod') { params.TotalId = config.id; } utils.ajaxPost({ url: apiPath + '/comment', data: params, success: function (res) { var errorText = ''; if (res.IsSuccess == true) { alert(commentLanguage.success); } else { switch(res.Code) { case 'BadIp': errorText = commentLanguage.errorBadIp; break; case 'BadWord': errorText = res.Target + commentLanguage.errorBadWord; break; case 'BadUserId': errorText = res.Target + commentLanguage.errorBadUser; break; default: errorText = commentLanguage.fail; } alert(errorText); } if (isShare === true) { sendSNS({ message: obj.content }); } obj.callback && obj.callback(res); isWrite = false; setTimeout(function () { isWrite = true; }, 60000); } }); } function getReporterList(callback) { $.getScript(reporterDataUrl, function () { try { callback && callback(); } catch (e) { } }); } function getCommentList(obj) { var url = ''; if (config.page === 'jtbc' || config.page === 'event') { url = apiPath + '/event/comment'; } else { url = apiPath + '/' + config.page + '/' + config.id + '/comment'; } var params = { page: obj.currentPage || config.currentPage, pagesize: obj.perPage || config.perPage, sort: config.sortType, UsedCache: true, referurl: config.referUrl }; //if (config.page !== 'jtbc') { params.UserId = userInfo.id; } utils.getJsonp({ url: url, data: params, success: function (res) { obj.callback && obj.callback(res); } }); } function renderHeader($el, d) { var directive = { 'subtit_comm': { html: function () { return commentLanguage.totalCount + '' + (this.subtit_comm === undefined ? 0 : this.subtit_comm) + ''; } } }, html = commentHtml.getHtml('head'), data = { subtit_comm: d.displayCount }; if ($el.find('.subtit_comm').length === 0) { $el.html(html); } $el.render(data, directive); $("#cmt_total_count").text(commentDatas.displayCount); } // 댓글 입력 폼 function renderForm($el) { var directive = { 'select_sns': { list: { item: { html: function () { var $ele = $(arguments[0].element), active = '', loginUrl = webPath + this.loginUrl, target = '_blank'; $ele.addClass(this.cls); active = isLogin === true && userInfo.type.toLowerCase() === this.code ? 'on' : ''; if (this.code === 'joins' || this.code === 'kakao' || this.code === 'apple') { loginUrl = joinsLogin_url.pc; target = '_self'; } return '' + this.name + ''; } } }, 'sns_cmt': { html: function () { var $ele = $(arguments[0].element); $ele.toggle(!isLogin); return commentLanguage.messageLogin; } }, 'sns_cmt_fb': { html: function () { /*var html = '', directive = { mg: { html: function () { return '' + this.mg.type + commentLanguage.shareSNS; } } }, data = { mg: userInfo }, $ele = $(arguments[0].element); $ele.toggle(isLogin); if (userInfo.type !== 'joins' && userInfo.type !== 'kakao' && userInfo.type !== 'twitter' && userInfo.type !== 'facebook' && userInfo.type !== 'apple') { return $('
').wrapInner(html).render(data, directive).html(); }*/ } } }, 'logout_area': { 'btn_logout': { html: function () { var $ele = $(arguments[0].element); $ele.parent().toggle(isLogin); return commentLanguage.btnLogout; } } }, 'fieldset': { 'class': function () { var $ele = $(arguments[0].element), cls = $ele.attr('class'); return isLogin === true ? cls + ' comment_login' : cls; }, //'nick_img': { // profile: { // html: function () { // var $ele = $(arguments[0].element); // var imageUrl = this.profile.profileImage !== '' && this.profile.profileImage !== undefined ? this.profile.profileImage : noImage; // $ele.toggle(isLogin); // return '