var SITE = function(){
var openPolicy = function(is_sub){
is_sub = (is_sub == true);
if(!is_sub){
$.cocoaDialog.close();
}
$.ajax({
type: 'POST',
data: {},
url: ('/dialog/policy.cm'),
dataType: 'html',
async: true,
cache: false,
success: function(html){
var $html = $(html);
$.cocoaDialog.open({type: 'site_policy', custom_popup: $html});
}
});
};
var openPrivacy = function(){
$.cocoaDialog.close();
$.ajax({
type: 'POST',
data: {},
url: ('/dialog/privacy.cm'),
dataType: 'html',
async: true,
cache: false,
success: function(html){
var $html = $(html);
$.cocoaDialog.open({type: 'site_privacy', custom_popup: $html});
}
});
};
var openDomestic = function(){
$.cocoaDialog.close();
$.ajax({
type: 'POST',
data: {},
url: ('/dialog/tour_policy_domestic.cm'),
dataType: 'html',
async: true,
cache: false,
success: function(html){
var $html = $(html);
$.cocoaDialog.open({type: 'site_domestic', custom_popup: $html});
}
});
};
var openOverseas = function(){
$.cocoaDialog.close();
$.ajax({
type: 'POST',
data: {},
url: ('/dialog/tour_policy_overseas.cm'),
dataType: 'html',
async: true,
cache: false,
success: function(html){
var $html = $(html);
$.cocoaDialog.open({type: 'site_overseas', custom_popup: $html});
}
});
};
var openDomesticOverseas = function(){
$.cocoaDialog.close();
$.ajax({
type: 'POST',
data: {},
url: ('/dialog/tour_policy.cm'),
dataType: 'html',
async: true,
cache: false,
success: function(html){
var $html = $(html);
$.cocoaDialog.open({type: 'site_domesticoverseas', custom_popup: $html});
}
});
};
var openThirdParty = function(){
$.cocoaDialog.close();
$.ajax({
type: 'POST',
data: {},
url: ('/dialog/third_party.cm'),
dataType: 'html',
async: true,
cache: false,
success: function(html){
var $html = $(html);
$.cocoaDialog.open({type: 'site_thirdparty', custom_popup: $html});
}
});
};
var openOauthDataInterlock = function(){
$.cocoaDialog.close();
$.ajax({
type: 'POST',
data: {},
url: ('/dialog/oauth_data_interlock.cm'),
dataType: 'html',
async: true,
cache: false,
success: function(html){
var $html = $(html);
$.cocoaDialog.open({type: 'site_thirdparty', custom_popup: $html});
}
});
};
/**
* 모달 메뉴를 띄움
* @param menu_code 모달 메뉴의 menu_code
* @param base_menu_code 모달 밖에 깔리는 메뉴(모달을 호출한 메뉴)의 menu_code, 모달 내부에서 back_url 처리 등을 위해 사용
*/
var openModalMenu = function(menu_code, base_menu_code){
$.cocoaDialog.close();
$.ajax({
type: 'POST',
data: {
'menu_code': menu_code,
'base_menu_code': base_menu_code
},
url: ('/ajax/get_modal_menu.cm'),
dataType: 'json',
async: true,
cache: false,
success: function(res){
if ( res.msg === 'SUCCESS' ) {
// 웹접근성을 위해 모달 열기 전에 마지막 포커스를 저장하고 모달 닫힐 때 해당 포커스로 복귀
let lastFocus = document.activeElement;
$.cocoaDialog.open({
type: 'site_modal_menu',
custom_popup: res.html,
opened: function(){
$('.modal_site_modal_menu').attr('tabindex', 0).attr('role', 'dialog');
$('.modal_site_modal_menu').lightGallery({
selector: '._image_widget_lightbox',
thumbnail: false,
animateThumb: false,
swipeThreshold : 20,
showThumbByDefault: false,
mode: 'lg-fade',
speed: 200,
galleryId: 'img_lg',
});
},
hide_event: async function(e){
const target = $(e.target);
if (target.data('lightGallery')) await target.data('lightGallery').destroy(true);
target.removeData('bs.modal').find('.modal-content').html('');
$('.modal_site_modal_menu').attr('tabindex', -1).attr('role', '');
// 이전 포커스 복귀 및 포커스 초기화
if (lastFocus) lastFocus.focus();
lastFocus = null;
}
});
} else {
alert(res.msg);
}
}
});
};
var changeAlarmCheckbox = function(obj, is_mobile){
if(is_mobile == 'Y'){
$('#alarm_popup').find("input:checkbox").prop("checked", false);
var $alarm_popup = $('#alarm_popup_mobile');
}else{
$('#alarm_popup_mobile').find("input:checkbox").prop("checked", false);
var $alarm_popup = $('#alarm_popup');
}
if($(obj).hasClass("_all")){
$alarm_popup.find("input:checkbox").not(":disabled").prop("checked", obj.checked);
toggleAlarmActive(is_mobile);
}else{
var $alarm_checkbox_list = $alarm_popup.find("input:checkbox").not("._all").not(":disabled");
var count_total = $alarm_checkbox_list.length;
var count_check = $alarm_checkbox_list.filter(":checked").length;
if(count_total == count_check && (count_check != 0 && count_total != 0)){
$alarm_popup.find("._all").prop("checked", true);
}else{
$alarm_popup.find("._all").prop("checked", false);
}
toggleAlarmActive(is_mobile);
}
};
var toggleAlarmPopup = function(is_mobile){
if(is_mobile == 'Y'){
var $alarm_popup = $('#alarm_popup_mobile');
var $dLabel = $('#dLabel_mobile');
var $id = 'alarm_popup_mobile';
var $clos_id = 'alarm_popup';
var $layer = '_alarm_layer_mobile';
}else{
var $alarm_popup = $('#alarm_popup');
var $dLabel = $('#dLabel');
var $id = 'alarm_popup';
var $clos_id = 'alarm_popup_mobile';
var $layer = '_alarm_layer';
}
$alarm_popup.toggleClass('open');
if($alarm_popup.hasClass('open')){
$(window).off('mousedown.'+$clos_id);
$(window).on('mousedown.'+$id,function(event){
if($(event.target).closest('.'+$layer).length == 0){
$alarm_popup.removeClass('open');
$(window).off('mousedown.'+$id);
}
});
}
};
var toggleAlarmActive = function(is_mobile){
if(is_mobile == 'Y'){
var $alarm_popup = $('#alarm_popup_mobile');
var $dLabel = $('#dLabel_mobile');
}else{
var $alarm_popup = $('#alarm_popup');
var $dLabel = $('#dLabel');
}
var count_check = $alarm_popup.find("li input:checkbox:checked").length;
if(count_check == 0){
$dLabel.removeClass('active');
}else{
$dLabel.addClass('active');
}
};
var androidUpdateAlert = function (package) {
$.ajax({
type : 'POST',
data: {'package':package},
url : ('dialog/android_update_form.cm'),
dataType : 'html',
async : false,
cache : false,
success : function(html){
$.cocoaDialog.open({type : 'site_alert', custom_popup : $(html)});
}
});
};
var firstScrollFixed = function(id){
var stop_fixed = {};
var fixed_observer = null;
clearInterval(stop_fixed);
// 최상단에서 scrollToFixed가 붙인 scroll-to-fixed-fixed를 fixed2로 변환 (겹치기 투명 상태 유지)
var convertFixedAtTop = function(){
var $fixed = $('#' + id).find('div[data-type="section-wrap"].scroll-to-fixed-fixed');
var $fixed2 = $('#' + id).find('div[data-type="carousel_menu"].scroll-to-fixed-fixed');
if($fixed.length > 0 || $fixed2.length > 0){
$fixed.toggleClass('scroll-to-fixed-fixed', false).toggleClass('scroll-to-fixed-fixed2', true);
$fixed2.toggleClass('scroll-to-fixed-fixed', false).toggleClass('scroll-to-fixed-fixed2', true);
return true;
}
return false;
};
var setCss = function(id){
var top = $(window).scrollTop();
clearInterval(stop_fixed);
if(top > 0){
if(fixed_observer){
fixed_observer.disconnect();
fixed_observer = null;
}
$('#'+id).toggleClass('first_scroll_fixed',false);
$('#' + id).find('div[data-type="section-wrap"].scroll-to-fixed-fixed2').toggleClass('scroll-to-fixed-fixed',true).toggleClass('scroll-to-fixed-fixed2',false);
$('#' + id).find('div[data-type="carousel_menu"].scroll-to-fixed-fixed2').toggleClass('scroll-to-fixed-fixed',true).toggleClass('scroll-to-fixed-fixed2',false);
}else{
$('#'+id).toggleClass('first_scroll_fixed',true);
if(window.MutationObserver && document.getElementById(id)){
// 폴링(200ms) 대기 중 상단 기본 배경이 잠깐 노출되는 깜빡임 방지: 클래스가 붙는 즉시(paint 전) 변환 (IMOPS-14635)
if(!fixed_observer){
fixed_observer = new MutationObserver(function(){
if($(window).scrollTop() > 0){
return;
}
convertFixedAtTop();
});
fixed_observer.observe(document.getElementById(id), {attributes: true, attributeFilter: ['class'], subtree: true});
}
}else{
stop_fixed = setInterval(function(){
if(convertFixedAtTop()){
clearInterval(stop_fixed);
}
},200);
}
convertFixedAtTop();
}
};
$(window).bind('scroll.firstScrollFixed',function(){
setCss(id);
});
$(window).bind('resize.firstScrollFixed',function(){
setCss(id);
});
setCss(id);
};
/**
*
* @returns {boolean}
*/
var setBookMark = function(){
var bookmarkURL = window.location.href;
var bookmarkTitle = document.title;
var triggerDefault = false;
if (window.sidebar && window.sidebar.addPanel) {
// Firefox version < 23
window.sidebar.addPanel(bookmarkTitle, bookmarkURL, '');
} else if ((window.sidebar && (navigator.userAgent.toLowerCase().indexOf('firefox') > -1)) || (window.opera && window.print)) {
// Firefox version >= 23 and Opera Hotlist
var $this = $(this);
$this.attr('href', bookmarkURL);
$this.attr('title', bookmarkTitle);
$this.attr('rel', 'sidebar');
$this.off(e);
triggerDefault = true;
} else if (window.external && ('AddFavorite' in window.external)) {
// IE Favorite
window.external.AddFavorite(bookmarkURL, bookmarkTitle);
} else {
// WebKit - Safari/Chrome
alert(LOCALIZE.설명_즐겨찾기등록키안내( (navigator.userAgent.toLowerCase().indexOf('mac') != -1 ? 'Cmd' : 'Ctrl') + '+D') );
}
return triggerDefault;
};
var setSnsShare = function(_type, snsDataOrEl){
var snsData = null;
if (snsDataOrEl) {
if (snsDataOrEl instanceof HTMLElement) {
var attr = snsDataOrEl.getAttribute('data-sns-share');
if (attr) {
try { snsData = JSON.parse(attr); } catch(e) {}
}
} else if (typeof snsDataOrEl === 'object') {
snsData = snsDataOrEl;
}
}
SNS.init(snsData || MENU_SNS_INIT_DATA);
switch(_type){
case 'kakaotalk':
SNS.shareKakaoTalk();
break;
case 'line':
SNS.shareLine();
break;
case 'band':
SNS.shareBand();
break;
case 'naver':
SNS.shareNaver();
break;
case 'facebook':
SNS.shareFacebook();
break;
case 'twitter':
SNS.shareTwitter();
break;
case 'default':
default:
SNS.showDefalutSnsShareList();
break;
}
};
/**
* 대상 없이 단일 라이트갤러리를 띄움
* @param d {type: gallery 또는 video, img_url: gallery일 때 url, video_url: video일 때 url, loop: video일 때 반복재생 여부 Y 또는 N, hide_title: video일 때 타이틀 숨김 여부 Y 또는 N}
*/
var showLightGallery = function(d){
var _data = d;
var _type = _data.type;
var modalZ = 17000;
if($('#cocoaModal').length == 1) modalZ = $('#cocoaModal').css('z-index'); // 모달의 z-index보다 상위로 설정
if(_type == 'gallery'){
var img_url = _data.img_url;
var $_body = $("body");
if($("#lg-temp-gallery").length > 0){ // 이전에 사용된 라이트갤러리 제거
$("#lg-temp-gallery").remove();
}
var $_html = '
' +
'';
$_body.append($_html);
$("#lg-temp-gallery").lightGallery();
$("#lg-temp-gallery a").trigger('click');
}else if(_type == 'video'){
var video_url = _data.video_url; // 바른 주소가 아닐 경우 예외처리 필요
var loop = _data.loop;
var hide_title = _data.hide_title;
var youtube_id = '';
var video_id = getVideoId(video_url);
if(typeof video_id != 'undefined'){
if (typeof video_id['youtube'] != 'undefined' && video_id['youtube'][1] != ''){
youtube_id = video_id['youtube'][1];
}
}
var $_body = $("body");
if($("#lg-temp-gallery").length > 0){
$("#lg-temp-gallery").remove();
}
var $_html = '' +
'';
$_body.append($_html);
// vimeo의 경우 자동재생 시에는 타이틀 노출이 되지 않으므로 자동재생이 되지 않는 모바일에서 타이틀 확인 가능
// YouTube는 playlist 인자를 넘길 경우 매일 1회 동영상을 제대로 못부르는 경우가 발생함
var lg_option = {
youtubePlayerParams: {
rel : 0,
showinfo: hide_title=='Y'?0:''
},
vimeoPlayerParams : {
autoplay : 1,
rel : 0,
title: hide_title=='Y'?0:1
},
controls: 0,
zoom: false,
fullScreen: false,
download: false,
counter: false,
hash: false,
videoMaxWidth:1140
};
if(loop === 'Y'){
lg_option.youtubePlayerParams = Object.assign(lg_option.youtubePlayerParams, {loop: 1, playlist: youtube_id});
lg_option.vimeoPlayerParams = Object.assign(lg_option.vimeoPlayerParams, {loop: 1});
}
$("#lg-temp-gallery").lightGallery(lg_option);
$("#lg-temp-gallery a").trigger('click');
}
};
var hidePermissionMenu = function(){
if($('.pms_check').length > 0){
$.ajax({
type: 'POST',
data: {unit_code : UNIT_CODE},
url: ('/ajax/get_permission_limit_menu_list.cm'),
dataType: 'json',
async: true,
cache: false,
success: function(res){
if(res.msg === 'SUCCESS'){
var limit_menu_list = res.limit_menu_list;
$.each(limit_menu_list, function(key, value){
$('.pms_check[data-code=' + value + ']').remove();
});
$('.pms_check').removeClass('pms_check');
rebuildMobileTableMenu();
rebuildSlideMenu();
}else{
$('.pms_check').remove();
}
},
error: function(){
$('.pms_check').remove();
}
});
}
};
var rebuildMobileTableMenu = function(){
var $mobile_table_nav_wrap = $('._mobile_table_nav_wrap');
if($mobile_table_nav_wrap.length > 0){
var table_line_count = $mobile_table_nav_wrap.data('table_line_count');
var nav_item_cnt = 0;
var rebuild_table_html = '';
$mobile_table_nav_wrap.find('td[data-rel=table_nav]').each(function(key, value){
if(nav_item_cnt == 0){
rebuild_table_html += "";
}
rebuild_table_html += value.outerHTML;
nav_item_cnt++;
if(nav_item_cnt % table_line_count == 0){
rebuild_table_html += "
";
}
});
var table_row_cnt, max_item_cnt, empty_cnt;
if(nav_item_cnt > 0){
table_row_cnt = Math.ceil(nav_item_cnt / table_line_count);
max_item_cnt = table_row_cnt * table_line_count;
empty_cnt = max_item_cnt - nav_item_cnt;
}
for(var i = 0; i < empty_cnt; i++){
rebuild_table_html += ' | ';
if(i == empty_cnt - 1){
rebuild_table_html += '';
}
}
$mobile_table_nav_wrap.html(rebuild_table_html);
}
};
var rebuildSlideMenu = function(){
MOBILE_SLIDE_MENU.rebuildAccordion();
PC_SLIDE_MENU.rebuildAccordion();
};
var setViewportBtn = function(color, background_color){
var $last_section = $('body');
var viewport_mode = getCookie('viewport_mode');
if($('#doz_footer').length > 0){
$last_section = $('#doz_footer .footer-section .inside');
}else{
if(viewport_mode === 'PC'){
var $pc_section = $('div[doz_type=section][doz_mobile_section=N]');
if($pc_section.length > 0){
var $pc_section_last = $($pc_section[$pc_section.length - 1]);
if($pc_section_last.hasClass('visual_section')){
$last_section = $pc_section_last;
}else{
var $pc_section_last_inside = $pc_section_last.find('div[doz_type=inside], div[doz_type=row]');
$last_section = $($pc_section_last_inside[$pc_section_last_inside.length - 1]);
}
}
}else{
var $mobile_show_section = $('div[doz_type=section][doz_mobile_hide=N]');
if($mobile_show_section.length > 0){
var $mobile_show_section_last = $($mobile_show_section[$mobile_show_section.length - 1]);
if($mobile_show_section_last.hasClass('visual_section')){
$last_section = $mobile_show_section_last;
}else{
var $mobile_show_section_last_inside = $mobile_show_section_last.find('div[doz_type=inside], div[doz_type=row]');
$last_section = $($mobile_show_section_last_inside[$mobile_show_section_last_inside.length - 1]);
}
}
}
}
if(viewport_mode === 'PC'){
var pc_mode_str = getLocalizeString('타이틀_모바일모드로보기', '', '모바일 모드로 보기');
}else{
var pc_mode_str = getLocalizeString('타이틀_PC모드로보기', '', 'PC 모드로 보기');
}
var border_color = tinycolor(color).setAlpha(tinycolor(color).getAlpha() * 0.2).toRgbString();
$last_section.append('' + pc_mode_str + '
');
};
var toggleViewport = function(){
var viewport_mode = getCookie('viewport_mode');
if(viewport_mode === 'PC'){
setCookie('viewport_mode', 'm');
}else{
setCookie('viewport_mode', 'PC');
}
location.href = location.search;
};
var alarm_html_data = {"group_html":"","app_html":""};
var is_loaded = false;
/***
* 알림 발송 타겟 리스트 불러오기
*/
var loadAlarmTargetList = function(board_code){
if(alarm_html_data.group_html === ""){
if(!is_loaded){
var $alarm_popup = $('#alarm_popup');
var $alarm_popup_mobile = $('#alarm_popup_mobile');
$.ajax({
type: 'POST',
data: {'board_code' : board_code},
url: ('/ajax/get_alarm_target_list.cm'),
dataType: 'json',
async: true,
cache: false,
success: function(res){
is_loaded = true;
if(res.msg === 'SUCCESS'){
alarm_html_data.group_html= res.group_html;
alarm_html_data.app_html= res.app_html;
$alarm_popup.find(".dLabel").html('').append(alarm_html_data.group_html);
$alarm_popup.find("._alarm_layer").append(alarm_html_data.app_html);
$alarm_popup_mobile.find(".dLabel").html('').append(alarm_html_data.group_html);
$alarm_popup_mobile.find("._alarm_layer_mobile").append(alarm_html_data.app_html);
$alarm_popup.find("._all_check").off("click._all_check").on("click._all_check",function(){
SITE.changeAlarmCheckbox(this,'N');
});
$alarm_popup_mobile.find("._all_check").off("click._all_check_m").on("click._all_check_m",function(){
SITE.changeAlarmCheckbox(this,'Y');
});
$alarm_popup.find("._alarm_group_list").off("click._alarm_group_list").on("click._alarm_group_list",function(){
SITE.changeAlarmCheckbox(this,'N');
});
$alarm_popup_mobile.find("._alarm_group_list").off("click._alarm_group_list_m").on("click._alarm_group_list_m",function(){
SITE.changeAlarmCheckbox(this,'Y');
});
}
},
error: function(){
is_loaded = true;
}
});
}
}
};
const createTermsMode = function() {
const termsModeFnMap = {
policy: openPolicy,
privacy: openPrivacy,
domesticoverseas: openDomesticOverseas,
third_party: openThirdParty,
};
const allowTermsMode = Object.keys(termsModeFnMap);
const allowTermsModeType = ['modal', 'link'];
const defaultTermsModeType = 'link';
const getTemsModeType = (termsModeType) => {
const isAllowed = allowTermsModeType.includes(termsModeType);
return isAllowed ? termsModeType : defaultTermsModeType;
}
function init() {
const $target = $('[data-terms-mode]').filter(function() {
return allowTermsMode.includes($(this).data('terms-mode'));
});
$target.off('click.terms').on('click.terms', function(e) {
e.preventDefault();
const termsMode = $(this).data('terms-mode');
const termsModeType = getTemsModeType($(this).data('terms-mode-type'));
if (termsModeType === 'modal') {
termsModeFnMap[termsMode]();
}
if (termsModeType === 'link') {
window.location.href = `?mode=${termsMode}`;
}
});
}
return { init };
}
const termsMode = createTermsMode();
return {
'openPolicy' : function(is_sub){
openPolicy(is_sub);
},
'openPrivacy' : function(){
openPrivacy();
},
'openDomestic' : function(){
openDomestic();
},
'openOverseas' : function(){
openOverseas();
},
'openDomesticOverseas' : function(){
openDomesticOverseas();
},
'openThirdParty' : function(){
openThirdParty()
},
'openOauthDataInterlock' : function(){
openOauthDataInterlock();
},
'openModalMenu' : function(menu_code, base_menu_code){
openModalMenu(menu_code, base_menu_code);
},
'changeAlarmCheckbox' : function(obj, is_mobile){
changeAlarmCheckbox(obj,is_mobile);
},
'toggleAlarmPopup' : function(is_mobile){
toggleAlarmPopup(is_mobile);
},
'androidUpdateAlert' : function (package) {
androidUpdateAlert(package);
},
'firstScrollFixed' : function(id){
firstScrollFixed(id);
},
'setBookMark' : function(){
setBookMark();
},
'setSnsShare' : function(type, snsDataOrEl){
setSnsShare(type, snsDataOrEl);
},
'showLightGallery' : function(d){
showLightGallery(d);
},
'hidePermissionMenu' : function(){
hidePermissionMenu();
},
'rebuildMobileTableMenu' : function(){
rebuildMobileTableMenu();
},
'rebuildSlideMenu' : function(){
rebuildSlideMenu();
},
'setViewportBtn' : function(color, background_color){
setViewportBtn(color, background_color);
},
'toggleViewport' : function(){
toggleViewport();
},
'loadAlarmTargetList' : function(board_code){
loadAlarmTargetList(board_code);
},
'initTermsModeElements': function() {
termsMode.init();
}
}
}();
var SITE_TWO_FACTOR_LOGIN = function(){
var limit_time;
var interval_time_event;
var $cert_request_btn;
var $cert_input_wrap;
var $limit_time_wrap;
var $cert_code;
var $two_factor_cert_save_btn;
var challenge_token;
// 인증 앱(OTP)은 발송이 없어 전송 버튼·남은 시간 타이머를 쓰지 않는다.
var two_factor_type;
// 등록 단계 QR 은 사내 vendor 라이브러리를 그때만 받아 그린다(외부 CDN 금지).
var renderOtpEnrollQr = function($html){
var $qr = $html.find('._otp_qr');
if($qr.length === 0) return;
var uri = $qr.attr('data-uri') || '';
var lib = $qr.attr('data-lib') || '';
if(uri === '' || lib === ''){
$qr.hide();
return;
}
var draw = function(){
try{
new QRCode($qr.get(0), {
text : uri,
width : 160,
height : 160,
correctLevel : QRCode.CorrectLevel.M
});
}catch(e){
// QR 을 못 그려도 링크·키로 등록할 수 있게 QR 영역만 숨긴다.
$qr.hide();
}
};
if(typeof QRCode !== 'undefined'){
draw();
return;
}
$.getScript(lib).done(draw).fail(function(){
$qr.hide();
});
};
var reloadByTwoFactorChallengeExpired = function(res){
if(res.reload == 'Y'){
alert(res.msg);
location.reload();
return true;
}
return false;
};
var openAdminTwoFactor = function(back_url,is_social,requested_two_factor_type){
$.cocoaDialog.close();
$.ajax({
type : 'POST',
// 고른 수단은 서버가 받을 수 있는 수단과 대조해 대기 데이터에 남긴다. 고르지 않으면 지금처럼 빈 요청이다.
data : requested_two_factor_type ? {'two_factor_type' : requested_two_factor_type} : {},
url : ('/dialog/admin_two_factor_login.cm'),
dataType : 'json',
async : true,
cache : false,
success : function(res){
if(res.msg == 'SUCCESS'){
var $html = $(res.html);
clearInterval(interval_time_event);
$html.on('hidden.bs.modal', function(){
clearInterval(interval_time_event);
});
challenge_token = $html.find("input[name='challenge_token']").val();
two_factor_type = $html.find("input[name='two_factor_type']").val() || '';
var $channel = $html.find("select[name='enrollment_channel']");
if($channel.length) $channel.val($channel.find('option:not(:disabled)').first().val() || '');
$cert_request_btn = $html.find('._cert_request_btn');
limit_time = $html.find("input[name='limit_time']").val();
$html.find("._lime_time_obj").html(limit_time);
$cert_input_wrap = $html.find("._cert_input_wrap");
$limit_time_wrap = $html.find("._limit_time_wrap");
$cert_code = $html.find("input[name='cert_code']");
$two_factor_cert_save_btn = $html.find("._two_factor_cert_save_btn");
// 받을 번호 선택지는 서버가 숨긴 채 내려보낸다. 이 스크립트가 있어야 고른 값이 전송되므로 여기서 보이게 한다.
// 번호를 바꾸면 화면의 가린 번호도 고른 쪽으로 맞춘다(인증번호는 전송 시점에 고른 번호로 간다).
var $owner_phone_choice_wrap = $html.find('._owner_phone_choice_wrap');
if($owner_phone_choice_wrap.length){
$owner_phone_choice_wrap.show();
$owner_phone_choice_wrap.find("input[name='owner_phone_choice']").off('change.owner_phone_choice').on('change.owner_phone_choice', function(){
var masked = $(this).attr('data-masked') || '';
if(masked !== '') $html.find('._cert_request_btn').closest('.form-group').find('.control-label').first().text(masked);
});
}
// 사이트가 수단을 여러 개 켰으면 서버가 다른 수단 링크를 숨긴 채 내려보낸다. 누르면 그 수단으로 인증 화면을 다시 연다.
var $two_factor_type_others_wrap = $html.find('._two_factor_type_others_wrap');
if($two_factor_type_others_wrap.length){
$two_factor_type_others_wrap.show();
$two_factor_type_others_wrap.find('._two_factor_type_link').off('click.two_factor_type').on('click.two_factor_type', function(){
$html.data('otp_contact_transition', true);
openAdminTwoFactor(back_url, is_social, $(this).attr('data-type') || '');
return false;
});
}
// 인증 앱은 발송 요청 자체가 없어 전송 버튼과 남은 시간 타이머를 붙이지 않는다.
if(two_factor_type !== 'otp'){
$cert_request_btn.off("click.cert_request_btn").on("click.cert_request_btn", function(){
if($cert_request_btn.hasClass("disabled")) return false;
$.ajax({
type : 'POST',
data : {
'challenge_token' : challenge_token,
'owner_phone_choice' : $html.find("input[name='owner_phone_choice']:checked").val() || '',
'enrollment_channel' : two_factor_type === 'otp_contact' ? $html.find("select[name='enrollment_channel']").val() : ''
},
url : ('/backpg/request_two_factor_certification.cm'),
dataType : 'json',
async : true,
cache : false,
success : function(res){
if(res.msg !== 'SUCCESS'){
if(reloadByTwoFactorChallengeExpired(res)) return false;
alert(res.msg);
}else{
$cert_input_wrap.show();
$cert_request_btn.addClass("disabled");
setTimeout(function(){
$cert_request_btn.removeClass("disabled");
},5000);
clearInterval(interval_time_event);
//모달 닫을때 이벤트 제거
$html.on('hidden.bs.modal', function () {
clearInterval(interval_time_event);
});
$limit_time_wrap.show();
$html.find("._lime_time_obj").html(limit_time);
interval_time_event = setInterval(function(){
var _limit_time = $html.find("._lime_time_obj").html();
$html.find("._lime_time_obj").html(_limit_time-1);
if((_limit_time-1) <= 0) clearInterval(interval_time_event);
},1000);
}
}
});
});
}
$two_factor_cert_save_btn.off("click.cert_save_btn").on("click.cert_save_btn",function(){
var cert_code = $cert_code.val();
if(cert_code === ""){
alert(LOCALIZE.설명_인증번호를입력해주세요());
$cert_code.focus();
return false;
}
$.ajax({
type: 'POST',
data:{
'cert_code' : cert_code,
'challenge_token' : challenge_token,
'back_url' : back_url,
'is_social' : is_social,
'enrollment_channel' : two_factor_type === 'otp_contact' ? $html.find("select[name='enrollment_channel']").val() : ''
},
url: ('/backpg/update_two_factor_certification.cm'),
dataType: 'json',
async: true,
cache: false,
success: function (res) {
if(res.msg === 'OTP_CONTACT_VERIFIED'){
$html.data('otp_contact_transition', true);
openAdminTwoFactor(back_url, is_social);
return;
}
if(res.msg === 'SUCCESS'){
alert(LOCALIZE.설명_인증이완료되었습니다());
// 운영자 세션이 새로 생긴 경우 이전 신원의 토큰을 지운다(login.cm 과 같은 키).
if(res.clear_admin_storage){
try {
window.sessionStorage.removeItem("imweb_site_auth_token");
var matchedKey = [];
for (var i = 0; i < localStorage.length; i++) {
var key = localStorage.key(i);
if (key && key.indexOf('c3ef8c14m') === 0) {
matchedKey.push(key);
}
}
matchedKey.forEach(function(key){ localStorage.removeItem(key); });
} catch (e) {}
}
if(back_url != 'Y'){
// 서버가 이동 주소를 주면 재POST 폼이 없는 경로(소셜·소유주)다.
if (is_social === 'Y' || typeof res.site_back_url !== 'undefined') {
if (res.site_back_url != '') {
window.parent.location.href = res.site_back_url;
} else {
location.reload();
}
} else {
$html.append(res.form);
var $admin_form = $html.find('#admin_two_factor_login_form');
$admin_form.submit();
}
}else{
if(res.site_back_url != '') window.parent.location.href = res.site_back_url;
else location.reload();
}
}else{
if(reloadByTwoFactorChallengeExpired(res)) return false;
alert(res.msg);
}
}
});
});
$.cocoaDialog.open({
type : 'site_two_factor_login', custom_popup : $html, hide_event : function(e){
if($html.data('otp_contact_transition') === true) return;
if(confirm(getLocalizeString('설명_2단계인증을진행하지않으면로그인이불가능합니다', '', '2단계 인증을 진행하지 않으면 로그인이 불가능합니다. 인증을 중단할까요?'))){
$cert_code.val('');
$cert_input_wrap.hide();
clearTwoFactorLoginData();
}else{
e.preventDefault(); // 다이얼로그 닫기 중단
return false;
}
}
});
// 모달이 열려 DOM 에 붙은 뒤에 그린다.
renderOtpEnrollQr($html);
}else{
alert(res.msg);
if(res.retry === 'Y') return;
clearTwoFactorLoginData();
}
}
});
};
var clearTwoFactorLoginData = function(){
$.ajax({
type : 'POST',
url : ('/backpg/clear_two_factor_login.cm'),
dataType : 'json',
async : true,
cache : false,
success : function(res){
if(res.msg == 'SUCCESS'){
location.href = '/';
}else{
alert(res.msg);
}
}
});
};
return {
'openAdminTwoFactor' : function(back_url,is_social){
openAdminTwoFactor(back_url,is_social);
},
'clearTwoFactorLoginData' : function(){
clearTwoFactorLoginData();
}
}
}();