|
71 | 71 |
|
72 | 72 | <script async src="https://www.googletagmanager.com/gtag/js?id=G-CJMRTGSHND"></script> |
73 | 73 | <script> |
74 | | - function showAlert(category, message) { |
75 | | - // Create the alert element |
76 | | - const alert = document.createElement('div'); |
77 | | - alert.classList.add('alert', `alert-${category}`, 'alert-dismissible', 'fade', 'show'); |
78 | | - alert.setAttribute('role', 'alert'); |
79 | | - alert.innerHTML = ` |
80 | | - <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button> |
81 | | - ${message} |
| 74 | + function showAlert(category, message, title = null) { |
| 75 | + // Create the notification element |
| 76 | + const notification = document.createElement('div'); |
| 77 | + notification.classList.add('notification', category); |
| 78 | + |
| 79 | + // Set icon based on category |
| 80 | + let icon = ''; |
| 81 | + switch(category) { |
| 82 | + case 'success': |
| 83 | + icon = 'fa-check-circle'; |
| 84 | + break; |
| 85 | + case 'warning': |
| 86 | + icon = 'fa-exclamation-triangle'; |
| 87 | + break; |
| 88 | + case 'danger': |
| 89 | + icon = 'fa-times-circle'; |
| 90 | + break; |
| 91 | + case 'info': |
| 92 | + icon = 'fa-info-circle'; |
| 93 | + break; |
| 94 | + } |
| 95 | + |
| 96 | + // Create notification content |
| 97 | + notification.innerHTML = ` |
| 98 | + <i class="fa ${icon} icon"></i> |
| 99 | + <div class="content"> |
| 100 | + ${title ? `<div class="title">${title}</div>` : ''} |
| 101 | + <div class="message">${message}</div> |
| 102 | + </div> |
| 103 | + <button class="close" aria-label="Close"> |
| 104 | + <i class="fa fa-times"></i> |
| 105 | + </button> |
82 | 106 | `; |
83 | | - |
84 | | - // Append the alert in the top of the page |
85 | | - const container = document.querySelector('.alerts'); |
86 | | - container.insertBefore(alert, container.firstChild); |
| 107 | + |
| 108 | + // Add to container |
| 109 | + const container = document.getElementById('notification-container'); |
| 110 | + container.appendChild(notification); |
| 111 | + |
| 112 | + // Add click handler for close button |
| 113 | + const closeBtn = notification.querySelector('.close'); |
| 114 | + closeBtn.addEventListener('click', () => { |
| 115 | + notification.classList.add('closing'); |
| 116 | + setTimeout(() => { |
| 117 | + notification.remove(); |
| 118 | + }, 300); |
| 119 | + }); |
| 120 | + |
| 121 | + // Auto remove after 5 seconds |
| 122 | + setTimeout(() => { |
| 123 | + if (notification.parentElement) { |
| 124 | + notification.classList.add('closing'); |
| 125 | + setTimeout(() => { |
| 126 | + notification.remove(); |
| 127 | + }, 300); |
| 128 | + } |
| 129 | + }, 5000); |
87 | 130 | } |
88 | 131 | </script> |
89 | 132 |
|
@@ -207,8 +250,7 @@ <h1 class="logo"> |
207 | 250 | </header> |
208 | 251 |
|
209 | 252 | <main id="main"> |
210 | | - <div class="container alerts"></div> |
211 | | - <!-- <h1 id="page-title">{% block page_title %}{% endblock %}</h1> --> |
| 253 | + <div id="notification-container"></div> |
212 | 254 | {% block body %}{% endblock %} |
213 | 255 | <button type="button" id="btn-up" class="btn btn-dark" title="Go to top"><i class="fa fa-arrow-up"></i></button> |
214 | 256 | </main> |
|
0 commit comments