theme: avoid javascript errors if toc isn't present #268

This commit is contained in:
Sören Weber 2022-06-12 14:06:30 +02:00
parent c7b2eee5a6
commit b1444965f4
No known key found for this signature in database
GPG key ID: 07D17FF580AE7589

View file

@ -306,6 +306,10 @@ function initMenuScrollbar(){
return; return;
} }
var elc = document.querySelector('#body-inner');
var elm = document.querySelector('#content-wrapper');
var elt = document.querySelector('#TableOfContents');
var autofocus = false; var autofocus = false;
document.addEventListener('keydown', function(event){ document.addEventListener('keydown', function(event){
// for initial keyboard scrolling support, no element // for initial keyboard scrolling support, no element
@ -315,9 +319,9 @@ function initMenuScrollbar(){
// it and give focus to the scrollbar - only // it and give focus to the scrollbar - only
// to just remove the focus right after scrolling // to just remove the focus right after scrolling
// happend // happend
var c = document.querySelector('#body-inner').matches(':hover'); var c = elc && elc.matches(':hover');
var m = document.querySelector('#content-wrapper').matches(':hover'); var m = elm && elm.matches(':hover');
var t = document.querySelector('#TableOfContents').matches(':hover'); var t = elt && elt.matches(':hover');
var f = event.target.matches( formelements ); var f = event.target.matches( formelements );
if( !c && !m && !t && !f ){ if( !c && !m && !t && !f ){
// only do this hack if none of our scrollbars // only do this hack if none of our scrollbars
@ -343,9 +347,9 @@ function initMenuScrollbar(){
// scrollbars will install their own keyboard handlers // scrollbars will install their own keyboard handlers
// that need to be executed inbetween our own handlers // that need to be executed inbetween our own handlers
// PSC removed for #242 #243 #244 // PSC removed for #242 #243 #244
// psc = new PerfectScrollbar('#body-inner'); // psc = elc && new PerfectScrollbar('#body-inner');
psm = new PerfectScrollbar('#content-wrapper'); psm = elm && new PerfectScrollbar('#content-wrapper');
pst = document.querySelector('#TableOfContents') ? new PerfectScrollbar('#TableOfContents') : null; pst = elt && new PerfectScrollbar('#TableOfContents');
document.addEventListener('keydown', function(){ document.addEventListener('keydown', function(){
// if we facked initial scrolling, we want to // if we facked initial scrolling, we want to
// remove the focus to not leave visual markers on // remove the focus to not leave visual markers on