/* eslint-disable camelcase */ (() => { const containerEl = document.querySelector('[shopby-footer-container]'); const shortcut = { async initialize(commonData) { await this.replaceManifestWith(this.generateManifestUrl(commonData)); this.executeServiceWorker(); }, replaceManifestWith(manifestURL) { const manifestPlaceholderEl = document.querySelector('[shopby-manifest-placeholder]'); manifestPlaceholderEl?.setAttribute('href', manifestURL); }, generateManifestUrl(commonData) { const mallName = commonData.mallConfig.mall?.mallName; const manifest = { name: mallName, short_name: mallName, description: mallName, start_url: location.origin, display: 'standalone', orientation: 'portrait', incognito: 'split', icons: [ { src: `https:${commonData.bannerConfig?.appIcon}`, sizes: '144x144', type: 'image/png', purpose: 'any', }, ], }; const blob = new Blob([JSON.stringify(manifest)], { type: 'application/json' }); return URL.createObjectURL(blob); }, executeServiceWorker() { this.deferPromptEvent(); }, deferPromptEvent() { window.addEventListener('beforeinstallprompt', (event) => { event.preventDefault(); window.deferredPrompt = event; }); window.addEventListener('appinstalled', (event) => { event.preventDefault(); window.deferredPrompt = null; }); }, }; const CLICK_EVENT_HANDLER_MAP = { HANDLE_ADD_TO_HOME_BTN_CLICK: async () => { const promptEvent = window.deferredPrompt; if (!promptEvent) return; promptEvent.prompt(); const { outcome } = await promptEvent.userChoice; if (outcome === 'accepted') { // eslint-disable-next-line require-atomic-updates window.deferredPrompt = null; window.close(); } }, }; const clickEventListener = (e) => { const action = e.target.getAttribute('shopby-action'); CLICK_EVENT_HANDLER_MAP[action]?.(e); }; containerEl?.addEventListener('click', clickEventListener); window.addEventListener('scroll', function() { if (window.scrollY > 200) { document.querySelector('.side_fixed').classList.add('show'); } else { document.querySelector('.side_fixed').classList.remove('show'); } }); $('#goTop').click(function(){ $('html, body').animate({ scrollTop: 0 }, 'fast'); }); // Mutation Observer // 감시자의 설정 let option = { attributes: true, childList: true, //characterData: true, }; // 감시자 인스턴스 만들기 let observer = new MutationObserver((mutations) => { // 노드가 변경 됐을 때의 작업 mutations.forEach(recode => { recode.addedNodes.forEach(node => { if(node.nodeType === 1 && node.getAttribute('id') === 'ch-plugin'){ observer.observe(document.querySelector('#ch-plugin'), option); // $('#ch-plugin').removeAttr('style'); } }); if(recode.target.getAttribute('id') == 'ch-plugin'){ // $('#ch-plugin').removeAttr('style'); } }); }) // 대상 노드에 감시자 전달 observer.observe(document.querySelector('body'), option); })();