1if ('serviceWorker' in navigator) { 2 // service worker registration in progress 3 navigator.serviceWorker.register('/service-worker.js').then(function () { 4 // service worker registration in complete 5 }, function () { 6 // service worker registration in failure 7 }); 8} 9 10var deferredPrompt, 11 pushPanel = document.getElementById('push-panel'), 12 pushPanelClose = document.querySelector('.push-panel__btn--cancel'), 13 installBtn = document.getElementById('pwa-install'); 14 15function closePushPanel(event) { 16 event.target.closest('#push-panel').classList.remove('is-shown'); 17 localStorage.setItem('pushInteraction', 'true'); 18} 19 20function isApplePlatform() { 21 if ( 22 -1 !== navigator.appVersion.indexOf("Mac") || 23 -1 !== navigator.platform.indexOf('iPhone') || 24 -1 !== navigator.platform.indexOf('iPad') 25 ) { 26 return true; 27 } 28} 29 30function isAndroidPlatform() { 31 return -1 !== navigator.userAgent.toLowerCase().indexOf("android"); 32} 33 34if (null !== pushPanel && 'true' !== localStorage.getItem('pushInteraction') && window.innerWidth < 1025) { 35 if (!isApplePlatform() && isAndroidPlatform()) { 36 window.addEventListener('beforeinstallprompt', (e) => { 37 e.preventDefault(); 38 deferredPrompt = e; 39 pushPanel.classList.add('is-shown'); 40 }); 41 42 pushPanelClose.addEventListener('click', (e) => { 43 closePushPanel(e); 44 }); 45 46 installBtn.addEventListener('click', (e) => { 47 closePushPanel(e); 48 if (undefined === deferredPrompt) { 49 return; 50 } 51 deferredPrompt.prompt(); 52 deferredPrompt.userChoice.then((choiceResult) => { 53 if (choiceResult.outcome === 'accepted') { 54 // User accepted prompt 55 } else { 56 // User dismissed prompt 57 } 58 deferredPrompt = null; 59 }); 60 }); 61 } 62}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.