|
1 | 1 | <!doctype html>
|
2 |
| -<html lang="en"> |
| 2 | +<html lang="en" class="dark"> |
3 | 3 |
|
4 | 4 | <head>
|
5 | 5 | <meta charset="UTF-8">
|
@@ -152,17 +152,24 @@ <h2 class="mb-6 text-2xl font-semibold text-gray-800">
|
152 | 152 |
|
153 | 153 | <script>
|
154 | 154 | $(function () {
|
155 |
| - $('select').each(function () { |
156 |
| - $(this).select2({ |
157 |
| - theme: 'tailwindcss-3', |
158 |
| - width: $(this).data('width') ? $(this).data('width') : $(this).hasClass('w-100') ? '100%' : 'style', |
159 |
| - placeholder: $(this).data('placeholder') || 'Select an option', |
160 |
| - allowClear: Boolean($(this).data('allow-clear')), |
161 |
| - closeOnSelect: !$(this).attr('multiple'), |
162 |
| - tags: Boolean($(this).data('tags')), |
163 |
| - }); |
| 155 | + // On page load or when changing themes, best to add inline in `head` to avoid FOUC |
| 156 | + document.documentElement.classList.toggle( |
| 157 | + 'dark', |
| 158 | + localStorage.theme === 'dark' || (!('theme' in localStorage) && window.matchMedia('(prefers-color-scheme: dark)').matches) |
| 159 | + ); |
| 160 | + |
| 161 | + // Select2 init |
| 162 | + $('select').each(function () { |
| 163 | + $(this).select2({ |
| 164 | + theme: 'tailwindcss-3', |
| 165 | + width: $(this).data('width') ? $(this).data('width') : $(this).hasClass('w-100') ? '100%' : 'style', |
| 166 | + placeholder: $(this).data('placeholder') || 'Select an option', |
| 167 | + allowClear: Boolean($(this).data('allow-clear')), |
| 168 | + closeOnSelect: !$(this).attr('multiple'), |
| 169 | + tags: Boolean($(this).data('tags')), |
164 | 170 | });
|
165 | 171 | });
|
| 172 | + }); |
166 | 173 | </script>
|
167 | 174 |
|
168 | 175 | </body>
|
|
0 commit comments