Skip to content

Commit dc645be

Browse files
committed
Added left menu nav for 'Quick access to APIs' and auto expanded that section
1 parent 08d52a9 commit dc645be

2 files changed

Lines changed: 18 additions & 17 deletions

File tree

app/templates/api-swagger-index.twig

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
{% if pluginSpecs is empty %}
77
<p>No API modules are currently available.</p>
88
{% else %}
9-
<h2>Quick access to APIs</h2>
109
<ul id="api-docs-list">
1110
{% for pluginSpec in pluginSpecs %}
1211
<li>
@@ -36,12 +35,11 @@
3635
});
3736
}
3837
39-
function createSectionButton(heading, sectionId) {
38+
function createSectionButton(heading) {
4039
let button = document.createElement('button');
4140
button.type = 'button';
4241
button.className = 'api-swagger-index-toggle';
4342
button.setAttribute('aria-expanded', 'false');
44-
button.setAttribute('data-section-id', sectionId);
4543
4644
let label = document.createElement('span');
4745
label.className = 'api-swagger-index-toggle-label';
@@ -63,6 +61,12 @@
6361
return button;
6462
}
6563
64+
function shouldStartCollapsed(section) {
65+
return !section.elements.some(function (element) {
66+
return element.id === 'api-docs-list';
67+
});
68+
}
69+
6670
function sectionContainsTarget(section, targetId) {
6771
if (section.heading.id === targetId) {
6872
return true;
@@ -115,36 +119,32 @@
115119
return;
116120
}
117121
118-
let sections = {};
122+
let sections = [];
119123
let currentSection = null;
120124
121125
Array.prototype.forEach.call(docsParent.children, function (child) {
122126
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);
131132
132133
return;
133134
}
134135
135136
if (currentSection) {
136-
sections[currentSection].elements.push(child);
137+
currentSection.elements.push(child);
137138
}
138139
});
139140
140-
let collapsibleSections = Object.keys(sections).map(function (sectionId) {
141-
let section = sections[sectionId];
141+
let collapsibleSections = sections.map(function (section) {
142142
if (!section.elements.length) {
143143
return null;
144144
}
145145
146146
section.heading.classList.add('api-swagger-index-heading');
147-
section.button = createSectionButton(section.heading, sectionId);
147+
section.button = createSectionButton(section.heading);
148148
section.indicator = section.button.querySelector('.api-swagger-index-toggle-icon');
149149
150150
section.button.addEventListener('click', function () {
@@ -162,7 +162,7 @@
162162
docsParent.classList.add('api-swagger-index-collapsible-ready');
163163
164164
collapsibleSections.forEach(function (section) {
165-
setSectionCollapsedState(section, true);
165+
setSectionCollapsedState(section, shouldStartCollapsed(section));
166166
});
167167
168168
expandSectionForHash(collapsibleSections, window.location.hash);

docs/5.x/api.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,3 +235,4 @@ Here is a list of metrics returned by the API and their definition.
235235

236236
All the commonly used terms in Matomo Analytics are documented in the [Glossary](https://glossary.matomo.org) including all metrics and reports.
237237

238+
## Quick access to APIs

0 commit comments

Comments
 (0)