var ADMIN = (function(){ var init = function(){ }; var openProfile = function(){ $.ajax({ type: 'POST', data: {}, url: ('/admin/ajax/dialog/profile.cm'), dataType: 'html', async: false, cache: false, success: function (res) { var $html = $(res); $.cocoaDialog.open({type:'mypage',custom_popup:$html}); } }); }; var openOpinion = function(){ $.ajax({ type: 'POST', data: {}, url: ('/admin/ajax/dialog/opinion.cm'), dataType: 'html', async: false, cache: false, success: function (res) { var $html = $(res); $.cocoaDialog.open({type:'opinion',custom_popup:$html}); } }); }; var showLoader = function(){ $('#dashboard_loader').show(); }; var hideLoader = function(){ $('#dashboard_loader').hide(); }; /*** * 관리자페이지 언어 변경처리 * @param lang */ var changeAdminLang = function(lang){ $.ajax({ type: 'POST', data: {'lang':lang}, url: ('/admin/ajax/change_admin_lang.cm'), dataType: 'json', async: false, cache: false, success: function (res) { if(res.msg == 'SUCCESS'){ location.href = res.back_url; }else{ console.log(res.msg); } } }); }; return { init : function(){ init(); }, openProfile : function(){ openProfile(); }, openOpinion : function(){ openOpinion(); }, showLoader : function(){ showLoader(); }, hideLoader : function(){ hideLoader(); }, changeAdminLang : function(lang){ changeAdminLang(lang); } }; })(); var HEADER_CONTROL = function(){ var $header, $option_list,$footer_option_list; var btn_list = []; var btn_type = { "save": { key : 'save', name : getLocalizeString("버튼_저장", "", "저장"), changing : true }, "add": { key : 'add', name : getLocalizeString("버튼_추가", "", "추가"), changing : true }, "cancel": { key : 'cancel', name : getLocalizeString("버튼_취소", "", "취소"), changing : false }, "delete": { key : 'delete', name : getLocalizeString("버튼_삭제", "", "삭제"), changing : false }, "navi": { key : 'navi', name : 'navi', changing : false } }; var init = function(){ $header = $('#header'); $option_list = $header.find('._option_list'); $footer_option_list = $('
'); $('#content').find("section").append($footer_option_list); $(window).bind('beforeunload', function(){ if(!$(".headerbar").find(".btn-primary").hasClass('disabled')){ return getLocalizeString("설명_변경사항이저장되지않을", "", "변경사항이 저장되지 않을 수 있습니다."); } }); }; var init2 = function($save_btn_bottom_wrap){ $header = $('#header'); $option_list = $header.find('._option_list'); $footer_option_list = $('
'); if( $save_btn_bottom_wrap !== undefined ){ $save_btn_bottom_wrap.append($footer_option_list); } $(window).bind('beforeunload', function(){ if(!$(".headerbar").find(".btn-primary").hasClass('disabled')){ return getLocalizeString("설명_변경사항이저장되지않을", "", "변경사항이 저장되지 않을 수 있습니다."); } }); }; var addBtn = function(type, callback){ switch(type){ case 'save' : case 'add' : var $footer_btn_wrap; var $footer_btn; var $btn_wrap = $('
  • '); var $btn = $('') .text(btn_type[type].name) .toggleClass('disabled', btn_type[type].changing) .data({ btn_data : btn_type[type], changing : false }); if(typeof callback == 'function'){ $btn.off('click').on('click', function(){ if($(this).data('changing') || !btn_type[type].changing){ callback(); } }); } $footer_btn_wrap = $btn_wrap.clone(); $footer_btn = $btn.clone(true); $btn_wrap.append($btn); $option_list.append($btn_wrap); btn_list.push($btn); $footer_option_list.append($footer_btn); btn_list.push($footer_btn); break; case 'delete' : case 'cancel' : var $btn_wrap = $('
  • '); var $btn = $('') .text(btn_type[type].name) .data({ btn_data : btn_type[type] }); if(typeof callback == 'function'){ $btn.off('click').on('click', function(){ callback(); }); } $btn_wrap.append($btn); $option_list.append($btn_wrap); btn_list.push($btn); break; case 'navi' : var $btn_wrap = $('
  • '); var $btn_group = $('
    '); var $btn_prev = $('').data({ btn_data : btn_type[type] }); var $btn_next = $('').data({ btn_data : btn_type[type] }); if(typeof callback == 'function'){ $btn_prev.off('click').on('click', function(){ callback('prev'); }); $btn_next.off('click').on('click', function(){ callback('next'); }); } $btn_group.append($btn_prev); $btn_group.append($btn_next); $btn_wrap.append($btn_group); $option_list.append($btn_wrap); btn_list.push($btn); break; } }; var change = function(){ $.each(btn_list, function(e, $v){ if($v.data('btn_data').changing){ $v.toggleClass('disabled', false).data({ changing : true }); } }); }; var save = function(){ $.each(btn_list, function(e, $v){ if($v.data('btn_data').changing){ $v.toggleClass('disabled', true).data({ changing : false }); } }); }; var isChange = function(){ var is = false; $.each(btn_list, function(e, $v){ if($v.data('btn_data').changing){ if($v.data('changing')){ is = true; return false; } } }); return is; }; return { init : function(){ init(); }, init2: function($save_btn_bottom_wrap){ init2($save_btn_bottom_wrap); }, change : function(){ change(); }, save : function(){ save(); }, addBtn : function(type, callback){ addBtn(type, callback); }, isChange : function(){ return isChange(); } }; }; var IDENTITY_VERIFICATION_POPUP = function(){ const openVerificationPopup = function(){ $.ajax({ type : 'GET', url : ('/admin/ajax/dialog/popup_identity_verification.cm'), dataType: 'html', async: false, cache: false, success: function (res) { var $html = $(res); $.cocoaDialog.open({type:'verification_popup', custom_popup:$html}); } }); }; return { openVerificationPopup : function(){ openVerificationPopup(); }, }; }() var SADMIN_POPUP = (function(){ var openPopup = function(issue){ if(typeof issue == 'undefined') issue = ''; $.ajax({ type : 'POST', data : {'issue' : issue}, url : ('/admin/ajax/dialog/popup.cm'), dataType: 'html', async: false, cache: false, success: function (res) { var $html = $(res); $.cocoaDialog.open({type:'admin',custom_popup:$html}); } }); }; var openPopupExpire = function(popup_type, remain_period){ $.ajax({ type : 'POST', data : { 'popup_type' : popup_type, 'remain_period' : remain_period }, url : ('/admin/ajax/dialog/popup_expire.cm'), dataType: 'html', async: false, cache: false, success: function (res) { var $html = $(res); if($html) { $.cocoaDialog.open({type:'alert_expire',custom_popup:$html}); } } }); }; const openPopupCrmService = () => { $.ajax({ type: 'GET', url: '/admin/ajax/dialog/popup_crm_service.cm', dataType: 'html', async: false, cache: false, success: function(res) { const $html = $(res); if($html){ $.cocoaDialog.open({ type: 'ad_service', custom_popup: $html, pc_width: 380, }); const setCookieTodayExpire = function(name, value) { const today = new Date(); today.setDate(today.getDate() + 14); document.cookie = name + "=" + encodeURIComponent(value) + "; path=/; expires=" + today.toUTCString() + ";"; } $('#_close_btn_crm_service_popup').off('click').on('click', function() { setCookieTodayExpire('close_popup_crm_promotion', 'Y'); $.cocoaDialog.close(); }); } } }); }; const openPopupCrmCouponService = () => { if(window.location.search) { return; } $.ajax({ type: 'GET', url: '/admin/ajax/dialog/popup_crm_service-coupon.cm', dataType: 'html', async: false, cache: false, success: function(res) { const $html = $(res); if($html){ $.cocoaDialog.open({ type: 'ad_service', custom_popup: $html, pc_width: 380, }); const setCookieTodayExpire = function(name, value) { const today = new Date(); today.setDate(today.getDate() + 7); document.cookie = name + "=" + encodeURIComponent(value) + "; path=/; expires=" + today.toUTCString() + ";"; } $('#_close_btn_crm_service_popup').off('click').on('click', function() { $.cocoaDialog.close(); }); $('#_close_seven_day_btn_crm_service_popup').off('click').on('click', function() { setCookieTodayExpire('close_popup_crm_coupon', 'Y'); $.cocoaDialog.close(); }); } } }); }; const openPopupAdService = () => { $.ajax({ type: 'GET', url: ('/admin/ajax/dialog/popup_ad_service.cm'), dataType: 'html', async: false, cache: false, success: function(res) { const $html = $(res); if($html){ $.cocoaDialog.open({ type: 'ad_service', custom_popup: $html, pc_width: 380, }); const setCookieTodayExpire = function(name, value) { const today = new Date(); today.setDate(today.getDate() + 12); document.cookie = name + "=" + encodeURIComponent(value) + "; path=/; expires=" + today.toUTCString() + ";"; } $('#_close_btn_ad_service_popup').off('click').on('click', function() { setCookieTodayExpire('close_popup_ad_promotion', 'Y'); $.cocoaDialog.close(); }); } } }); }; const openPopupFcmHttpV1 = () => { $.ajax({ type: 'GET', url: ('/admin/ajax/dialog/popup_fcm_httpv1.cm'), dataType: 'html', async: false, cache: false, success: function(res) { const $html = $(res); if($html){ $.cocoaDialog.open({ type: 'fcm_httpv1', custom_popup: $html, pc_width: 380, }); const setCookieTodayExpire = function(name, value) { const today = new Date(); today.setHours(23); today.setMinutes(59); today.setSeconds(59); document.cookie = name + "=" + encodeURIComponent(value) + "; path=/; expires=" + today.toUTCString() + ";"; } $('#_close_btn_fcm_httpv1_popup').off('click').on('click', function() { setCookieTodayExpire('CLOSE_POPUP_FCM_HTTPV1', 'Y'); $.cocoaDialog.close(); }); } } }); }; const openPopupTiktokWebinar = () => { $.ajax({ type: 'GET', url: ('/admin/ajax/dialog/popup_tiktok_webinar.cm'), dataType: 'html', async: false, cache: false, success: function(res) { const $html = $(res); if($html){ $.cocoaDialog.open({ type: 'ad_service', custom_popup: $html, pc_width: 380, }); $('#_close_btn_tiktok_webinar').off('click').on('click', function() { setCookie('close_popup_tiktok_webinar', 'Y', 365); $.cocoaDialog.close(); }); } } }); }; const openPopupImwebPrivacyAgree = function(){ $.ajax({ type : 'POST', data : {}, url : ('/admin/ajax/dialog/popup_imweb_privacy_agree.cm'), dataType: 'html', async: false, cache: false, success: function (html) { const $html = $(html); if (!$html) { return window.alert('개인정보 처리 방침 동의 모달을 불러오는데 실패하였습니다'); } const modalOptions = { type: 'alert_privacy_agree', close_block: true, custom_popup: $html, }; $.cocoaDialog.open(modalOptions, function(){ $html.find('#imweb_privacy_agree_btn').on('click', function(){ var payload = { 'privacy_agree': 'Y', // 해당 버튼 클릭은 동의를 의미하므로 Y로 고정 'marketing_agree': 'N', // 마케팅 동의는 현재 사용하지 않아 N으로 고정 }; $.ajax({ type : 'POST', data : payload, url : ('/admin/ajax/imweb_privacy_agree.cm'), dataType: 'JSON', async: false, cache: false, success: function (res) { if(res.msg != 'SUCCESS'){ alert(res.msg); }else{ location.reload(); } } }); }); }); } }); } return { openPopup : function(issue){ openPopup(issue); }, openPopupExpire : function(popup_type, remain_period) { openPopupExpire(popup_type, remain_period); }, openPopupCrmService: function() { openPopupCrmService(); }, openPopupCrmCouponService: function() { openPopupCrmCouponService(); }, openPopupAdService: function() { openPopupAdService(); }, openPopupTiktokWebinar: function() { openPopupTiktokWebinar(); }, openPopupImwebPrivacyAgree : function(){ openPopupImwebPrivacyAgree(); }, openPopupFcmHttpV1: function() { openPopupFcmHttpV1(); }, }; })(); var ADMIN_POPUP = (function(){ const setCookieTodayExpires = function(name, value) { const today = new Date(); today.setHours(23); today.setMinutes(59); today.setSeconds(59); document.cookie = name + "=" + encodeURIComponent(value) + "; path=/; expires=" + today.toUTCString() + ";"; } const changeBackdropColor = (bgColor = 'rgba(0, 0, 0, 0.15)') => { const $backdrop = $('.modal-backdrop.in'); $backdrop.css('background-color', bgColor); $backdrop.css('opacity', 1); } // 컨텐츠 영역이 backdrop 부분을 가려 모달이 닫히지 않을 경우 해당 함수 사용 const attachCloseEventOnModalDialog = (type, selector) => { const $dialog = $(`.modal_${type}`).find(selector); $dialog.on('click', function(e) { const event = e.originalEvent; if (event.target === event.currentTarget) { $.cocoaDialog.hide(); } }); } var openPopupGiftNudge = function() { const COOKIE_NAME = 'close_popup_gift_nudge'; $.ajax({ type: 'GET', url: '/admin/ajax/dialog/popup_gift_nudge.cm', dataType: 'html', async: false, cache: false, success: function(res) { const $html = $(res); const callback = () => { const $animationContainer = document.querySelector('._animation-container'); const $submitButton = $('._btn_submit'); const $closeButton = $('._btn-close'); const animation = bodymovin.loadAnimation({ container: $animationContainer, path: '/admin/json/gift-nudge-visual.json', renderer: 'svg', rendererSettings: { preserveAspectRatio: 'xMaxYMax meet', filterSize: { width: '200%', height: '200%', x: '-50%', y: '-50%', } } }); $submitButton.on('click', () => { $.ajax({ type: 'POST', url: '/admin/enable_gift_by_popup.cm', dataType: 'json', async: false, cache: false, success: function(res) { if (res.msg === 'SUCCESS') { location.href = '/admin/shopping/gift'; }else{ alert(res.msg); } } }); }); $closeButton.on('click', function() { setCookieTodayExpires(COOKIE_NAME, 'Y'); $.cocoaDialog.close(); }); $.cocoaDialog.obj.on('hidden.bs.modal', () => { animation.destroy(); }); }; $.cocoaDialog.open({ type: 'gift_nudge', custom_popup: $html, pc_width: 380 }, callback); } }); } var openOMSTransitionPendingModal = function() { const COOKIE_NAME = 'close_oms_transition_pending_modal'; $.ajax({ type: 'GET', url: '/admin/ajax/dialog/commerce_bo/20250508_oms_transition_pending_modal.cm', dataType: 'html', async: false, cache: false, success: function(res) { const $html = $(res); const callback = () => { const $closeButton = $('._btn-close'); $closeButton.on('click', function() { setCookieTodayExpires(COOKIE_NAME, 'Y'); $.cocoaDialog.close(); }); const $close2Button = $('._btn-close2'); $close2Button.on('click', function() { $.cocoaDialog.close(); }); const $animationContainer = document.querySelector('._animation-container'); const animation = bodymovin.loadAnimation({ container: $animationContainer, path: '/admin/json/oms-activate-usage.json', renderer: 'svg', rendererSettings: { preserveAspectRatio: 'xMidYMin slice', } }); $.cocoaDialog.obj.on('hidden.bs.modal', () => { animation.destroy(); }); }; $.cocoaDialog.open({ type: 'oms_transition_pending', custom_popup: $html, pc_width: 540 }, callback); } }); } var openOMSTransitionReadyModal = function() { const COOKIE_NAME = 'close_oms_transition_ready_modal'; $.ajax({ type: 'GET', url: '/admin/ajax/dialog/commerce_bo/20250508_oms_transition_ready_modal.cm', dataType: 'html', async: false, cache: false, success: function(res) { const $html = $(res); const callback = () => { const $closeButton = $('._btn-close'); $closeButton.on('click', function() { setCookieTodayExpires(COOKIE_NAME, 'Y'); $.cocoaDialog.close(); }); const $close2Button = $('._btn-close2'); $close2Button.on('click', function() { $.cocoaDialog.close(); }); const $animationContainer = document.querySelector('._animation-container'); const animation = bodymovin.loadAnimation({ container: $animationContainer, path: '/admin/json/oms-activate-usage.json', renderer: 'svg', rendererSettings: { preserveAspectRatio: 'xMidYMin slice', } }); $.cocoaDialog.obj.on('hidden.bs.modal', () => { animation.destroy(); }); }; $.cocoaDialog.open({ type: 'oms_transition_ready', custom_popup: $html, pc_width: 540 }, callback); } }); } var openOMSPaypalModal = function() { const COOKIE_NAME = 'close_oms_paypal_modal'; $.ajax({ type: 'GET', url: '/admin/ajax/dialog/commerce_bo/20250509_oms_paypal_modal.cm', dataType: 'html', async: false, cache: false, success: function(res) { const $html = $(res); const callback = () => { const $closeButton = $('._btn-close'); $closeButton.on('click', function() { setCookieTodayExpires(COOKIE_NAME, 'Y'); $.cocoaDialog.close(); }); const $close2Button = $('._btn-close2'); $close2Button.on('click', function() { $.cocoaDialog.close(); }); }; $.cocoaDialog.open({ type: 'oms_paypal', custom_popup: $html, pc_width: 540 }, callback); } }); } var creatorMarketingModalRequested = false; var openCreatorMarketingVisualModal = function(siteCode) { // 크리에이터 마케팅(어필리에이트) 유도 비주얼 모달 var CAMPAIGN = '202610'; var STORAGE_KEY = 'creator_marketing_visual_modal:' + CAMPAIGN + ':' + siteCode; var AFFILIATE_PRODUCT_URL = '/admin/affiliate/product'; var ACTION_LOG_URL = '/admin/ajax/affiliate/creator_marketing_visual_modal_action_log.cm'; var ACTION_TYPE_POSITIVE = 'positive'; var ACTION_TYPE_NEGATIVE = 'negative'; var isActionHandled = false; if (typeof siteCode !== 'string' || !siteCode || creatorMarketingModalRequested || $('.modal:visible').length) { return; } try { if (Number(window.localStorage.getItem(STORAGE_KEY)) > Date.now()) { return; } } catch (e) { // 숨김 선택을 유지할 수 없는 브라우저에서는 반복 노출하지 않는다. return; } creatorMarketingModalRequested = true; var logAction = function(actionType) { if (window.navigator && typeof window.navigator.sendBeacon === 'function' && typeof window.FormData === 'function') { var formData = new FormData(); formData.append('action_type', actionType); window.navigator.sendBeacon(ACTION_LOG_URL, formData); return; } $.ajax({ type: 'POST', url: ACTION_LOG_URL, data: { action_type: actionType }, async: true }); }; var handleAction = function(actionType) { if (isActionHandled) { return; } isActionHandled = true; try { window.localStorage.setItem(STORAGE_KEY, String(Date.now() + 365 * 24 * 60 * 60 * 1000)); } catch (e) { // 저장 실패가 닫기와 메뉴 이동을 막지 않도록 한다. } logAction(actionType); }; $.ajax({ type: 'GET', url: '/admin/ajax/dialog/affiliate/creator_marketing_visual_modal.cm', data: { campaign: CAMPAIGN }, dataType: 'html', async: true, timeout: 5000, cache: false, success: function(res) { var $html = $($.parseHTML(res || '', document, false)); var $content = $html.filter('.creator-marketing-modal'); // 구버전 템플릿·빈 응답·로그인 화면에서는 모달을 열지 않는다. if ($content.length !== 1 || $content.attr('data-campaign') !== CAMPAIGN || $content.attr('data-site-code') !== siteCode) { return; } var callback = function() { var $modal = $('#cocoaModal.modal_creator_marketing_202610'); // 시작 버튼: 기존 크리에이터 마케팅 메뉴로 이동 $content.find('._btn-explore').on('click.creatorMarketing', function() { handleAction(ACTION_TYPE_POSITIVE); location.href = AFFILIATE_PRODUCT_URL; }); // '다시 보지 않기': 모달 닫기 $content.find('._btn-close').on('click.creatorMarketing', function() { handleAction(ACTION_TYPE_NEGATIVE); $.cocoaDialog.close(); }); $modal.one('hide.bs.modal.creatorMarketingVisualModal', function() { handleAction(ACTION_TYPE_NEGATIVE); $(this).off('hide.bs.modal.creatorMarketingVisualModal'); }); // 백드롭 오버레이 색상 보정 (rgba(0, 0, 0, 0.15)) changeBackdropColor(); // cocoaDialog가 열기 직후 포커스를 해제하므로 그 처리가 끝난 뒤 이동한다. window.setTimeout(function() { if ($modal.is(':visible')) { $content.find('._btn-explore')[0].focus({ preventScroll: true }); } }, 10); }; // 이미지 누락·부분 배포에서는 깨진 비주얼을 노출하지 않는다. var images = $content.find('img').toArray(); Promise.all(images.map(function(img) { return new Promise(function(resolve, reject) { img.onload = resolve; img.onerror = reject; if (img.complete) { if (img.naturalWidth > 0) resolve(); else reject(); } }); })).then(function() { // 조회 중 먼저 열린 안내/동의 팝업을 덮지 않는다. if (!$('.modal:visible').length) { $.cocoaDialog.open({ type: 'creator_marketing_202610', custom_popup: $html, pc_width: 380 }, callback); } }).catch(function() { // 이미지 실패는 이번 진입의 모달만 생략한다. }); } }); } const openIntegrationNudge = function() { const type = 'integration_nudge'; const cookieName = 'close_integration_nudge'; $.ajax({ type: 'GET', url: '/admin/ajax/dialog/integration_nudge.cm', dataType: 'html', async: false, cache: false, success: function(res) { const $html = $(res); const callback = () => { mixpanel.track('view_bo_dashboard_visual_modal_banner',{'site_code':SITE_CODE}); const $closeButton = $('._btn-close'); $closeButton.on('click', function() { setCookieTodayExpires(cookieName, 'Y'); $.cocoaDialog.hide(); }); changeBackdropColor(); attachCloseEventOnModalDialog(type, '.modal-content'); }; $.cocoaDialog.open({ type, custom_popup: $html }, callback); } }); } const openPopupInterlocking = function() { const type = 'popup_interlocking'; const cookieName = 'close_popup_interlocking'; $.ajax({ type: 'GET', url: '/admin/ajax/dialog/popup_interlocking.cm', dataType: 'html', async: false, cache: false, success: function(res) { const $html = $(res); const callback = () => { const $checkButton = $('._btn-check'); const $closeButton = $('._btn-close'); $checkButton.on('click', function() { window.open('https://smartstore-link.imweb.me/', '_blank'); $.cocoaDialog.close(); }); $closeButton.on('click', function() { setCookieTodayExpires(cookieName, 'Y'); $.cocoaDialog.close(); }); changeBackdropColor(); attachCloseEventOnModalDialog(type, '.modal-content'); }; $.cocoaDialog.open({ type, custom_popup: $html }, callback); // $.cocoaDialog.obj.on('hidden.bs.modal', () => { // if ( getCookie('NO_EXPIRE_POPUP') !== "Y" && EXPIRE_TYPE !== '') { // SADMIN_POPUP.openPopupExpire(EXPIRE_TYPE, EXPIRE_PERIOD); // } // }); } }); } const openFontExpirationNudge = function() { const type = 'font_expiration_nudge'; const cookieName = 'close_font_expiration_nudge'; $.ajax({ type: 'GET', url: '/admin/ajax/dialog/font_expiration_nudge.cm', dataType: 'html', async: false, cache: false, success: function(res) { const $html = $(res); const callback = () => { const $checkButton = $('._btn-check'); const $closeButton = $('._btn-close'); $checkButton.on('click', function() { $.cocoaDialog.close(); }); $closeButton.on('click', function() { setCookieTodayExpires(cookieName, 'Y'); $.cocoaDialog.close(); }); changeBackdropColor(); attachCloseEventOnModalDialog(type, '.modal-content'); }; $.cocoaDialog.open({ type, custom_popup: $html }, callback); $.cocoaDialog.obj.on('hidden.bs.modal', () => { if ( getCookie('NO_EXPIRE_POPUP') !== "Y" && EXPIRE_TYPE !== '') { SADMIN_POPUP.openPopupExpire(EXPIRE_TYPE, EXPIRE_PERIOD); } }); } }); } const openFontAdditionNudge = function() { console.log('openFontAdditionNudge'); const type = 'font_addition_nudge'; const cookieName = 'close_font_addition_nudge'; $.ajax({ type: 'GET', url: '/admin/ajax/dialog/font_addition_nudge.cm', dataType: 'html', async: false, cache: false, success: function(res) { const $html = $(res); const callback = () => { const $checkButton = $('._btn-check'); const $closeButton = $('._btn-close'); $checkButton.on('click', function() { $.cocoaDialog.close(); }); $closeButton.on('click', function() { setCookieTodayExpires(cookieName, 'Y'); $.cocoaDialog.close(); }); changeBackdropColor(); attachCloseEventOnModalDialog(type, '.modal-content'); }; $.cocoaDialog.open({ type, custom_popup: $html }, callback); $.cocoaDialog.obj.on('hidden.bs.modal', () => { if ( getCookie('NO_EXPIRE_POPUP') !== "Y" && EXPIRE_TYPE !== '') { SADMIN_POPUP.openPopupExpire(EXPIRE_TYPE, EXPIRE_PERIOD); } }); } }); } const openPopupNotificationLaunching = function() { const COOKIE_NAME = 'close_popup_notification_launching'; $.ajax({ type: 'POST', dataType: 'html', url: '/admin/ajax/dialog/popup_notification_launching.cm', async: false, cache: false, success: function(res) { const $html = $(res); $($html).find('._button-close').click(function() { setCookieTodayExpires(COOKIE_NAME, 'Y'); $.cocoaDialog.close(); }); $($html).find('._button-notification').click(function() { window.setTimeout(() => { mixpanel.track('click_bo_notification', { 'site_code': SITE_CODE, 'source': 'modal', }); getNotifyHandler().openModal(); }, 0); $.cocoaDialog.close(); }); $.cocoaDialog.open({ type: 'notification_launching', custom_popup: $html, }, function() { changeBackdropColor(); }); } }); } const openPopupCollectCategory = function() { const type = 'collect-category'; $.ajax({ cache: false, type: 'POST', dataType: 'html', url: '/admin/ajax/dialog/popup_collect_category.cm', }).then((html) => { const $html = $(html); $.cocoaDialog.open({ type, custom_popup: $html, }, function() { changeBackdropColor(); attachCloseEventOnModalDialog(type, `._${type}`); }); }); } const openPopupSiteVersionUpgrade = function() { const type = 'site-version-upgrade'; $.ajax({ cache: false, type: 'POST', dataType: 'html', url: '/admin/ajax/dialog/popup_site_version_upgrade.cm', }).then((html) => { const $html = $(html); const callback = () => { $html.find('._btn-close').on('click', function() { $.cocoaDialog.close(); }); changeBackdropColor(); attachCloseEventOnModalDialog(type, '.modal-content'); } $.cocoaDialog.open({ type, custom_popup: $html }, callback); }); } return { openPopupGiftNudge, openCreatorMarketingVisualModal, openCreatorMarketingVisualModal202610: openCreatorMarketingVisualModal, openIntegrationNudge, openFontExpirationNudge, openFontAdditionNudge, openPopupNotificationLaunching, openPopupCollectCategory, openOMSTransitionPendingModal, openOMSTransitionReadyModal, openOMSPaypalModal, openPopupSiteVersionUpgrade, openPopupInterlocking, } })(); var SADMIN_MENU_ALERT = function(){ var openAlert = function(){ this.ajaxUrl = '/admin/ajax/dialog/menu_alert.cm'; var str_url = location.pathname; if ( IMWEB_SESSIONSTORAGE.get("MENU_ALERT_EMPTY_" + str_url) == 'Y' ) return; $.ajax({ url : this.ajaxUrl, type : 'POST', dataType : 'HTML', data : {'mode' : 'open', 'str_url': str_url}, success : function(res){ if ( res.length == 0 ) { IMWEB_SESSIONSTORAGE.set("MENU_ALERT_EMPTY_" + str_url, 'Y', 60); } else { if($("#menu_alert").length == 0 ){ $('#content #alertBox').append(res); $("#menu_alert").show(); } } } }); }; var closeAlert = function(idx){ $.ajax({ url : this.ajaxUrl, type : 'POST', dataType : 'HTML', data : {mode : 'close', 'idx' : idx}, success : function(){ $("#menu_alert").hide(); } }); }; var closeBannerAlert = function(type){ $.ajax({ url : '/admin/ajax/dialog/banner_alert.cm', type : 'POST', dataType : 'HTML', data : {'type' : type}, success : function(){ $("#banner_alert_"+type).css({'display':'none'}); } }); }; return { ajaxUrl : null, 'openAlert' : function(){ openAlert(); }, 'closeAlert' : function(idx){ closeAlert(idx); }, 'closeBannerAlert' : function(type){ closeBannerAlert(type); } }; }(); const dateFormatUtils = (function() { const pad = (v) => { return `0${v}`.slice(-2); } const toHyphenString = (dateObj) => { const year = dateObj.getFullYear(); const month = pad(dateObj.getMonth() + 1); const date = pad(dateObj.getDate()); return [year, month, date].join('-'); } const toButtonString = (dateString) => { const [year, month, date] = dateString.split('-').map(v => parseInt(v, 10)); const dateObj = new Date(year, month - 1, date); const day = dateObj.toLocaleString(window.ADMIN_LANG_CODE || 'en', { weekday: 'short' }); const yearText = year.toString().substring(2); const monthText = pad(month); const dateText = pad(date); return `${yearText}.${monthText}.${dateText} (${day})`; } return { pad, toHyphenString, toButtonString }; })(); const datepickerButtonHandler = (function($) { const defaultRefreshUrl = (start, end) => { const parser = querystringParser(); const query = parser(window.location.search); window.location.href = getQuerystring({ ...query, start, end, }); } function DatepickerButtonHandler(options) { this.$container = options.$container; this.$start = options.$start; this.$end = options.$end; this.$middleIcon = options.$middleIcon; this.startDate = options.startDate; this.endDate = options.endDate; } DatepickerButtonHandler.prototype.init = function() { const { $container, $start, $end, startDate, endDate } = this; const update = ($e, date) => { if (!isValidDate(date)) { return false; } const hyphenText = dateFormatUtils.toHyphenString(date); const buttonText = dateFormatUtils.toButtonString(hyphenText); $e.data('text.hyphen', hyphenText); $e.text(buttonText); return { buttonText, hyphenText }; } const { hyphenText: startText } = update($start, startDate); const { hyphenText: endText } = update($end, endDate); if (startText === endText) { $container.addClass('same'); } else { $container.removeClass('same'); } } DatepickerButtonHandler.prototype.update = function(startDate, endDate) { this.startDate = new Date(startDate); this.endDate = new Date(endDate); this.init(); } DatepickerButtonHandler.prototype.onClick = function(callback) { const self = this; const { $container } = self if ($container.data('has.click')) { return false; } $container.data('has.click', true); const handler = function() { if (callback) { const { startDate, endDate } = self; callback(self, startDate, endDate); } } $container.on('click', handler); return handler; } DatepickerButtonHandler.prototype.refreshUrl = function() { const { $start, $end } = this; const startHyphenText = $start.data('text.hyphen'); const endHyphenText = $end.data('text.hyphen'); DatepickerButtonHandler.dependencies.refreshUrl(startHyphenText, endHyphenText); } DatepickerButtonHandler.prototype.hyphenText = function() { const { $start, $end } = this; return { start: $start.data('text.hyphen'), end: $end.data('text.hyphen'), }; } DatepickerButtonHandler.dependencies = { refreshUrl: defaultRefreshUrl, }; /** * @param {Object} options - 옵션 * @param {string} [options.container='._datepicker'] - container 셀렉터 * @param {Object} [options.selectors={}] - start, end 텍스트 selectors * @param {string} [options.selectors.start='._datepicker-start'] - start 텍스트 셀렉터 * @param {string} [options.selectors.middleIcon='._datepicker-middle-icon'] - middle icon 셀렉터 * @param {string} [options.selectors.end='._datepicker-end'] - end 텍스트 셀렉터 * @param {Date} [options.startDate] - start date * @param {Date} [options.endDate] - end date */ return (options = {}) => { const container = options.container || '._datepicker'; const selectors = options.selectors || {}; const startDate = options.startDate; const endDate = options.endDate; const startDateSelector = selectors.start || '._datepicker-start'; const middleIconSelector = selectors.middleIcon || '._datepicker-middle-icon'; const endDateSelector = selectors.end || '._datepicker-end'; const _options = { $container: $(container), $start: $(startDateSelector), $middleIcon: $(middleIconSelector), $end: $(endDateSelector), startDate: new Date(startDate), endDate: new Date(endDate), }; return new DatepickerButtonHandler(_options); }; })(window.jQuery); const getNotifyHandler = (function() { const utils = (function () { const throttle = (callback, delay = 0) => { let timer = null; return function(...args) { if (timer !== null) { return false; } timer = window.setTimeout(() => { callback.call(this, ...args); timer = null; }, delay) } } const listenEvents = (events, command) => { Object.entries(events).forEach((event) => { const [eventName, listener] = event; window[`${command}EventListener`](eventName, listener); }); } const dismissMobileMenubar = () => { Object.getPrototypeOf(window.doznutadmin.AppNavigation)._handleMenubarLeave(); } const blurCurrentActiveElement = () => { if (document.activeElement instanceof HTMLElement) { document.activeElement.blur(); } } const getWindowWidth = () => { return window.innerWidth; } const isMobileBreakpoint = (breakpointKey) => { return breakpointKey !== 'lg'; } const getBreakpointKey = (windowWidth, breakpoints) => { const breakpoint = Object.values(breakpoints).find((breakpoint) => { return windowWidth <= breakpoint.threshold; }) ?? breakpoints.lg; return breakpoint.key; } const getCurrentBreakpointKey = (breakpoints) => { const windowWidth = getWindowWidth(); return getBreakpointKey(windowWidth, breakpoints); } const getIframeURL = (url, breakpoints) => { const params = { from: location.href, layout: 'panel', breakpoint: getCurrentBreakpointKey(breakpoints), }; const query = new URLSearchParams(params); return `${url}?${query.toString()}`; } const isSidebarMini = () => { return $('body').hasClass('sidebar-mini'); } return { throttle, listenEvents, dismissMobileMenubar, blurCurrentActiveElement, getWindowWidth, isMobileBreakpoint, getBreakpointKey, getCurrentBreakpointKey, getIframeURL, isSidebarMini, }; })(); const scrollLock = (function() { const state = { isLock: false, restore: { scrollY: 0, bodyStyles: null, }, }; const isScrollable = () => { return Boolean(window.innerWidth - document.documentElement.clientWidth); } const getCurrentScrollY = () => { return window.scrollY; } const getCurrentBodyStyles = () => { const bodyStyles = document.body.style; return { position: bodyStyles.position, top: bodyStyles.top, overflowY: bodyStyles.overflowY, width: bodyStyles.width, }; } const lock = () => { const scrollable = isScrollable(); const currentScrollY = getCurrentScrollY(); const currentBodyStyles = getCurrentBodyStyles(); state.isLock = true; state.restore.scrollY = currentScrollY; state.restore.bodyStyles = currentBodyStyles; document.body.style.setProperty('position', 'fixed'); document.body.style.setProperty('top', `-${currentScrollY}px`); document.body.style.setProperty('width', '100%'); if (scrollable) { document.body.style.setProperty('overflow-y', 'scroll'); } } const unlock = () => { const { scrollY, bodyStyles } = state.restore; document.body.style.setProperty('position', bodyStyles.position); document.body.style.setProperty('top', bodyStyles.top); document.body.style.setProperty('width', bodyStyles.width); document.body.style.setProperty('overflow-y', bodyStyles.overflowY); window.scrollTo(0, scrollY); state.isLock = false; state.restore.scrollY = 0; state.restore.bodyStyles = null; } const wrap = (isLockCondition, fn) => () => { if (state.isLock === isLockCondition) { fn(); } } return { lock: wrap(false, lock), unlock: wrap(true, unlock) }; })(); const createChannel = ($iframe, messageHandler) => { const channel = new MessageChannel(); $iframe.addEventListener('load', function() { window.setTimeout(() => { this.contentWindow.postMessage('init:port', location.origin, [channel.port2]); }, 10); }); channel.port1.onmessage = messageHandler; const postMessage = (message) => { channel.port1.postMessage(message); } const close = () => { channel.port1.close(); channel.port2.close(); } return { postMessage, close }; } function NotifyHandler(options) { const { $provider, $button } = options; this.$provider = $provider; this.$button = $button; this.isOpen = false; this.breakpointKey = ''; this.channel = null; this.windowEvent = { isAttached: false, events: { resize: utils.throttle(this.handleWindowResize, 500).bind(this), click: this.handleWindowClick.bind(this), keydown: this.handleWindowKeydown.bind(this), }, }; this.handleMessage = this.handleMessage.bind(this); } NotifyHandler.prototype.handleWindowResize = function() { const breakpoints = NotifyHandler.CONST.breakpoints; const nextBreakpointKey = utils.getCurrentBreakpointKey(breakpoints); if (utils.isMobileBreakpoint(nextBreakpointKey)) { scrollLock.lock(); } else { scrollLock.unlock(); } this.breakpointKey = nextBreakpointKey; this.postMessage(`resize:${nextBreakpointKey}`); } NotifyHandler.prototype.handleWindowClick = function(e) { const { $provider } = this; const isProviderContext = $provider.contains(e.target); if (isProviderContext) { return false; } this.closeModal(); } NotifyHandler.prototype.handleWindowKeydown = function(e) { const { breakpointKey } = this; if (e.key === 'Escape' && utils.isMobileBreakpoint(breakpointKey)) { this.closeModal(); } } NotifyHandler.prototype.attachWindowEvents = function() { const { windowEvent } = this; windowEvent.isAttached = true; utils.listenEvents(windowEvent.events, 'add'); } NotifyHandler.prototype.detachWindowEvents = function() { const { windowEvent } = this; windowEvent.isAttached = false; utils.listenEvents(windowEvent.events, 'remove'); } NotifyHandler.prototype.postMessage = function(message) { this.channel.postMessage(message); } NotifyHandler.prototype.handleMessage = function(e) { const { data } = e; // 알림 모달 열였을 시 if (data === 'open') { // Nothing } // 알림 모달 닫았을 시 if (data === 'close') { this.closeModal(); } // 단일 읽기 처리 시 if (data === 'confirm') { // Nothing } // 전체 읽기 처리 시 if (data === 'confirm:all') { this.interval.clearBadge(); } // 설정 화면 진입 버튼 클릭 시 if (data === 'open:setting') { mixpanel.track('click_bo_notification_settings', { 'site_code': SITE_CODE }); } // 알림 항목 클릭 시 if (data.startsWith('itemclick')) { const type = data.split(':')[1]; mixpanel.track('click_bo_notification_list_item', { type, 'site_code': SITE_CODE }); } // 배너 클릭 시 if (data.startsWith('bannerclick')) { const name = data.split(':')[1]; mixpanel.track('click_bo_notification_banner', { name, 'site_code': SITE_CODE }); } } NotifyHandler.prototype.openModal = function() { const { $provider, $button } = this; const createElement = () => { const $modal = document.createElement('div'); const $backdrop = document.createElement('div'); const $panel = document.createElement('div'); const $contents = document.createElement('div'); const $iframe = document.createElement('iframe'); $modal.classList.add('notify-modal'); $backdrop.classList.add('notify-modal__backdrop'); $panel.classList.add('notify-modal__panel'); $contents.classList.add('notify-modal__contents'); $iframe.classList.add('notify-modal__iframe'); if (utils.isSidebarMini()) { $modal.classList.add('notify-modal--narrow'); } $iframe.referrerPolicy = 'strict-origin'; $iframe.src = utils.getIframeURL(NotifyHandler.CONST.iframeSource, NotifyHandler.CONST.breakpoints); $contents.appendChild($iframe); $panel.appendChild($contents); $modal.appendChild($backdrop); $modal.appendChild($panel); return $modal; } const attachEvent = ($modal) => { const $panel = $modal.querySelector('.notify-modal__panel'); $panel.addEventListener('click', () => { this.closeModal(); }); } const breakpointKey = utils.getCurrentBreakpointKey(NotifyHandler.CONST.breakpoints); const $modal = createElement(); const channel = createChannel( $modal.querySelector('.notify-modal__iframe'), this.handleMessage, ); attachEvent($modal); $button.classList.add('focus'); $provider.appendChild($modal); this.attachWindowEvents(); if (utils.isMobileBreakpoint(breakpointKey)) { utils.dismissMobileMenubar(); scrollLock.lock(); } utils.blurCurrentActiveElement(); this.breakpointKey = breakpointKey; this.isOpen = true; this.channel = channel; this.postMessage('open'); this.interval.stop(); } NotifyHandler.prototype.closeModal = function() { const { $provider, $button, channel } = this; this.postMessage('close'); channel.close(); this.detachWindowEvents(); scrollLock.unlock(); $button.classList.remove('focus'); // channel.postMessage('close') 하기 위함 window.setTimeout(() => { $provider.innerHTML = ''; }, 0); this.breakpointKey = ''; this.isOpen = false; this.channel = null; this.interval.start(); } NotifyHandler.prototype.toggleModal = function() { const { isOpen } = this; if (isOpen) { this.closeModal(); } else { this.openModal(); } } NotifyHandler.prototype.setInterval = function(interval) { this.interval = interval; } NotifyHandler.CONST = { iframeSource: `${location.origin}/admin/notify`, providerSelector: '._notify-modal-provider', buttonSelector: '._gnb_notification_button', breakpoints: { sm: { key: 'sm', threshold: 587 }, md: { key: 'md', threshold: 992 }, lg: { key: 'lg', threshold: Number.MAX_VALUE }, }, }; let instance = null; return () => { if (instance === null) { const options = { $provider: document.querySelector(NotifyHandler.CONST.providerSelector), $button: document.querySelector(NotifyHandler.CONST.buttonSelector), }; instance = new NotifyHandler(options); } return instance; } })(); const getNotifyBadgeInterval = (function() { const SELECTOR = '_badge'; // 서버(html/site/ajax/notification/api.sub:82)가 배지 숫자를 Redis 에 180초 캐시한다. // 그보다 짧은 주기로 폴링하면 같은 값을 받으려고 전체 부트스트랩만 반복하므로 // 폴링 주기를 캐시 TTL 과 같은 180초로 맞춘다. const POLLING_INTERVAL_MS = 1000 * 60 * 3; // menu.sub 의 initNotifyHandler 는 데스크톱 GNB 로드(load-gnb)와 // 모바일 GNB 열기(open-gnb-mobile)마다 호출되며 그때마다 새 Interval 을 만든다. // 이때 직전 인스턴스를 무조건 멈추면, 한 번만 렌더되는 데스크톱 GNB 의 폴링이 // 모바일 사이드바를 열자마자 멈춰 버린다. 그래서 인스턴스를 목록으로 들고, // 같은 버튼이거나 DOM 에서 분리된 버튼의 인스턴스만 정리한다. // (모바일 사이드바는 열 때마다 다시 마운트되므로 이전 버튼이 DOM 에서 빠진다.) const activeIntervals = []; function fetchBadgeCount() { return $.ajax({ cache: false, type: 'GET', dataType: 'json', url: '/ajax/notification/notification.cm?apiPath=list&req=count', }).promise().then(res => res.unReadTotalCount ?? 0); } function createBadgeElement(type, text) { const $badge = document.createElement('span'); $badge.classList.add(SELECTOR); $badge.textContent = text; switch(type) { case 'count': $badge.classList.add('badge_icon', 'badge_count'); break; case 'new': $badge.textContent = ''; break; } return $badge; } function setBadge(count, $button) { const $prevBadge = $button.find(`.${SELECTOR}`); if ($prevBadge.length) { $prevBadge.remove(); } const countText = count > 99 ? '99+' : count; const $badge = count > 0 ? createBadgeElement('count', countText) : createBadgeElement('new', 'New'); $button.append($badge); } function createUpdateBadgeCount($button) { return () => { return fetchBadgeCount().then((count) => setBadge(count, $button)); } } function Interval(fn, interval, $button) { let timer = null; // 숨김 탭에서 건너뛴 폴링이 있는지 — 탭 복귀 시 한 번만 즉시 갱신하기 위해 둔다. let hasSkippedWhileHidden = false; const tick = () => { // 보이지 않는 탭은 배지를 볼 사람이 없으므로 요청을 보내지 않고, // 복귀 시 갱신해야 한다는 표시만 남긴다. if (document.hidden) { hasSkippedWhileHidden = true; return; } fn(); } const handleVisibilityChange = () => { // 다시 보이게 됐고 건너뛴 폴링이 있을 때만 1회 갱신한다. if (document.hidden || !hasSkippedWhileHidden) { return; } hasSkippedWhileHidden = false; fn(); } const start = () => { // 같은 인스턴스에서 타이머가 중복 생성되지 않게 막는다. if (timer !== null) { return; } timer = window.setInterval(tick, interval); document.addEventListener('visibilitychange', handleVisibilityChange); } const stop = () => { window.clearInterval(timer); timer = null; hasSkippedWhileHidden = false; document.removeEventListener('visibilitychange', handleVisibilityChange); } const force = () => { // 최초 진입·모달 닫기처럼 명시적인 즉시 갱신이므로 숨김 여부를 보지 않는다. hasSkippedWhileHidden = false; fn(); } const clearBadge = () => { setBadge(0, $button); } return { start, stop, force, clearBadge }; } /** 그 버튼이 아직 문서에 붙어 있는지 — 분리됐으면 더 갱신할 배지가 없다. */ function isAttached(element) { return !!element && document.documentElement.contains(element); } /** * 새 인스턴스를 만들기 전, 쓸모없어진 인스턴스만 멈추고 목록에서 뺀다. * 대상은 같은 버튼(중복 호출)과 DOM 에서 분리된 버튼(모바일 재마운트)이고, * 아직 붙어 있는 다른 버튼(모바일을 열었을 때의 데스크톱)은 살려 둔다. */ function releaseStaleIntervals(element) { for (let i = activeIntervals.length - 1; i >= 0; i -= 1) { const entry = activeIntervals[i]; // 아직 화면에 붙어 있는 다른 버튼(모바일을 열었을 때의 데스크톱)은 살려 둔다. if (entry.element !== element && isAttached(entry.element)) { continue; } entry.interval.stop(); activeIntervals.splice(i, 1); } } return ($button) => { const element = $button && $button.length ? $button[0] : undefined; // 재마운트·중복 호출로 쓸모없어진 인스턴스의 타이머·visibilitychange 핸들러를 // 먼저 정리한다. 살아 있는 다른 표면(데스크톱 GNB)의 폴링은 건드리지 않는다. releaseStaleIntervals(element); const updateBadgeCount = createUpdateBadgeCount($button); const interval = new Interval(updateBadgeCount, POLLING_INTERVAL_MS, $button); activeIntervals.push({ element: element, interval: interval }); return interval; } })();