-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexplore.html
More file actions
376 lines (327 loc) · 16.6 KB
/
Copy pathexplore.html
File metadata and controls
376 lines (327 loc) · 16.6 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Explore Systems - What's Your Metaphysics?</title>
<link rel="icon"
href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22>📖</text></svg>">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link
href="https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;600;800&family=Playfair+Display:ital,wght@0,400;0,700;1,400&display=swap"
rel="stylesheet">
<link rel="stylesheet" href="css/style.css">
<!-- Firebase SDKs -->
<script src="https://www.gstatic.com/firebasejs/8.10.1/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.10.1/firebase-firestore.js"></script>
<!-- App Stats Logic -->
<script src="js/firebase-config.js"></script>
<script src="js/stats.js"></script>
<body>
<div class="app-container">
<header>
<div class="header-content">
<a href="index.html" class="back-home-btn" aria-label="Back to Home">
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none"
stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path d="M3 9l9-7 9 7v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z"></path>
<polyline points="9 22 9 12 15 12 15 22"></polyline>
</svg>
</a>
<h1>Metaphysical Systems</h1>
<button id="theme-toggle" class="theme-toggle" aria-label="Toggle Dark Mode">
<svg class="sun-icon" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"
fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"
stroke-linejoin="round">
<circle cx="12" cy="12" r="5"></circle>
<line x1="12" y1="1" x2="12" y2="3"></line>
<line x1="12" y1="21" x2="12" y2="23"></line>
<line x1="4.22" y1="4.22" x2="5.64" y2="5.64"></line>
<line x1="18.36" y1="18.36" x2="19.78" y2="19.78"></line>
<line x1="1" y1="12" x2="3" y2="12"></line>
<line x1="21" y1="12" x2="23" y2="12"></line>
<line x1="4.22" y1="19.78" x2="5.64" y2="18.36"></line>
<line x1="18.36" y1="5.64" x2="19.78" y2="4.22"></line>
</svg>
<svg class="moon-icon" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"
fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"
stroke-linejoin="round">
<path d="M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"></path>
</svg>
</button>
</div>
<p class="subtitle">A catalog of philosophical worldviews.</p>
</header>
<main id="explore-content">
<div class="navigation-top"
style="display: flex; justify-content: center; margin-bottom: 2rem;">
<div class="sort-toggle">
<button id="sort-alpha" class="sort-btn active" title="Sort alphabetically">
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none"
stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path d="M3 6h7"></path>
<path d="M3 12h10"></path>
<path d="M3 18h13"></path>
</svg>
A-Z
</button>
<button id="sort-popular" class="sort-btn" title="Sort by popularity">
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none"
stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path d="M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"></path>
<circle cx="9" cy="7" r="4"></circle>
<path d="M23 21v-2a4 4 0 0 0-3-3.87"></path>
<path d="M16 3.13a4 4 0 0 1 0 7.75"></path>
</svg>
Popular
</button>
</div>
</div>
<div id="alpha-nav" class="alpha-nav">
<!-- Letters will be injected here -->
</div>
<div id="systems-grid" class="systems-grid">
<!-- Systems will be injected here -->
</div>
</main>
<footer>
<p>Developed by Arthur Juliani | <a href="https://github.com/awjuliani/metaphysics-quiz"
target="_blank">View Source</a></p>
</footer>
</div>
<script src="js/theme.js"></script>
<script src="js/utils.js"></script>
<script>
// Theme is handled by js/theme.js (auto-initializes on load)
setupThemeToggle();
// Store systems and stats globally for re-sorting
let allSystems = [];
let systemStats = {};
let totalCount = 0;
let currentSort = 'alpha'; // Default to alphabetical
// Build alphabet/number navigation
function buildAlphaNav(systems) {
const alphaNav = document.getElementById('alpha-nav');
// Store references for cleanup
if (window.alphaNavCleanup) {
window.alphaNavCleanup();
}
function renderNav() {
if (currentSort === 'alpha') {
renderAlphaNav();
} else {
renderNumNav();
}
positionAlphaNav();
}
function renderAlphaNav() {
const letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('');
const activeLetters = new Set(
systems.map(s => s.name.charAt(0).toUpperCase())
);
alphaNav.innerHTML = letters.map(letter => {
const isActive = activeLetters.has(letter);
return `<button class="alpha-btn${isActive ? '' : ' disabled'}"
data-letter="${letter}"
${isActive ? '' : 'disabled'}
title="${isActive ? `Jump to ${letter}` : 'No systems'}">${letter}</button>`;
}).join('');
// Add click handlers
alphaNav.querySelectorAll('.alpha-btn:not(.disabled)').forEach(btn => {
btn.addEventListener('click', () => {
const letter = btn.dataset.letter;
const cards = document.querySelectorAll('.system-card');
for (const card of cards) {
const name = card.querySelector('h2').textContent;
if (name.charAt(0).toUpperCase() === letter) {
scrollToCard(card);
break;
}
}
});
});
}
function renderNumNav() {
const total = systems.length;
// Show 1, 5, 10, 15, ... up to total
const positions = [1];
for (let i = 5; i <= total; i += 5) {
positions.push(i);
}
if (positions[positions.length - 1] !== total) {
positions.push(total);
}
alphaNav.innerHTML = positions.map(num => {
return `<button class="alpha-btn" data-position="${num}" title="Jump to #${num}">${num}</button>`;
}).join('');
// Add click handlers
alphaNav.querySelectorAll('.alpha-btn').forEach(btn => {
btn.addEventListener('click', () => {
const position = parseInt(btn.dataset.position);
const cards = document.querySelectorAll('.system-card');
if (cards[position - 1]) {
scrollToCard(cards[position - 1]);
}
});
});
}
function scrollToCard(card) {
card.scrollIntoView({ behavior: 'smooth', block: 'start' });
card.style.borderColor = 'var(--primary-color)';
card.style.boxShadow = '0 0 0 2px var(--primary-color)';
setTimeout(() => {
card.style.borderColor = '';
card.style.boxShadow = '';
}, 1500);
}
// Scroll listener to highlight current item
function updateActiveOnScroll() {
const cards = document.querySelectorAll('.system-card');
let currentIndex = 0;
let currentLetter = null;
for (let i = 0; i < cards.length; i++) {
const card = cards[i];
const rect = card.getBoundingClientRect();
if (rect.top >= 0 && rect.top < window.innerHeight / 2) {
currentIndex = i;
currentLetter = card.querySelector('h2').textContent.charAt(0).toUpperCase();
break;
}
if (rect.top < window.innerHeight / 2 && rect.bottom > 0) {
currentIndex = i;
currentLetter = card.querySelector('h2').textContent.charAt(0).toUpperCase();
}
}
if (currentSort === 'alpha') {
alphaNav.querySelectorAll('.alpha-btn').forEach(btn => {
btn.classList.toggle('active', btn.dataset.letter === currentLetter);
});
} else {
const position = currentIndex + 1;
alphaNav.querySelectorAll('.alpha-btn').forEach(btn => {
const btnPos = parseInt(btn.dataset.position);
const nextBtn = btn.nextElementSibling;
const nextPos = nextBtn ? parseInt(nextBtn.dataset.position) : Infinity;
btn.classList.toggle('active', position >= btnPos && position < nextPos);
});
}
}
// Position nav relative to grid (desktop only)
function positionAlphaNav() {
if (window.innerWidth <= 900) return;
const grid = document.getElementById('systems-grid');
const gridRect = grid.getBoundingClientRect();
const navWidth = alphaNav.offsetWidth;
const gap = 12;
const leftPos = gridRect.left - navWidth - gap;
alphaNav.style.left = Math.max(8, leftPos) + 'px';
}
window.addEventListener('scroll', updateActiveOnScroll, { passive: true });
window.addEventListener('resize', positionAlphaNav);
// Store cleanup function and re-render function
window.alphaNavCleanup = () => {
window.removeEventListener('scroll', updateActiveOnScroll);
window.removeEventListener('resize', positionAlphaNav);
};
window.updateAlphaNav = renderNav;
renderNav();
}
// Render systems to the grid
function renderSystems(systems) {
const grid = document.getElementById('systems-grid');
grid.innerHTML = '';
systems.forEach(system => {
const card = document.createElement('div');
card.className = 'card system-card';
const systemId = getSystemSlug(system.name);
card.id = systemId;
const popularityHtml = getPopularityHtml(system.name, systemStats, totalCount);
const profileKeys = Object.keys(system.profile);
const metaHtml = profileKeys.map(key => `
<div class="meta-item">
<span class="label">${key}</span>
<a href="dimensions.html#${key}" class="value dimension-link">${system.profile[key]}</a>
</div>
`).join('');
card.innerHTML = `
<div class="card-header-flex" style="display: flex; justify-content: space-between; align-items: start;">
<h2>${system.name}</h2>
${popularityHtml}
</div>
<p class="system-description">${system.description}</p>
<div class="system-links">
<a href="${system.wiki}" target="_blank" class="wiki-link">Read on Wikipedia →</a>
${system.primary_source ? `<div class="primary-source"><span class="source-label">📖 Recommended:</span> <em class="source-text">${system.primary_source}</em></div>` : ''}
</div>
<div class="system-meta">
${metaHtml}
</div>
`;
grid.appendChild(card);
});
}
// Sort and render systems
function sortSystems(sortType) {
currentSort = sortType;
const sorted = [...allSystems];
if (sortType === 'alpha') {
sorted.sort((a, b) => a.name.localeCompare(b.name));
} else if (sortType === 'popular') {
sorted.sort((a, b) => {
const countA = systemStats[a.name] || 0;
const countB = systemStats[b.name] || 0;
return countB - countA; // Descending by popularity
});
}
renderSystems(sorted);
// Update button states
document.getElementById('sort-alpha').classList.toggle('active', sortType === 'alpha');
document.getElementById('sort-popular').classList.toggle('active', sortType === 'popular');
// Update nav to show letters or numbers
if (window.updateAlphaNav) {
window.updateAlphaNav();
}
}
// Load Systems
async function loadSystems() {
try {
const [systemsResponse, stats] = await Promise.all([
fetch('data/systems.json'),
getSystemStats()
]);
allSystems = await systemsResponse.json();
systemStats = stats;
totalCount = Object.values(stats).reduce((a, b) => a + b, 0);
// Build alphabet navigation
buildAlphaNav(allSystems);
// Initial sort (alphabetical)
sortSystems('alpha');
// Set up sort button listeners
document.getElementById('sort-alpha').addEventListener('click', () => sortSystems('alpha'));
document.getElementById('sort-popular').addEventListener('click', () => sortSystems('popular'));
// Check for hash and scroll to it
if (window.location.hash) {
const id = window.location.hash.substring(1);
const element = document.getElementById(id);
if (element) {
setTimeout(() => {
element.scrollIntoView({ behavior: 'smooth', block: 'start' });
element.style.borderColor = 'var(--primary-color)';
element.style.boxShadow = '0 0 0 2px var(--primary-color)';
setTimeout(() => {
element.style.borderColor = '';
element.style.boxShadow = '';
}, 2000);
}, 100);
}
}
} catch (error) {
console.error('Error loading systems:', error);
document.getElementById('systems-grid').innerHTML = '<p>Error loading systems. Please try again later.</p>';
}
}
loadSystems();
</script>
</body>
</html>