|
223 | 223 | }
|
224 | 224 | }
|
225 | 225 | }
|
226 |
| - highlightSourceLines(null); |
| 226 | + |
| 227 | + function expandSection(id) { |
| 228 | + var elem = document.getElementById(id); |
| 229 | + if (elem && isHidden(elem)) { |
| 230 | + var h3 = elem.parentNode.previousSibling; |
| 231 | + if (h3 && h3.tagName !== 'H3') { |
| 232 | + h3 = h3.previousSibling; // skip div.docblock |
| 233 | + } |
| 234 | + |
| 235 | + if (h3) { |
| 236 | + var collapses = h3.getElementsByClassName("collapse-toggle"); |
| 237 | + if (collapses.length > 0) { |
| 238 | + // The element is not visible, we need to make it appear! |
| 239 | + collapseDocs(collapses[0], "show"); |
| 240 | + } |
| 241 | + } |
| 242 | + } |
| 243 | + } |
| 244 | + |
227 | 245 | window.onhashchange = highlightSourceLines;
|
228 | 246 |
|
229 | 247 | // Gets the human-readable string for the virtual-key code of the
|
|
317 | 335 | }
|
318 | 336 | }
|
319 | 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 | + |
320 | 347 | document.onkeypress = handleShortcut;
|
321 | 348 | document.onkeydown = handleShortcut;
|
322 | 349 | document.onclick = function(ev) {
|
|
354 | 381 | } else if (!hasClass(document.getElementById("help"), "hidden")) {
|
355 | 382 | addClass(document.getElementById("help"), "hidden");
|
356 | 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 | + } |
357 | 391 | }
|
358 | 392 | };
|
359 | 393 |
|
|
2213 | 2247 | autoCollapse(getPageId(), getCurrentValue("rustdoc-collapse") === "true");
|
2214 | 2248 |
|
2215 | 2249 | if (window.location.hash && window.location.hash.length > 0) {
|
2216 |
| - var hash = getPageId(); |
2217 |
| - if (hash !== null) { |
2218 |
| - var elem = document.getElementById(hash); |
2219 |
| - if (elem && elem.offsetParent === null) { |
2220 |
| - if (elem.parentNode && elem.parentNode.previousSibling) { |
2221 |
| - var collapses = elem.parentNode |
2222 |
| - .previousSibling |
2223 |
| - .getElementsByClassName("collapse-toggle"); |
2224 |
| - if (collapses.length > 0) { |
2225 |
| - // The element is not visible, we need to make it appear! |
2226 |
| - collapseDocs(collapses[0], "show"); |
2227 |
| - } |
2228 |
| - } |
2229 |
| - } |
2230 |
| - } |
| 2250 | + expandSection(window.location.hash.replace(/^#/, '')); |
2231 | 2251 | }
|
2232 | 2252 | }());
|
2233 | 2253 |
|
|
0 commit comments