|
1 | 1 | --- |
2 | | -
|
3 | 2 | --- |
4 | 3 | <div id="install-pwa" class="hidden"> |
5 | | - <p>Add website to home screen and get easy access to the schedule!</p> |
6 | | - <button id="install-btn" class="button-link font-bold text-lg px-4 py-4 rounded-lg inline-flex items-center justify-center leading-4 transition-colors duration-200 not-prose border text-white |
7 | | - bg-primary hover:bg-primary-hover border-transparent">Add to home screen</button> |
| 4 | + <div class="flex flex-row items-center justify-between gap-4"> |
| 5 | + <div class="grid w-full"> |
| 6 | + <p>Add website to home screen and get easy access to the schedule!</p> |
| 7 | + <button id="install-btn" class="button-link font-bold text-lg px-4 py-4 rounded-lg inline-flex items-center justify-center leading-4 transition-colors duration-200 not-prose border text-white m-5 |
| 8 | + bg-primary hover:bg-primary-hover border-transparent">Add to home screen</button> |
| 9 | + </div> |
| 10 | + <button id="close-btn" class="text-white hover:text-gray-300 transition-colors duration-200 p-2" aria-label="Close"> |
| 11 | + <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> |
| 12 | + <line x1="18" y1="6" x2="6" y2="18"></line> |
| 13 | + <line x1="6" y1="6" x2="18" y2="18"></line> |
| 14 | + </svg> |
| 15 | + </button> |
| 16 | + </div> |
8 | 17 | </div> |
9 | | - |
10 | 18 | <style> |
11 | 19 | #install-pwa { |
12 | 20 | position: fixed; |
|
20 | 28 | transition: all 0.3s ease; |
21 | 29 | z-index: 200; |
22 | 30 | } |
23 | | - |
24 | 31 | #install-pwa.hidden { |
25 | 32 | transform: translateY(100%); |
26 | 33 | opacity: 0; |
27 | 34 | } |
28 | 35 | </style> |
29 | | - |
30 | 36 | <script> |
31 | 37 | function showInstallPrompt() { |
32 | 38 | const installBanner = document.getElementById('install-pwa') as HTMLElement; |
33 | 39 | installBanner.classList.remove('hidden'); |
34 | 40 | } |
35 | 41 |
|
36 | | - const installBtn = document.getElementById('install-btn') as HTMLElement; |
37 | | - installBtn.addEventListener('click', () => { |
| 42 | +function hideInstallPrompt() { |
| 43 | + const installBanner = document.getElementById('install-pwa') as HTMLElement; |
| 44 | + installBanner.classList.add('hidden'); |
| 45 | +} |
| 46 | + |
| 47 | +const installBtn = document.getElementById('install-btn') as HTMLElement; |
| 48 | +const closeBtn = document.getElementById('close-btn') as HTMLElement; |
| 49 | + |
| 50 | +installBtn.addEventListener('click', () => { |
38 | 51 | if (deferredPrompt) { |
39 | 52 | deferredPrompt.prompt(); |
40 | 53 | deferredPrompt.userChoice.then((choiceResult: any) => { |
41 | 54 | console.log(choiceResult.outcome); |
42 | 55 | deferredPrompt = null; |
| 56 | + hideInstallPrompt(); |
43 | 57 | }); |
44 | 58 | } |
45 | 59 | }); |
46 | 60 |
|
47 | | -let deferredPrompt: any; |
| 61 | +closeBtn.addEventListener('click', () => { |
| 62 | + hideInstallPrompt(); |
| 63 | +}); |
48 | 64 |
|
| 65 | +let deferredPrompt: any; |
49 | 66 | window.addEventListener('beforeinstallprompt', (e) => { |
50 | 67 | e.preventDefault(); |
51 | 68 | deferredPrompt = e; |
52 | | - |
53 | 69 | showInstallPrompt(); |
54 | 70 | }); |
55 | 71 | </script> |
0 commit comments