Skip to content

clean up side-menu open/close logic #461

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 11 additions & 27 deletions js/side-menu/index.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,17 @@
export default function () {

// highlight active integration on the source/destinatino catalog pages
const re_integrations = /^\/docs\/connections\/(destinations|sources)\/catalog\/(.*)\/$/
const re_warehouses = /^\/docs\/connections\/(warehouses)\/catalog\/(.*)\/$/
// highlight active link slug in side menu
const pathname = document.location.pathname

if (re_integrations.test(pathname)) {
// find all links associated with active catalog page
const links = document.querySelectorAll(`[data-class-active="menu-item--active"] > ul > li > a[href="${pathname}"]`)
// only open the first 'category' that contains the active integrations
links[0].parentElement.parentElement.parentElement.className += ' menu-item--active'
for (let i = 0; i < links.length; i++) {
let link = links[i]
if (link.classList.contains('menu-item__link')) {
// set link to be active
link.parentElement.className += ' menu-item--active menu-item--indicator'
link.className += ' menu-item__link--indicator'
}
}
} else if (re_warehouses.test(pathname)) {
const links = document.querySelectorAll(`[data-ref="accordion[body]"] > li > a[href="${pathname}"]`)
// only open the first 'category' that contains the active integrations
for (let i = 0; i < links.length; i++) {
let link = links[i]
if (link.classList.contains('menu-item__link')) {
// set link to be active
link.parentElement.className += ' menu-item--active menu-item--indicator'
link.className += ' menu-item__link--indicator'
}
// find all links associated with active catalog page
const links = document.querySelectorAll(`[data-class-active="menu-item--active"] > ul > li > a[href="${pathname}"]`)
// only open the first 'category' that contains the active integrations
links[0].parentElement.parentElement.parentElement.className += ' menu-item--active'
for (let i = 0; i < links.length; i++) {
let link = links[i]
if (link.classList.contains('menu-item__link')) {
// set link to be active
link.parentElement.className += ' menu-item--active menu-item--indicator'
link.className += ' menu-item__link--indicator'
}
}
}
4 changes: 2 additions & 2 deletions src/_includes/menu/menu-item.html
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@
{% assign currentPage = page.path | downcase | replace: "/index.md" "" | replace: ".md" "" %}
{% assign currentPath = subsubsection.path | downcase | replace_first: "/" "" %}

<li class="menu-item {% if currentPage == currentPath %}menu-item--active menu-item--indicator{% endif %}">
<a class="menu-item__link {% if currentPage == currentPath %}menu-item__link--indicator{% endif %} flex" href="{{ site.baseurl }}{{ subsubsection.path }}/">{{ subsubsection.title }}</a>
<li class="menu-item">
<a class="menu-item__link flex" href="{{ site.baseurl }}{{ subsubsection.path }}/">{{ subsubsection.title }}</a>
</li>
{% endfor %}
</ul>
Expand Down
2 changes: 1 addition & 1 deletion src/_includes/menu/menu-legal.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
{% capture currentSectionSlug %}{{ currentSectionPage[0] | downcase }}/{{ currentSectionPage[1] | downcase }}{% endcapture %}

<li class="menu-item menu-item--gray">
<a class="menu-item__link {% if currentPage == currentPath or currentSectionSlug == currentSectionPath %}menu-item__link--indicator-large{% endif %} flex" href="{{ site.baseurl }}{{ item.path }}/">{{ item.title }}</a>
<a class="menu-item__link flex" href="{{ site.baseurl }}{{ item.path }}/">{{ item.title }}</a>
</li>
{% endfor %}
</ul>
Expand Down
4 changes: 2 additions & 2 deletions src/_includes/menu/menu-partners.html
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@
{% assign currentPage = page.path | downcase | replace: "/index.md" "" | replace: ".md" "" %}
{% assign currentPath = subsubsection.path | downcase | replace_first: "/" "" %}

<li class="menu-item {% if currentPage == currentPath %}menu-item--active menu-item--indicator{% endif %}">
<a class="menu-item__link {% if currentPage == currentPath %}menu-item__link--indicator{% endif %} flex" href="{{ site.baseurl }}{{ subsubsection.path }}/">{{ subsubsection.title }}</a>
<li class="menu-item">
<a class="menu-item__link flex" href="{{ site.baseurl }}{{ subsubsection.path }}/">{{ subsubsection.title }}</a>
</li>
{% endfor %}
</ul>
Expand Down