User talk:Phlsph7/ClassicalTOC(Vector2022)

Page contents not supported in other languages.
From Wikipedia, the free encyclopedia

toc below infobox[edit]

Thank you for the script. It is great to have the TOC back in the article. On some pages with an infobox, the TOC appears below the infobox, with a lot of white space between the lead and the TOC. Examples: Charles_III, Rishi_Sunak Uwappa (talk) 21:40, 13 February 2023 (UTC)[reply]

Problem seems fixed already. Thank you. Uwappa (talk) 22:32, 13 February 2023 (UTC)[reply]
Hi Uwappa and thanks for letting me know! It seems the problem was that the TOC waited for the infobox to end before it was displayed. I changed its display-style and now it seems to work, at least for the two articles you mentioned. Thanks for the feedback and please let me know if you come across other pages where the TOC is not displayed as intended. Phlsph7 (talk) 22:35, 13 February 2023 (UTC)[reply]
Thank you for the quick fix. The fix works on the mentioned pages and most others. Yet, on SARS-CoV-2_Omicron_variant the problem persists. On SARS-CoV-2_Omicron_variant, the problem seems to persist, but that seems a problem in the page, as when not signed in, no toc but still whitespace. Uwappa (talk) 22:53, 13 February 2023 (UTC)[reply]
From what I can tell, this seems to be a problem with the Vector 2022 skin, since, as you say, it also happens without the classical TOC. But using the old skin, it is displayed correctly, see https://en.wikipedia.org/wiki/SARS-CoV-2_Omicron_variant?useskin=vector. I'll tinker a little around when I get the time to see if there is a simple fix. Phlsph7 (talk) 07:29, 14 February 2023 (UTC)[reply]
Strange:
  • The wikisource contains a TOC before a clear, see positioning the TOC
  • The generated HTML contains a TOC after a div style="clear:both"
Uwappa (talk) 09:40, 14 February 2023 (UTC)[reply]
I think you are onto something. The template "clear" produces the HTML <div style="clear:both;"></div>. If that comes before the TOC, it forces it to move the TOC down until the info-box on the right is finished. In the wikitext, this is solved by defining the TOC before the clear-template through the code __TOC__. The problem is that my script does not see the wikitext, it only sees the HTML. I solved the problem the following way: the script checks whether the element before the TOC corresponds to this clear-template and, if so, switches their positions. This works for the article SARS-CoV-2_Omicron_variant. I think in most cases, this should have the desired outcome. There is also the following code in the HTML: <meta property="mw:PageProp/toc">. Maybe something could be done with that as well. Phlsph7 (talk) 09:41, 14 February 2023 (UTC)[reply]
Yes, it looks like the meta property offers the right position for inserting the generated TOC. Uwappa (talk) 09:59, 14 February 2023 (UTC)[reply]
One idea would be to insert the TOC right after the meta-element if it is there. But I'm a little hesitant since meta-elements usually belong into the head of the document, not into the body. Phlsph7 (talk) 10:04, 14 February 2023 (UTC)[reply]
It looks like the odd metatag is a rudiment of the old TOC. Probably older skins replaced that meta tag by a TOC, on server side. So, yes, it probably works fine if you insert the TOC right after it. And when it is not there, no worries, assume there is already a TOC, generated on server side . Uwappa (talk) 10:29, 14 February 2023 (UTC)[reply]
This solution would work for the article SARS-CoV-2_Omicron_variant but I don't know how the element is used in other articles so it might produce surprising effects if the element is used differently there or found in different positions. It may be a good idea to keep it in mind as a plan B in case it turns out that the current solution does not work as planned. Phlsph7 (talk) 10:42, 14 February 2023 (UTC)[reply]

toc pushes down chapter on deep linked page[edit]

After landing on a deep link, e.g. Sun#Observation_by_eyes the generated TOC pushes the deeplinked chapter down the page. Uwappa (talk) 09:54, 14 February 2023 (UTC)[reply]

I assume something like the following happens: the page loads and moves the scoll position to the headline. After that, the TOC is added and this changes the scoll position so the headline is not on the top anymore. It doesn't happen for me but it might happen if it takes longer to load the TOC and different browsers might behave differently. I added a function that scolls to the right position after everything else is done. Could you check whether this solves the problem for you? Phlsph7 (talk) 10:30, 14 February 2023 (UTC)[reply]
Yes, it solves the problem. The page now lands with the chapter at the top of the screen, then scrolls briefly but immediately a second scroll moves the chapter back to top. Thank you. Uwappa (talk) 10:35, 14 February 2023 (UTC)[reply]
I saw now, the same happens to me for very long pages, for example, when visiting Wikipedia_talk:Vector_2022#Bug:_Atom. Phlsph7 (talk) 12:07, 14 February 2023 (UTC)[reply]