MediaWiki

Foreground.js: Difference between revisions

From Grouse House Wiki

No edit summary
No edit summary
 
(5 intermediate revisions by the same user not shown)
Line 1: Line 1:
/* Scroll to top and sidebar logo */


var scrollbutton = document.getElementById("scrollToTop");
var sidebarlogo = document.getElementById("sidebarlogo");


/* Adding link to discussion button */
window.onscroll = function() {scrollFunction()};


$(function() {
function scrollFunction() {
    $('h1#firstHeading').each(function () {
  if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) {
        var $header = $(this).children('span').html();
    scrollbutton.style.display = "block";
        $pagetitle = $header.split(' ').join('_');
    sidebarlogo.style.display = "block";
        $url = $(location).attr('href');
  } else {
        $spliturl = $url.split(':').join(' ');
    scrollbutton.style.display = "none";
 
     sidebarlogo.style.display = "none";
        var main = $spliturl.indexOf("Main");
  }
        var mediawiki = $spliturl.indexOf("MediaWiki");
        var special = $spliturl.indexOf("Special");
        var edit = $spliturl.indexOf("edit");
        if(main !== -1){
          $(this).children('div').children('a').css("display", "none");
        } else if(mediawiki !== -1){
          $(this).children('div').children('a').css("display", "none");
        } else if(special !== -1){  
          $(this).children('div').children('a').css("display", "none");
        } else if(edit !== -1){
          $(this).children('div').children('a').css("display", "none");
        } else{
        $talklink = "https://grousehouse.wiki/Talk:" + $pagetitle;
        $link = $(this).children('div').children('a');
        $link.attr("href", $talklink);
        }
 
     });
});
 
/* Section toggles */
 
function toggleSectionsOn() {
    var sections = document.getElementsByClassName("c-header"),
        len = sections !== null ? sections.length : 0,
        i = 0;
    for(i; i < len; i++) {
        var content = sections[i].nextElementSibling;
        content.style.display = "block";
        sections[i].classList.remove("hidden");  
        sections[i].classList.add("active")
    }
}
}


function toggleSectionsOff() {
function topFunction() {
    var sections = document.getElementsByClassName("c-header"),
  document.body.scrollTop = 0;  
        len = sections !== null ? sections.length : 0,
  document.documentElement.scrollTop = 0;
        i = 0;
    for(i; i < len; i++) {
        var content = sections[i].nextElementSibling;
        content.style.display = "none";
        sections[i].classList.remove("active");  
        sections[i].classList.add("hidden")
    }
}
}

Latest revision as of 01:43, 1 April 2024

/* Scroll to top and sidebar logo */

var scrollbutton = document.getElementById("scrollToTop");
var sidebarlogo = document.getElementById("sidebarlogo");

window.onscroll = function() {scrollFunction()};

function scrollFunction() {
  if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) {
    scrollbutton.style.display = "block";
    sidebarlogo.style.display = "block";
  } else {
    scrollbutton.style.display = "none";
    sidebarlogo.style.display = "none";
  }
}

function topFunction() {
  document.body.scrollTop = 0; 
  document.documentElement.scrollTop = 0;
}