-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscripts.js
More file actions
458 lines (396 loc) · 17.8 KB
/
scripts.js
File metadata and controls
458 lines (396 loc) · 17.8 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
document.addEventListener('DOMContentLoaded', function() {
// Initialize Feather icons
feather.replace();
// Theme Toggle
const themeToggle = document.getElementById('theme-toggle');
const themeToggleIcon = themeToggle.querySelector('i');
themeToggle.addEventListener('click', () => {
document.body.classList.toggle('light-mode');
if (document.body.classList.contains('light-mode')) {
themeToggleIcon.setAttribute('data-feather', 'sun');
} else {
themeToggleIcon.setAttribute('data-feather', 'moon');
}
feather.replace();
// Save user preference
const theme = document.body.classList.contains('light-mode') ? 'light' : 'dark';
localStorage.setItem('theme', theme);
});
// Check for saved user preference
const savedTheme = localStorage.getItem('theme');
if (savedTheme === 'light') {
document.body.classList.add('light-mode');
themeToggleIcon.setAttribute('data-feather', 'sun');
feather.replace();
}
// Copyright year - fixing the syntax error by adding the missing parenthesis
const currentYear = new Date().getFullYear();
document.querySelector('.copyright p').textContent = `© ${currentYear} POLA. All rights reserved.`;
// Mobile menu toggle
const menuToggle = document.getElementById('menu-toggle');
const mobileNav = document.querySelector('.mobile-nav');
menuToggle.addEventListener('click', () => {
mobileNav.classList.toggle('active');
});
// Clone the TOC for mobile
const toc = document.querySelector('.toc');
const mobileToc = document.querySelector('.mobile-toc');
if (toc && mobileToc) {
mobileToc.innerHTML = toc.innerHTML;
// Close mobile nav when a link is clicked
mobileToc.querySelectorAll('a').forEach(link => {
link.addEventListener('click', () => {
mobileNav.classList.remove('active');
});
});
}
// Back to top functionality
document.querySelectorAll('.back-to-top').forEach(button => {
button.addEventListener('click', (e) => {
e.preventDefault();
window.scrollTo({ top: 0, behavior: 'smooth' });
});
});
// Add global back to top button
const backToTopGlobal = document.createElement('div');
backToTopGlobal.className = 'back-to-top-global';
backToTopGlobal.innerHTML = '<i data-feather="chevron-up"></i>';
document.body.appendChild(backToTopGlobal);
// Initialize the icon
feather.replace();
// Handle global back to top button
backToTopGlobal.addEventListener('click', () => {
window.scrollTo({ top: 0, behavior: 'smooth' });
});
// Show/hide global back to top button based on scroll position
window.addEventListener('scroll', () => {
if (window.scrollY > 300) {
backToTopGlobal.classList.add('visible');
} else {
backToTopGlobal.classList.remove('visible');
}
});
// Expandable sections
document.querySelectorAll('.expandable-toggle').forEach(toggle => {
toggle.addEventListener('click', () => {
toggle.classList.toggle('active');
const content = toggle.nextElementSibling;
content.classList.toggle('active');
// Check if the span element exists before trying to change its text content
const spanElement = toggle.querySelector('span');
if (spanElement) {
if (content.classList.contains('active')) {
spanElement.textContent = 'Hide Merged Table';
} else {
spanElement.textContent = 'Show Merged Table';
}
}
});
});
// Search functionality
const searchInput = document.getElementById('search-input');
const searchContainer = document.querySelector('.search-container');
if (searchInput) {
// Focus search with keyboard shortcut
document.addEventListener('keydown', function(e) {
if (e.key === '/' && document.activeElement !== searchInput) {
e.preventDefault();
searchInput.focus();
}
});
searchInput.addEventListener('input', function() {
const searchTerm = this.value.toLowerCase();
// If the search term is empty, show all content
if (searchTerm.trim() === '') {
document.querySelectorAll('table tbody tr').forEach(row => {
row.style.display = '';
// Remove any highlighting
row.innerHTML = row.innerHTML.replace(/<mark class="search-highlight">(.*?)<\/mark>/g, '$1');
});
document.querySelectorAll('.section-card, .subsection, .subsubsection, .expandable-content').forEach(section => {
section.style.display = '';
if (section.classList.contains('expandable-content')) {
section.classList.remove('active');
const toggle = section.previousElementSibling;
if (toggle && toggle.classList.contains('expandable-toggle')) {
toggle.classList.remove('active');
}
}
});
// Hide "no results" message when search is empty
const noResultsMsg = document.querySelector('.no-results-message');
if (noResultsMsg) {
noResultsMsg.style.display = 'none';
}
return;
}
// Special handling for rarity terms
const isRaritySearch = ['pink', 'red', 'teal'].includes(searchTerm);
// Keep track of which sections have matches
const sectionsWithMatches = new Set();
const subsectionsWithMatches = new Set();
const subsubsectionsWithMatches = new Set();
const tableCategories = new Set(); // To track which table categories (pink/red) have matches
// Hide all expandable content sections first
document.querySelectorAll('.expandable-content').forEach(section => {
section.style.display = 'none';
section.classList.remove('active');
const toggle = section.previousElementSibling;
if (toggle && toggle.classList.contains('expandable-toggle')) {
toggle.classList.remove('active');
}
});
// Search within tables (but not in expandable content tables)
document.querySelectorAll('table tbody tr').forEach(row => {
// Skip rows in expandable content
if (row.closest('.expandable-content')) return;
const textContent = row.textContent.toLowerCase();
const cells = row.querySelectorAll('td');
let hasMatch = false;
// First, revert any previous highlighting
cells.forEach(cell => {
// Save the original HTML before any search highlighting was applied
if (!cell.hasAttribute('data-original-html')) {
cell.setAttribute('data-original-html', cell.innerHTML);
} else {
// Restore original HTML before applying new highlights
cell.innerHTML = cell.getAttribute('data-original-html');
}
});
// Special handling for rarity search
if (isRaritySearch) {
// Check if this row contains rarity information
const hasRarity = row.innerHTML.toLowerCase().includes(`class="rarity ${searchTerm}"`) ||
row.innerHTML.toLowerCase().includes(`class="${searchTerm}"`) ||
row.innerHTML.toLowerCase().includes(`kbd class="${searchTerm}"`);
// For rarity search, we want to show the row even if it doesn't contain the term directly
if (hasRarity || textContent.includes(searchTerm)) {
hasMatch = true;
}
} else {
// Standard search
hasMatch = textContent.includes(searchTerm);
}
if (hasMatch) {
row.style.display = '';
// Highlight the matching text
cells.forEach(cell => {
if (cell.textContent.toLowerCase().includes(searchTerm)) {
// Clone the cell to work with it safely
const tempDiv = document.createElement('div');
tempDiv.innerHTML = cell.getAttribute('data-original-html');
// Function to highlight text while preserving HTML structure
const highlightHTML = (element) => {
if (element.nodeType === Node.TEXT_NODE) {
const text = element.textContent;
const lowerText = text.toLowerCase();
const index = lowerText.indexOf(searchTerm);
if (index >= 0) {
// Create text nodes and highlight element
const before = document.createTextNode(text.substring(0, index));
const match = document.createElement('mark');
match.className = 'search-highlight';
match.textContent = text.substring(index, index + searchTerm.length);
const after = document.createTextNode(text.substring(index + searchTerm.length));
// Replace the original text node
const parent = element.parentNode;
parent.insertBefore(before, element);
parent.insertBefore(match, element);
parent.insertBefore(after, element);
parent.removeChild(element);
// Continue searching in the remaining text
if (after.textContent.toLowerCase().includes(searchTerm)) {
highlightHTML(after);
}
}
} else if (element.nodeType === Node.ELEMENT_NODE) {
// Skip highlighting in existing mark elements
if (element.nodeName !== 'MARK') {
// Process child nodes
const childNodes = Array.from(element.childNodes);
childNodes.forEach(highlightHTML);
}
}
};
// Process all child nodes
Array.from(tempDiv.childNodes).forEach(highlightHTML);
// Update cell with highlighted content
cell.innerHTML = tempDiv.innerHTML;
}
});
// Track containing sections
let parent = row.closest('.section-card');
if (parent) {
sectionsWithMatches.add(parent.id);
}
parent = row.closest('.subsection');
if (parent) {
subsectionsWithMatches.add(parent.id);
// Track which category (pink/red) the match belongs to
const categoryH3 = parent.querySelector('h3');
if (categoryH3) {
if (categoryH3.textContent.toLowerCase().includes('pink')) {
tableCategories.add('pink');
} else if (categoryH3.textContent.toLowerCase().includes('red')) {
tableCategories.add('red');
} else if (categoryH3.textContent.toLowerCase().includes('teal')) {
tableCategories.add('teal');
}
}
}
parent = row.closest('.subsubsection');
if (parent) {
subsubsectionsWithMatches.add(parent.id);
// Track which category (pink/red) the match belongs to
const categoryH4 = parent.querySelector('h4');
if (categoryH4) {
if (categoryH4.textContent.toLowerCase().includes('pink')) {
tableCategories.add('pink');
} else if (categoryH4.textContent.toLowerCase().includes('red')) {
tableCategories.add('red');
} else if (categoryH4.textContent.toLowerCase().includes('teal')) {
tableCategories.add('teal');
}
}
// Also track its parent subsection
const subsection = parent.closest('.subsection');
if (subsection) {
subsectionsWithMatches.add(subsection.id);
}
}
} else {
row.style.display = 'none';
}
});
// After processing all rows, count total matches
let matchCount = 0;
document.querySelectorAll('table tbody tr').forEach(row => {
if (row.style.display !== 'none' && !row.closest('.expandable-content')) {
matchCount++;
}
});
// Check if we have any matches
const hasVisibleResults = matchCount > 0;
// Show "no results" message if needed
let noResultsMsg = document.querySelector('.no-results-message');
if (!hasVisibleResults && searchTerm.trim() !== '') {
if (!noResultsMsg) {
noResultsMsg = document.createElement('div');
noResultsMsg.className = 'no-results-message';
noResultsMsg.innerHTML = '<i data-feather="search"></i><p>No results found for "' + searchTerm + '"</p>';
document.querySelector('.content').prepend(noResultsMsg);
feather.replace();
} else {
noResultsMsg.innerHTML = '<i data-feather="search"></i><p>No results found for "' + searchTerm + '"</p>';
feather.replace();
noResultsMsg.style.display = '';
}
} else if (noResultsMsg) {
noResultsMsg.style.display = 'none';
}
// Hide sections that don't have matches
document.querySelectorAll('.section-card').forEach(section => {
if (sectionsWithMatches.has(section.id)) {
section.style.display = '';
} else {
section.style.display = 'none';
}
});
// Handle rarity filtering for subsections
document.querySelectorAll('.subsection').forEach(subsection => {
if (subsectionsWithMatches.has(subsection.id)) {
subsection.style.display = '';
// For rarity searches, make sure we show all matching categories
const subsectionH3 = subsection.querySelector('h3');
if (subsectionH3 && isRaritySearch) {
const text = subsectionH3.textContent.toLowerCase();
if (text.includes(searchTerm)) {
subsection.style.display = '';
}
} else {
// Hide category-specific subsections that don't match the found categories
// (e.g., hide Pinks section if only Reds have matches)
if (subsectionH3) {
const text = subsectionH3.textContent.toLowerCase();
if ((text.includes('pink') && !tableCategories.has('pink')) ||
(text.includes('red') && !tableCategories.has('red')) ||
(text.includes('teal') && !tableCategories.has('teal'))) {
subsection.style.display = 'none';
}
}
}
// Hide sibling subsections that don't have matches
const parentSection = subsection.closest('.section-card');
if (parentSection) {
parentSection.querySelectorAll('.subsection').forEach(siblingSubsection => {
if (siblingSubsection !== subsection && !subsectionsWithMatches.has(siblingSubsection.id)) {
siblingSubsection.style.display = 'none';
}
});
}
} else {
subsection.style.display = 'none';
}
});
// Hide subsubsections that don't have matches
document.querySelectorAll('.subsubsection').forEach(subsubsection => {
if (subsubsectionsWithMatches.has(subsubsection.id)) {
subsubsection.style.display = '';
// For rarity searches, make sure we show all matching categories
const subsubsectionH4 = subsubsection.querySelector('h4');
if (subsubsectionH4 && isRaritySearch) {
const text = subsubsectionH4.textContent.toLowerCase();
if (text.includes(searchTerm)) {
subsubsection.style.display = '';
}
} else {
// Hide category-specific subsubsections that don't match the found categories
if (subsubsectionH4) {
const text = subsubsectionH4.textContent.toLowerCase();
if ((text.includes('pink') && !tableCategories.has('pink')) ||
(text.includes('red') && !tableCategories.has('red')) ||
(text.includes('teal') && !tableCategories.has('teal'))) {
subsubsection.style.display = 'none';
}
}
}
// Hide sibling subsubsections that don't have matches
const parentSubsection = subsubsection.closest('.subsection');
if (parentSubsection) {
parentSubsection.querySelectorAll('.subsubsection').forEach(siblingSubsubsection => {
if (siblingSubsubsection !== subsubsection && !subsubsectionsWithMatches.has(siblingSubsubsection.id)) {
siblingSubsubsection.style.display = 'none';
}
});
}
} else {
subsubsection.style.display = 'none';
}
});
});
}
// Highlight active section in sidebar based on scroll position
const sections = document.querySelectorAll('section[id]');
const navLinks = document.querySelectorAll('.toc a');
// Only set up scroll highlighting if sections exist
if (sections.length > 0) {
function highlightNavigation() {
const scrollPosition = window.scrollY;
sections.forEach(section => {
const sectionTop = section.offsetTop - 100;
const sectionHeight = section.offsetHeight;
const sectionId = section.getAttribute('id');
if (scrollPosition >= sectionTop && scrollPosition < sectionTop + sectionHeight) {
document.querySelectorAll(`.toc a[href="#${sectionId}"]`).forEach(link => {
link.classList.add('active');
});
} else {
document.querySelectorAll(`.toc a[href="#${sectionId}"]`).forEach(link => {
link.classList.remove('active');
});
}
});
}
window.addEventListener('scroll', highlightNavigation);
}
});