问题
I've been trying to find a method on moving the TOC in MediaWiki to the sidebar or any location really that I want it outside of the main content but with no success.
The simplest looking solution brought up the following but it doesn't seem to actually move the TOC.
<div id="toc_sidebar_holder"> </div>
<script type="text/javascript">
var toc = document.getElementById('toc');
var toc_holder = document.getElementById('toc_sidebar_holder');
if(toc && toc_holder){
toc.parentNode.removeChild(toc);
toc_holder.appendChild(toc);
}
</script>
Then here is what the HTML looks like for the TOC currently.
<table id="toc" class="toc"><tr><td><div id="toctitle"><h2>Contents</h2></div>
<ul>
<li class="toclevel-1 tocsection-1"><a href="#Cats"><span class="tocnumber">1</span> <span class="toctext">Cats</span></a>
<ul>
<li class="toclevel-2 tocsection-2"><a href="#Type"><span class="tocnumber">1.1</span> <span class="toctext">Type</span></a></li>
<li class="toclevel-2 tocsection-3"><a href="#Meows"><span class="tocnumber">1.2</span> <span class="toctext">Meows</span></a></li>
</ul>
</li>
<li class="toclevel-1 tocsection-4"><a href="#Dogs"><span class="tocnumber">2</span> <span class="toctext">Dogs</span></a>
<ul>
<li class="toclevel-2 tocsection-5"><a href="#Woof"><span class="tocnumber">2.1</span> <span class="toctext">Woof</span></a></li>
</ul>
</li>
</ul>
</td></tr></table>
Really looking for a solution or figuring out how to get the function above to work.
回答1:
That script looks fine, but if you you test it, you might notice that toc
is not assigned.
Put the script at the bottom of your skin, so it is executed when both elements are already available.
来源:https://stackoverflow.com/questions/23716918/move-mediawiki-toc-to-sidebar