MediaWiki:Common.js

Revision as of 08:39, 12 February 2021 by BBlackmoor (talk | contribs)
Jump to navigation Jump to search

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
/* Any JavaScript here will be loaded for all users on every page load. */

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";
});