Skip to content

Commit 65539c9

Browse files
committed
cleaned up navigation
1 parent 9e9e729 commit 65539c9

3 files changed

Lines changed: 53 additions & 2 deletions

File tree

app/routes/page.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ function renderGuide(Slim\Views\Twig $view, Response $response, Psr\Http\Message
116116
'selectedPiwikVersion' => Environment::getPiwikVersion(),
117117
'urlIfAvailableInNewerVersion' => (Environment::isLatestPiwikVersion() ? false : Url::getUrlIfDocumentIsAvailableInPiwikVersion($request->getUri()->getPath(), LATEST_PIWIK_DOCS_VERSION)),
118118
'pluginSpecs' => $pluginSpecs,
119-
'hideGuideSections' => true,
120119
]);
121120
});
122121

app/templates/api-swagger-index.twig

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,52 @@
6262
return button;
6363
}
6464
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+
65111
function initCollapsibleSections() {
66112
let docsParent = document.querySelector('.documentation');
67113
if (!docsParent) {
@@ -117,6 +163,12 @@
117163
collapsibleSections.forEach(function (section) {
118164
setSectionCollapsedState(section, true);
119165
});
166+
167+
expandSectionForHash(collapsibleSections, window.location.hash);
168+
169+
window.addEventListener('hashchange', function () {
170+
expandSectionForHash(collapsibleSections, window.location.hash);
171+
});
120172
}
121173
122174
if (document.readyState === 'loading') {

app/templates/left-menu.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
</div>
4343
{% endif %}
4444

45-
{% if pluginSpecs is defined and pluginSpecs is not empty %}
45+
{% if pluginSpecs is defined and pluginSpecs is not empty and hideGuideSections|default(false) %}
4646
<div class="guide-sections panel panel-default">
4747
<div class="panel-heading">
4848
<h4 class="panel-title">

0 commit comments

Comments
 (0)