MediaWiki:Common.js: Difference between revisions

From Hazeron Wiki
Jump to navigation Jump to search
(Implemented section-collapse and stop-section-collapse.)
 
(Lets see if I understand JS.)
Line 6: Line 6:
     for (var i = 0; i < collapsing.length ; i++) {
     for (var i = 0; i < collapsing.length ; i++) {
         collapsing.item(i).addEventListener('click',collapseHandler,false);
         collapsing.item(i).addEventListener('click',collapseHandler,false);
        if (collapsing.item(i).contains("section-collapsed")) {
            collapseHandler(collapsing.item(i));
        }
     }
     }
}
}
Line 11: Line 14:
function collapseHandler() {
function collapseHandler() {
   var c = this.parentNode.parentNode.nextSibling;
   var c = this.parentNode.parentNode.nextSibling;
  collapseHandlerThis(c);
}
function collapseHandlerThis(c) {
   while (c) {
   while (c) {
       if (c.classList) {
       if (c.classList) {

Revision as of 09:44, 7 April 2019

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

/* Implements section-collapse and stop-section-collapse */
var collapsing = document.querySelectorAll(".section-collapse");
if (collapsing.length>0) {
    for (var i = 0; i < collapsing.length ; i++) {
        collapsing.item(i).addEventListener('click',collapseHandler,false);
        if (collapsing.item(i).contains("section-collapsed")) {
            collapseHandler(collapsing.item(i));
        }
    }
}

function collapseHandler() {
   var c = this.parentNode.parentNode.nextSibling;
   collapseHandlerThis(c);
}
function collapseHandlerThis(c) {
   while (c) {
      if (c.classList) {
        if (c.classList.contains("section-collapse") || c.classList.contains("stop-section-collapse"))
           break;
        c.classList.toggle('section-collapsed');
      }
      c = c.nextSibling;
   }
   this.classList.toggle('collapsed-icon');
}