Skip to content

Commit 37e7063

Browse files
Merge pull request #3 from copilot-dev-days/copilot/make-checkboxes-clickable
Enable interactive workshop checkboxes on GitHub Pages
2 parents 1865c48 + b4abd98 commit 37e7063

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

docs/step.html

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
}
8181

8282
const GITHUB_RAW_BASE = 'https://raw.githubusercontent.com/copilot-dev-days/agent-lab-typescript/main/workshop/';
83+
const CHECKBOX_STATE_KEY_PREFIX = 'workshop-checkboxes:';
8384

8485
function getCurrentStepId() {
8586
const params = new URLSearchParams(window.location.search);
@@ -162,6 +163,41 @@
162163
return md;
163164
}
164165

166+
function getCheckboxStorageKey(stepId) {
167+
return `${CHECKBOX_STATE_KEY_PREFIX}${stepId}`;
168+
}
169+
170+
function setupInteractiveCheckboxes(stepId) {
171+
const container = document.getElementById('markdown-content');
172+
const checkboxes = container.querySelectorAll('input[type="checkbox"]');
173+
if (!checkboxes.length) return;
174+
175+
const storageKey = getCheckboxStorageKey(stepId);
176+
let checkedIndexes = [];
177+
178+
try {
179+
checkedIndexes = JSON.parse(localStorage.getItem(storageKey) || '[]');
180+
if (!Array.isArray(checkedIndexes)) checkedIndexes = [];
181+
} catch {
182+
checkedIndexes = [];
183+
}
184+
185+
checkboxes.forEach((checkbox, index) => {
186+
checkbox.disabled = false;
187+
checkbox.checked = checkedIndexes.includes(index) || checkbox.checked;
188+
checkbox.setAttribute('aria-label', `Checklist item ${index + 1}`);
189+
190+
checkbox.addEventListener('change', () => {
191+
const updated = Array.from(checkboxes)
192+
.reduce((acc, cb, i) => {
193+
if (cb.checked) acc.push(i);
194+
return acc;
195+
}, []);
196+
localStorage.setItem(storageKey, JSON.stringify(updated));
197+
});
198+
});
199+
}
200+
165201
async function loadContent() {
166202
const idx = getCurrentStepIndex();
167203
if (idx === -1) {
@@ -188,6 +224,7 @@
188224

189225
marked.setOptions({ breaks: true, gfm: true });
190226
document.getElementById('markdown-content').innerHTML = marked.parse(md);
227+
setupInteractiveCheckboxes(step.id);
191228

192229
if (step.id === '05-complete') {
193230
setTimeout(celebrate, 500);

0 commit comments

Comments
 (0)