From 2a2159ea3af7c01e50870ba1acdb6f3660e8bad5 Mon Sep 17 00:00:00 2001 From: Neale Pickett Date: Wed, 21 Nov 2018 22:15:15 +0000 Subject: [PATCH] webapp work, push required for https --- toys/starship/index.md | 3 ++- toys/starship/starship.js | 40 +++++++++++++++++++-------------------- 2 files changed, 22 insertions(+), 21 deletions(-) diff --git a/toys/starship/index.md b/toys/starship/index.md index d38b5e9..8841e5c 100644 --- a/toys/starship/index.md +++ b/toys/starship/index.md @@ -16,7 +16,6 @@ headers: - I work in a building with no HVAC, which means we can hear everything people are saying, @@ -30,3 +29,5 @@ You can leave it running forever, if you like. For those interested, it uses the new (in 2017), perfect for this application, [Web Audio API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API) + + diff --git a/toys/starship/starship.js b/toys/starship/starship.js index 82a0497..721da84 100644 --- a/toys/starship/starship.js +++ b/toys/starship/starship.js @@ -53,26 +53,6 @@ function init() { if ("serviceWorker" in navigator) { navigator.serviceWorker.register("sw.js"); } - - // Let people add this app - let deferredPrompt; - let installButton = document.querySelector("#install"); - installButton.style.display = "none"; - window.addEventListener("beforeinstallprompt", e => { - console.log(e); - deferredPrompt = e; - installButton.style.display = "block"; - }); - installButton.addEventListener("click", e => { - console.log(e); - deferredPrompt.prompt(); - deferredPrompt.userChoice - .then(result => { - if (result.output == "accepted") { - installButton.style.display = "none"; - } - }); - }); } if (document.readyState === "loading") { @@ -80,3 +60,23 @@ if (document.readyState === "loading") { } else { init(); } + +// Let people add this app +let deferredPrompt; +let installButton = document.querySelector("#install"); +installButton.style.display = "none"; +window.addEventListener("beforeinstallprompt", e => { + console.log(e); + deferredPrompt = e; + installButton.style.display = "block"; +}); +installButton.addEventListener("click", e => { + console.log(e); + deferredPrompt.prompt(); + deferredPrompt.userChoice + .then(result => { + if (result.output == "accepted") { + installButton.style.display = "none"; + } + }); +});