From a46ceea6fb4ee1d8718da99b3d53c2cf683f4345 Mon Sep 17 00:00:00 2001 From: Naomi Pentrel <5212232+npentrel@users.noreply.github.com> Date: Fri, 8 Sep 2023 14:31:42 -0400 Subject: [PATCH] Update toc null error (#1780) --- 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; + } } }