|
80 | 80 | } |
81 | 81 |
|
82 | 82 | const GITHUB_RAW_BASE = 'https://raw.githubusercontent.com/copilot-dev-days/agent-lab-typescript/main/workshop/'; |
| 83 | + const CHECKBOX_STATE_KEY_PREFIX = 'workshop-checkboxes:'; |
83 | 84 |
|
84 | 85 | function getCurrentStepId() { |
85 | 86 | const params = new URLSearchParams(window.location.search); |
|
162 | 163 | return md; |
163 | 164 | } |
164 | 165 |
|
| 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 | + |
165 | 201 | async function loadContent() { |
166 | 202 | const idx = getCurrentStepIndex(); |
167 | 203 | if (idx === -1) { |
|
188 | 224 |
|
189 | 225 | marked.setOptions({ breaks: true, gfm: true }); |
190 | 226 | document.getElementById('markdown-content').innerHTML = marked.parse(md); |
| 227 | + setupInteractiveCheckboxes(step.id); |
191 | 228 |
|
192 | 229 | if (step.id === '05-complete') { |
193 | 230 | setTimeout(celebrate, 500); |
|
0 commit comments