User:N8wilson/NudgeTOC.js

/* [/[Category:Wikipedia scripts]/] Originally designed to replace User:Ugog Nizdast/FloatingTOC.js. ... which was ... Originally designed to replace User:Osarius/FloatingTOC.css.

// some global defaults if (typeof hideDefault === 'undefined') var hideDefault; // initially hide floating TOC (default: show) if (typeof leftDefault === 'undefined') var leftDefault; // show floating TOC on left (default: right) if (typeof keepOldTOC === 'undefined') var keepOldTOC;  // preserve old TOC in article (default: remove)

// update text of node [header] based on visibility of node [content] function hideShow(header, content) { header.text(function {        return content.is(":visible") ? "Hide" : "Show";    }); }

// install new TOC $(function {   importStylesheet('User:N8wilson/NudgeTOC.css');

var itm = document.getElementById("toc"); var cln;

if (itm) { //check if toc exists cln = itm.cloneNode(true); // clone and append the toc cln.id = "NudgedToc"; document.body.appendChild(cln);

$('#NudgedToc').wrap(" "); $('#NT_wrap_div').append(" Hide "); $('#NT_wrap_div').wrapAll(" "); $("#NudgedToc .toctogglespan").remove; //remove the broken "hide" option

$header = $("#NT_toggle_div"); $content = $header.prev; // if prefer left side, remove css attribute for right: 0; otherwise use it       $("#NT_wrap_outer_div").css('right', leftDefault ? "" : "0"); if (hideDefault) { // hide the new TOC and make link say "Show" $("#NudgedToc").css('display', "none"); hideShow($header, $content); }       if (!keepOldTOC) { // clean up article flow itm.remove; }

// Apply and install height adjustments var adjustTocHeight = function{ return visualViewport.height - 120; }; $("#NudgedToc").height(adjustTocHeight); $(window).resize(function{           $("#NudgedToc").height(adjustTocHeight);        });

// Install behaviour to hide/show $("#NT_toggle_div").click(function {             $content.slideToggle( function  { hideShow($header, $content); });       });    } });