2020-07-02 21:06:24 +03:00
|
|
|
// 'More projects' button on use case pages
|
|
|
|
(() => {
|
2020-08-27 19:38:08 +03:00
|
|
|
const button = document.querySelector('.js-moreProjectsBtn');
|
2020-07-02 21:06:24 +03:00
|
|
|
if (!button) return;
|
2020-08-27 19:38:08 +03:00
|
|
|
const hiddenProjects = document.querySelectorAll('.js-featuredUsersRow[hidden]');
|
2020-07-02 21:06:24 +03:00
|
|
|
button.addEventListener('click', () => {
|
2020-08-27 19:38:08 +03:00
|
|
|
button.setAttribute('hidden', true);
|
2020-07-02 21:06:24 +03:00
|
|
|
hiddenProjects.forEach(project => {
|
2020-08-27 19:38:08 +03:00
|
|
|
project.removeAttribute('hidden');
|
2020-07-02 21:06:24 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
})();
|
|
|
|
|
|
|
|
// Use case pages section navigation
|
|
|
|
(() => {
|
|
|
|
const stickyNav = document.querySelector('.js-useCaseStickyNav');
|
2021-11-09 20:55:57 +03:00
|
|
|
if (!stickyNav) return;
|
|
|
|
const linkData = {
|
|
|
|
'overview': 'Overview',
|
|
|
|
'key-benefits': 'Key Benefits',
|
|
|
|
'use-case': 'Use Case',
|
|
|
|
'featured-users': 'Featured Users',
|
|
|
|
'get-started': 'Get Started',
|
|
|
|
};
|
|
|
|
const container = document.querySelector('.js-useCaseSubnav');
|
|
|
|
const subNavAnchorLinks = document.querySelector('.js-useCaseSubnavLinks');
|
|
|
|
const siteHeader = document.querySelector('.js-siteHeader');
|
|
|
|
const header = document.querySelector('.js-useCaseSubnavHeader');
|
|
|
|
const icon = document.querySelector('.js-useCaseSubnavMenuIcon');
|
|
|
|
const menu = document.querySelector('.js-useCaseSubnavMenu');
|
|
|
|
const contentBody = document.querySelector('.js-useCaseContentBody');
|
|
|
|
const headerHeightPx = 56;
|
|
|
|
const sectionHeadings = Array.from(
|
|
|
|
document.querySelectorAll('.sectionHeading')
|
2022-03-10 20:11:28 +03:00
|
|
|
);
|
2021-11-09 20:55:57 +03:00
|
|
|
let distanceFromTop =
|
|
|
|
window.pageYOffset +
|
|
|
|
contentBody.getBoundingClientRect().top -
|
|
|
|
headerHeightPx;
|
|
|
|
if (!header || !menu) return;
|
|
|
|
container.addEventListener('click', handleClick);
|
|
|
|
container.addEventListener('keydown', handleKeydown);
|
|
|
|
changeScrollPosition();
|
|
|
|
|
|
|
|
function handleClick(event) {
|
|
|
|
if (event.target === header) {
|
|
|
|
toggleMenu();
|
|
|
|
} else {
|
|
|
|
closeMenu();
|
2020-07-02 21:06:24 +03:00
|
|
|
}
|
2021-11-09 20:55:57 +03:00
|
|
|
}
|
2020-07-02 21:06:24 +03:00
|
|
|
|
2021-11-09 20:55:57 +03:00
|
|
|
function handleKeydown(event) {
|
|
|
|
if (event.key === 'Enter') {
|
|
|
|
closeMenu();
|
|
|
|
} else {
|
|
|
|
openMenu();
|
2020-07-02 21:06:24 +03:00
|
|
|
}
|
2021-11-09 20:55:57 +03:00
|
|
|
}
|
2020-07-02 21:06:24 +03:00
|
|
|
|
2021-11-09 20:55:57 +03:00
|
|
|
function openMenu() {
|
|
|
|
menu.classList.add('UseCaseSubNav-menu--open');
|
|
|
|
icon.classList.add('UseCaseSubNav-menuIcon--open');
|
|
|
|
}
|
2020-07-02 21:06:24 +03:00
|
|
|
|
2021-11-09 20:55:57 +03:00
|
|
|
function closeMenu() {
|
|
|
|
menu.classList.remove('UseCaseSubNav-menu--open');
|
|
|
|
icon.classList.remove('UseCaseSubNav-menuIcon--open');
|
|
|
|
}
|
2020-07-02 21:06:24 +03:00
|
|
|
|
2021-11-09 20:55:57 +03:00
|
|
|
function toggleMenu() {
|
|
|
|
menu.classList.toggle('UseCaseSubNav-menu--open');
|
|
|
|
icon.classList.toggle('UseCaseSubNav-menuIcon--open');
|
|
|
|
}
|
2020-07-02 21:06:24 +03:00
|
|
|
|
2021-11-09 20:55:57 +03:00
|
|
|
sectionHeadings.forEach(heading => {
|
|
|
|
let a = document.createElement('a');
|
|
|
|
a.classList.add('UseCase-anchorLink', 'anchor-link');
|
|
|
|
a.href = `${window.location.pathname}#${heading.id}`;
|
|
|
|
a.textContent = linkData[heading.id];
|
|
|
|
stickyNav.appendChild(a);
|
|
|
|
a = a.cloneNode();
|
|
|
|
a.textContent = linkData[heading.id];
|
|
|
|
subNavAnchorLinks.appendChild(a);
|
|
|
|
});
|
2020-07-02 21:06:24 +03:00
|
|
|
|
2021-11-09 20:55:57 +03:00
|
|
|
// Selected section styles
|
|
|
|
const anchorLinks = document.querySelectorAll('.anchor-link');
|
|
|
|
anchorLinks.forEach(link => {
|
|
|
|
link.addEventListener('click', () => {
|
|
|
|
document
|
|
|
|
.querySelectorAll('.anchor-link')
|
|
|
|
.forEach(el => el.classList.remove('selected'));
|
|
|
|
link.classList.add('selected');
|
2020-07-02 21:06:24 +03:00
|
|
|
});
|
2021-11-09 20:55:57 +03:00
|
|
|
});
|
2020-07-02 21:06:24 +03:00
|
|
|
|
2021-11-09 20:55:57 +03:00
|
|
|
window.addEventListener('scroll', () => {
|
|
|
|
// delay in case the user clicked the anchor link and we are autoscrolling
|
|
|
|
setTimeout(setSelectedAnchor, 500);
|
|
|
|
});
|
2020-07-02 21:06:24 +03:00
|
|
|
|
2021-11-09 20:55:57 +03:00
|
|
|
function setSelectedAnchor() {
|
|
|
|
for (heading of sectionHeadings) {
|
|
|
|
const {offsetTop} = heading;
|
|
|
|
if (offsetTop > window.scrollY) {
|
|
|
|
anchorLinks.forEach(link => {
|
|
|
|
const anchorId = link.href.slice(link.href.indexOf('#') + 1);
|
|
|
|
if (anchorId === heading.id) {
|
|
|
|
link.classList.add('selected');
|
|
|
|
} else {
|
|
|
|
link.classList.remove('selected');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
break;
|
2020-07-02 21:06:24 +03:00
|
|
|
}
|
|
|
|
}
|
2021-11-09 20:55:57 +03:00
|
|
|
}
|
2020-07-02 21:06:24 +03:00
|
|
|
|
2021-11-09 20:55:57 +03:00
|
|
|
/* sticky nav logic -- uses content for y position because reloading page
|
|
|
|
when not scrolled to the top creates bug if using current y position of
|
|
|
|
sticky nav */
|
|
|
|
window.addEventListener('scroll', setStickyNav);
|
2020-07-02 21:06:24 +03:00
|
|
|
|
2021-11-09 20:55:57 +03:00
|
|
|
window.addEventListener('resize', () => {
|
|
|
|
distanceFromTop =
|
|
|
|
window.pageYOffset +
|
|
|
|
contentBody.getBoundingClientRect().top -
|
|
|
|
headerHeightPx;
|
2020-07-28 00:04:56 +03:00
|
|
|
|
2021-11-09 20:55:57 +03:00
|
|
|
changeScrollPosition()
|
|
|
|
});
|
2020-07-02 21:06:24 +03:00
|
|
|
|
2021-11-09 20:55:57 +03:00
|
|
|
/**
|
|
|
|
* Changes scroll position according to the size of the header and menu
|
|
|
|
* Also changes according to the user's browser
|
|
|
|
*/
|
|
|
|
function changeScrollPosition() {
|
|
|
|
const SUPPORTS_SCROLL_BEHAVIOR = document.body.style.scrollBehavior !== undefined;
|
|
|
|
const WINDOW_WIDTH_BREAKPOINT_PX = 923;
|
|
|
|
let scrollPosition = headerHeightPx;
|
|
|
|
|
|
|
|
if (SUPPORTS_SCROLL_BEHAVIOR) {
|
|
|
|
if (window.innerWidth < WINDOW_WIDTH_BREAKPOINT_PX) {
|
|
|
|
scrollPosition += header.clientHeight;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (window.innerWidth >= WINDOW_WIDTH_BREAKPOINT_PX) {
|
|
|
|
scrollPosition = siteHeader.clientHeight
|
2020-07-28 00:04:56 +03:00
|
|
|
} else {
|
2021-11-09 20:55:57 +03:00
|
|
|
scrollPosition = siteHeader.clientHeight + header.clientHeight;
|
2020-07-28 00:04:56 +03:00
|
|
|
}
|
|
|
|
}
|
2021-11-09 20:55:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function setStickyNav() {
|
|
|
|
if (window.scrollY > distanceFromTop) {
|
|
|
|
stickyNav.classList.add('UseCaseSubNav-anchorLinks--sticky');
|
|
|
|
} else {
|
|
|
|
stickyNav.classList.remove('UseCaseSubNav-anchorLinks--sticky');
|
2020-07-02 21:06:24 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})();
|