: How to use toggleToc() in a MediaWiki installation I admin a wiki site running MediaWiki 1.29 and I have a problem collapsing the TOC on pages. I would be interesting in keeping the Contents
I admin a wiki site running MediaWiki 1.29 and I have a problem collapsing the TOC on pages.
I would be interesting in keeping the Contents box, but loading the page with it collapsed by default.
It appears there is a simple solution here www.mediawiki.org/wiki/Manual_talk:Table_of_contents#Improved_Solution, but I fail to implement it and I have no idea where the error is, hopefully someone can help.
I integrated the code as explained and checked that MediaWiki:Common.js is used by the site.
During page rendering, I checked the Java code is loaded and executed, but it appears to fail because
ReferenceError: toggleToc is not defined
I also checked this page www.mediawiki.org/wiki/ResourceLoader/Migration_guide_(users)#MediaWiki_1.29 , but in the table there is a empty cell where it should be explained how to migrate toggleToc();. I am not even entirely sure it should be migrated.
Any help on this topic will be appreciated.
Thanks
Luca
More posts by @Megan663
2 Comments
Sorted by latest first Latest Oldest Best
After consulting with MediaWiki support desk, I finally had confirmation that the fact that the function is listed in the table How to migrate with no text in the column Replaced by means this function was removed for good.
This is not clearly explained, in my opinion.
So the function cannot be used out-of-the-box any longer.
For the ones interested in this function, the source code can be found in a MediaWiki package older than version 1.29.
The function is written in the file
resourcessrcmediawikimediawiki.toc.js
I hope this can help others to sort things out.
In the media wiki link provided above, it explains that the following code needs to be implemented:
// The enclosed code runs only after the page has been loaded and parsed.
window.addEventListener('DOMContentLoaded', function() {
try {
// Detect whether the page's TOC is being displayed.
if (document.getElementById('toc').getElementsByTagName('ul')[0].style.display != 'none') {
// Use MW's toggleToc() to hide TOC, change "hide/show" link text, and set cookie.
toggleToc();
}
} catch (exception) {
// Probably this page doesn't have a TOC, ignore the exception to prevent console clutter.
}
}, false);
If you have implemented the above code on your website and it has not be functioning properly, my best understanding of the code above is as follows:
`window.addEventListener('DOMContentLoaded',
This listens for the page content to be loaded, then performs the following function
if (document.getElementById('toc').getElementsByTagName('ul')[0].style.display != 'none') { toggleToc();
If the elements in name="toc" are NOT set to
display:none, then perform the function "toggleToc"
You first must make sure that the element defined by name="toc" is not set to display:none. And then you must make sure that somewhere on your page or in your .js files that the function toggleToc has been set. If toggleToc has NOT yet been set or defined then you must write this code yourself or find the code online and implement it on your page or .js files.
Since you have received the notice of:
ReferenceError: toggleToc is not defined
My best guess is that you do not actually have the function toggleToc
in any of your .js files or in on your webpage. I would check to make
sure that it is there.
Hope I was of help to you.
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.