From b1444965f44271a0f2ad476ca98bb088d84f966b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren=20Weber?= Date: Sun, 12 Jun 2022 14:06:30 +0200 Subject: [PATCH] theme: avoid javascript errors if toc isn't present #268 --- static/js/theme.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/static/js/theme.js b/static/js/theme.js index b3ae2f65c0..11fc55644a 100644 --- a/static/js/theme.js +++ b/static/js/theme.js @@ -306,6 +306,10 @@ function initMenuScrollbar(){ return; } + var elc = document.querySelector('#body-inner'); + var elm = document.querySelector('#content-wrapper'); + var elt = document.querySelector('#TableOfContents'); + var autofocus = false; document.addEventListener('keydown', function(event){ // for initial keyboard scrolling support, no element @@ -315,9 +319,9 @@ function initMenuScrollbar(){ // it and give focus to the scrollbar - only // to just remove the focus right after scrolling // happend - var c = document.querySelector('#body-inner').matches(':hover'); - var m = document.querySelector('#content-wrapper').matches(':hover'); - var t = document.querySelector('#TableOfContents').matches(':hover'); + var c = elc && elc.matches(':hover'); + var m = elm && elm.matches(':hover'); + var t = elt && elt.matches(':hover'); var f = event.target.matches( formelements ); if( !c && !m && !t && !f ){ // only do this hack if none of our scrollbars @@ -343,9 +347,9 @@ function initMenuScrollbar(){ // scrollbars will install their own keyboard handlers // that need to be executed inbetween our own handlers // PSC removed for #242 #243 #244 - // psc = new PerfectScrollbar('#body-inner'); - psm = new PerfectScrollbar('#content-wrapper'); - pst = document.querySelector('#TableOfContents') ? new PerfectScrollbar('#TableOfContents') : null; + // psc = elc && new PerfectScrollbar('#body-inner'); + psm = elm && new PerfectScrollbar('#content-wrapper'); + pst = elt && new PerfectScrollbar('#TableOfContents'); document.addEventListener('keydown', function(){ // if we facked initial scrolling, we want to // remove the focus to not leave visual markers on