(() => { const { EventManager, utils, constants } = ShopbySkin; 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); ShopbySkin.utils.myappProxyRegistry.applyToSlideMenu = (proxyFn) => { if (typeof proxyFn === 'function') { slideMenuEL?.removeEventListener('click', clickEventListener); slideMenuEL?.addEventListener('click', proxyFn(clickEventListener)); } }; ShopbySkin.utils.myappProxyRegistry.applyToSlideMenu.proxyFnKey = 'slideMenuProxy'; EventManager.fire('INIT_MYAPP'); ////////////////////////// /* PWA 설치 버튼 관련 */ ////////////////////////// // PWA 설치 프롬프트 저장 변수 let deferredPrompt = null; let isPageLoaded = false; // 인앱브라우저 체크 const isInAppBrowser = /inapp|NAVER|KAKAOTALK|Instagram|FBAN|FBAV|Twitter|Line|Daum/i.test( navigator.userAgent ); // beforeinstallprompt 이벤트 캡처 window.addEventListener('beforeinstallprompt', (e) => { e.preventDefault(); deferredPrompt = e; // 페이지 로드가 이미 완료됐으면 버튼 다시 표시 if (isPageLoaded) { const btnWrapper = document.querySelector('.pwaInstallWrapper'); if (btnWrapper) { btnWrapper.style.display = ''; } } }); // 이미 설치된 경우 처리 window.addEventListener('appinstalled', () => { deferredPrompt = null; const btnWrapper = document.querySelector('.pwaInstallWrapper'); if (btnWrapper) { btnWrapper.style.display = 'none'; } }); // ShopBy 페이지 로드 완료 후 PWA 버튼 초기화 EventManager.on('PAGE_LOAD_COMPLETED', () => { isPageLoaded = true; // 2차 카테고리 '전담' 스타일 적용 document.querySelectorAll('.slide-menu__nav-category-label--two-depth span').forEach((el) => { if (el.textContent.trim() === 'LIMITED EDITION') { el.style.setProperty('font-weight', '600', 'important'); } }); const installBtn = document.querySelector('.pwaInstall'); const btnWrapper = document.querySelector('.pwaInstallWrapper'); if (!installBtn) return; // 이미 설치된 앱인지 확인 (standalone 모드 = PWA로 실행 중) const isStandalone = window.matchMedia('(display-mode: standalone)').matches || window.navigator.standalone === true; if (isStandalone) { btnWrapper.style.display = 'none'; return; } // 미지원 브라우저 체크 (beforeinstallprompt 미지원) const isIOS = /iPad|iPhone|iPod/.test(navigator.userAgent); const isUnsupportedBrowser = /Firefox|MSIE|Trident|Opera Mini|UCBrowser/i.test(navigator.userAgent) || (/Safari/.test(navigator.userAgent) && !/Chrome/.test(navigator.userAgent)); // 조건: deferredPrompt 있거나 인앱브라우저거나 미지원 브라우저면 버튼 표시 if (deferredPrompt || isInAppBrowser || isUnsupportedBrowser) { btnWrapper.style.display = ''; } else { // 그 외 (이미 설치됨) → 숨김 btnWrapper.style.display = 'none'; } // 클릭 이벤트 바인딩 installBtn.addEventListener('click', () => { // 인앱브라우저 안내 if (isInAppBrowser) { alert('이 브라우저는 앱 설치를 지원하지 않습니다.\nChrome, 삼성 인터넷 등을 이용해주세요.'); return; } // 설치 프롬프트가 있으면 실행 if (deferredPrompt) { deferredPrompt.prompt(); deferredPrompt = null; return; } // iOS Safari 안내 const isSafari = /Safari/.test(navigator.userAgent) && !/Chrome/.test(navigator.userAgent); if (isIOS && isSafari) { alert( '홈 화면에 추가하려면:\n1. 하단의 공유 버튼(📤)을 탭하세요\n2. "홈 화면에 추가"를 선택하세요' ); return; } // 그 외 (미지원 브라우저) alert('이 브라우저는 앱 설치를 지원하지 않습니다.\nChrome, 삼성 인터넷 등을 이용해주세요.'); }); }); })();