-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.html
More file actions
178 lines (151 loc) · 6.56 KB
/
index.html
File metadata and controls
178 lines (151 loc) · 6.56 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
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
<meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Haxademic.js</title>
<link rel="stylesheet" href="css/pico.css" />
<link rel="stylesheet" href="css/haxademic.css" />
<link rel="stylesheet" href="css/site.css" />
</head>
<body>
<!-- Hero -->
<div class="hero" data-theme="dark">
<header class="container">
<hgroup>
<h1>Haxademic.js</h1>
<p>A personal JavaScript toolkit of utilities and realtime/graphics helpers.</p>
<p>View the code <a href="https://github.com/cacheflowe/haxademic.js">on GitHub</a></p>
</hgroup>
</header>
</div>
<!-- Main -->
<main class="container">
<div class="grid">
<section>
<hgroup>
<h2>Catalog</h2>
<h3>Demos, tools, and bookmarklets</h3>
</hgroup>
<input type="search" id="search-input" placeholder="Search..." aria-label="Search demos and bookmarklets" />
<div id="catalog-demos"></div>
<div id="catalog-bookmarklets" class="catalog-section"></div>
</section>
</div>
</main>
<!-- Footer -->
<footer class="container">
<small>Built by <a href="https://cacheflowe.com">Cacheflowe</a> <date-year>©</date-year></small>
</footer>
<!-- Components -->
<script src="src/components/date-year.js" type="module"></script>
<script type="module">
// -----------------------------------------------------------------------
// Load manifest and render catalog
// -----------------------------------------------------------------------
const manifest = await fetch("./demo/manifest.json").then((r) => r.json());
// --- Demos section ---
function groupBy(arr, key) {
const map = {};
for (const item of arr) {
(map[item[key]] = map[item[key]] || []).push(item);
}
return map;
}
const demosByCategory = groupBy(manifest.demos, "category");
const demosEl = document.getElementById("catalog-demos");
const demoHeader = document.createElement("hgroup");
demoHeader.innerHTML = "<h3>Demos</h3>";
demosEl.appendChild(demoHeader);
for (const [category, demos] of Object.entries(demosByCategory)) {
const h = document.createElement("h4");
h.textContent = category;
h.dataset.categoryHeader = category;
demosEl.appendChild(h);
const ul = document.createElement("ul");
ul.dataset.categoryList = category;
for (const demo of demos) {
const li = document.createElement("li");
li.dataset.searchText = `${demo.title} ${demo.category} ${demo.description}`.toLowerCase();
li.innerHTML = `<a href="./demo/#${demo.id}">${demo.title}</a>${demo.description ? ` <small>— ${demo.description}</small>` : ""}`;
ul.appendChild(li);
}
demosEl.appendChild(ul);
}
// --- Bookmarklets section ---
const bookmarkletsEl = document.getElementById("catalog-bookmarklets");
if (manifest.bookmarklets.length > 0) {
const bmHeader = document.createElement("hgroup");
bmHeader.innerHTML =
"<h3>Bookmarklets</h3><p>Drag a title to your bookmarks bar to install, or expand to copy the source.</p>";
bookmarkletsEl.appendChild(bmHeader);
for (const bm of manifest.bookmarklets) {
const wrapper = document.createElement("div");
wrapper.className = "bookmarklet-entry";
wrapper.dataset.searchText = `${bm.title} ${bm.description}`.toLowerCase();
const details = document.createElement("details");
details.innerHTML = `
<summary>
<strong>${bm.title}</strong>
${bm.description ? `<span class="bookmarklet-drag">${bm.description}</span>` : ""}
</summary>
<div class="bookmarklet-source">
<pre><code>Loading...</code></pre>
<div class="bookmarklet-actions">
<button class="copy-btn secondary outline" style="width:auto">Copy source</button>
<small class="bookmarklet-drag">Drag to bookmarks bar to install</small>
</div>
</div>
`;
// Lazy-load source when expanded
const pre = details.querySelector("pre code");
const copyBtn = details.querySelector(".copy-btn");
let sourceLoaded = false;
let sourceText = "";
details.addEventListener("toggle", async () => {
if (!details.open || sourceLoaded) return;
sourceLoaded = true;
try {
sourceText = await fetch(`./bookmarklets/${bm.file}`).then((r) => r.text());
pre.textContent = sourceText;
} catch {
pre.textContent = "(could not load source)";
}
});
copyBtn.addEventListener("click", () => {
navigator.clipboard.writeText(sourceText).then(() => {
copyBtn.textContent = "Copied!";
setTimeout(() => (copyBtn.textContent = "Copy source"), 1500);
});
});
wrapper.appendChild(details);
bookmarkletsEl.appendChild(wrapper);
}
}
// --- Search / filter ---
document.getElementById("search-input").addEventListener("input", (e) => {
const q = e.target.value.toLowerCase().trim();
// Filter demo list items
for (const li of demosEl.querySelectorAll("li")) {
const match = !q || li.dataset.searchText.includes(q);
li.toggleAttribute("data-hidden", !match);
}
// Hide empty category headers + lists
for (const ul of demosEl.querySelectorAll("ul[data-category-list]")) {
const hasVisible = [...ul.querySelectorAll("li")].some((li) => !li.hasAttribute("data-hidden"));
const category = ul.dataset.categoryList;
const h = demosEl.querySelector(`[data-category-header="${category}"]`);
ul.toggleAttribute("data-hidden", !hasVisible);
if (h) h.toggleAttribute("data-hidden", !hasVisible);
}
// Filter bookmarklet entries
for (const entry of bookmarkletsEl.querySelectorAll(".bookmarklet-entry")) {
const match = !q || entry.dataset.searchText.includes(q);
entry.toggleAttribute("data-hidden", !match);
}
});
</script>
</body>
</html>