(() => { const { EventManager, utils } = ShopbySkin; const { isMobileDevice } = utils; const headerEl = document.querySelector('shopby-header-v2'); // 외부스크립트 등록 기능. 삭제금지 ShopbyExternalScript?.initialize({ apiOption: { platform: 'PC', }, }).then(() => { EventManager.fire('QUERY_PAGE_SCRIPTS', ShopbyExternalScript?.scripts); }); // 클릭이벤트 맵 // 1. SIGN_OUT : 로그아웃 const headerActionMap = { SIGN_OUT: () => { EventManager.fire('SIGN_OUT'); }, GO_MY_MENU: (e) => { if (!utils.isSignedIn()) { e.preventDefault(); const from = e.target.href; const nextUrl = `${location.origin}/pages/sign-in/sign-in.html`; location.href = `${nextUrl}?from=${encodeURIComponent(from)}`; } }, SEARCH: () => { EventManager.fire('OPEN_LAYER_MODAL', { name: 'search-keyword', modalAddClass: 'title-modal--full search-keyword-modal', isFull: true, }); // 모달 열리고 난 뒤 input에 커서 위치 (약간의 지연 필요) (2025/06/11일) setTimeout(() => { const input = document.getElementById('searchstring'); if (input) input.focus(); }, 100); // 100ms 정도가 일반적으로 안정적 }, }; // 클릭이벤트 핸들러 const clickEventListener = (e) => { const action = e?.target?.closest('[shopby-action]')?.getAttribute('shopby-action'); headerActionMap[action]?.(e); }; // 상단 카테고리 slider 초기화 EventManager.on('PAGE_LOAD_COMPLETED', ({ profile }) => { EventManager.fire('INIT_CATEGORY_SLIDER', { direction: 'horizontal', effect: 'slide', slidesPerView: 'auto', spaceBetween: 20, }); // 외부스크립트 등록 기능. 삭제금지 ShopbyExternalScript?.setGlobalObjectSb({ getPlatform: () => (isMobileDevice ? 'MOBILE_WEB' : 'PC'), profile, }); if ( profile != null ){ //console.log(`email : ${profile.email}\nmemberId : ${profile.memberId}\nmemberName : ${profile.memberName}\nmobileNo : ${profile.mobileNo}\nproviderType : ${profile.providerType}`); const providerType = profile.providerType; if ( providerType != null ){ localStorage.setItem('providerType', providerType); } else { localStorage.removeItem('providerType'); } } else { //localStorage.removeItem('providerType'); } }); headerEl?.addEventListener('click', clickEventListener); const searchParams = new URLSearchParams(location.search); const trackingKey = searchParams.get('trackingKey'); const channelType = searchParams.get('channelType'); const { setTrackingKey, setChannelType } = ShopbySkin.utils; setTrackingKey(trackingKey); setChannelType(channelType); //------------------------------ 상단메뉴를 재구성 S ------------------------------ // 1. observer 선언 & 감시 시작 const observer = new MutationObserver(function (mutationsList, observer) { setTimeout(() => { const targetElement = document.getElementById('test'); if (targetElement) { const menuRoot = document.querySelector('.nav__all-menu1'); // 2. 재구성 전 메뉴 전체 숨김 const allWraps = menuRoot.querySelectorAll('.depth1SubWrap'); allWraps.forEach(el => { el.style.visibility = 'hidden'; }); // 3. 재구성 시작 document.querySelectorAll('.nav__all-menu1 .all-menu__category').forEach((target1, index) => { // 하위 1차 카테고리가 없을때 onmouseover 제거 하여 메뉴 열리지 않게 처리 2025.06.10 if (target1.querySelectorAll('.depth1Wrap').length == 0) { const nav = document.querySelectorAll('.nav__slider-item-wrap'); nav.forEach((el, index2) => { if (index == index2) { el.querySelector('span').removeAttribute('onmouseover'); } }); } const hasSubItem = target1.querySelector('.all-menu__list') !== null; //if (hasSubItem) { // let reHeight = 0; // document.getElementById('test').style.display = 'block'; // target1.style.display = 'block'; // reHeight = target1.querySelector('.all-menu__list').offsetHeight * 1; // reHeight += 30; // target1.style.height = `${reHeight}px`; // target1.style.overflow = 'hidden'; // target1.style.display = 'none'; // console.log(`index : ${index}, reHeight : ${reHeight}`); //} target1.querySelectorAll('.depth1Wrap').forEach((target2) => { const existingDepth1Sub = target2.querySelectorAll('.depth1Sub'); existingDepth1Sub.forEach(el => el.classList.add('hidden')); let subIndex = 1; let depth1Sub; let isFirst = true; let cnt = 0; const fragment = document.createDocumentFragment(); target2.querySelectorAll('.depth2Wrap').forEach((target3) => { let currentCount = 1; const depth3Wraps = target3.querySelectorAll('.depth3Wrap'); currentCount += depth3Wraps.length; if (isFirst) { depth1Sub = document.createElement('ul'); depth1Sub.className = `depth1Sub depth1Sub${subIndex}`; isFirst = false; } if (cnt + currentCount <= 15) { depth1Sub.appendChild(target3.cloneNode(true)); cnt += currentCount; } else { fragment.appendChild(depth1Sub); subIndex++; depth1Sub = document.createElement('ul'); depth1Sub.className = `depth1Sub depth1Sub${subIndex}`; depth1Sub.appendChild(target3.cloneNode(true)); cnt = currentCount; } }); if (depth1Sub) { fragment.appendChild(depth1Sub); } const depth1SubWrap = target2.querySelector('.depth1SubWrap'); if (depth1SubWrap) { depth1SubWrap.innerHTML = ''; depth1SubWrap.appendChild(fragment); } }); }); // 4. 재구성 끝나고 메뉴 표시 const showMenus = () => { const allWraps = menuRoot.querySelectorAll('.depth1SubWrap'); allWraps.forEach(el => { el.style.visibility = 'visible'; }); }; showMenus(); // 5. 감시 중단 observer.disconnect(); } document.getElementById('test').style.display = 'none'; }, 0); }); // 6. 감시 시작 (꼭 맨 아래에 있어야 함) observer.observe(document.body, { childList: true, subtree: false }); })();