MediaWiki:MutiToc.js

// Support for multicolumn TOCs // Usage: //needs updating whenever Wikia gets around to fixing the new TOC at least partially // changing all #toc ul to #toc ol doesn't quite work $(window).load(function{ if ($(".toc-multicol #toc").size !== 0) {    $(function{ var x, tdToAppend, listToAppend, showtext = 'show', hidetext = 'hide'; $("#toc").css("width","100%"); //need to subtract 12px from this for padding for some reason $("#toc ul").html(" "); var liList = $("#toc ul li").toArray;

$('table#toc ul').remove; if (liList.length % 3 === 0) { x = 0; }else{ x = 3 - (liList.length % 3); }		var perCol = (liList.length + x) / 3;

for (var colNum=0; colNum < 3; colNum++){ listToAppend = ""; for (var i=0+(colNum*perCol); i<(perCol*(colNum+1)); i++){ if (typeof(liList[i]) == "undefined"){break;} tempElement = document.createElement("div"); tempElement.appendChild(liList[i]); listToAppend += tempElement.innerHTML; }			tdToAppend += '    '; }

$('#toc tbody').append(' '+tdToAppend+' '); $('#toc tbody tr:eq(0) td').attr("colspan", "3"); var indentFactor = 10; $("head").append(" .toclevel-1{padding-left: "+(indentFactor*1)+"px !important}.toclevel-2{padding-left: "+(indentFactor*2)+"px !important}.toclevel-3{padding-left: "+(indentFactor*3)+"px !important}.toclevel-4{padding-left: "+(indentFactor*4)+"px !important} "); $("#togglelink").off("click").click(function(e){e.preventDefault; $('#toc ul').slideToggle("fast");			if ($(this).text === showtext) { $(this).text(hidetext); } else { $(this).text(showtext); } }); if (!$('#toc ul').is(':hidden') && $('#togglelink').text === showtext) { $('#togglelink').text(hidetext); }   });  } });