// widget.js (function ($, window, document) { var WIDGET_INFO = { Ad: { key: 'Ad', fn: 'loadAd' }, DepartmentSns: { key: 'DepartmentSns', fn: 'widgetDepartmentSns' }, // 부서별 SNS HotArticles: { key: 'HotArticles', fn: 'widgetHotArticles' }, // 많이 본 기사 HotArticlesOrderByReplyCount: { key: 'HotArticlesOrderByReplyCount', fn: 'widgetHotArticlesOrderByReplyCount' }, // 댓글 많은 기사 HotIssues: { key: 'HotIssues', fn: 'widgetHotIssues' }, // 핫 이슈 HotJPlus: { key: 'HotJPlus', fn: 'widgetHotJPlus' }, // 인기 J플러스 //20180131 삭제예정 PrismStarReporter: { key: 'PrismStarReporter', fn: 'widgetPrismStarReporter' }, // 스타기자 //20180131 HotJPlusOrderByReplyCount: { key: 'HotJPlusOrderByReplyCount', fn: 'widgetHotArticlesOrderByReplyCount' }, // 댓글 많은 수 인기 J플러스 //20180131 삭제예정 HotVideos: { key: 'HotVideos', fn: 'widgetHotVideos' }, // 많이 본 동영상 JoongangIssue: { key: 'JoongangIssue', fn: 'widgetJoongangIssue' }, // 중앙 연재 Link: { key: 'Link', fn: 'widgetLink' }, // 링크 PhotoIssues: { key: 'PhotoIssues', fn: 'widgetPhotoIssues' }, // 포토 이슈 RecommendedIssues: { key: 'RecommendedIssues', fn: 'widgetRecommendedIssues' }, // 추천 연재 RelatedKeyword: { key: 'RelatedKeyword', fn: 'widgetRelatedKeyword' }, // 관련 키워드 RecommendedArticle: { key: 'RecommendedArticle', fn: 'widgetRecommendedArticle' }, // 추천 기사 OpinionCast: { key: 'OpinionCast', fn: 'widgetOpinionCast' }, // 오피니언 방송 (최신기사3건) PortalSearchKeyword: { key: 'PortalSearchKeyword', fn: 'widgetPortalSearchKeyword' }, // 포탈 실시간 검색어 SnsArticle: { key: 'SnsArticle', fn: 'widgetSnsArticle' }, // SNS 뉴스 MajorArticle: { key: 'MajorArticle', fn: 'widgetMajorArticle' }, // 주요 뉴스 FastNews: { key: 'FastNews', fn: 'widgetFastNews' }, // 지면보다 빠른 뉴스 TrendArticle: { key: 'TrendArticle', fn: 'widgetTrendArticle' }, // 추천 기사 ReporterQnA: { key: 'ReporterQnA', fn: 'widgetReporterQnA' }, // 기자 Q&A MorningPoem: { key: 'MorningPoem', fn: 'widgetMorningPoem' }, // 시가 있는 아침 DirectInterview: { key: 'DirectInterview', fn: 'widgetDirectInterview' }, // 오피니언 직격 인터뷰 PopularReporter: { key: 'PopularReporter', fn: 'widgetPopularReporter' }, // 인기 기자 TalkNk: { key: 'TalkNk', fn: 'widgetTalkNk' }, // TALK NK VoiceOfAmerica: { key: 'VoiceOfAmerica', fn: 'widgetVoiceOfAmerica' }, // VoiceOfAmerica WeeklyTravel: { key: 'WeeklyTravel', fn: 'widgetWeeklyTravel' }, // 금주의 Week&+ ImcBanner: { key: 'ImcBanner', fn: 'widgetImcBanner' }, // Imc Banner SpecialColumnD: { key: 'SpecialColumnD', fn: 'widgetSpecialColumnD' }, // 오피니언 비즈니스현장에 묻다 EditorialInsite: { key: 'EditorialInsite', fn: 'widgetEditorialInsite' }, // 오피니언 한반도평화워치 / 차이나인사이트 DigitalOpinion: { key: 'DigitalOpinion', fn: 'widgetDigitalOpinion' }, // 오피니언 퍼스 펙티브 SpecialCartoon: { key: 'SpecialCartoon', fn: 'widgetSpecialCartoon' }, // 오피니언 이코노믹스 MorningPoem: { key: 'MorningPoem', fn: 'widgetMorningPoem' }, // 오피니언 미래를 묻다 MmCampaign: { key: 'MmCampaign', fn: 'widgetMmCampaign' }, // Mr.밀리터리 캠페인 MmBannerAd: { key: 'MmBannerAd', fn: 'widgetMmBannerAd' }, // Mr.밀리터리 소개 팝업 MmRequest: { key: 'MmRequest', fn: 'widgetMmRequest' }, // Mr.밀리터리 게시판 MmInfo: { key: 'MmInfo', fn: 'widgetMmInfo' }, // Mr.밀리터리 소개 팝업 InnovationLabList: { key: 'InnovationLabList', fn: 'widgetInnovationLab' }, UniversityRanking: { key: 'UniversityRanking', fn: 'widgetUniversityRanking' }, RealtimeArticle: { key: 'RealtimeArticle', fn: 'widgetRealtimeArticle' }, // 실시간 검색어 RecommendedMovie: { key: 'RecommendedMovie', fn: 'widgetRecommendedMovie' }, // 추천 영화 RecommendedTheme: { key: 'RecommendedTheme', fn: 'widgetRecommendedTheme' }, // 추천 테마 PeopleMic: { key: 'PeopleMic', fn: 'widgetPeopleMic' }, // 시민마이크 PeopleLatest: { key: 'PeopleLatest', fn: 'widgetPeopleLatest' }, // 피플 > 최신 기사 EgleWeekBest: { key: 'EgleWeekBest', fn: 'widgetEgleWeekBest' }, // e글중심>주간 인기 글 TagNews: { key: 'TagNews', fn: 'widgetTagNews' } // PC 이슈패키지 ,RetirementWriter: { key: 'RetirementWriter', fn: 'widgetRetirementWriter' } // 퇴직 준비 필진신청 ,RetirementNotice: { key: 'RetirementNotice', fn: 'widgetRetirementNotice' } // 퇴직 준비 공지사항 ,JpodEpisode: { key: 'JpodEpisode', fn: 'widgetJpodEpisode' } //JPOD }; var apiPath = utils.config('apiPath'); $.fn.widget = function () { var $p = this; $p.children().each(function (i, v) { var $w = $(v), type = $w.data('widgetType'), service = $w.data('widgetService'), category = $w.data('widgetCategory'), fn = WIDGET_INFO[type] && WIDGET_INFO[type].fn; if (type && typeof $.fn[fn] == 'function') { $w[fn]({ type: service, category: category }); } }); }; $.fn.wideWidget = function () { var $p = this; $p.children().each(function (i, v) { var $w = $(v), type = $w.data('widgetType'), service = $w.data('widgetService'), category = $w.data('widgetCategory'), fn = WIDGET_INFO[type] && WIDGET_INFO[type].fn; //utils.log($w); //utils.log('## type : ' + type); if (type != undefined) { $w[fn]({ type: service, category: category }); } }); }; $.fn.articleBottom = function () { var $p = this; $('div.hot_click_wrap', $p).widgetHotClickTaboola(); if (utils.getArticleSourceCode() == "b8") { $('.ab_related', $p).widgetHotClickUSA(); // USA 핫클릭 } $('>div.photo_video', $p).widgetPhotoVideo(); // PhotoVideo $('>div.special_link', $p).widgetSpecialLink(); // widgetSpecialLink if ($('#divRelateTag').length > 0) { $('#divRelateTag').widgetRelationsTag(); // 태그뉴스 $("#divRelateTag").widgetOutstreamAD(); } if($('div.soundcloud').length > 0) { $('div.soundcloud').widgetPrehear(); //미리듣는 오늘 } // Jpod if ($('div.jpod_temp2').length > 0) { $('div.jpod_temp2').widgetJpodEpisode(); } //쇼핑박스 $('#shpping_life_1').loadAd({ type: 'joongang_pc_200x200_1_test' }); $('#shpping_life_2').loadAd({ type: 'joongang_pc_200x200_2_test' }); $('#shpping_life_3').loadAd({ type: 'joongang_pc_200x200_3_test' }); // 아티클 바이라인 하단 광고 $('#ab_adtxt_lt').loadAd({ type: 'ab_adtxt_lt' }); $('#ab_adtxt_rt').loadAd({ type: 'ab_adtxt_rt' }); $('#da_article_right_middle').loadAd({ type: 'da_article_right_middle' }); }; $.fn.widgetWeeklyTravel = function () { var $w = this, widgetHtml = '

금주의 week&+

', template = '', directives = { list: { link: utils.decorators.link, image: utils.decorators.image, thumb: { html: function (params) { if (params.index != 0) { $(params.element).remove(); } } } } }; getApiData('/static/traveloftheweek', render); function render(res) { var html = '', data = { list: [] }; try { res.List.forEach(function (v) { data.list.push(utils.models.getLinkFromApiArticle(v)); }); } catch (e) { utils.log(e); }; if (data.list.length) { html = $.renderTemplate({ template: template, data: data, directives: directives }); renderWidgetBody($w, widgetHtml, html); $w.show(); } else { $w.hide(); } } }; $.fn.widgetVoiceOfAmerica = function () { var $w = this, widgetHtml = '

Voice of America

', template = '', directives = { link: utils.decorators.link, image: utils.decorators.image }; getApiData('/static/voiceofamerica', render); function render(res) { var html = '', data = {}; try { data = utils.models.getLinkFromApiArticle(res.item); } catch (e) { utils.log(e); }; if (data && data.link && data.link.href && data.link.text) { html = $.renderTemplate({ template: template, data: data, directives: directives }); renderWidgetBody($w, widgetHtml, html); $w.show(); } else { $w.hide(); } } }; // TALK NK $.fn.widgetTalkNk = function () { var $w = this, widgetHtml = '

TALK NK

', template = '', directives = { list: { link: utils.decorators.link, image: utils.decorators.image } }; getApiData('/static/talknks', render); function render(d) { var html = '', data = { list: [] }; try { d.List.forEach(function (v, i) { var bbsLink = utils.config('bbsPath') + '/app/index.php?mid={MID}&document_srl={ID}'; bbsLink = bbsLink.replace('{MID}', v.Mid).replace('{ID}', v.Id); data.list.push({ link: { href: bbsLink, html: v.Title } }); }); } catch (e) { utils.log(e); }; if (data.list.length) { html = $.renderTemplate({ template: template, data: data, directives: directives }); renderWidgetBody($w, widgetHtml, html); $w.show(); } else { utils.error('widgetTalkNk', true); $w.hide(); } } }; // 기자 Q&A // TODO : 데이타 확인하고 작업하자. $.fn.widgetReporterQnA = function () { var $w = this, department = ($w.data('widgetCategory') || 'Politics').toLowerCase(), widgetHtml = '', template = '' + '

기자 Q&A

' + '
' + '

무엇이든 물어보세요, 기자의 꿀팁!

' + '
' + '
Q.
' + '
Re:
' + '
' + '
' + '
기자 Q&A 더보기
', directives = { question: { link: utils.decorators.link }, answer: { link: utils.decorators.link, html: function (params) { if (!this.answer.link.text) { $(params.element).remove(); } } }, reporter: { link: utils.decorators.link } }; getApiData('/static/reporterqna', render); function render(d) { var html = '', data = {}; try { data = { question: { link: { text: d.Qna.Title, href: d.Qna.TotalId == 0 ? d.Qna.Link : utils.getUrlFormat(URL_NAMES.article, d.Qna.TotalId) } }, answer: { link: { text: d.Qna.Content, href: d.Qna.TotalId == 0 ? d.Qna.Link : utils.getUrlFormat(URL_NAMES.article, d.Qna.TotalId) } }, reporter: { link: { href: utils.getUrlFormat(URL_NAMES.reporter, d.Qna.Reporter.Id) } } }; } catch (e) { utils.log(e); }; if (data) { html = $.renderTemplate({ template: template, data: data, directives: directives }); $w.html(html); $w.show(); } else { $w.hide(); } } }; // 시가 있는 아침 $.fn.widgetMorningPoem = function () { var $w = this, widgetName = '시가 있는 아침', listLink = utils.config('webPcPath') + '/find/list?Keyword=%22' + encodeURIComponent(widgetName) + '%22&ServiceCode=20&SearchCategoryType=OnlyJoongangNews&display=' + encodeURIComponent(widgetName), widgetHtml = '

' + widgetName + '

', template = '', directives = { list: { link: utils.decorators.link } }; getApiData('/static/morningpoem', render); function render(d) { var html = '', data = { list: [] }; try { d.List.forEach(function (v, i) { var articleLink = utils.getUrlFormat(URL_NAMES.article, v.Id); data.list.push({ link: { href: articleLink, html: v.Title } }); }); } catch (e) { utils.log(e); }; if (data.list.length) { html = $.renderTemplate({ template: template, data: data, directives: directives }); renderWidgetBody($w, widgetHtml, html); $w.show(); } else { $w.hide(); } } }; // 직격 인터뷰 $.fn.widgetDirectInterview = function () { var $w = this, widgetName = '직격 인터뷰', listLink = utils.config('webPcPath') + '/find/list?Keyword=%22' + encodeURIComponent(widgetName) + '%22&ServiceCode=20&SearchCategoryType=OnlyJoongangNews&display=' + encodeURIComponent(widgetName), widgetHtml = '

' + widgetName + '

', template = '', directives = { list: { link: utils.decorators.link } }; getApiData('/static/directinterview', render); function render(d) { var html = '', data = { list: [] }; try { d.List.forEach(function (v, i) { var articleLink = utils.getUrlFormat(URL_NAMES.article, v.Id); data.list.push({ link: { href: articleLink, html: v.Title } }); }); } catch (e) { utils.log(e); }; if (data.list.length) { html = $.renderTemplate({ template: template, data: data, directives: directives }); renderWidgetBody($w, widgetHtml, html); $w.show(); } else { $w.hide(); } } }; // 인기 기자 $.fn.widgetPopularReporter = function () { var $w = this; $.getScript(utils.config('staticPath') + '/scripts/data/home/js/right_today_reporter_gen.js', render); function render(d) { var idx, reporter, reporterLink, listIdx; var html = '', data = { list: [] } reporterList = utils.convertList(today_reporter_list); var strHtml = []; strHtml.push("

오늘의 기자

"); strHtml.push("
"); try { for (listIdx = 0; listIdx < reporterList.length; listIdx++) { reporter = reporterList[listIdx]; reporterLink = utils.config('webPcPath') + "/reporter/" + reporter.ReporterSeq; strHtml.push("
"); strHtml.push(""); strHtml.push("" + reporter.ReporterName + ""); strHtml.push("" + reporter.ReporterName + ""); strHtml.push("" + reporter.ReporterTitle + "
"); } } catch (e) { utils.log('widgetHomeTodayReporter'); utils.log(e); }; strHtml.push("
"); var randomRepIdx = 0; try { randomRepIdx = Math.floor(Math.random() * reporterList.length); } catch (e) { randomRepIdx = 0; } if (reporterList.length) { $w.append(strHtml.join('')); var $slideWrap = $('.slide_wrap', $w); $slideWrap.find('.slide_list').slideMotion({ infinite: true, initialSlide: randomRepIdx, slidesToShow: 1, slidesToScroll: 1, swipe: false, prevArrow: $slideWrap.find('.btn-prev'), nextArrow: $slideWrap.find('.btn-next') }); $w.show(); } else { $w.hide(); } $w.find('a').each(function () { $(this).attr('href', utils.getClocUrl($(this).attr('href'), 'joongang|home|todayreporter')); }); } }; // 추천연재 $.fn.widgetRecommendedIssues = function () { utils.log('### widgetRecommendedIssues'); var $w = this, category = ($w.data('widgetCategory') || 'Travel').toLowerCase(), widgetHtml = '' + '

추천 연재

' + '
' + '
' + '
' + '' + '
' + '
', template = '
', apiUrl = '/static/travel/recommandedseries'; directives = { list: { link: utils.decorators.link, image: utils.decorators.image } }; if (category === 'lifestyle') { apiUrl = '/static/lifestyle/recommandedseries'; } getApiData(apiUrl, render); function render(d) { var html = '', data = { list: [] }, groupIndex = 0; try { d.List.forEach(function (v, i) { var articleLink = v.Id == 0 ? v.Link : utils.getUrlFormat(URL_NAMES.article, v.Id); groupIndex = parseInt(i / 8, 16); data.list.push({ group: groupIndex, link: { href: articleLink, html: v.Title } }); }); } catch (e) { utils.log(e); }; if (data.list.length) { $w.html(widgetHtml); for (var i = 0, len = groupIndex + 1; i < len; i++) { var listData = data.list.filter(function (v) { return v.group == i; }); html = $.renderTemplate({ template: template, data: { list: listData }, directives: directives }); $w.find('.slide_list').append(html); } // 낱장일때 Widget 높이 보정. var $firstSlide = $w.find('.slide:first'); $firstSlide.closest('.slide_wrap').height($firstSlide.children().height()); //utils.log('# groupIndex : ' + groupIndex); //utils.log('children height : ' + $firstSlide.children().height()); // Page(groupIndex) 가 1개 이상이면 버튼 활성화 if (groupIndex > 0) { $w.find('.btn_wrap').show(); var $slideWrap = $('.slide_wrap', $w); $slideWrap.find('.slide_list').slideMotion({ infinite: true, slidesToShow: 1, slidesToScroll: 1, swipe: false, prevArrow: $slideWrap.find('.btn-prev'), nextArrow: $slideWrap.find('.btn-next') }); } $w.show(); } else { utils.error('widgetRecommendedIssues', true); $w.hide(); } } }; $.fn.widgetLink = function () { var $w = this, department = ($w.data('widgetCategory') || 'Politics').toLowerCase(), widgetHtml = '

정치 관련 사이트 바로가기

', template = '', linkInfo = { politics: { title: '정치', list: [ utils.linkService.getData('assembly'), utils.linkService.getData('president'), utils.linkService.getData('theminjoo'), utils.linkService.getData('saenuriparty'), utils.linkService.getData('npad'), utils.linkService.getData('bareun') ] }, money: [], society: [], world: [], mm: { title: 'Mr.밀리터리', list: [ utils.linkService.getData('mnd'), utils.linkService.getData('kida'), utils.linkService.getData('kinu'), utils.linkService.getData('csis'), utils.linkService.getData('globalsecurity'), utils.linkService.getData('38north') ] } }, data = linkInfo[department], directives = { title: { text: function (params) { return this.title + ' ' + params.value; } }, list: { link: utils.decorators.link, image: utils.decorators.image } }; render(); function render() { var html = '', data = []; try { data = linkInfo[department]; } catch (e) { }; if (data.list.length) { html = $.renderTemplate({ template: template, data: data, directives: directives }); switch (department) { case 'mm': widgetHtml = '
군사안보 관련 사이트 바로가기
'; break; default: break; } renderWidgetBody($w, widgetHtml, html); $w.show(); } else { utils.error('widgetLink', true); $w.hide(); } } }; $.fn.widgetHotClickTaboola = function () { var html = '' + '
' + ''; $(this).html(html); }; // 미주 중앙일보 핫클릭 $.fn.widgetHotClickUSA = function () { var regExp = /[\{\}\[\]\/?.,;:|\)*~`!^\-_+<>@\#$%&\\\=\(\'\"]/gi; var $w = this, widgetHtml = '
미주 중앙일보 핫클릭
', template = '
', directives = { list: { link: utils.decorators.link, title: this.title } }; getApiData('/static/hotclickusa', render); function render(d) { var html = '', data = { list: [] }; try { d.List.forEach(function (v, i) { if (v.Title) { data.list.push({ link: { href: v.Link }, title: String(v.Title).replace(/(<([^>]+)>)/ig, "") }); } }); } catch (e) { utils.log(e); }; if (data.list.length) { html = $.renderTemplate({ template: template, data: data, directives: directives }); html = widgetHtml + html; $w.html(html); $w.show(); } else { $w.hide(); } // 핫클릭 Cloc $w.find('a').each(function () { $(this).attr('href', utils.getClocUrl($(this).attr('href'), 'joongang|article|hotclickj')); }); } }; //부서별 sns $.fn.widgetDepartmentSns = function (obj) { /*
중앙일보 정치부
*/ var $w = this, defaultCategory = 'politics', category = obj.category ? obj.category.toLowerCase() : defaultCategory, SNS_URI = { joongang: { text: '중앙일보 FB', link: 'https://www.facebook.com/joongang' }, politics: { text: '정치부', link: 'https://www.facebook.com/joinspolitics' }, money: { text: '경제부', link: 'https://www.facebook.com/joinsmoney' }, society: { text: '사회부', link: 'https://www.facebook.com/joinssociety' }, world: { text: '국제부', link: 'https://www.facebook.com/joonganginternational' }, sports: { text: '스포츠', link: 'https://www.facebook.com/joongangilbosports' }, culture: { text: '문화부', link: 'https://www.facebook.com/jmoonhwa' }, opinion: { text: '오피니언', link: 'https://www.facebook.com/pages/%EC%A4%91%EC%95%99%EC%9D%BC%EB%B3%B4-%EB%85%BC%EC%84%A4%EC%9C%84%EC%9B%90%EC%8B%A4/756556791101437?fref=nf' }, travel: { text: 'Week', link: 'https://www.facebook.com/weeknplus' }, retirement: { text: '반퇴시대', link: 'https://www.facebook.com/theore88' }, magazinem: { text: '매거진M', link: 'https://www.facebook.com/magazineM2017' }, ourhistory: { text: '아워히스토리', link: 'https://www.facebook.com/ourhistoryO/' }, sunday: { text: 'SUNDAY', link: 'https://www.facebook.com/joongangsunday' }, peoplemic: { text: '시민마이크', link: 'https://www.facebook.com/peoplemic' }, lifestyle: { text: '중앙일보 강남인류', link: 'https://www.facebook.com/itisyourstyle' } }, widgetHtml = '
', snsData = SNS_URI[category] || SNS_URI[defaultCategory], link = snsData.link, text = snsData.text, html_ = '
' + '
중앙일보 ' + text + '
' + '
', html = '
' + //'
' + '
'; if (utils.browser && utils.browser.msie == true && parseInt(utils.browser.version, 10) <= 7) { //$w.browserNotice(); } else { render(); } function render() { //var html = $.renderTemplate({ data: {}, template: template, directives: directives }); $w.html(widgetHtml).show().find('.bd').html(html); if (window.FB) { window.FB.init({ appId: '1011513095546498', version: 'v2.4' }); window.FB.XFBML.parse($w[0]); } else { (function (d, s, id) { var js, fjs = d.getElementsByTagName(s)[0]; if (d.getElementById(id)) { return; } js = d.createElement(s); js.id = id; js.src = "https://connect.facebook.net/ko_KR/sdk.js#xfbml=1&version=v2.4&appId=1011513095546498"; fjs.parentNode.insertBefore(js, fjs); }(document, 'script', 'facebook-jssdk')); } } }; // PhotoVideo $.fn.widgetPhotoVideo = function () { var $w = this, widgetHtml = '

PHOTO & VIDEO

PHOTO & VIDEO 더보기
', template = '', directives = { list: { title: { link: utils.decorators.link }, thumb: { image: utils.decorators.image, link: utils.decorators.link, html: function (params) { if (this.thumb.iconClass) { $(params.element).find('a').append('동영상'); } } } } }; getApiData('/static/homephotoandvideos', render); function render(d) { var html = '', data = { cls: 'list', list: [] }; try { d.List.forEach(function (v, i) { if (i < 3) { data.list.push({ title: { link: { href: v.Link, html: v.Title } }, thumb: { link: { href: v.Link }, image: { src: v.Thumbnail, alt: v.Title }, iconClass: v.InfomationText, text: v.Title } }); } }); } catch (e) { utils.log(e); }; //utils.log(data); if (data.list.length) { html = $.renderTemplate({ data: data, template: template, directives: directives }); renderWidgetBody($w, widgetHtml, html); $w.show(); //utils.resetArticleSubWidget && utils.resetArticleSubWidget(); $('.thumb a', $w).each(function () { var $link = $(this); var href = $link.attr('href') || ''; var pathname = this.pathname; var arrPathName = pathname.split('/'); var id = arrPathName[arrPathName.length - 1]; if (isPhoto(href)) { //#화보 레이어 $link.data({ viewer: 'photo', id: id }); $link.imageViewer(); } function isPhoto(href) { return href.indexOf('pic/photoviewer') > -1; } }); } else { utils.error('widgetPhotoVideo', true); $w.hide(); } // 포토비디오 Cloc $w.find('a').each(function () { $(this).attr('href', utils.getClocUrl($(this).attr('href'), 'joongang|article|photovod')); }); } }; // widgetSpecialLink // @param options $.fn.widgetSpecialLink = function (options) { var $t = this; $t.find('.link1').loadAd({ type: 'special_link1' }); $t.find('.link2').loadAd({ type: 'special_link2' }); $t.find('.rt').loadAd({ type: 'da_250_1' }); }; // 추천 기사 $.fn.widgetRecommendedArticle = function () { $(this).load(apiPath + "/pagecall/?u=" + utils.config('webPcPath') + "/Widget/RecommendedArticles?from=article").show(); }; $.fn.widgetAppendItem = function () { }; // 주요 포털 실시간 검색어 $.fn.widgetPortalSearchKeyword = function () { //utils.log('## widgetPortalSearchKeyword'); var $w = this, widgetData = $w.data(), widgetHtml = '

주요 포털 실시간 검색어

', template = '', directives = { list: { thumb: { link: utils.decorators.link, image: utils.decorators.image, html: function (params) { if (!this.thumb.useThumbnail) { $(params.element).remove(); } } }, title: { link: utils.decorators.link }, lead: { link: utils.decorators.link } } }; getApiData('/static/portalrealtimesearchwords', render); function render(d) { var html = '', data = { list: [] }; try { d.List.forEach(function (v, i) { if (i < 10) { var link = utils.getUrlFormat(URL_NAMES.article, v.Id); data.list.push({ thumb: { link: { href: link, html: v.Title }, image: { src: utils.getIrPath(utils.getPdsFullPath(v.Thumbnail), 50, 50), alt: v.SubTitle }, useThumbnail: v.Thumbnail ? true : false }, title: { link: { href: link, html: v.Title } }, lead: { link: { href: link, html: v.SubTitle } } }); } }); } catch (e) { utils.log(e); }; if (data.list.length) { html = $.renderTemplate({ data: data, template: template, directives: directives }); renderWidgetBody($w, widgetHtml, html); $w.show(); utils.resetArticleSubWidget && utils.resetArticleSubWidget(); } else { utils.error('widgetPortalSearchKeyword', true); $w.hide(); } // cloc 적용. var clocPageType = utils.config('pageType'), cloc = ''; if (clocPageType == 'Home' || clocPageType == 'Article') { cloc = 'joongang|' + clocPageType.toLowerCase() + '|portalcheck'; } else { cloc = 'joongang|section|portalcheck'; } $w.find('a').each(function () { $(this).attr('href', utils.getClocUrl($(this).attr('href'), cloc)); }); } }; // SNS 기사 $.fn.widgetSnsArticle = function () { //utils.log('## widgetSnsArticle'); var $w = this, widgetData = $w.data(), widgetHtml = '

SNS 기사

', template = '', directives = { list: { link: utils.decorators.link, image: utils.decorators.image, thumb: { html: function (params) { if (!this.image.src) { $(params.element).remove(); } } } } }; getApiData('/article/snsarticles', render); function render(d) { var topHtml = '', html = '', data = { list: [] }; try { d.forEach(function (v, i) { if (i < 10) { data.list.push({ link: { href: utils.getUrlFormat(URL_NAMES.article, v.TotalId), html: v.Title }, image: { src: utils.getIrPath(utils.getPdsFullPath(v.Thumbnail), 50, 50), alt: v.Title } }); } }); } catch (e) { utils.log(e); }; //utils.log(data); if (data.list.length) { html = $.renderTemplate({ data: data, template: template, directives: directives }); renderWidgetBody($w, widgetHtml, topHtml + html); $w.show(); utils.resetArticleSubWidget && utils.resetArticleSubWidget(); } else { utils.error('widgetSnsArticle', true); $w.hide(); } // cloc 적용. var clocPageType = utils.config('pageType'), cloc = ''; if (clocPageType == 'Home' || clocPageType == 'Article') { cloc = 'joongang|' + clocPageType.toLowerCase() + '|snscheck'; } else { cloc = 'joongang|section|snscheck'; } $w.find('a').each(function () { $(this).attr('href', utils.getClocUrl($(this).attr('href'), cloc)); }); } }; var regTitleFilter = /[\{\}\[\]\/?.,;:|\)*~`!^\-_+<>@\#$%&\\\=\(\'\"]/gi; // 주요 뉴스 $.fn.widgetMajorArticle = function () { //return false; //utils.log('## widgetMajorArticle'); var $w = this, widgetData = $w.data(), apiFormat = '/static/wide/majorarticles', widgetHtml = '

주요뉴스

중앙일보 주요기사를 읽어보세요

', template = '', directives = { list: { link: utils.decorators.link, image: utils.decorators.image, thumb: { html: function (params) { if (!this.image.src) { $(params.element).remove(); } } } } }; getApiData(apiFormat, render); function render(d) { //utils.log('----------------widgetMajorArticle'); //utils.log(d); var topHtml = '', html = '', data = { list: [] }, pathname = location.pathname.toLowerCase(), clocName = ''; try { d.List.forEach(function (v, i) { var alt = v.Title.replace(regTitleFilter, ''); if (i < 10) { data.list.push({ type: v.Type, link: { href: $.trim(v.Link), html: v.Title }, image: { src: utils.getPdsFullPath(v.Thumbnail), alt: alt } }); } }); } catch (e) { utils.log(e); }; if (data.list.length) { //html = $.renderTemplate({data: data, template: template, directives: directives}); //renderWidgetBody($w, widgetHtml, topHtml + html); $w.html(widgetHtml).show(); data.list.forEach(function (v, i) { appendItem(v, i); }); $w.show(); utils.resetArticleSubWidget && utils.resetArticleSubWidget(); } else { utils.error('widgetMajorArticle', true); $w.hide(); } function appendItem(item, i) { var html = '
  • '; if (item.image.src) { html += '' + item.image.alt + ''; } html += ''; html += '
  • '; var $html = $(html); $html.find('strong a').html(item.link.html); $w.find('ul').append($html); } // 더보기 주요뉴스 Cloc if (pathname == '/') { clocName = 'joongang|home|morehomenews'; } else if (pathname.indexOf('article') > -1) { clocName = 'joongang|article|morehomenews'; } else { clocName = 'joongang|section|morehomenews'; } $w.find('a').each(function () { $(this).attr('href', utils.getClocUrl($(this).attr('href'), clocName)); }); } }; // 지면보다 빠른 뉴스 //$.fn.widgetFastNews = function () { // //utils.log('## widgetFastNews'); // var $w = this, // widgetData = $w.data(), // //widgetHtml = // template = '' + // '
    지면보다 빠른 뉴스

    디지털에서만 만날 수 있는 중앙일보 뉴스

    ' + // '
    ' + // '
    ' + // '' + // '
    ' + // '
    ', // listTemplate = '' + // '', // directives = { // list: { // link: utils.decorators.link, // image: utils.decorators.image, // thumb: { // html: function (params) { // if (!this.image.src) { // $(params.element).remove(); // } // } // } // } // }; // getApiData('/article/fastarticles', render); // function render(d) { // var html = '', // data = { times: [], list: [] }, // pathname = location.pathname.toLowerCase(), // clocName = '', // serviceDate = ''; // try { // d.forEach(function (v, i) { // serviceDate = v.RegistedDateTime; // if (serviceDate.indexOf('.') > -1) { // serviceDate = serviceDate.substr(0, serviceDate.indexOf('.')); // } // serviceDate = serviceDate.toDateISO8061().format('HH:00'); // if (!data.times.filter(function (v) { // return v.time == serviceDate; // }).length) { // data.times.push({ time: serviceDate }); // } // data.list.push({ // time: serviceDate, // link: { href: utils.getUrlFormat(URL_NAMES.article, v.TotalId), html: v.Title }, // image: { src: utils.getIrPath(utils.getPdsFullPath(v.Thumbnail.replace('.tn_120.jpg', '')), 170, 126, '.tn_350.jpg'), alt: v.Title } // }); // }); // } catch (e) { // utils.log(e); // }; // if (data.times.length) { // html = $.renderTemplate({ data: { group: data.times }, template: template }); // //utils.log(html); // $w.html(html).show().find('[data-bind="time"]').each(function () { // var $group = $(this), // time = $group.text(), // listData = data.list.filter(function (v) { // return v.time == time; // }), // listHtml = html = $.renderTemplate({ data: { list: listData }, template: listTemplate, directives: directives }); // $group.parent().append(listHtml); // }); // } else { // utils.error('widgetFastNews', true); // $w.hide(); // } // // 지면보다 빠른뉴스 Cloc // if (pathname == '/') { // clocName = 'joongang|home|moredigitalfirst'; // } else if (pathname.indexOf('article') > -1) { // clocName = 'joongang|article|moredigitalfirst'; // } // else { // clocName = 'joongang|section|moredigitalfirst'; // } // $w.find('a').each(function () { // $(this).attr('href', utils.getClocUrl($(this).attr('href'), clocName)); // }); // } //}; // 지면보다 빠른 뉴스 $.fn.widgetFastNews = function () { var clocName = ""; var pathname = location.pathname.toLowerCase(); if (pathname == '/') { clocName = 'home'; } else if (pathname.indexOf('article') > -1) { clocName = 'article'; } else { clocName = 'section'; } var apiUrl = apiPath + "/pagecall/?u=" + utils.config('webPcPath') + encodeURIComponent("/Widget/FastNews?from=)" + clocName); $(this).load(apiUrl).show(); }; // 와이드 영역 트렌드 뉴스 $.fn.widgetTrendArticle = function () { // 실시간 추천 뉴스 Cloc var clocName = ""; var pathname = location.pathname.toLowerCase(); if (pathname == '/') { clocName = 'home'; } else if (pathname.indexOf('article') > -1) { clocName = 'article'; } else { clocName = 'section'; } var apiUrl = apiPath + "/pagecall/?u=" + utils.config('webPcPath') + encodeURIComponent("/Widget/TrendArticle?from=" + clocName + "&sort=attention"); $(this).load(apiUrl).show(); }; //포토 이슈 $.fn.widgetPhotoIssues = function () { var $w = this; $w.find('.current_page').text('1'); $w.find('.total_page').text($w.data("count")); var $slideWrap = $('.slide_list_wrap', $w), $thumbItems = $('div.thumb_list li', $w); $slideWrap.find('.slide').eq(0).addClass('active'); $thumbItems.find('.slide').eq(0).addClass('active'); $slideWrap.find('.slide_list').slideMotion({ infinite: true, slidesToShow: 1, slidesToScroll: 1, swipe: false, thumbnails: $thumbItems, prevArrow: $slideWrap.find('.btn-prev'), nextArrow: $slideWrap.find('.btn-next'), beforeChange: function (event, slick, currentIndex, nextIndex) { $thumbItems.eq(nextIndex).addClass('active').siblings().removeClass('active'); $w.find('.current_page').text(nextIndex + 1); } }); $w.show(); }; // 많이 본 기사 $.fn.widgetHotArticles = function () { $('#widget_favorite_articlesAD').loadAd({ type: 'favorite_ad' }).show(); //utils.log('---------------------widgetHotArticles start'); //많이 본 기사 하단광고 var $w = this, pageType = utils.config('pageType'), apiFormat = '/static/mostviewedarticles/{KEY}', categoryKey = $w.data('widgetCategory') || '', title = (categoryKey.toLowerCase() == 'jplus' ? '많이 본 J플러스' : '많이 본 기사'), widgetHtml = '

    ' + title + '

    ', template = '', directives = { list: { link: utils.decorators.link, image: utils.decorators.image, item: { 'class': function (obj) { return obj.index < 3 ? 'top' : ''; } } } }; if (pageType === PAGE_TYPE.article) { var sectionKey = utils.menu.getPageMenuKey().split(',')[0].toLowerCase(); categoryKey = sectionKey; if (categoryKey != null && categoryKey == 'worldcup2018') categoryKey = 'sports'; // 종합의 경우 categoryKey를 셋팅하지 않는다. api에서 categoryKey가 없을 경우 종합으로 데이터를 내려줌. switch (categoryKey) { case 'university': case 'cartoon': case 'ourhistory': case 'resetkorea': case 'nk': case 'brandnews': categoryKey = ''; break; } } $w.hide(); getApiData(apiFormat.replace('{KEY}', categoryKey), render); function render(d) { //utils.log('---------------------widgetHotArticles 1'); var html = '', data = { list: [] }; try { d.List.forEach(function (v, i) { data.list.push({ link: { href: utils.getUrlFormat(URL_NAMES.article, v.Id), html: v.Title }, position: (i + 1) }); }); } catch (e) { //utils.log('widgetHotArticles'); utils.log(e); }; //utils.log(data); if (data.list.length) { html = $.renderTemplate({ template: template, data: data, directives: directives }); renderWidgetBodyPrepend($w, widgetHtml, html); $w.show(); utils.resetArticleSubWidget && utils.resetArticleSubWidget(); } else { $w.hide(); } // 많이 본 기사 Cloc - 미확인 $w.find('a').each(function () { var pageType = utils.config('pageType') || ''; pageType = pageType.toLowerCase(); $(this).attr('href', utils.getClocUrl($(this).attr('href'), 'joongang|' + pageType + '|clickraking')); }); } }; // 많이 본 동영상 ( general, opinion ) $.fn.widgetHotVideos = function () { var $w = this, categoryKey = $w.data('widgetCategory') || '', apiUrl = '/static/mostviewedvideos', widgetHtml = '

    많이 본 동영상

    ', template = '