MediaWiki:Common.js: Difference between revisions

Jump to navigation Jump to search
(Created page with "→‎Any JavaScript here will be loaded for all users on every page load.: //TOC begins collapsed on page load function hideToc() { var toc = document.getElementById('toc'...")
 
mNo edit summary
 
(4 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. */


//TOC begins collapsed on page load
// The enclosed code runs only after the page has been loaded and parsed.
function hideToc() {  
window.addEventListener('DOMContentLoaded', function() {
   var toc = document.getElementById('toc').getElementsByTagName('ul')[0];
   try {
  var toggleLink = document.getElementById('togglelink');
    // Detect whether the page's TOC is being displayed.
  toc.style.display = 'none';  
    if (document.getElementById('toc').getElementsByTagName('ul')[0].style.display != 'none') {
}  
      // Use MW's toggleToc() to hide TOC, change "hide/show" link text, and set cookie.
hideToc();
      toggleToc();
    }
  } catch (exception) {
    // Probably this page doesn't have a TOC, ignore the exception to prevent console clutter.
  }
}, false);

Latest revision as of 09:59, 3 April 2023

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

// The enclosed code runs only after the page has been loaded and parsed.
window.addEventListener('DOMContentLoaded', function() {
  try {
    // Detect whether the page's TOC is being displayed.
    if (document.getElementById('toc').getElementsByTagName('ul')[0].style.display != 'none') {
      // Use MW's toggleToc() to hide TOC, change "hide/show" link text, and set cookie.
      toggleToc();
    }
  } catch (exception) {
    // Probably this page doesn't have a TOC, ignore the exception to prevent console clutter.
  }
}, false);