MediaWiki

Group-Grouse.js: Difference between revisions

From Grouse House Wiki

No edit summary
No edit summary
Line 134: Line 134:
/* Mobile TOC */
/* Mobile TOC */


window.onload = function () {
$(document).ready(function () {
    var toc = "";
            setTimeout(() => {
    var level = 0;
                // Get ToC div
               
                toc = document.getElementById("mobiletoc"); //Add a header
                tocHeader = document.createElement("h2");
                tocHeader.innerText = "Table of contents";
                toc.appendChild(tocHeader); // Get the h3 tags — ToC entries


    document.getElementById("bodyContent").innerHTML =
                // Create a list for the ToC entries
        document.getElementById("bodyContent").innerHTML.replace(
                tocList = document.createElement("ul");
            /<h([\d])>([^<]+)<\/h([\d])>/gi,
            function (str, openLevel, titleText, closeLevel) {
                if (openLevel != closeLevel) {
                    return str;
                }


                 if (openLevel > level) {
                 $('h3').each(function () {
                    toc += (new Array(openLevel - level + 1)).join("<ul>");
                     tocListItem = document.createElement("li");
                } else if (openLevel < level) {
                    // a link for the h3
                     toc += (new Array(level - openLevel + 1)).join("</ul>");
                    tocEntry = document.createElement("a");
                }
                    tocEntry.setAttribute("href", "#" + $(this).attr('id'));
 
                     tocEntry.innerText = $(this).text();
                level = parseInt(openLevel);
                    tocListItem.appendChild(tocEntry);
 
                     tocList.appendChild(tocListItem);
                var anchor = titleText.replace(/ /g, "_");
                });
                toc += "<li>href=\"#" + anchor + "\">" + titleText
                toc.appendChild(tocList);
                     + "</li>";
            });
 
        });
                return "<h" + openLevel + ">"
                     + titleText + "</h" + closeLevel + ">";
            }
        );
 
    if (level) {
        toc += (new Array(level + 1)).join("</ul>");
    }
 
    document.getElementById("mobiletoc").innerHTML += toc;
};

Revision as of 04:27, 4 February 2024


$(function() {
    $('h2.c-header.active span.mw-headline').each(function () {
        var $header = $(this);
        var $headername = $header.html();
        $headernameu = $headername.split(' ').join('_');

        var $secondheader = "#" + $headernameu + "_2";

        var $editsection = $( $secondheader ).next().children('a').attr("href");

        $header.after('[Edit]');
        $header.next().css( 'font-size', '0.6em').css( 'margin-left', '1em');

        var $pagename = $('h1#firstHeading').html();
        $pagenameu = $pagename.split(' ').join('_');
        
        $toclink = "https://grousehouse.wiki/" + $pagenameu + $secondheader;

        $("a[href*='" + $secondheader + "']").hide();
    });
 });

$(function() {
    $('h2.c-header.hidden span.mw-headline').each(function () {
        var $header = $(this);
        var $headername = $header.html();
        $headernameu = $headername.split(' ').join('_');

        var $secondheader = "#" + $headernameu + "_2";

        var $editsection = $( $secondheader ).next().children('a').attr("href");

        $header.after('[Edit]');
        $header.next().css( 'font-size', '0.6em').css( 'margin-left', '1em');

        var $pagename = $('h1#firstHeading').html();
        $pagenameu = $pagename.split(' ').join('_');
        
        $toclink = "https://grousehouse.wiki/" + $pagenameu + $secondheader;

        $("a[href*='" + $secondheader + "']").hide();
    });
 });

$(function() {
    $('h2.h-static span.mw-headline').each(function () {
        var $header = $(this);
        var $headername = $header.html();
        $headernameu = $headername.split(' ').join('_');

        var $secondheader = "#" + $headernameu + "_2";

        var $editsection = $( $secondheader ).next().children('a').attr("href");

        $header.after('[Edit]');
        $header.next().css( 'font-size', '0.6em').css( 'margin-left', '1em');

        var $pagename = $('h1#firstHeading').html();
        $pagenameu = $pagename.split(' ').join('_');
        
        $toclink = "https://grousehouse.wiki/" + $pagenameu + $secondheader;

        $("a[href*='" + $secondheader + "']").hide();
    });
 });

$(function() {
    $('h3.c-header.active span.mw-headline').each(function () {
        var $header = $(this);
        var $headername = $header.html();
        $headernameu = $headername.split(' ').join('_');

        var $secondheader = "#" + $headernameu + "_2";

        var $editsection = $( $secondheader ).next().children('a').attr("href");

        $header.after('[Edit]');
        $header.next().css( 'font-size', '0.6em').css( 'margin-left', '1em');

        var $pagename = $('h1#firstHeading').html();
        $pagenameu = $pagename.split(' ').join('_');
        
        $toclink = "https://grousehouse.wiki/" + $pagenameu + $secondheader;

        $("a[href*='" + $secondheader + "']").hide();
    });
 });

$(function() {
    $('h3.c-header.hidden span.mw-headline').each(function () {
        var $header = $(this);
        var $headername = $header.html();
        $headernameu = $headername.split(' ').join('_');

        var $secondheader = "#" + $headernameu + "_2";

        var $editsection = $( $secondheader ).next().children('a').attr("href");

        $header.after('[Edit]');
        $header.next().css( 'font-size', '0.6em').css( 'margin-left', '1em');

        var $pagename = $('h1#firstHeading').html();
        $pagenameu = $pagename.split(' ').join('_');
        
        $toclink = "https://grousehouse.wiki/" + $pagenameu + $secondheader;

        $("a[href*='" + $secondheader + "']").hide();
    });
 });

$(function() {
    $('h3.h-static span.mw-headline').each(function () {
        var $header = $(this);
        var $headername = $header.html();
        $headernameu = $headername.split(' ').join('_');

        var $secondheader = "#" + $headernameu + "_2";

        var $editsection = $( $secondheader ).next().children('a').attr("href");

        $header.after('[Edit]');
        $header.next().css( 'font-size', '0.6em').css( 'margin-left', '1em');

        var $pagename = $('h1#firstHeading').html();
        $pagenameu = $pagename.split(' ').join('_');
        
        $toclink = "https://grousehouse.wiki/" + $pagenameu + $secondheader;

        $("a[href*='" + $secondheader + "']").hide();
    });
 });

/* Mobile TOC */

$(document).ready(function () {
            setTimeout(() => {
                // Get ToC div
                
                toc = document.getElementById("mobiletoc"); //Add a header
                tocHeader = document.createElement("h2");
                tocHeader.innerText = "Table of contents";
                toc.appendChild(tocHeader); // Get the h3 tags — ToC entries

                // Create a list for the ToC entries
                tocList = document.createElement("ul");

                $('h3').each(function () {
                    tocListItem = document.createElement("li");
                    // a link for the h3
                    tocEntry = document.createElement("a");
                    tocEntry.setAttribute("href", "#" + $(this).attr('id'));
                    tocEntry.innerText = $(this).text();
                    tocListItem.appendChild(tocEntry);
                    tocList.appendChild(tocListItem);
                });
                toc.appendChild(tocList);
            });
        });