From e2dd7926cb1d59211429027d58f0ff0ca76bcb9b Mon Sep 17 00:00:00 2001 From: Naomi Pentrel <5212232+npentrel@users.noreply.github.com> Date: Fri, 8 Sep 2023 14:05:09 -0400 Subject: [PATCH] Update toc null error --- assets/js/index.js | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/assets/js/index.js b/assets/js/index.js index 1fc6c5ca14..86874dcff7 100644 --- a/assets/js/index.js +++ b/assets/js/index.js @@ -97,18 +97,21 @@ if (toc) { for (var i = 0; i < tocItems.length; i++) { let item = tocItems[i]; - var targetBounds = item.target.getBoundingClientRect(); - - if( targetBounds.bottom > windowHeight * TOP_MARGIN && targetBounds.top < windowHeight * ( 1 - BOTTOM_MARGIN ) ) { - visibleItems += 1; - item.listItem.classList.add( 'toc-active' ); - atLeastOne = true; - } else { - item.listItem.classList.remove( 'toc-active' ); - } + if (item.target) { + + var targetBounds = item.target.getBoundingClientRect(); + + if( targetBounds.bottom > windowHeight * TOP_MARGIN && targetBounds.top < windowHeight * ( 1 - BOTTOM_MARGIN ) ) { + visibleItems += 1; + item.listItem.classList.add( 'toc-active' ); + atLeastOne = true; + } else { + item.listItem.classList.remove( 'toc-active' ); + } - if (targetBounds.bottom < windowHeight) { - lastElem = item; + if (targetBounds.bottom < windowHeight) { + lastElem = item; + } } }