User talk:SGrabarczuk (WMF)/faq
Add topicAppearance
Latest comment: 3 years ago by Nux in topic Static ToC function
| This page used the Structured Discussions extension to give structured discussions. It has since been converted to wikitext, so the content and history here are only an approximation of what was actually displayed at the time these comments were made. |
Static ToC function
[edit]Hi. For the sake of future compatibility and fixes I think it would be best to add a some mw.uitls function for the flying toc. Having a function would be much easier to fix instead of changing 10s or 100s of custom JS pages.
So you should add a function that converts new ToC to a static ToC. Maybe something like `mw.util.tocMakeStatic();`.
Note that current suggestion is not a complete code snippet:
$('.mw-table-of-contents-container')
.removeClass('mw-sticky-header-element' )
.removeClass('mw-table-of-contents-container')
.appendTo(document.getElementsByTagName('mw:tocplace')[0])
Couple of problems there:
- When you decide to add another class to sticky toc another class would need to be removed.
- Even currently there is bug there. A class `vector-sticky-header-enabled` should be removed from `html` tag.
- When you run above code the ToC is not fully working as a sttic ToC. It has a scrollbar.
- You might decide to change the name of the tag from mw:tocplace to a div in future. In that case the code would just stop working and also brake new ToC. You don't check if `getElementsByTagName` is empty and so you would just remove classes.
Cheers, Nux (talk) 20:43, 10 August 2022 (UTC)