|
6 | 6 | {% if pluginSpecs is empty %} |
7 | 7 | <p>No API modules are currently available.</p> |
8 | 8 | {% else %} |
9 | | - <h2>Quick access to APIs</h2> |
10 | 9 | <ul id="api-docs-list"> |
11 | 10 | {% for pluginSpec in pluginSpecs %} |
12 | 11 | <li> |
|
36 | 35 | }); |
37 | 36 | } |
38 | 37 |
|
39 | | - function createSectionButton(heading, sectionId) { |
| 38 | + function createSectionButton(heading) { |
40 | 39 | let button = document.createElement('button'); |
41 | 40 | button.type = 'button'; |
42 | 41 | button.className = 'api-swagger-index-toggle'; |
43 | 42 | button.setAttribute('aria-expanded', 'false'); |
44 | | - button.setAttribute('data-section-id', sectionId); |
45 | 43 |
|
46 | 44 | let label = document.createElement('span'); |
47 | 45 | label.className = 'api-swagger-index-toggle-label'; |
|
63 | 61 | return button; |
64 | 62 | } |
65 | 63 |
|
| 64 | + function shouldStartCollapsed(section) { |
| 65 | + return !section.elements.some(function (element) { |
| 66 | + return element.id === 'api-docs-list'; |
| 67 | + }); |
| 68 | + } |
| 69 | +
|
66 | 70 | function sectionContainsTarget(section, targetId) { |
67 | 71 | if (section.heading.id === targetId) { |
68 | 72 | return true; |
|
115 | 119 | return; |
116 | 120 | } |
117 | 121 |
|
118 | | - let sections = {}; |
| 122 | + let sections = []; |
119 | 123 | let currentSection = null; |
120 | 124 |
|
121 | 125 | Array.prototype.forEach.call(docsParent.children, function (child) { |
122 | 126 | if (child.tagName === 'H2') { |
123 | | - currentSection = child.id || null; |
124 | | -
|
125 | | - if (currentSection) { |
126 | | - sections[currentSection] = { |
127 | | - heading: child, |
128 | | - elements: [] |
129 | | - }; |
130 | | - } |
| 127 | + currentSection = { |
| 128 | + heading: child, |
| 129 | + elements: [] |
| 130 | + }; |
| 131 | + sections.push(currentSection); |
131 | 132 |
|
132 | 133 | return; |
133 | 134 | } |
134 | 135 |
|
135 | 136 | if (currentSection) { |
136 | | - sections[currentSection].elements.push(child); |
| 137 | + currentSection.elements.push(child); |
137 | 138 | } |
138 | 139 | }); |
139 | 140 |
|
140 | | - let collapsibleSections = Object.keys(sections).map(function (sectionId) { |
141 | | - let section = sections[sectionId]; |
| 141 | + let collapsibleSections = sections.map(function (section) { |
142 | 142 | if (!section.elements.length) { |
143 | 143 | return null; |
144 | 144 | } |
145 | 145 |
|
146 | 146 | section.heading.classList.add('api-swagger-index-heading'); |
147 | | - section.button = createSectionButton(section.heading, sectionId); |
| 147 | + section.button = createSectionButton(section.heading); |
148 | 148 | section.indicator = section.button.querySelector('.api-swagger-index-toggle-icon'); |
149 | 149 |
|
150 | 150 | section.button.addEventListener('click', function () { |
|
162 | 162 | docsParent.classList.add('api-swagger-index-collapsible-ready'); |
163 | 163 |
|
164 | 164 | collapsibleSections.forEach(function (section) { |
165 | | - setSectionCollapsedState(section, true); |
| 165 | + setSectionCollapsedState(section, shouldStartCollapsed(section)); |
166 | 166 | }); |
167 | 167 |
|
168 | 168 | expandSectionForHash(collapsibleSections, window.location.hash); |
|
0 commit comments