Skip to content
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

added lhn-backbutton #44753

Closed
wants to merge 6 commits into from
Closed
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
54 changes: 36 additions & 18 deletions docs/assets/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,27 +49,41 @@ function isInRange(num, min, max) {
* If a page is directly accessed (e.g., via deep link, bookmark, or opened in a new tab),the user will be navigated
* back to the relevant hub page of that article.
*/
function navigateBack() {
const currentHost = window.location.host;
const referrer = document.referrer;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Taiwrash do you know why this code was removed?


if (referrer.includes(currentHost) && window.history.length > 1) {
window.history.back();
return;
}

// Path name is of the form /articles/[platform]/[hub]/[resource]
const path = window.location.pathname.split('/');
if (path[2] && path[3]) {
window.location.href = `/${path[2]}/hubs/${path[3]}`;
function navigateBack() {
const currentPath = window.location.pathname;
const pathSegments = currentPath.split('/');
let newPath;

// Check if we're in an article page
if (pathSegments.length >= 5 && pathSegments[1] === 'articles') {
// Extract the product (new-expensify or expensify-classic) and the hub
const product = pathSegments[2];
const hub = pathSegments[3];

// Construct the path to the hub page
newPath = `/${product}/hubs/${hub}/`;
} else if (pathSegments.length > 4 && (pathSegments[2] === 'new-expensify' || pathSegments[2] === 'expensify-classic')) {
// This is the existing logic for other cases
newPath = `/${pathSegments[2]}/hubs/${pathSegments[3]}/`;
} else {
window.location.href = '/';
// If we're not in an article or a recognizable path, go to the home page
newPath = '/';
}

// Add a little delay to avoid showing the previous content in a fraction of a time
setTimeout(toggleHeaderMenu, 250);
if (newPath !== currentPath) {
window.location.href = newPath;

// Add a little delay to avoid showing the previous content in a fraction of a time
setTimeout(toggleHeaderMenu, 250);
}
}

window.addEventListener('popstate', (e)=>{
e.preventDefault()
navigateBack()
});

function injectFooterCopywrite() {
const footer = document.getElementById('footer-copywrite-date');
footer.innerHTML = `©2008-${new Date().getFullYear()} Expensify, Inc.`;
Expand Down Expand Up @@ -272,11 +286,13 @@ window.addEventListener('DOMContentLoaded', () => {
});

document.getElementById('header-button').addEventListener('click', toggleHeaderMenu);

// Back button doesn't exist on all the pages

const backButton = document.getElementById('back-button');
if (backButton) {
backButton.addEventListener('click', navigateBack);
backButton.addEventListener('click', function(event) {
event.preventDefault();
navigateBack();
});
}

const articleContent = document.getElementById('article-content');
Expand All @@ -293,6 +309,7 @@ window.addEventListener('DOMContentLoaded', () => {
}
}
});

lhnContent.addEventListener('wheel', (e) => {
const scrollTop = lhnContent.scrollTop;
const isScrollingPastLHNTop = e.deltaY < 0 && scrollTop === 0;
Expand All @@ -301,6 +318,7 @@ window.addEventListener('DOMContentLoaded', () => {
e.preventDefault();
}
});

window.addEventListener('scroll', (e) => {
const scrollingElement = e.target.scrollingElement;
const scrollPercentageInArticleContent = clamp(scrollingElement.scrollTop - articleContent.offsetTop, 0, articleContent.scrollHeight) / articleContent.scrollHeight;
Expand Down
Loading