MediaWiki:Common.js: Difference between revisions

From Weegeepie Wiki
Jump to navigation Jump to search
(Created page with "→‎Any JavaScript here will be loaded for all users on every page load.: $('<a class="infoboxtoggle" href="#">+/-</a>').appendTo( $('.infobox tr.header').filter(function(){ return $(this).attr('header').split(" ").length > 1 }).find("th") ); $(".infobox tr.header").each(function(){ var $this = $(this); if( $this.hasClass("hidden") ){ var firstclass = $this.attr("header").split(" ")[0]; $this.siblings("." + firstclass).ad...")
 
No edit summary
 
(11 intermediate revisions by the same user not shown)
Line 1: Line 1:
/* Any JavaScript here will be loaded for all users on every page load. */
/* Any JavaScript here will be loaded for all users on every page load. */


    $('<a class="infoboxtoggle" href="#">+/-</a>').appendTo(
setTimeout(500);
      $('.infobox tr.header').filter(function(){ return $(this).attr('header').split(" ").length > 1 }).find("th")
    );


    $(".infobox tr.header").each(function(){
function isMobile() {
      var $this = $(this);
return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
}


      if( $this.hasClass("hidden") ){
if (!isMobile()) {
        var firstclass = $this.attr("header").split(" ")[0];
        $this.siblings("." + firstclass).addClass("hidden");
      }
  });


     $('a.infoboxtoggle').click (
/* Taken from MD wiki lol */
      function (infoboxtoggle)
$('#ca-talk').append(
      {
     $('<a/>').addClass('hover-community-header-wrapper')
         var parent  = $(this).parent ();
         .append($('<div/>')
        var grandparent  = parent.parent ();
            .addClass('wgp-ep-msg')
         var firstclass  = grandparent.attr ('header').split(" ")[0];
            .text('Click here to view the latest episode!')
        )
         .attr('href', 'https://www.youtube.com/watch?v=9driCvToAOA&t=0s')
);


        infoboxtoggle.preventDefault();
}
        grandparent.siblings ('.' + firstclass).has ('td').toggleClass ('hidden');
 
      }
var toc, toggleLink;
     );
try {
  toc = document.getElementById('toc').getElementsByTagName('ul')[0];
  toggleLink = document.getElementById('toctogglecheckbox');
  // if (tocIsHidden()) {
  toggleToc();
  // }
} catch (error) {
  console.log('erred', error);
}
function tocIsHidden () {
    return !toc || !toggleLink || window.getComputedStyle(toc).display !== 'block';
}
 
function toggleToc() {
  var hidden = tocIsHidden();
  if (hidden && document.cookie.indexOf('hidetoc=0') > -1) {
    toggleLink.click();
    // changeText(toggleLink, tocShowText);
    // toc.style.display = 'none';
  } else if (!hidden && document.cookie.indexOf('hidetoc=1') > -1) {
    toggleLink.click();
    // changeText(toggleLink, tocHideText);
    // toc.style.display = 'block';
  }
}
toggleLink && toggleLink.addEventListener('click', function () {
  var isHidden = tocIsHidden();
  document.cookie = isHidden
    ? "hidetoc=1"
     : "hidetoc=0";
});

Latest revision as of 11:56, 31 May 2024

/* Any JavaScript here will be loaded for all users on every page load. */

setTimeout(500);

function isMobile() {
return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
}

if (!isMobile()) {

/* Taken from MD wiki lol */
$('#ca-talk').append(
    $('<a/>').addClass('hover-community-header-wrapper')
        .append($('<div/>')
            .addClass('wgp-ep-msg')
            .text('Click here to view the latest episode!')
        )
        .attr('href', 'https://www.youtube.com/watch?v=9driCvToAOA&t=0s')
);

}

var toc, toggleLink;
try {
  toc = document.getElementById('toc').getElementsByTagName('ul')[0];
  toggleLink = document.getElementById('toctogglecheckbox');
  // if (tocIsHidden()) {
  toggleToc();
  // }
} catch (error) {
  console.log('erred', error);
}
function tocIsHidden () {
    return !toc || !toggleLink || window.getComputedStyle(toc).display !== 'block';
}

function toggleToc() {
  var hidden = tocIsHidden();
  if (hidden && document.cookie.indexOf('hidetoc=0') > -1) {
    toggleLink.click();
    // changeText(toggleLink, tocShowText);
    // toc.style.display = 'none';
  } else if (!hidden && document.cookie.indexOf('hidetoc=1') > -1) {
    toggleLink.click();
    // changeText(toggleLink, tocHideText);
    // toc.style.display = 'block';
  }
}
toggleLink && toggleLink.addEventListener('click', function () {
  var isHidden = tocIsHidden();
  document.cookie = isHidden
    ? "hidetoc=1"
    : "hidetoc=0";
});