(() => { const { EventManager, utils, constants, Handlebars } = ShopbySkin; let mallName = ''; if(langCode === ''){ langCode = localStorage.getItem('langCode'); langCode = langCode !== undefined && langCode !== '' && langCode !== null ? langCode : 'ko'; } const slideMenuEL = document.querySelector('slide-menu'); const slideMenuClickActionMap = { CLOSE_SLIDE_MENU: () => { EventManager.fire('TOGGLE_HEADER_SLIDE_MENU', { type: 'close' }); }, TOGGLE_SLIDE_MENU_CHILD_CATEGORY: (e) => { const categoryWrapEl = e?.target?.closest('[shopby-category-no]'); EventManager.fire('TOGGLE_SLIDE_MENU_CHILD_CATEGORY', { wrapEl: categoryWrapEl, }); }, SIGN_OUT: () => { slideMenuClickActionMap.CLOSE_SLIDE_MENU(); EventManager.fire('SIGN_OUT'); }, GO_MY_MENU: (e) => { if (!utils.isSignedIn()) { e.preventDefault(); slideMenuClickActionMap.CLOSE_SLIDE_MENU(); const from = e.target.href; const nextUrl = `${location.origin}${constants.PAGE.SIGN_IN}`; utils.moveTo({ url: `${nextUrl}?from=${encodeURIComponent(from)}` }); } else { if (!e.target.href) { return; } slideMenuClickActionMap.CLOSE_SLIDE_MENU(); utils.moveTo({ url: e.target.href }); } }, GO_NEXT: (event) => { event.preventDefault(); const { target } = event; const href = target?.href ?? target.closest('[shopby-action="GO_NEXT"]')?.href; if (!href) { return; } slideMenuClickActionMap.CLOSE_SLIDE_MENU(); utils.moveTo({ url: href }); }, }; const clickEventListener = (e) => { const action = e?.target?.closest('[shopby-action]')?.getAttribute('shopby-action'); slideMenuClickActionMap[action]?.(e); }; slideMenuEL?.addEventListener('click', clickEventListener); EventManager.fire('MYAPP:PROXY_REGISTER', { proxyFnKey: 'slideMenuProxy', applyProxy: (proxyFn) => { slideMenuEL?.removeEventListener('click', clickEventListener); slideMenuEL?.addEventListener('click', proxyFn(clickEventListener)); }, }); // 240702 $('#cateEnergyBtn').on('click', function() { $(this).toggleClass('show'); $(this).siblings('.nav_tabmenu_box').slideToggle('fast'); }); $('#cateBtn').click(function() { $(this).toggleClass('show'); $(this).siblings('.nav_tabmenu_box').slideToggle('fast'); }); $('.cate_manual_btn').click(function() { $(this).toggleClass('show'); $(this).siblings('.nav_tabmenu_box').slideToggle('fast'); }); $(document).ready(function () { const sidebar = { posY: null, resizeChk: 0, sc: 0, initiate() { this.bindEvents(); }, bindEvents() { $('.side_menu, nav .bg, .left_close').on('click', this.openSidebar.bind(this)); $(window).on('resize', this.windowResize.bind(this)); }, windowResize() { if ($('#navigation nav').css('display') !== 'none') { this.blockResize(); } else { this.noneResize(); } }, blockResize() { if ($('body').css('overflow') !== 'hidden') this.posY = $('body').scrollTop(); $('.nav_content_box').height($(window).innerHeight()); $('.nav_content_box').css('overflow-y', 'scroll'); $('#navigation').height($(window).innerHeight()); $('#navigation').css('overflow-y', 'scroll'); if ($('body').css('overflow') !== 'hidden') $('#navigation').scrollTop(this.posY); $('#navigation, body').css('overflow', 'hidden'); this.resizeChk = 0; }, noneResize() { $('#navigation, body').removeAttr('style'); if (this.resizeChk == 0) { $('body').scrollTop(this.posY); this.resizeChk = 1; } }, openSidebar() { function motionEvent(width_num, callback) { $('.nav_bg_box .nav_box').animate({ 'margin-left': width_num }, 300, callback); } const navBox = $('.nav_bg_box .nav_box'); const navigationNav = $('#navigation nav'); let navBoxWidth; if (navigationNav.css('display') == 'none') { // 일시적으로 display를 block으로 변경하여 너비를 계산 navigationNav.css('display', 'block'); navBoxWidth = navBox.outerWidth(); navigationNav.css('display', 'none'); navigationNav.show(); $('#navigation nav .bg').fadeIn(); $('#navigation nav .bg').bind('touchmove', function (e) { e.preventDefault(); }); // 모바일 스크롤 방지 navBox.css('margin-left', `-${navBoxWidth}px`); motionEvent('0px', this.blockResize.bind(this)); } else { navBoxWidth = navBox.outerWidth(); motionEvent(`-${navBoxWidth}px`, () => { $('nav .bg').fadeOut(function () { navigationNav.hide(); }); this.noneResize(); }); } }, }; sidebar.initiate(); }); EventManager.on('PAGE_LOAD_COMPLETED', (commonData) => { mallName = commonData.mallConfig.mall.mallName; setCategoriesEnergy(commonData.mallConfig.categories.multiLevelCategories); setCategoryBest(); }); const setCategoriesEnergy = (categories) => { const rootCategoryValue = Object.values(rootCategory); let multiLevelCategories = []; let rootCategoryCnt = 0; categories.forEach(item => { if(rootCategoryValue.includes(item.categoryNo)){ rootCategoryCnt++; } }); categories.forEach(category => { if(rootCategoryCnt == 0){ if((mallCategory[langCode] !== undefined && Number(category.categoryNo) === Number(mallCategory[langCode]['energy'])) || (mallCategory[langCode] === undefined && Number(category.categoryNo) === Number(mallCategory['energy']))){ multiLevelCategories = category; } }else{ if(category.categoryNo === rootCategory[langCode]){ category.children.forEach(category => { if((mallCategory[langCode] !== undefined && Number(category.categoryNo) === Number(mallCategory[langCode]['energy'])) || (mallCategory[langCode] === undefined && Number(category.categoryNo) === Number(mallCategory['energy']))){ multiLevelCategories = category; } }); } } }); const template = Handlebars.compile(document.querySelector("categories-energy").innerHTML); let list = template({ categoriesEnergy: multiLevelCategories.children, }); document.querySelector("#category-navigation-energy").innerHTML = list; document.querySelector("categories-energy").innerHTML = ''; }; const setCategoryBest = () => { const category = mallCategory[langCode] !== undefined ? mallCategory[langCode]['best'] : mallCategory['best']; if(category !== ''){ let href = document.querySelector(".categoryBest").getAttribute('href') + category; document.querySelector(".categoryBest").setAttribute('href', href); } }; Handlebars.registerHelper({ chkCategoryVisible(categoryNo){ return mallCategory[langCode] !== undefined ? Number(categoryNo) !== Number(mallCategory[langCode]['energy']) && Number(categoryNo) !== Number(mallCategory[langCode]['best']) : Number(categoryNo) !== Number(mallCategory['energy']) && Number(categoryNo) !== Number(mallCategory['best']); }, }); })();