/** * 생성일자 Formatting * @param date * @param format * @returns {string} */ function getFormattedDate(date, format) { // 현재 시간 var d = new Date(date.substring(0, date.length - 9)); var now = new Date(); // 분 단위로 현재 시간과 input 시간의 차이를 계산 var diffMs = (now - d); // 차이가 1시간 이내이면 if (diffMs < 36000000) { var diffMins = Math.round(((diffMs % 86400000) % 3600000) / 60000); } else { diffMins = 100 } if (format === 'yyyy.mm.dd') { return d.getFullYear() + "." + ('0' + (d.getMonth() + 1)).slice(-2) + "." + ('0' + d.getDate()).slice(-2); } // // console.log(d); // // console.log(diffMins); // 1분 전일 경우 -> 방금 전 // if (diffMins === 0) { // return "방금"; // // 60분 전 일경우 -> 몇 분 전 // } else if (diffMins < 61) { // return diffMins + "분전"; // // 이후 YYYY.MM.DD hh:mm // } else { // if (format === 'yyyy.mm.dd hh:mm') { d = d.getFullYear() + "." + ('0' + (d.getMonth() + 1)).slice(-2) + "." + ('0' + d.getDate()).slice(-2) + " " + ('0' + d.getHours()).slice(-2) + ":" + ('0' + d.getMinutes()).slice(-2); // } return d; // } } /** * 기사 URL * @return */ function getArticleUrl(article) { if (article === null) { return ""; } return "/News/Read/" + article.articleId; } /** * 이미지 경로 * @param fileServer * @param filePath * @return */ function getFilePath(fileServer, filePath) { if (!filePath) { return "/images/Default-Image.png"; } if(/^(http|https)\:\/\//.test(filePath)){ return filePath; }else{ filePath = fileServer + (filePath.indexOf("/") == 0 ? filePath : "/cms/articlerelease/" + filePath); return filePath; } } /** * 기사 썸네일 파일 경로 * @param fileServer * @param articleId * @param file * @returns {string} */ function getArticleThumbnailFilePath(fileServer, articleId, file) { if (file==null || file.filePath === undefined) return ""; var filePath = file.filePath; var fileOriginExt = file.fileOriginExt; if (!file) { return "/images/Default-Image.png"; } if ("" == fileOriginExt.trim() ){ fileOriginExt = filePath.substring(filePath.lastIndexOf('.')+1 ); } if(articleId.indexOf("A") == 0) { if(filePath.indexOf("/cms") > -1 || (filePath.indexOf("/") != 0 && filePath.indexOf("http")!=0) ){ // to-be data return fileServer + "/cms/thumbnail/articlerelease/" + articleId.substring(1,5) + "/" + articleId.substring(5,7) + "/" + articleId.substring(7,9) + "/" + articleId + "." + fileOriginExt; } else if(filePath.indexOf("herb-api") > -1){ return filePath; } else{ var filePathArr = filePath.split("."); filePathArr[filePathArr.length-2] = filePathArr[filePathArr.length-2]+"_t"; filePath = filePathArr.join("."); return filePath; } } else { // as-is data return getFilePath(fileServer, filePath); } } function getImageThumbnailFilePath(fileServer, path) { if (!path) { return "/images/Default-Image.png"; } var filePath = fileServer + path; return filePath; } /** * 대표 이미지 경로 * @param fileServer * @param article * @returns {string} */ function getRepFilePath(fileServer, article) { if (!article) { return "/images/Default-Image.png"; } var filePath = ''; if (article.articleWebAttach) { filePath = article.articleWebAttach.filePath; } else if (article.repAttach) { filePath = article.repAttach.filePath; } return getFilePath(fileServer, filePath); } function getShoulderUrl(shoulder) { if (!shoulder) { return ""; } if ("LIVEISSUE" === shoulder.articleShoulderType) { return "/Liveissue/" + shoulder.shoulderId; } else { return "/Series/" + shoulder.shoulderId; } } // show loading function showLoading() { $("#commonLoading").addClass('on'); } // hide loading function hideLoading() { $("#commonLoading").removeClass('on'); } // create loading function createLoading() { var loading = '
'; $("body").append(loading); } // 세자리수 마다 콤마 function numberWithCommas(x) { return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","); } function Request() { this.getParameter = function(name) { var rtnval = ''; var nowAddress = unescape(location.href); var parameters = (nowAddress.slice(nowAddress.indexOf('?') + 1, nowAddress.length)).split('&'); for (var i = 0; i < parameters.length; i++) { var varName = parameters[i].split('=')[0]; if (varName.toUpperCase() == name.toUpperCase()) { rtnval = parameters[i].split('=')[1]; break; } } return rtnval; } } var request = new Request(); // 이어보기 기사 id 삭제 function removeLastReadArticle() { var param = {lastReadArticleId: 'null'}; $.ajax({ url: '/users/me', method: 'PATCH', contentType: 'application/json', data: JSON.stringify(param), success: function (response) { if (response.data) { // console.log('이어보기 기사 삭제 성공') } else { // console.log('이어보기 기사 삭제 실패') } } }) } /** * 기사 컷 제목 * @param article * @return */ function getArticleCutName(article) { if (!article) { return ""; } if ("Speed" === article.articleType) { return "[속보] "; } else if ("Exclusive" === article.articleType) { return "[단독] "; } return ""; } function replaceCut(title) { switch (true) { case /^\[LIVE\]/g.test(title) : return title.replace(/^\[LIVE\]/g, 'Live'); default : return title; } } /** * uuid 생성 * @returns {string} */ function getUUID() { // UUID v4 generator in JavaScript (RFC4122 compliant) return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 3 | 8); return v.toString(16); }); } // 랜덤 섞기 function shuffle(a) { var j, x, i; for (i = a.length; i; i -= 1) { j = Math.floor(Math.random() * i); x = a[i - 1]; a[i - 1] = a[j]; a[j] = x; } } // get sub domain function getSubdomain() { var hostname = document.domain; var regexParse = new RegExp('[a-z\-0-9]{2,63}\.[a-z\.]{2,5}$'); var urlParts = regexParse.exec(hostname); var subDomain = hostname.replace(urlParts[0],'').slice(0, -1); return hostname.substr(subDomain.length); } var reloadSTO = undefined; /** * 페이지 3분 마다 리로드 */ function refreshPage() { if (reloadSTO !== undefined) { clearTimeout(reloadSTO); } reloadSTO = setTimeout(function() { // 메인주제판 let isMainPage = $(".container.main"); if(isMainPage.length){ // setCookie("hk_topic_view", isMainPage.find(".category-tab .tab-list li.on").data("id")); fn_setCookie("hk_topic_view", isMainPage.find(".category-tab .tab-list li.on").data("id")); } location.reload(); }, 180000); } /** * 3분 마다 리로드 해제 */ function stopRefreshPage() { if (reloadSTO !== undefined) { clearTimeout(reloadSTO); reloadSTO = undefined; } } /** * UUID 생성 * @returns {string} */ function generateUuid() { return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8); return v.toString(16); }); } function getUsersSubscriptionYNCheck(usersSubscriptionPart="empty", usersSubscriptionValue="empty") { let seriesType = usersSubscriptionPart; switch (usersSubscriptionPart){ case 'SeriesColumn': seriesType = 'NEWS_SERIES' break; case 'Planning': seriesType = 'NEWS_PLANNING' break; case 'Series': seriesType = 'NEWS_PLANNING' break; case 'NameColumn': seriesType = 'NEWS_SERIES' break; } const url = '/api/section/users-subscription-yn-check?usersSubscriptionValue='+usersSubscriptionValue+'&usersSubscriptionPart='+seriesType; var subscriptionYN = false; $.ajax({ url: url, method: 'GET', contentType: 'application/json', async: false, }).success(function (response) { var flag = response.message; if ('Y' === flag) { subscriptionYN = true; // console.log('구독가능 :'+seriesType+ ', '+usersSubscriptionValue); } else { // console.log('구독불가 :'+seriesType+ ', '+usersSubscriptionValue); //$('.btn-subsc').removeClass('on'); } }).fail(function (err) { }); return subscriptionYN; } //웹 취약점 - cookie 속성 누락 (secure, samesite) 적용하기 위한 함수 생성 //일괄적용위해 만든 함수, 추후 생성시에는 기존대로 Cokies.set 형식으로 생성해도 됨(단 secure, samesite 포함) const fn_setCookie = (name, value, options= {}) => { const data = { ...options, secure: true, samesite: 'None' }; Cookies.set(name, value, data); } $(document).ready(function () { // createLoading(); });