|
6 | 6 | {% if pluginSpecs is empty %} |
7 | 7 | <p>No API modules are currently available.</p> |
8 | 8 | {% else %} |
9 | | - <h2>Available API modules</h2> |
10 | | - <ul> |
| 9 | + <ul id="api-docs-list"> |
11 | 10 | {% for pluginSpec in pluginSpecs %} |
12 | 11 | <li> |
13 | 12 | <a href="{{ ('/api-reference/api/' ~ pluginSpec.slug)|completeUrl }}">{{ pluginSpec.name }}</a> |
|
16 | 15 | </ul> |
17 | 16 | {% endif %} |
18 | 17 | {% endblock %} |
| 18 | + |
| 19 | +{% block footer %} |
| 20 | + {{ parent() }} |
| 21 | + |
| 22 | + <script type="text/javascript"> |
| 23 | + (function () { |
| 24 | + let collapsedIndicator = '+'; |
| 25 | + let expandedIndicator = '−'; |
| 26 | +
|
| 27 | + function setSectionCollapsedState(section, isCollapsed) { |
| 28 | + section.button.setAttribute('aria-expanded', isCollapsed ? 'false' : 'true'); |
| 29 | + section.heading.classList.toggle('api-swagger-index-heading-collapsed', isCollapsed); |
| 30 | + section.indicator.textContent = isCollapsed ? collapsedIndicator : expandedIndicator; |
| 31 | +
|
| 32 | + section.elements.forEach(function (element) { |
| 33 | + element.classList.toggle('api-swagger-index-collapsed', isCollapsed); |
| 34 | + element.setAttribute('aria-hidden', isCollapsed ? 'true' : 'false'); |
| 35 | + }); |
| 36 | + } |
| 37 | +
|
| 38 | + function createSectionButton(heading) { |
| 39 | + let button = document.createElement('button'); |
| 40 | + button.type = 'button'; |
| 41 | + button.className = 'api-swagger-index-toggle'; |
| 42 | + button.setAttribute('aria-expanded', 'false'); |
| 43 | +
|
| 44 | + let label = document.createElement('span'); |
| 45 | + label.className = 'api-swagger-index-toggle-label'; |
| 46 | +
|
| 47 | + while (heading.firstChild) { |
| 48 | + label.appendChild(heading.firstChild); |
| 49 | + } |
| 50 | +
|
| 51 | + let indicator = document.createElement('span'); |
| 52 | + indicator.className = 'api-swagger-index-toggle-icon'; |
| 53 | + indicator.setAttribute('aria-hidden', 'true'); |
| 54 | + indicator.textContent = collapsedIndicator; |
| 55 | +
|
| 56 | + button.appendChild(label); |
| 57 | + button.appendChild(indicator); |
| 58 | +
|
| 59 | + heading.appendChild(button); |
| 60 | +
|
| 61 | + return button; |
| 62 | + } |
| 63 | +
|
| 64 | + function shouldStartCollapsed(section) { |
| 65 | + return !section.elements.some(function (element) { |
| 66 | + return element.id === 'api-docs-list'; |
| 67 | + }); |
| 68 | + } |
| 69 | +
|
| 70 | + function sectionContainsTarget(section, targetId) { |
| 71 | + if (section.heading.id === targetId) { |
| 72 | + return true; |
| 73 | + } |
| 74 | +
|
| 75 | + return section.elements.some(function (element) { |
| 76 | + if (element.id === targetId) { |
| 77 | + return true; |
| 78 | + } |
| 79 | +
|
| 80 | + return Array.prototype.some.call(element.querySelectorAll('[id]'), function (child) { |
| 81 | + return child.id === targetId; |
| 82 | + }); |
| 83 | + }); |
| 84 | + } |
| 85 | +
|
| 86 | + function scrollToHashTarget(targetId) { |
| 87 | + let target = document.getElementById(targetId); |
| 88 | + if (!target) { |
| 89 | + return; |
| 90 | + } |
| 91 | +
|
| 92 | + target.scrollIntoView(); |
| 93 | + } |
| 94 | +
|
| 95 | + function expandSectionForHash(sections, hash) { |
| 96 | + let targetId = (hash || '').replace(/^#/, ''); |
| 97 | + if (!targetId) { |
| 98 | + return; |
| 99 | + } |
| 100 | +
|
| 101 | + let didExpand = false; |
| 102 | + sections.forEach(function (section) { |
| 103 | + if (sectionContainsTarget(section, targetId)) { |
| 104 | + setSectionCollapsedState(section, false); |
| 105 | + didExpand = true; |
| 106 | + } |
| 107 | + }); |
| 108 | +
|
| 109 | + if (didExpand) { |
| 110 | + window.requestAnimationFrame(function () { |
| 111 | + scrollToHashTarget(targetId); |
| 112 | + }); |
| 113 | + } |
| 114 | + } |
| 115 | +
|
| 116 | + function initCollapsibleSections() { |
| 117 | + let docsParent = document.querySelector('.documentation'); |
| 118 | + if (!docsParent) { |
| 119 | + return; |
| 120 | + } |
| 121 | +
|
| 122 | + let sections = []; |
| 123 | + let currentSection = null; |
| 124 | +
|
| 125 | + Array.prototype.forEach.call(docsParent.children, function (child) { |
| 126 | + if (child.tagName === 'H2') { |
| 127 | + currentSection = { |
| 128 | + heading: child, |
| 129 | + elements: [] |
| 130 | + }; |
| 131 | + sections.push(currentSection); |
| 132 | +
|
| 133 | + return; |
| 134 | + } |
| 135 | +
|
| 136 | + if (currentSection) { |
| 137 | + currentSection.elements.push(child); |
| 138 | + } |
| 139 | + }); |
| 140 | +
|
| 141 | + let collapsibleSections = sections.map(function (section) { |
| 142 | + if (!section.elements.length) { |
| 143 | + return null; |
| 144 | + } |
| 145 | +
|
| 146 | + section.heading.classList.add('api-swagger-index-heading'); |
| 147 | + section.button = createSectionButton(section.heading); |
| 148 | + section.indicator = section.button.querySelector('.api-swagger-index-toggle-icon'); |
| 149 | +
|
| 150 | + section.button.addEventListener('click', function () { |
| 151 | + let isExpanded = section.button.getAttribute('aria-expanded') === 'true'; |
| 152 | + setSectionCollapsedState(section, isExpanded); |
| 153 | + }); |
| 154 | +
|
| 155 | + return section; |
| 156 | + }).filter(Boolean); |
| 157 | +
|
| 158 | + if (!collapsibleSections.length) { |
| 159 | + return; |
| 160 | + } |
| 161 | +
|
| 162 | + docsParent.classList.add('api-swagger-index-collapsible-ready'); |
| 163 | +
|
| 164 | + collapsibleSections.forEach(function (section) { |
| 165 | + setSectionCollapsedState(section, shouldStartCollapsed(section)); |
| 166 | + }); |
| 167 | +
|
| 168 | + expandSectionForHash(collapsibleSections, window.location.hash); |
| 169 | +
|
| 170 | + window.addEventListener('hashchange', function () { |
| 171 | + expandSectionForHash(collapsibleSections, window.location.hash); |
| 172 | + }); |
| 173 | + } |
| 174 | +
|
| 175 | + if (document.readyState === 'loading') { |
| 176 | + document.addEventListener('DOMContentLoaded', initCollapsibleSections); |
| 177 | + } else { |
| 178 | + initCollapsibleSections(); |
| 179 | + } |
| 180 | + })(); |
| 181 | +
|
| 182 | + </script> |
| 183 | +{% endblock %} |
0 commit comments