]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
docs/sphinx: Fix TOC scroll hack for the home page
authorGustavo Sousa <gustavo.sousa@intel.com>
Tue, 23 Jan 2024 16:21:58 +0000 (13:21 -0300)
committerJonathan Corbet <corbet@lwn.net>
Tue, 23 Jan 2024 21:33:13 +0000 (14:33 -0700)
When on the documentation home page, there won't be any ".current"
element since no entry from the TOC was selected yet. That results in a
javascript error. Fix that by only trying to set the scrollTop if we
have matches for current entries.

Signed-off-by: Gustavo Sousa <gustavo.sousa@intel.com>
Signed-off-by: Jonathan Corbet <corbet@lwn.net>
Link: https://lore.kernel.org/r/20240123162157.61819-2-gustavo.sousa@intel.com
Documentation/sphinx/templates/kernel-toc.html

index b58efa99df527d3d870d9572e6ee7f18912fe99f..41f1efbe64bb2898f1770deb128630b316a68a08 100644 (file)
@@ -12,5 +12,7 @@
 <script type="text/javascript"> <!--
   var sbar = document.getElementsByClassName("sphinxsidebar")[0];
   let currents = document.getElementsByClassName("current")
-  sbar.scrollTop = currents[currents.length - 1].offsetTop;
+  if (currents.length) {
+    sbar.scrollTop = currents[currents.length - 1].offsetTop;
+  }
   --> </script>