|
135 | 135 | if (e.target.closest("ol a")) setToc(false); |
136 | 136 | }); |
137 | 137 |
|
| 138 | + var navStateKey = "knowledge-base:collapsed-sidebar-groups"; |
| 139 | + if (document.body.classList.contains("is-home")) { |
| 140 | + try { |
| 141 | + window.localStorage.removeItem(navStateKey); |
| 142 | + } catch (e) { |
| 143 | + // No saved sidebar state exists when storage is unavailable. |
| 144 | + } |
| 145 | + } |
| 146 | + |
| 147 | + function readCollapsedNavGroups() { |
| 148 | + try { |
| 149 | + var saved = JSON.parse(window.localStorage.getItem(navStateKey) || "[]"); |
| 150 | + if (!Array.isArray(saved)) return []; |
| 151 | + return saved.filter(function (key, index) { |
| 152 | + return typeof key === "string" && saved.indexOf(key) === index; |
| 153 | + }); |
| 154 | + } catch (e) { |
| 155 | + return []; |
| 156 | + } |
| 157 | + } |
| 158 | + function writeCollapsedNavGroups(groups) { |
| 159 | + try { |
| 160 | + window.localStorage.setItem(navStateKey, JSON.stringify(groups)); |
| 161 | + } catch (e) { |
| 162 | + // The sidebar still works for this page when storage is unavailable. |
| 163 | + } |
| 164 | + } |
| 165 | + |
| 166 | + var collapsedNavGroups = readCollapsedNavGroups(); |
| 167 | + document.querySelectorAll(".nav-group-toggle").forEach(function (btn) { |
| 168 | + var key = btn.dataset.navKey; |
| 169 | + if (key && collapsedNavGroups.indexOf(key) !== -1) { |
| 170 | + btn.setAttribute("aria-expanded", "false"); |
| 171 | + } |
| 172 | + |
| 173 | + btn.addEventListener("click", function () { |
| 174 | + var open = btn.getAttribute("aria-expanded") === "true"; |
| 175 | + btn.setAttribute("aria-expanded", open ? "false" : "true"); |
| 176 | + |
| 177 | + if (!key) return; |
| 178 | + var savedIndex = collapsedNavGroups.indexOf(key); |
| 179 | + if (open && savedIndex === -1) { |
| 180 | + collapsedNavGroups.push(key); |
| 181 | + } else if (!open && savedIndex !== -1) { |
| 182 | + collapsedNavGroups.splice(savedIndex, 1); |
| 183 | + } |
| 184 | + writeCollapsedNavGroups(collapsedNavGroups); |
| 185 | + }); |
| 186 | + }); |
| 187 | + |
138 | 188 | document.querySelectorAll(".show-more").forEach(function (btn) { |
139 | 189 | btn.addEventListener("click", function () { |
140 | 190 | var open = btn.getAttribute("aria-expanded") === "true"; |
|
0 commit comments