User:Sudhiksha v/Floatingtoc-enhd.js

// Floating TOC - Enhanced Version

// Ensure variables are declared as global let hideDefault, leftDefault;

// Function to toggle visibility of header content function hideShow(header, content) { header.text(function {        return content.is(":visible") ? "Hide" : "Show";    }); }

$(function {   // Import external stylesheet    importStylesheet('User:Ugog Nizdast/FloatingTOC.css');

// Check if TOC exists const tocElement = document.getElementById("toc"); if (tocElement) { // Clone the TOC and append const clonedToc = tocElement.cloneNode(true); clonedToc.id = "toc2"; document.body.appendChild(clonedToc);

// Wrap TOC with header and container $('#toc2').wrap(" "); const header = " Hide  "; $('.content1').append(header); $('#main1').wrapAll(" ");

// Remove unnecessary "hide" option $(".toctoggle").eq(1).remove;

// Configure variables if (leftDefault) $("#main2").css('right', ""); if (hideDefault) { $("#toc2").css('display', "none"); const $header = $(".header1"); const $content = $header.prev; hideShow($header, $content); }

// Toggle visibility on click $(".header1").click(function {            const $content = $(this).prev;            $content.slideToggle(function  { hideShow($(this), $content); });       });    } });