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

Add contact menu item with smooth scrolling for #links #297

Merged
merged 1 commit into from
Jun 14, 2024
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
3 changes: 2 additions & 1 deletion src/client/components/home/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ export const STEP = {
ERROR: 'ERROR',
};

const menuDef = [
export const menuDef = [
{ label: "FAQ", href: '/#faq' },
{ label: "About", href: '/#about' },
{ label: "Contact", href: 'https://baderlab.org/', target: '_blank' }
];

const logosDef = [
Expand Down
7 changes: 4 additions & 3 deletions src/client/components/home/header.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { Button, Typography } from '@material-ui/core';

import MenuIcon from '@material-ui/icons/Menu';
import { AppLogoIcon } from '../svg-icons';
import { openPageLink } from '../util';


const useHeaderStyles = makeStyles(theme => ({
Expand Down Expand Up @@ -70,8 +71,8 @@ const useHeaderStyles = makeStyles(theme => ({
export function Header({ menuDef, showRecentNetworks, mobile, tablet, onClickGetStarted, onOpenMobileMenu }) {
const classes = useHeaderStyles();

const handleClick = (href) => {
window.location.href = href;
const handleClick = (href, target) => {
openPageLink(href, target);
};

const ToolbarDivider = ({ unrelated }) => {
Expand All @@ -89,7 +90,7 @@ export function Header({ menuDef, showRecentNetworks, mobile, tablet, onClickGet
<ToolbarDivider />
<Typography variant="inherit" className={classes.title}>EnrichmentMap:RNA-Seq</Typography>
{!mobile && !tablet && menuDef.map((menu, idx) => (
<MenuItem key={idx} className={classes.menuItem} onClick={() => handleClick(menu.href)}>
<MenuItem key={idx} className={classes.menuItem} onClick={() => handleClick(menu.href, menu.target)}>
{ menu.label }
</MenuItem>
))}
Expand Down
9 changes: 6 additions & 3 deletions src/client/components/home/mobile-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { Button, Typography } from '@material-ui/core';

import KeyboardArrowUpIcon from '@material-ui/icons/KeyboardArrowUp';
import { AppLogoIcon } from '../svg-icons.js';
import { openPageLink } from '../util.js';


const useStyles = makeStyles((theme) => ({
Expand Down Expand Up @@ -56,8 +57,10 @@ const useStyles = makeStyles((theme) => ({
export function MobileMenu({ menuDef, open, onClose }) {
const classes = useStyles();

const handleClick = (href) => {
setTimeout(() => window.location.href = href, 100);
const handleClick = (href, target) => {
openPageLink(href, target);

// setTimeout(() => window.location.href = href, 100);
onClose();
};

Expand All @@ -77,7 +80,7 @@ export function MobileMenu({ menuDef, open, onClose }) {
</Button>
</Toolbar>
{menuDef.map((menu, idx) => (
<MenuItem key={idx} onClick={() => handleClick(menu.href)} className={classes.menuItem}>
<MenuItem key={idx} onClick={() => handleClick(menu.href, menu.target)} className={classes.menuItem}>
{ menu.label }
</MenuItem>
))}
Expand Down
36 changes: 36 additions & 0 deletions src/client/components/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,40 @@ export function stringToBlob(str) {

export function networkURL(id) {
return `${window.location.origin}/document/${id}`;
}

const USE_SMOOTH_LINK_SCROLLING = true;

export function openPageLink(href, target) {
if (target === '_blank') {
window.open(href);
} else if (href.indexOf("#") >= 0 && USE_SMOOTH_LINK_SCROLLING) {
// get hash portion of url
const hash = href.split("#")[1];

document.getElementById(hash).scrollIntoView({
behavior: 'smooth'
});

let isScrolling;

// Listen for scroll events
const lis = function() {
// Clear the timeout if it was already set
window.clearTimeout(isScrolling);

// Set a timeout to run after scrolling ends
isScrolling = setTimeout(function() {
// Remove passive listener
window.removeEventListener('scroll', lis);

// Update the URL when scrolling has stopped
window.location.href = href;
}, 150); // delay after scrolling ends
};

window.addEventListener('scroll', lis, { passive: true });
} else {
window.location.href = href;
}
}
Loading