All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] docs/sphinx: Fix TOC scroll hack for the home page
@ 2024-01-23 16:21 Gustavo Sousa
  2024-01-23 21:33 ` Jonathan Corbet
  0 siblings, 1 reply; 3+ messages in thread
From: Gustavo Sousa @ 2024-01-23 16:21 UTC (permalink / raw)
  To: linux-doc, Jonathan Corbet; +Cc: gustavo.sousa

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>
---
 Documentation/sphinx/templates/kernel-toc.html | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/Documentation/sphinx/templates/kernel-toc.html b/Documentation/sphinx/templates/kernel-toc.html
index b58efa99df52..41f1efbe64bb 100644
--- a/Documentation/sphinx/templates/kernel-toc.html
+++ b/Documentation/sphinx/templates/kernel-toc.html
@@ -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>
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] docs/sphinx: Fix TOC scroll hack for the home page
  2024-01-23 16:21 [PATCH] docs/sphinx: Fix TOC scroll hack for the home page Gustavo Sousa
@ 2024-01-23 21:33 ` Jonathan Corbet
  2024-01-23 21:54   ` Gustavo Sousa
  0 siblings, 1 reply; 3+ messages in thread
From: Jonathan Corbet @ 2024-01-23 21:33 UTC (permalink / raw)
  To: Gustavo Sousa, linux-doc; +Cc: gustavo.sousa

Gustavo Sousa <gustavo.sousa@intel.com> writes:

> 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>
> ---
>  Documentation/sphinx/templates/kernel-toc.html | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/Documentation/sphinx/templates/kernel-toc.html b/Documentation/sphinx/templates/kernel-toc.html
> index b58efa99df52..41f1efbe64bb 100644
> --- a/Documentation/sphinx/templates/kernel-toc.html
> +++ b/Documentation/sphinx/templates/kernel-toc.html
> @@ -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>

Interesting, that's definitely a bug.  Did you stumble across this in
the console, or did it manifest in some other way for you?

Either way, I've applied this, thanks.

jon

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] docs/sphinx: Fix TOC scroll hack for the home page
  2024-01-23 21:33 ` Jonathan Corbet
@ 2024-01-23 21:54   ` Gustavo Sousa
  0 siblings, 0 replies; 3+ messages in thread
From: Gustavo Sousa @ 2024-01-23 21:54 UTC (permalink / raw)
  To: Jonathan Corbet, linux-doc

Quoting Jonathan Corbet (2024-01-23 18:33:52-03:00)
>Gustavo Sousa <gustavo.sousa@intel.com> writes:
>
>> 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>
>> ---
>>  Documentation/sphinx/templates/kernel-toc.html | 4 +++-
>>  1 file changed, 3 insertions(+), 1 deletion(-)
>>
>> diff --git a/Documentation/sphinx/templates/kernel-toc.html b/Documentation/sphinx/templates/kernel-toc.html
>> index b58efa99df52..41f1efbe64bb 100644
>> --- a/Documentation/sphinx/templates/kernel-toc.html
>> +++ b/Documentation/sphinx/templates/kernel-toc.html
>> @@ -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>
>
>Interesting, that's definitely a bug.  Did you stumble across this in
>the console, or did it manifest in some other way for you?

I just saw the error in the console :-)

Fortunately, the error is currently harmless, but it could become a
problem in the future if we were to put more stuff after the offending
line.

>
>Either way, I've applied this, thanks.

Thanks!

--
Gustavo Sousa

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-01-23 21:54 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-23 16:21 [PATCH] docs/sphinx: Fix TOC scroll hack for the home page Gustavo Sousa
2024-01-23 21:33 ` Jonathan Corbet
2024-01-23 21:54   ` Gustavo Sousa

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.