|
1 | 1 | {{ if eq .Name "Schedule" }} |
2 | | -<li class="menu-item-has-children"> |
| 2 | +<li class="menu-item-has-children" id="schedule-menu-item"> |
3 | 3 | <a href="#" style="border-bottom: 0px solid #e0e0e0;"><span>{{ .Name }}</span></a> |
4 | 4 | <div class="sub-menu" style="padding:0px;margin:0px;"> |
5 | 5 | <div style="width:100%;margin:0px;padding:0px;" id="calendar-container"> |
6 | | - <div id="calendar-loading" style="text-align:center;padding:40px;color:#666;"> |
7 | | - <i class="ti-reload" style="animation: spin 2s linear infinite;display:block;font-size:24px;margin-bottom:10px;"></i> |
8 | | - <span>Loading...</span> |
| 6 | + <div id="calendar-placeholder"> |
| 7 | + <div id="calendar-loading" style="text-align:center;padding:40px;color:#666;opacity:0;transition:opacity 0.3s ease-in-out;"> |
| 8 | + <i class="ti-reload" style="animation: spin 2s linear infinite;display:block;font-size:24px;margin-bottom:10px;"></i> |
| 9 | + <span>Loading...</span> |
| 10 | + </div> |
9 | 11 | </div> |
10 | 12 | </div> |
11 | 13 | </div> |
12 | 14 | </li> |
13 | 15 |
|
14 | 16 | <script> |
15 | | -document.addEventListener('DOMContentLoaded', function () { |
16 | | - var calendarContainer = document.getElementById('calendar-container'); |
17 | | - if(calendarContainer){ |
18 | | - const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone |
19 | | - const html = `<iframe src="https://calendar.google.com/calendar/embed?src=c_62694f414055ac569e5cb12dafbb0890ca22f3640b177a4b10b53171fbc9bdd4%40group.calendar.google.com&ctz=${timezone}" style="border:0; width:100%; min-height:500px;margin:0px;" frameborder="0" scrolling="no"></iframe>` |
20 | | - calendarContainer.innerHTML = html; |
| 17 | +let calendarLoaded = false; |
| 18 | + |
| 19 | +function loadCalendar() { |
| 20 | + if (calendarLoaded) return; |
| 21 | + |
| 22 | + const calendarContainer = document.getElementById('calendar-container'); |
| 23 | + const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone; |
| 24 | + const iframe = document.createElement('iframe'); |
| 25 | + iframe.style.border = '0'; |
| 26 | + iframe.style.width = '100%'; |
| 27 | + iframe.style.minHeight = '500px'; |
| 28 | + iframe.style.margin = '0px'; |
| 29 | + iframe.frameBorder = '0'; |
| 30 | + iframe.scrolling = 'no'; |
| 31 | + iframe.style.opacity = '0'; |
| 32 | + iframe.style.transition = 'opacity 0.3s ease-in-out'; |
| 33 | + |
| 34 | + const loadingElement = document.getElementById('calendar-loading'); |
| 35 | + if (loadingElement) { |
| 36 | + loadingElement.style.display = 'block'; |
| 37 | + setTimeout(() => { |
| 38 | + loadingElement.style.opacity = '1'; |
| 39 | + }, 50); |
21 | 40 | } |
22 | 41 |
|
23 | | - const observer = new MutationObserver((mutations) => { |
24 | | - mutations.forEach((mutation) => { |
25 | | - if (mutation.addedNodes.length > 0) { |
26 | | - const loadingElement = document.getElementById('calendar-loading'); |
27 | | - if (loadingElement) { |
28 | | - loadingElement.style.transition = 'opacity 0.5s ease-out'; |
29 | | - loadingElement.style.opacity = '1'; |
30 | | - |
31 | | - setTimeout(() => { |
32 | | - loadingElement.style.opacity = '0'; |
33 | | - setTimeout(() => { |
34 | | - loadingElement.style.display = 'none'; |
35 | | - }, 500); |
36 | | - }, 2000); |
37 | | - } |
| 42 | + iframe.onload = function() { |
| 43 | + if (loadingElement) { |
| 44 | + loadingElement.style.opacity = '0'; |
| 45 | + setTimeout(() => { |
| 46 | + loadingElement.style.display = 'none'; |
| 47 | + iframe.style.opacity = '1'; |
| 48 | + }, 300); |
| 49 | + } |
| 50 | + }; |
| 51 | + |
| 52 | + iframe.src = `https://calendar.google.com/calendar/embed?src=c_62694f414055ac569e5cb12dafbb0890ca22f3640b177a4b10b53171fbc9bdd4%40group.calendar.google.com&ctz=${timezone}`; |
| 53 | + |
| 54 | + calendarContainer.appendChild(iframe); |
| 55 | + calendarLoaded = true; |
| 56 | +} |
| 57 | + |
| 58 | +const menuItem = document.getElementById('schedule-menu-item'); |
| 59 | +if (menuItem) { |
| 60 | + menuItem.addEventListener('mouseenter', loadCalendar); |
| 61 | + |
| 62 | + const menuLink = menuItem.querySelector('a'); |
| 63 | + if (menuLink) { |
| 64 | + menuLink.addEventListener('click', function(e) { |
| 65 | + if (window.innerWidth <= 991) { |
| 66 | + loadCalendar(); |
38 | 67 | } |
39 | 68 | }); |
40 | | - }); |
41 | | - |
42 | | - if (calendarContainer) { |
43 | | - observer.observe(calendarContainer, { childList: true, subtree: true }); |
44 | 69 | } |
45 | | -}); |
| 70 | +} |
46 | 71 | </script> |
| 72 | +{{ else if eq .Name "Featured Articles" }} |
| 73 | +<li class="menu-item-has-children"> |
| 74 | + <a href="#" style="border-bottom: 0px solid #e0e0e0;"><span>{{ .Name }}</span></a> |
| 75 | + <div class="sub-menu"> |
| 76 | + {{ range $section, $articles := site.Data.featured_articles }} |
| 77 | + {{ range $articles }} |
| 78 | + {{ if .visible }} |
| 79 | + <div class="featured-article"> |
| 80 | + <a href="{{ .link }}" {{ if hasPrefix .link "http" }}target="_blank"{{ end }}> |
| 81 | + <div class="featured-article-image"> |
| 82 | + <img src="{{ .image }}" alt="{{ .title }}"> |
| 83 | + </div> |
| 84 | + <div class="featured-article-title">{{ .title }}</div> |
| 85 | + </a> |
| 86 | + </div> |
| 87 | + {{ end }} |
| 88 | + {{ end }} |
| 89 | + {{ end }} |
| 90 | + </div> |
| 91 | +</li> |
47 | 92 | {{else}} |
48 | 93 | <li class="menu-item"> |
49 | 94 | <a href="{{ .URL | absURL }}" {{ with .Pre }} target="{{ . }}" {{ end }}><span>{{ .Name }}</span></a> |
|
0 commit comments