-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
35 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,39 @@ | ||
/** | ||
* PWA — easy way to Progressive Web App - v1.5.9 | ||
* PWA — easy way to Progressive Web App - v1.6.0 | ||
* https://github.com/iworks/iworks-pwa | ||
* Copyright (c) 2024; * Licensed GPLv3+ */ | ||
window.addEventListener('load', function(event) { | ||
var iworks_pwa_deferred_prompt; | ||
const iworks_pwa_add_button = document.querySelector('#iworks-pwa-add-button'); | ||
const iworks_pwa_add_button_container = document.querySelector('#iworks-pwa-add-button-container'); | ||
if (iworks_pwa_add_button) { | ||
window.addEventListener('beforeinstallprompt', function(event) { | ||
// Prevent Chrome 67 and earlier from automatically showing the prompt | ||
event.preventDefault(); | ||
// Stash the event so it can be triggered later. | ||
iworks_pwa_deferred_prompt = event; | ||
// Update UI to notify the user they can add to home screen | ||
iworks_pwa_add_button_container.style.display = 'block'; | ||
iworks_pwa_add_button.addEventListener('click', function() { | ||
// hide our user interface that shows our A2HS button | ||
iworks_pwa_add_button_container.style.display = 'none'; | ||
// Show the prompt | ||
iworks_pwa_deferred_prompt.prompt(); | ||
// Wait for the user to respond to the prompt | ||
iworks_pwa_deferred_prompt.userChoice.then(function(choiceResult) { | ||
if (choiceResult.outcome === 'accepted') { | ||
// console.log('User accepted the A2HS prompt'); | ||
} else { | ||
// console.log('User dismissed the A2HS prompt'); | ||
} | ||
iworks_pwa_deferred_prompt = null; | ||
}); | ||
}); | ||
}); | ||
} | ||
var iworks_pwa_deferred_prompt; | ||
const iworks_pwa_add_button = document.querySelector('#iworks-pwa-add-button'); | ||
const iworks_pwa_add_button_container = document.querySelector('#iworks-pwa-add-button-container'); | ||
if (iworks_pwa_add_button) { | ||
window.addEventListener('beforeinstallprompt', function(event) { | ||
// Prevent Chrome 67 and earlier from automatically showing the prompt | ||
event.preventDefault(); | ||
// Stash the event so it can be triggered later. | ||
iworks_pwa_deferred_prompt = event; | ||
// Update UI to notify the user they can add to home screen | ||
iworks_pwa_add_button_container.style.display = 'block'; | ||
iworks_pwa_add_button.addEventListener('click', function() { | ||
// hide our user interface that shows our A2HS button | ||
iworks_pwa_add_button_container.style.display = 'none'; | ||
// Show the prompt | ||
iworks_pwa_deferred_prompt.prompt(); | ||
// Wait for the user to respond to the prompt | ||
iworks_pwa_deferred_prompt.userChoice.then(function(choiceResult) { | ||
if (choiceResult.outcome === 'accepted') { | ||
// console.log('User accepted the A2HS prompt'); | ||
} else { | ||
// console.log('User dismissed the A2HS prompt'); | ||
} | ||
iworks_pwa_deferred_prompt = null; | ||
}); | ||
}); | ||
}); | ||
} | ||
}); | ||
|
||
if ('serviceWorker' in navigator) { | ||
navigator.serviceWorker.register(window.iworks_pwa.serviceWorkerUri) | ||
.then(function(reg) {}) | ||
.catch(function(err) {}); | ||
navigator.serviceWorker.register(window.iworks_pwa.serviceWorkerUri) | ||
.then(function(reg) {}) | ||
.catch(function(err) {}); | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters