User:Surjection/tocColumn.js
Jump to navigation
Jump to search
Note: You may have to bypass your browser’s cache to see the changes. In addition, after saving a sitewide CSS file such as MediaWiki:Common.css, it will take 5-10 minutes before the changes take effect, even if you clear your cache.
- Mozilla / Firefox / Safari: hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (Command-R on a Macintosh);
- Konqueror and Chrome: click Reload or press F5;
- Opera: clear the cache in Tools → Preferences;
- Internet Explorer: hold Ctrl while clicking Refresh, or press Ctrl-F5.
- This script lacks a documentation subpage. Please create it.
- Useful links: root page • root page’s subpages • links • redirects • your own
mw.hook("wikipage.content").add(function($) {
var toc = document.getElementById("toc");
var bodyContent = document.getElementById("bodyContent");
var contentText = document.getElementById("mw-content-text");
var tocUl = document.getElementById("toc").querySelector("ul");
if (toc && bodyContent && contentText) {
var tocHolder = document.createElement("div");
var tocParent = document.createElement("div");
tocHolder.style.display = "flex";
tocParent.style.marginLeft = "0.5em";
bodyContent.insertBefore(tocHolder, contentText);
tocHolder.appendChild(contentText);
tocHolder.appendChild(tocParent);
tocParent.appendChild(toc);
contentText.style.flex = "1";
contentText.style.flexShrink = "0";
if (tocUl) {
tocUl.style.width = "16em";
}
}
});