Skip to content

Commit 31a2315

Browse files
Merge pull request #2 from copilot-dev-days/copilot/make-checkboxes-clickable
Enable interactive workshop checklist checkboxes on GitHub Pages
2 parents 8dbd23f + d4d1a19 commit 31a2315

1 file changed

Lines changed: 51 additions & 0 deletions

File tree

docs/step.html

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,8 @@
220220
const GITHUB_RAW_BASE = isLocal
221221
? '../workshop/'
222222
: 'https://raw.githubusercontent.com/copilot-dev-days/agent-lab-python/main/workshop/';
223+
const CHECKBOX_STORAGE_KEY = 'agent-lab-checkboxes-v1';
224+
let checkboxSaveTimeout;
223225

224226
// Get current step from URL
225227
function getCurrentStepId() {
@@ -232,6 +234,54 @@
232234
return steps.findIndex(s => s.id === stepId);
233235
}
234236

237+
function readCheckboxState() {
238+
try {
239+
return JSON.parse(localStorage.getItem(CHECKBOX_STORAGE_KEY) || '{}');
240+
} catch {
241+
return {};
242+
}
243+
}
244+
245+
function writeCheckboxState(state) {
246+
try {
247+
localStorage.setItem(CHECKBOX_STORAGE_KEY, JSON.stringify(state));
248+
} catch {
249+
// Ignore storage failures (private mode / blocked storage)
250+
}
251+
}
252+
253+
function writeCheckboxStateDebounced(state) {
254+
clearTimeout(checkboxSaveTimeout);
255+
checkboxSaveTimeout = setTimeout(() => writeCheckboxState(state), 100);
256+
}
257+
258+
function initializeTaskListCheckboxes(stepId) {
259+
const container = document.getElementById('markdown-content');
260+
if (!container) return;
261+
const checkboxes = container.querySelectorAll('input[type="checkbox"]');
262+
if (checkboxes.length === 0) return;
263+
264+
const allState = readCheckboxState();
265+
if (!Array.isArray(allState[stepId])) {
266+
allState[stepId] = [];
267+
}
268+
const stepState = allState[stepId];
269+
270+
checkboxes.forEach((checkbox, index) => {
271+
checkbox.disabled = false;
272+
273+
if (typeof stepState[index] === 'boolean') {
274+
checkbox.checked = stepState[index];
275+
}
276+
277+
checkbox.addEventListener('change', () => {
278+
stepState[index] = checkbox.checked;
279+
allState[stepId] = stepState;
280+
writeCheckboxStateDebounced(allState);
281+
});
282+
});
283+
}
284+
235285
// Build sidebar navigation
236286
function buildSidebar() {
237287
const nav = document.getElementById('stepNav');
@@ -339,6 +389,7 @@
339389
});
340390

341391
document.getElementById('markdown-content').innerHTML = marked.parse(md);
392+
initializeTaskListCheckboxes(step.id);
342393

343394
// If this is the completion page, add confetti!
344395
if (step.id === '05-complete') {

0 commit comments

Comments
 (0)