|
224 | 224 | } |
225 | 225 | } |
226 | 226 |
|
227 | | - function expandSection() { |
228 | | - var hash = getPageId(); |
229 | | - if (hash === null) { |
230 | | - return; |
231 | | - } |
232 | | - |
233 | | - var elem = document.getElementById(hash); |
234 | | - if (elem && elem.offsetParent && isHidden(elem.offsetParent)) { |
| 227 | + function expandSection(id) { |
| 228 | + var elem = document.getElementById(id); |
| 229 | + if (elem && isHidden(elem)) { |
235 | 230 | var h3 = elem.parentNode.previousSibling; |
236 | 231 | if (h3 && h3.tagName !== 'H3') { |
237 | 232 | h3 = h3.previousSibling; // skip div.docblock |
|
247 | 242 | } |
248 | 243 | } |
249 | 244 |
|
250 | | - function onHashChange(ev) { |
251 | | - highlightSourceLines(ev); |
252 | | - expandSection(); |
253 | | - } |
254 | | - |
255 | | - highlightSourceLines(null); |
256 | | - window.onhashchange = onHashChange; |
| 245 | + window.onhashchange = highlightSourceLines; |
257 | 246 |
|
258 | 247 | // Gets the human-readable string for the virtual-key code of the |
259 | 248 | // given KeyboardEvent, ev. |
|
346 | 335 | } |
347 | 336 | } |
348 | 337 |
|
| 338 | + function findParentElement(elem, tagName) { |
| 339 | + do { |
| 340 | + if (elem && elem.tagName === tagName) { |
| 341 | + return elem; |
| 342 | + } |
| 343 | + } while (elem = elem.parentNode); |
| 344 | + return null; |
| 345 | + } |
| 346 | + |
349 | 347 | document.onkeypress = handleShortcut; |
350 | 348 | document.onkeydown = handleShortcut; |
351 | 349 | document.onclick = function(ev) { |
|
383 | 381 | } else if (!hasClass(document.getElementById("help"), "hidden")) { |
384 | 382 | addClass(document.getElementById("help"), "hidden"); |
385 | 383 | removeClass(document.body, "blur"); |
| 384 | + } else { |
| 385 | + // Making a collapsed element visible on onhashchange seems |
| 386 | + // too late |
| 387 | + var a = findParentElement(ev.target, 'A'); |
| 388 | + if (a && a.hash) { |
| 389 | + expandSection(a.hash.replace(/^#/, '')); |
| 390 | + } |
386 | 391 | } |
387 | 392 | }; |
388 | 393 |
|
|
2242 | 2247 | autoCollapse(getPageId(), getCurrentValue("rustdoc-collapse") === "true"); |
2243 | 2248 |
|
2244 | 2249 | if (window.location.hash && window.location.hash.length > 0) { |
2245 | | - expandSection(); |
| 2250 | + expandSection(window.location.hash.replace(/^#/, '')); |
2246 | 2251 | } |
2247 | 2252 | }()); |
2248 | 2253 |
|
|
0 commit comments