|
62 | 62 | return button; |
63 | 63 | } |
64 | 64 |
|
| 65 | + function sectionContainsTarget(section, targetId) { |
| 66 | + if (section.heading.id === targetId) { |
| 67 | + return true; |
| 68 | + } |
| 69 | +
|
| 70 | + return section.elements.some(function (element) { |
| 71 | + if (element.id === targetId) { |
| 72 | + return true; |
| 73 | + } |
| 74 | +
|
| 75 | + return Array.prototype.some.call(element.querySelectorAll('[id]'), function (child) { |
| 76 | + return child.id === targetId; |
| 77 | + }); |
| 78 | + }); |
| 79 | + } |
| 80 | +
|
| 81 | + function scrollToHashTarget(targetId) { |
| 82 | + let target = document.getElementById(targetId); |
| 83 | + if (!target) { |
| 84 | + return; |
| 85 | + } |
| 86 | +
|
| 87 | + target.scrollIntoView(); |
| 88 | + } |
| 89 | +
|
| 90 | + function expandSectionForHash(sections, hash) { |
| 91 | + let targetId = (hash || '').replace(/^#/, ''); |
| 92 | + if (!targetId) { |
| 93 | + return; |
| 94 | + } |
| 95 | +
|
| 96 | + let didExpand = false; |
| 97 | + sections.forEach(function (section) { |
| 98 | + if (sectionContainsTarget(section, targetId)) { |
| 99 | + setSectionCollapsedState(section, false); |
| 100 | + didExpand = true; |
| 101 | + } |
| 102 | + }); |
| 103 | +
|
| 104 | + if (didExpand) { |
| 105 | + window.requestAnimationFrame(function () { |
| 106 | + scrollToHashTarget(targetId); |
| 107 | + }); |
| 108 | + } |
| 109 | + } |
| 110 | +
|
65 | 111 | function initCollapsibleSections() { |
66 | 112 | let docsParent = document.querySelector('.documentation'); |
67 | 113 | if (!docsParent) { |
|
117 | 163 | collapsibleSections.forEach(function (section) { |
118 | 164 | setSectionCollapsedState(section, true); |
119 | 165 | }); |
| 166 | +
|
| 167 | + expandSectionForHash(collapsibleSections, window.location.hash); |
| 168 | +
|
| 169 | + window.addEventListener('hashchange', function () { |
| 170 | + expandSectionForHash(collapsibleSections, window.location.hash); |
| 171 | + }); |
120 | 172 | } |
121 | 173 |
|
122 | 174 | if (document.readyState === 'loading') { |
|
0 commit comments