且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将mediawiki TOC移至侧边栏

更新时间:2022-10-19 19:18:12

该脚本看起来很好,但如果您测试它,您可能会注意到 toc 未分配。

将脚本放在皮肤的底部,以便在两个元素都可用时执行。

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.

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.