|
102 | 102 | } |
103 | 103 | } |
104 | 104 |
|
| 105 | + /** |
| 106 | + * @param {HTMLElement} settingsElement |
| 107 | + */ |
105 | 108 | function setEvents(settingsElement) { |
106 | 109 | updateLightAndDark(); |
107 | 110 | onEachLazy(settingsElement.querySelectorAll("input[type=\"checkbox\"]"), toggle => { |
|
114 | 117 | changeSetting(toggle.id, toggle.checked); |
115 | 118 | }; |
116 | 119 | }); |
117 | | - onEachLazy(settingsElement.querySelectorAll("input[type=\"radio\"]"), elem => { |
118 | | - const settingId = elem.name; |
119 | | - let settingValue = getSettingValue(settingId); |
120 | | - if (settingId === "theme") { |
121 | | - const useSystem = getSettingValue("use-system-theme"); |
122 | | - if (useSystem === "true" || settingValue === null) { |
123 | | - // "light" is the default theme |
124 | | - settingValue = useSystem === "false" ? "light" : "system preference"; |
| 120 | + onEachLazy( |
| 121 | + settingsElement.querySelectorAll("input[type=\"radio\"]"), |
| 122 | + /** @param {HTMLInputElement} elem */ |
| 123 | + elem => { |
| 124 | + const settingId = elem.name; |
| 125 | + let settingValue = getSettingValue(settingId); |
| 126 | + if (settingId === "theme") { |
| 127 | + const useSystem = getSettingValue("use-system-theme"); |
| 128 | + if (useSystem === "true" || settingValue === null) { |
| 129 | + // "light" is the default theme |
| 130 | + settingValue = useSystem === "false" ? "light" : "system preference"; |
| 131 | + } |
125 | 132 | } |
| 133 | + if (settingValue !== null && settingValue !== "null") { |
| 134 | + elem.checked = settingValue === elem.value; |
| 135 | + } |
| 136 | + elem.addEventListener("change", ev => { |
| 137 | + changeSetting(elem.name, elem.value); |
| 138 | + }); |
126 | 139 | } |
127 | | - if (settingValue !== null && settingValue !== "null") { |
128 | | - elem.checked = settingValue === elem.value; |
129 | | - } |
130 | | - elem.addEventListener("change", ev => { |
131 | | - changeSetting(ev.target.name, ev.target.value); |
132 | | - }); |
133 | | - }); |
| 140 | + ); |
134 | 141 | } |
135 | 142 |
|
136 | 143 | /** |
137 | 144 | * This function builds the sections inside the "settings page". It takes a `settings` list |
138 | 145 | * as argument which describes each setting and how to render it. It returns a string |
139 | 146 | * representing the raw HTML. |
140 | 147 | * |
141 | | - * @param {Array<Object>} settings |
| 148 | + * @param {Array<rustdoc.Setting>} settings |
142 | 149 | * |
143 | 150 | * @return {string} |
144 | 151 | */ |
|
195 | 202 | * @return {HTMLElement} |
196 | 203 | */ |
197 | 204 | function buildSettingsPage() { |
198 | | - const theme_names = getVar("themes").split(",").filter(t => t); |
| 205 | + const theme_list = getVar("themes") |
| 206 | + const theme_names = (theme_list === null ? "" : theme_list) |
| 207 | + .split(",").filter(t => t); |
199 | 208 | theme_names.push("light", "dark", "ayu"); |
200 | 209 |
|
201 | 210 | const settings = [ |
|
0 commit comments