mirror of
https://github.com/daniviga/django-ram.git
synced 2025-08-05 05:37:50 +02:00
Import WebThrottle-EX from ca33f6a
This commit is contained in:
34
ram/driver/static/wt/js/pwa.js
Normal file
34
ram/driver/static/wt/js/pwa.js
Normal file
@@ -0,0 +1,34 @@
|
||||
$(document).ready(function(){
|
||||
let deferredPrompt;
|
||||
const addBtn = document.querySelector('.add-button');
|
||||
const removeBtn = document.querySelector('.installed-label');
|
||||
addBtn.style.display = 'none';
|
||||
removeBtn.style.display = 'block';
|
||||
window.addEventListener('beforeinstallprompt', (e) => {
|
||||
removeBtn.style.display = 'none';
|
||||
// Prevent Chrome 67 and earlier from automatically showing the prompt
|
||||
e.preventDefault();
|
||||
// Stash the event so it can be triggered later.
|
||||
deferredPrompt = e;
|
||||
// Update UI to notify the user they can add to home screen
|
||||
addBtn.style.display = 'block';
|
||||
|
||||
addBtn.addEventListener('click', (e) => {
|
||||
// hide our user interface that shows our A2HS button
|
||||
//addBtn.style.display = 'none';
|
||||
// Show the prompt
|
||||
deferredPrompt.prompt();
|
||||
// Wait for the user to respond to the prompt
|
||||
deferredPrompt.userChoice.then((choiceResult) => {
|
||||
if (choiceResult.outcome === 'accepted') {
|
||||
console.log('User accepted the prompt, app installed');
|
||||
addBtn.style.display = 'none';
|
||||
removeBtn.style.display = 'block';
|
||||
} else {
|
||||
console.log('User dismissed the prompt');
|
||||
}
|
||||
deferredPrompt = null;
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user