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

Check if scrollTo target is a valid DOM element #235

Open
SteelWagstaff opened this issue Apr 7, 2021 · 0 comments
Open

Check if scrollTo target is a valid DOM element #235

SteelWagstaff opened this issue Apr 7, 2021 · 0 comments
Labels
bug Something isn't working

Comments

@SteelWagstaff
Copy link
Member

Description

We use a scrollTo function on Aldine which produces an error if the # target is not present (see below).

if ( document.location.hash && document.location.hash !== '#' ) {
let anchorUponArrival = document.location.hash;
setTimeout( function () {
$( anchorUponArrival ).scrollTo( { duration: 1500 } );
$( anchorUponArrival ).focus();
}, 100 );
}

Sentry Issue: PRESSBOOKS-7D

TypeError: t(...).scrollTo is not a function
  at None (/app/themes/pressbooks-aldine/dist/scripts/aldine.js:2:122430)
  at r (/app/plugins/pressbooks/assets/dist/scripts/sentry.js:2:80044)

Steps to Reproduce

  1. Visit the network home page for a Pressbooks network and append a #string to the URL which does not correspond to an existing id on the page.
  2. Open the console to see the scrollTo JS error.
aldine_JS_error.mp4

To fix: could check if target exists before attempting to scrollTo or could replace with vanilla JS scrollTo behaviour (https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollTo).

@SteelWagstaff SteelWagstaff added the bug Something isn't working label Apr 7, 2021
@SteelWagstaff SteelWagstaff added this to the Pressbooks Aldine 1.10.0 milestone Jun 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant