Repository navigation
Expand file tree
/
Copy pathapp.js
More file actions
3273 lines (2847 loc) · 141 KB
/
Copy pathapp.js
File metadata and controls
3273 lines (2847 loc) · 141 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* UITS Event Raiders - SPA Client Application Controller
* Author: Antigravity AI & oU1TS Community
* Language: ES6+ (Vanilla JS)
*/
document.addEventListener('DOMContentLoaded', () => {
// Cache UI Selectors
const appThemeToggle = document.getElementById('theme-toggle');
const sections = document.querySelectorAll('.section');
const navLinks = document.querySelectorAll('#main-nav .nav-link');
const mobileToggle = document.getElementById('mobile-toggle');
const mainNav = document.getElementById('main-nav');
const raidsContainer = document.getElementById('raids-container');
// Available SPA Routes
const validRoutes = ['#home', '#raids', '#notes', '#join', '#learn-more'];
// State Variables
let pastRaidsData = null;
let isDataLoading = false;
let pendingRaidScroll = null;
let currentFilterType = 'all';
let showPastRaids = false;
function isPastRaid(raid) {
if (!raid) return false;
if (raid.Status === 'Past') return true;
if (raid.endDate) {
const today = new Date();
today.setHours(0, 0, 0, 0);
const checkDate = new Date(raid.endDate);
checkDate.setHours(0, 0, 0, 0);
if (today > checkDate) {
raid.Status = 'Past';
return true;
}
}
return false;
}
/* ==========================================================================
1. Theme Management (Light / Dark Mode)
========================================================================== */
function initializeTheme() {
const storedTheme = localStorage.getItem('theme');
// System preference default check
const prefersLight = window.matchMedia && window.matchMedia('(prefers-color-scheme: light)').matches;
if (storedTheme === 'light' || (!storedTheme && prefersLight)) {
document.body.classList.add('light-theme');
updateThemeToggleAccessibility(true);
} else {
document.body.classList.remove('light-theme');
updateThemeToggleAccessibility(false);
}
}
function toggleTheme() {
const isLightThemeActive = document.body.classList.toggle('light-theme');
localStorage.setItem('theme', isLightThemeActive ? 'light' : 'dark');
updateThemeToggleAccessibility(isLightThemeActive);
}
function updateThemeToggleAccessibility(isLight) {
appThemeToggle.setAttribute('aria-label', isLight ? 'Switch to Dark Theme' : 'Switch to Light Theme');
}
appThemeToggle.addEventListener('click', toggleTheme);
/* ==========================================================================
2. SPA Hash Routing
========================================================================== */
function routePage() {
if (window.closeCalendarModal) {
window.closeCalendarModal();
}
let currentHash = window.location.hash;
let targetRaidNum = null;
// Parse hash to see if it's a raid link, e.g., #raid-1
if (currentHash.startsWith('#raid-')) {
targetRaidNum = parseInt(currentHash.replace('#raid-', ''), 10);
currentHash = '#raids';
resetTypeFilter();
}
// Support backward compatibility for legacy hash
if (currentHash === '#past-raids') {
currentHash = '#raids';
history.replaceState(null, null, currentHash);
}
// Default route fallback if hash is empty or invalid
if (!currentHash || !validRoutes.includes(currentHash)) {
currentHash = '#home';
// Silently update hash without triggering another route run
history.replaceState(null, null, currentHash);
}
// 1. Update Active Navigation Links
navLinks.forEach(link => {
if (link.getAttribute('href') === currentHash) {
link.classList.add('active');
} else {
link.classList.remove('active');
}
});
// 2. Switch Section Visibility
sections.forEach(section => {
const sectionId = section.getAttribute('id');
if (`#${sectionId}` === currentHash) {
section.classList.add('active');
} else {
section.classList.remove('active');
}
});
// 3. Trigger Data Fetching when entering Past Raids & Event Notes
if (currentHash === '#raids' || currentHash === '#notes') {
if (targetRaidNum) {
if (pastRaidsData) {
const targetRaid = pastRaidsData.find(r => r.Raid_Num === targetRaidNum);
if (targetRaid && isPastRaid(targetRaid)) {
showPastRaids = true;
updatePastRaidsToggleUI();
}
filterAndRenderRaids();
scrollToRaid(targetRaidNum);
} else {
pendingRaidScroll = targetRaidNum;
loadPastRaids();
}
} else {
if (pastRaidsData) {
if (currentHash === '#notes') {
renderEventNotes(pastRaidsData);
} else {
filterAndRenderRaids();
}
} else {
loadPastRaids();
}
}
if (window.enableFloatingCalendarBtn) {
window.enableFloatingCalendarBtn(true);
}
} else {
if (window.enableFloatingCalendarBtn) {
window.enableFloatingCalendarBtn(false);
}
}
// 4. Scroll to top on navigation change (only if not scrolling to a specific raid card)
if (!targetRaidNum) {
window.scrollTo({ top: 0, behavior: 'instant' });
}
// 5. Close mobile navigation menu if open
closeMobileMenu();
}
function scrollToRaid(raidNum) {
// Wait slightly to ensure elements are rendered and transition finished
setTimeout(() => {
const card = document.getElementById(`raid-card-${raidNum}`);
if (card) {
if (card.tagName.toLowerCase() === 'details') {
card.open = true;
}
card.scrollIntoView({ behavior: 'smooth', block: 'center' });
card.classList.add('highlighted');
card.addEventListener('animationend', () => {
card.classList.remove('highlighted');
}, { once: true });
}
}, 200);
}
// Hash change event listener
window.addEventListener('hashchange', routePage);
/* ==========================================================================
3. Mobile Navigation Menu Toggle
========================================================================== */
function toggleMobileMenu() {
const isOpened = mainNav.classList.toggle('open');
mobileToggle.classList.toggle('open');
mobileToggle.setAttribute('aria-expanded', isOpened);
}
function closeMobileMenu() {
mainNav.classList.remove('open');
mobileToggle.classList.remove('open');
mobileToggle.setAttribute('aria-expanded', false);
}
mobileToggle.addEventListener('click', toggleMobileMenu);
// Close menu when clicking outside of the navbar
document.addEventListener('click', (event) => {
if (!mainNav.contains(event.target) && !mobileToggle.contains(event.target)) {
closeMobileMenu();
}
});
/* ==========================================================================
4. Asynchronous Data Load & Card Render
========================================================================== */
async function loadPastRaids(options = {}) {
// Prevent double loading or redundant fetches unless forced
if (pastRaidsData && !options.forceFresh) return;
if (isDataLoading) return;
isDataLoading = true;
try {
// Fetch from separate JSON file, force bypass browser cache if requested
const fetchOptions = options.forceFresh ? { cache: 'no-cache' } : {};
const response = await fetch('raids.json', fetchOptions);
if (!response.ok) {
throw new Error(`Failed to load data (HTTP ${response.status})`);
}
pastRaidsData = await response.json();
if (pendingRaidScroll) {
const targetRaid = pastRaidsData.find(r => r.Raid_Num === pendingRaidScroll);
if (targetRaid && isPastRaid(targetRaid)) {
showPastRaids = true;
updatePastRaidsToggleUI();
}
}
filterAndRenderRaids();
renderEventNotes(pastRaidsData);
} catch (error) {
console.error('Error fetching past raids:', error);
renderErrorBanner(error.message);
} finally {
isDataLoading = false;
}
}
function filterAndRenderRaids() {
if (!pastRaidsData) return;
let filtered = pastRaidsData;
// Filter out past raids if showPastRaids is false
if (!showPastRaids) {
filtered = filtered.filter(raid => !isPastRaid(raid));
}
if (currentFilterType !== 'all') {
filtered = filtered.filter(raid => raid.Type === currentFilterType);
}
renderRaids(filtered);
}
function getShortTitle(title) {
if (!title) return '';
let short = title;
if (short.includes('(')) {
short = short.split('(')[0];
}
if (short.includes(':')) {
short = short.split(':')[0];
}
return short.trim();
}
function renderEventNotes(raids) {
const notesContainer = document.getElementById('notes-container');
if (!notesContainer) return;
notesContainer.innerHTML = '';
// Filter raids that have a "notes" link
const notesRaids = raids.filter(raid => raid.links && raid.links.notes);
if (notesRaids.length === 0) {
notesContainer.innerHTML = '<p style="grid-column: 1/-1; text-align: center; color: var(--text-secondary);">No notes available at the moment.</p>';
return;
}
notesRaids.forEach(raid => {
const card = document.createElement('div');
card.className = 'resource-card';
// Build card content
const titleEl = document.createElement('h3');
titleEl.className = 'resource-title';
titleEl.textContent = getShortTitle(raid.title);
card.appendChild(titleEl);
const actionContainer = document.createElement('div');
actionContainer.style.display = 'flex';
actionContainer.style.gap = '1rem';
actionContainer.style.marginTop = 'auto';
actionContainer.style.flexWrap = 'wrap';
// Link to the rendered markdown notes
const notesUrl = raid.links.notes;
const notesLink = document.createElement('a');
notesLink.className = 'raid-link';
notesLink.href = `render.html?file=${encodeURIComponent(notesUrl)}`;
notesLink.innerHTML = `
<span>View Notes</span>
<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round">
<path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"></path>
<polyline points="14 2 14 8 20 8"></polyline>
<line x1="16" y1="13" x2="8" y2="13"></line>
<line x1="16" y1="17" x2="8" y2="17"></line>
<polyline points="10 9 9 9 8 9"></polyline>
</svg>
`;
actionContainer.appendChild(notesLink);
// Link to the corresponding raid card in the #raids section
const cardLink = document.createElement('a');
cardLink.className = 'raid-link';
cardLink.href = `#raid-${raid.Raid_Num}`;
cardLink.innerHTML = `
<span>View Campaign</span>
<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round">
<line x1="7" y1="17" x2="17" y2="7"></line>
<polyline points="7 7 17 7 17 17"></polyline>
</svg>
`;
actionContainer.appendChild(cardLink);
card.appendChild(actionContainer);
notesContainer.appendChild(card);
});
}
function formatLocalDate(dateStr) {
if (!dateStr) return '';
const parts = dateStr.split('-');
if (parts.length !== 3) return dateStr;
const year = parts[0];
const monthIndex = parseInt(parts[1], 10) - 1;
const day = parseInt(parts[2], 10);
const monthNames = [
'January', 'February', 'March', 'April', 'May', 'June',
'July', 'August', 'September', 'October', 'November', 'December'
];
if (monthIndex >= 0 && monthIndex < 12) {
return `${day} ${monthNames[monthIndex]} ${year}`;
}
return dateStr;
}
function renderRaids(raids) {
// Clear skeleton loader elements
raidsContainer.innerHTML = '';
if (!raids || raids.length === 0) {
raidsContainer.innerHTML = `
<div class="error-banner">
<p>No past raids recorded yet. Assemble your team and map out the first raid!</p>
</div>`;
return;
}
raids.forEach(raid => {
// Create Parent Collapsible Card Element (<details>)
const card = document.createElement('details');
card.className = 'raid-card parent-raid-card';
card.id = `raid-card-${raid.Raid_Num}`;
// Create Summary Header Element (<summary>)
const summaryEl = document.createElement('summary');
summaryEl.className = 'parent-raid-summary';
// Meta Section
const metaDiv = document.createElement('div');
metaDiv.className = 'raid-meta';
// Dynamically check and update Status from Future to Past if the date has passed
if (raid.endDate) {
const today = new Date();
today.setHours(0, 0, 0, 0);
const checkDate = new Date(raid.endDate);
checkDate.setHours(0, 0, 0, 0);
if (today > checkDate) {
raid.Status = "Past";
}
}
const statusText = raid.Status || "Future";
const statusClass = statusText.toLowerCase() === 'future' ? 'status-future' : 'status-past';
metaDiv.innerHTML = `
<div class="raid-date-wrapper">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round">
<rect x="3" y="4" width="18" height="18" rx="2" ry="2"></rect>
<line x1="16" y1="2" x2="16" y2="6"></line>
<line x1="8" y1="2" x2="8" y2="6"></line>
<line x1="3" y1="10" x2="21" y2="10"></line>
</svg>
<span>${escapeHTML(raid.dateRange)}</span>
</div>
<div class="raid-meta-right">
<span class="status-badge ${statusClass}">${escapeHTML(statusText)}</span>
</div>
`;
// If user is logged in, append Suggest Edit button next to status badge
if (currentSessionUser) {
const metaRight = metaDiv.querySelector('.raid-meta-right');
if (metaRight) {
const editBtn = document.createElement('button');
editBtn.type = 'button';
editBtn.className = 'raid-edit-suggest-btn';
editBtn.innerHTML = `
<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round">
<path d="M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"></path>
<path d="M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"></path>
</svg>
<span>Edit</span>
`;
editBtn.title = `Propose an update for Raid #${raid.Raid_Num}`;
editBtn.setAttribute('aria-label', `Propose update for Raid #${raid.Raid_Num}`);
editBtn.addEventListener('click', (e) => {
e.preventDefault();
e.stopPropagation();
if (window.openEventFormModal) {
window.openEventFormModal('update', raid);
}
});
metaRight.insertBefore(editBtn, metaRight.firstChild);
}
}
// Protruding Copy Link Button at top-right corner of card
const copyBtn = document.createElement('button');
copyBtn.className = 'copy-raid-link-btn';
copyBtn.title = 'Copy link to this raid';
copyBtn.setAttribute('aria-label', 'Copy link to this raid');
copyBtn.innerHTML = `
<svg class="copy-icon" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round">
<rect x="9" y="9" width="13" height="13" rx="2" ry="2"></rect>
<path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"></path>
</svg>
`;
copyBtn.addEventListener('click', (e) => {
e.preventDefault();
e.stopPropagation();
const raidUrl = window.location.href.split('#')[0] + '#raid-' + raid.Raid_Num;
navigator.clipboard.writeText(raidUrl).then(() => {
copyBtn.classList.add('copied');
copyBtn.innerHTML = `
<svg class="check-icon" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round">
<polyline points="20 6 9 17 4 12"></polyline>
</svg>
`;
setTimeout(() => {
copyBtn.classList.remove('copied');
copyBtn.innerHTML = `
<svg class="copy-icon" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round">
<rect x="9" y="9" width="13" height="13" rx="2" ry="2"></rect>
<path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"></path>
</svg>
`;
}, 2000);
}).catch(err => {
console.error('Failed to copy link: ', err);
});
});
summaryEl.appendChild(copyBtn);
summaryEl.appendChild(metaDiv);
// Title Row with Chevron Arrow
const titleRow = document.createElement('div');
titleRow.className = 'parent-raid-title-row';
const titleEl = document.createElement('h3');
titleEl.className = 'raid-title';
titleEl.textContent = raid.title;
titleRow.appendChild(titleEl);
const arrowSvg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
arrowSvg.setAttribute('class', 'parent-raid-arrow');
arrowSvg.setAttribute('width', '20');
arrowSvg.setAttribute('height', '20');
arrowSvg.setAttribute('viewBox', '0 0 24 24');
arrowSvg.setAttribute('fill', 'none');
arrowSvg.setAttribute('stroke', 'currentColor');
arrowSvg.setAttribute('stroke-width', '2.5');
arrowSvg.setAttribute('stroke-linecap', 'round');
arrowSvg.setAttribute('stroke-linejoin', 'round');
arrowSvg.innerHTML = '<polyline points="6 9 12 15 18 9"></polyline>';
titleRow.appendChild(arrowSvg);
summaryEl.appendChild(titleRow);
// Event Type Tag (Displayed below title)
if (raid.Type) {
const typeTag = document.createElement('span');
typeTag.className = 'raid-type-tag';
typeTag.textContent = raid.Type;
summaryEl.appendChild(typeTag);
}
// Venue Location Badge (Bottom-Right Corner of card summary)
if (raid.OutsideDhaka) {
// Outside Dhaka: Dynamic 2-second toggle between <s>Dhaka</s> and location icon only
const cornerBadge = document.createElement('a');
cornerBadge.className = 'raid-venue-corner-badge outside-dhaka-tag map-link';
cornerBadge.href = `https://www.google.com/maps/search/?api=1&query=${encodeURIComponent(raid.venue)}`;
cornerBadge.target = '_blank';
cornerBadge.rel = 'noopener noreferrer';
cornerBadge.title = 'View venue location on Google Maps';
cornerBadge.addEventListener('click', (e) => {
e.stopPropagation();
});
const pinSvg = `<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><path d="M21 10c0 7-9 13-9 13s-9-6-9-13a9 9 0 0 1 18 0z"></path><circle cx="12" cy="10" r="3"></circle></svg>`;
const htmlStateDhaka = `<s>Dhaka</s>`;
const htmlStateIcon = pinSvg;
cornerBadge.innerHTML = htmlStateDhaka;
let showIconOnly = false;
const cycleInterval = setInterval(() => {
if (!document.body.contains(cornerBadge)) {
clearInterval(cycleInterval);
return;
}
showIconOnly = !showIconOnly;
cornerBadge.classList.add('fade-transition');
setTimeout(() => {
cornerBadge.innerHTML = showIconOnly ? htmlStateIcon : htmlStateDhaka;
cornerBadge.classList.toggle('icon-only', showIconOnly);
cornerBadge.classList.remove('fade-transition');
}, 180);
}, 2000);
summaryEl.appendChild(cornerBadge);
} else if (raid.IsOnline) {
// Online Event: Online pill badge
const cornerBadge = document.createElement('span');
cornerBadge.className = 'raid-venue-corner-badge is-online-tag';
cornerBadge.textContent = 'Online';
summaryEl.appendChild(cornerBadge);
} else {
// OutsideDhaka = False & Physical Venue: Static borderless/backgroundless location icon linked to Google Maps
const cornerBadge = document.createElement('a');
cornerBadge.className = 'raid-venue-corner-badge static-location-tag map-link icon-only';
cornerBadge.href = `https://www.google.com/maps/search/?api=1&query=${encodeURIComponent(raid.venue)}`;
cornerBadge.target = '_blank';
cornerBadge.rel = 'noopener noreferrer';
cornerBadge.title = `View venue location on Google Maps`;
cornerBadge.addEventListener('click', (e) => {
e.stopPropagation();
});
cornerBadge.innerHTML = `<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><path d="M21 10c0 7-9 13-9 13s-9-6-9-13a9 9 0 0 1 18 0z"></path><circle cx="12" cy="10" r="3"></circle></svg>`;
summaryEl.appendChild(cornerBadge);
}
card.appendChild(summaryEl);
// Parent Body Container (Revealed when expanded)
const bodyDiv = document.createElement('div');
bodyDiv.className = 'parent-raid-body';
// Detailed Description (Supports multi-line display via pre-line)
const detailsEl = document.createElement('p');
detailsEl.className = 'raid-details';
detailsEl.textContent = raid.details;
bodyDiv.appendChild(detailsEl);
// Highlighted "See More" / "See Less" Button for Mobile
const seeMoreBtn = document.createElement('button');
seeMoreBtn.className = 'see-more-btn';
seeMoreBtn.textContent = 'See More';
seeMoreBtn.addEventListener('click', (e) => {
e.stopPropagation();
const isExpanded = detailsEl.classList.toggle('expanded');
seeMoreBtn.textContent = isExpanded ? 'See Less' : 'See More';
});
bodyDiv.appendChild(seeMoreBtn);
// Details Dropdown (Venue, Fees, Sub Events)
const detailsDropdown = document.createElement('details');
detailsDropdown.className = 'details-dropdown';
detailsDropdown.addEventListener('click', (e) => {
e.stopPropagation();
});
const detailsSummary = document.createElement('summary');
detailsSummary.className = 'details-summary';
detailsSummary.textContent = 'Details';
detailsDropdown.appendChild(detailsSummary);
// Information Group
const infoGroup = document.createElement('div');
infoGroup.className = 'details-content raid-info-group';
// Venue Info
const venueItem = createInfoItem('Venue', raid.venue);
infoGroup.appendChild(venueItem);
// Fee Info
const feeItem = createInfoItem('Fees', raid.fee);
infoGroup.appendChild(feeItem);
// Registration Deadline Info
if (raid.RegEndDate) {
const today = new Date();
today.setHours(0, 0, 0, 0);
const regDate = new Date(raid.RegEndDate);
regDate.setHours(0, 0, 0, 0);
const isClosed = today > regDate;
const formattedRegDate = formatLocalDate(raid.RegEndDate);
const regText = isClosed ? `${formattedRegDate} (Closed)` : formattedRegDate;
const regEndItem = createInfoItem('Reg Deadline', regText);
const valSpan = regEndItem.querySelector('.raid-info-value');
if (isClosed) {
valSpan.style.color = 'var(--text-muted)';
} else {
valSpan.style.color = 'var(--success-color)';
valSpan.style.fontWeight = '600';
}
infoGroup.appendChild(regEndItem);
}
// Sub Events Info (Supports string or array of collapsible schedule items)
if (raid.subEvents) {
const subEventsItem = document.createElement('div');
subEventsItem.className = 'raid-info-item raid-schedule-group';
const labelSpan = document.createElement('span');
labelSpan.className = 'raid-info-label';
labelSpan.textContent = 'Schedule';
subEventsItem.appendChild(labelSpan);
const valueSpan = document.createElement('div');
valueSpan.className = 'raid-info-value';
if (Array.isArray(raid.subEvents)) {
raid.subEvents.forEach(sub => {
const subDetailsEl = document.createElement('details');
subDetailsEl.className = 'schedule-dropdown';
subDetailsEl.addEventListener('click', (e) => {
e.stopPropagation();
});
const subSummaryEl = document.createElement('summary');
subSummaryEl.className = 'schedule-summary';
subSummaryEl.textContent = sub.title;
const contentDiv = document.createElement('div');
contentDiv.className = 'schedule-dropdown-content raid-sub-events';
contentDiv.textContent = sub.details;
subDetailsEl.appendChild(subSummaryEl);
subDetailsEl.appendChild(contentDiv);
valueSpan.appendChild(subDetailsEl);
});
} else {
const textSpan = document.createElement('span');
textSpan.className = 'raid-sub-events';
textSpan.textContent = raid.subEvents;
valueSpan.appendChild(textSpan);
}
subEventsItem.appendChild(valueSpan);
infoGroup.appendChild(subEventsItem);
}
detailsDropdown.appendChild(infoGroup);
bodyDiv.appendChild(detailsDropdown);
// Important Links Section
if (raid.links && Object.keys(raid.links).length > 0) {
const linksWrapper = document.createElement('div');
linksWrapper.className = 'raid-links-wrapper';
Object.entries(raid.links).forEach(([linkName, url]) => {
const anchor = document.createElement('a');
anchor.className = 'raid-link';
if (linkName.toLowerCase() === 'notes') {
anchor.href = `render.html?file=${encodeURIComponent(url)}`;
anchor.innerHTML = `
<span>View Notes</span>
<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round">
<path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"></path>
<polyline points="14 2 14 8 20 8"></polyline>
<line x1="16" y1="13" x2="8" y2="13"></line>
<line x1="16" y1="17" x2="8" y2="17"></line>
<polyline points="10 9 9 9 8 9"></polyline>
</svg>
`;
} else {
anchor.href = url;
anchor.target = '_blank';
anchor.rel = 'noopener noreferrer';
anchor.innerHTML = `
<span>${escapeHTML(linkName)}</span>
<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round">
<line x1="7" y1="17" x2="17" y2="7"></line>
<polyline points="7 7 17 7 17 17"></polyline>
</svg>
`;
}
linksWrapper.appendChild(anchor);
});
bodyDiv.appendChild(linksWrapper);
}
card.appendChild(bodyDiv);
// Append Card to container
raidsContainer.appendChild(card);
});
// Check for pending raid scroll
if (pendingRaidScroll) {
scrollToRaid(pendingRaidScroll);
pendingRaidScroll = null;
}
}
function createInfoItem(label, value) {
const itemDiv = document.createElement('div');
itemDiv.className = 'raid-info-item';
const labelSpan = document.createElement('span');
labelSpan.className = 'raid-info-label';
labelSpan.textContent = label;
const valueSpan = document.createElement('span');
valueSpan.className = 'raid-info-value';
valueSpan.textContent = value;
itemDiv.appendChild(labelSpan);
itemDiv.appendChild(valueSpan);
return itemDiv;
}
function renderErrorBanner(errorMessage) {
raidsContainer.innerHTML = `
<div class="error-banner">
<svg width="40" height="40" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="margin-bottom: 1rem;">
<circle cx="12" cy="12" r="10"></circle>
<line x1="12" y1="8" x2="12" y2="12"></line>
<line x1="12" y1="16" x2="12.01" y2="16"></line>
</svg>
<h3>Failed to Load Raids</h3>
<p>We encountered an issue while loading the past campaigns: "${escapeHTML(errorMessage)}".</p>
<button onclick="window.location.reload()" style="margin-top: 1rem; padding: 0.5rem 1.25rem; background-color: #ef4444; color: white; border-radius: 8px; font-weight: 600;">Retry</button>
</div>
`;
}
// Helper: Basic HTML escaping to prevent XSS injection
function escapeHTML(str) {
if (!str) return '';
return str
.replace(/&/g, '&')
.replace(/</g, '<')
.replace(/>/g, '>')
.replace(/"/g, '"')
.replace(/'/g, ''');
}
/* ==========================================================================
5. Campaign Calendar Controller
========================================================================== */
function initCalendar() {
const openCalendarBtn = document.getElementById('open-calendar-btn');
const floatingCalendarBtn = document.getElementById('floating-calendar-btn');
const floatingPastRaidsBtn = document.getElementById('floating-past-raids-btn');
const closeCalendarBtn = document.getElementById('close-calendar-btn');
const calendarModal = document.getElementById('calendar-modal');
const calendarBackdrop = document.getElementById('calendar-modal-backdrop');
const calendarMonthYear = document.getElementById('calendar-month-year');
const calendarDays = document.getElementById('calendar-days');
const prevMonthBtn = document.getElementById('prev-month-btn');
const nextMonthBtn = document.getElementById('next-month-btn');
const dayEventsOverlay = document.getElementById('day-events-overlay');
const overlayDateLabel = document.getElementById('overlay-date-label');
const overlayEventsList = document.getElementById('overlay-events-list');
const closeOverlayBtn = document.getElementById('close-overlay-btn');
// State for currently displayed calendar month (Default: July 2026)
let calendarYear = 2026;
let calendarMonth = 6; // July (0-indexed)
if (!openCalendarBtn || !calendarModal) return;
// State variables for routing page & scroll states
let isRaidsActive = false;
let isStaticBtnScrolledAway = false;
const updateFloatingBtnVisibility = () => {
if (isRaidsActive && isStaticBtnScrolledAway) {
if (floatingCalendarBtn) floatingCalendarBtn.classList.add('show');
if (floatingPastRaidsBtn) floatingPastRaidsBtn.classList.add('show');
} else {
if (floatingCalendarBtn) floatingCalendarBtn.classList.remove('show');
if (floatingPastRaidsBtn) floatingPastRaidsBtn.classList.remove('show');
}
};
// Window hook to enable/disable floating button from the router
window.enableFloatingCalendarBtn = (active) => {
isRaidsActive = active;
updateFloatingBtnVisibility();
};
// Floating button observer: trigger floating style when static container scrolls out of view
const calendarBtnContainer = document.querySelector('.calendar-btn-container');
if (calendarBtnContainer) {
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
isStaticBtnScrolledAway = !entry.isIntersecting && entry.boundingClientRect.top < 0;
updateFloatingBtnVisibility();
});
}, { threshold: 0 });
observer.observe(calendarBtnContainer);
}
const openModalWithData = () => {
if (!pastRaidsData) {
loadPastRaids().then(() => {
renderCalendarGrid();
openModal();
});
} else {
renderCalendarGrid();
openModal();
}
};
// Open modal
openCalendarBtn.addEventListener('click', openModalWithData);
if (floatingCalendarBtn) {
floatingCalendarBtn.addEventListener('click', openModalWithData);
}
// Close modal
closeCalendarBtn.addEventListener('click', closeModal);
if (calendarBackdrop) {
calendarBackdrop.addEventListener('click', closeModal);
}
// Prev/Next month navigation
prevMonthBtn.addEventListener('click', () => {
calendarMonth--;
if (calendarMonth < 0) {
calendarMonth = 11;
calendarYear--;
}
renderCalendarGrid();
});
nextMonthBtn.addEventListener('click', () => {
calendarMonth++;
if (calendarMonth > 11) {
calendarMonth = 0;
calendarYear++;
}
renderCalendarGrid();
});
// Close events overlay
closeOverlayBtn.addEventListener('click', closeOverlay);
function openModal() {
calendarModal.classList.add('open');
calendarModal.setAttribute('aria-hidden', 'false');
}
function closeModal() {
calendarModal.classList.remove('open');
calendarModal.setAttribute('aria-hidden', 'true');
closeOverlay();
}
// Export closeModal to window scope so routing can trigger it
window.closeCalendarModal = closeModal;
function closeOverlay() {
dayEventsOverlay.classList.remove('open');
}
// Helper: timezone-safe local date parser
function parseLocalDate(dateStr) {
if (!dateStr) return null;
const parts = dateStr.split('-');
if (parts.length !== 3) return null;
return {
year: parseInt(parts[0], 10),
month: parseInt(parts[1], 10) - 1, // 0-indexed
day: parseInt(parts[2], 10)
};
}
function renderCalendarGrid() {
calendarDays.innerHTML = '';
closeOverlay();
// Month names
const monthNames = [
'January', 'February', 'March', 'April', 'May', 'June',
'July', 'August', 'September', 'October', 'November', 'December'
];
calendarMonthYear.textContent = `${monthNames[calendarMonth]} ${calendarYear}`;
// First day of the month (0 = Sun, 1 = Mon, ..., 6 = Sat)
const firstDayIndex = new Date(calendarYear, calendarMonth, 1).getDay();
// Last day of the month
const lastDay = new Date(calendarYear, calendarMonth + 1, 0).getDate();
// Today's date info for today highlighting
const today = new Date();
const isCurrentMonthYear = today.getFullYear() === calendarYear && today.getMonth() === calendarMonth;
// Render empty cells for padding before the 1st of the month
for (let i = 0; i < firstDayIndex; i++) {
const emptyCell = document.createElement('div');
emptyCell.className = 'calendar-day empty';
calendarDays.appendChild(emptyCell);
}
// Group raids by day for this month and year
const eventsByDay = {};
if (pastRaidsData) {
pastRaidsData.forEach(raid => {
const parsed = parseLocalDate(raid.startDate);
if (parsed && parsed.year === calendarYear && parsed.month === calendarMonth) {
if (!eventsByDay[parsed.day]) {
eventsByDay[parsed.day] = [];
}
eventsByDay[parsed.day].push(raid);
}
});
}
// Render day cells
for (let day = 1; day <= lastDay; day++) {
const dayCell = document.createElement('div');
dayCell.className = 'calendar-day';
dayCell.textContent = day;
// Today highlighting
if (isCurrentMonthYear && today.getDate() === day) {
dayCell.classList.add('today');
}
// Check if any events fall on this day
const dayEvents = eventsByDay[day];
if (dayEvents && dayEvents.length > 0) {
dayCell.classList.add('highlighted');
dayCell.setAttribute('role', 'button');
dayCell.setAttribute('tabindex', '0');
// Gray out date cell if ALL events on this date are past raids
const allPastEvents = dayEvents.every(raid => isPastRaid(raid));
if (allPastEvents) {
dayCell.classList.add('past-only');
}
// If 2 or more events overlap, render badge count
if (dayEvents.length >= 2) {
const badge = document.createElement('span');
badge.className = 'event-count-badge';
badge.textContent = dayEvents.length;
dayCell.appendChild(badge);
}
// Click handler
dayCell.addEventListener('click', (e) => {
e.stopPropagation();
showDayEvents(day, monthNames[calendarMonth], dayEvents);
});
// Keyboard access
dayCell.addEventListener('keydown', (e) => {
if (e.key === 'Enter' || e.key === ' ') {
e.preventDefault();
showDayEvents(day, monthNames[calendarMonth], dayEvents);
}