Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

MediaWiki:Citizen.js: Difference between revisions

MediaWiki interface page
No edit summary
No edit summary
Line 3: Line 3:
mw.hook('wikipage.content').add(function() {
mw.hook('wikipage.content').add(function() {
   if (window.innerWidth >= 768) { // Only on desktop
   if (window.innerWidth >= 768) { // Only on desktop
     const idsToCollapse = [
     mw.hook('citizen-collapsibles-init').add(function() {
      'Muling', 'Misc', 'Anti-ban', 'Anti-PK', 'Trip_Settings', 'Skills_Settings', 'Equipment'
      setTimeout(function() { // Wait a tiny bit AFTER Citizen finishes
    ];
        const idsToCollapse = [
          'Muling', 'Misc', 'Anti-ban', 'Anti-PK', 'Trip_Settings', 'Skills_Settings', 'Equipment'
        ];


    mw.hook('citizen-collapsibles-init').add(function() {
        idsToCollapse.forEach(function(rawId) {
      idsToCollapse.forEach(function(rawId) {
          var id = rawId.replace(/ /g, "_");
        var id = rawId.replace(/ /g, "_");
          var header = document.getElementById(id);
        var header = document.getElementById(id);
          if (!header) return;
        if (!header) return;
 
          var section = header.closest('.citizen-section-heading');
          var content = section?.nextElementSibling;
          if (!section || !content) return;


        var section = header.closest('.citizen-section-heading');
          // --- Manually collapse section ---
        var content = section?.nextElementSibling;
          section.classList.add('citizen-section-collapsed'); // Add collapsed class
        if (!section || !content) return;
          content.style.display = 'none'; // Hide content manually


        // --- Manually collapse section ---
          // --- Remove old Citizen click event if any ---
        section.classList.add('citizen-section-collapsed'); // Add collapsed class
          var newSection = section.cloneNode(true);
        content.style.display = 'none'; // Hide content manually
          section.parentNode.replaceChild(newSection, section);


        // --- Remove old Citizen click event if any ---
          // --- Bind our clean click handler ---
        var newSection = section.cloneNode(true);
          newSection.addEventListener('click', function() {
        section.parentNode.replaceChild(newSection, section);
            if (content.style.display === 'none') {
       
              content.style.display = 'block';
        // --- Bind our clean click handler ---
              newSection.classList.remove('citizen-section-collapsed');
        newSection.addEventListener('click', function() {
            } else {
          if (content.style.display === 'none') {
              content.style.display = 'none';
            content.style.display = 'block';
              newSection.classList.add('citizen-section-collapsed');
            newSection.classList.remove('citizen-section-collapsed');
            }
          } else {
           });
            content.style.display = 'none';
            newSection.classList.add('citizen-section-collapsed');
           }
         });
         });
       });
       }, 50); // 🔥 50ms delay is enough to let Citizen finish expanding
     });
     });
   }
   }
});
});

Revision as of 14:31, 25 April 2025

/* All JavaScript here will be loaded for users of the Citizen skin */

mw.hook('wikipage.content').add(function() {
  if (window.innerWidth >= 768) { // Only on desktop
    mw.hook('citizen-collapsibles-init').add(function() {
      setTimeout(function() { // Wait a tiny bit AFTER Citizen finishes
        const idsToCollapse = [
          'Muling', 'Misc', 'Anti-ban', 'Anti-PK', 'Trip_Settings', 'Skills_Settings', 'Equipment'
        ];

        idsToCollapse.forEach(function(rawId) {
          var id = rawId.replace(/ /g, "_");
          var header = document.getElementById(id);
          if (!header) return;

          var section = header.closest('.citizen-section-heading');
          var content = section?.nextElementSibling;
          if (!section || !content) return;

          // --- Manually collapse section ---
          section.classList.add('citizen-section-collapsed'); // Add collapsed class
          content.style.display = 'none'; // Hide content manually

          // --- Remove old Citizen click event if any ---
          var newSection = section.cloneNode(true);
          section.parentNode.replaceChild(newSection, section);

          // --- Bind our clean click handler ---
          newSection.addEventListener('click', function() {
            if (content.style.display === 'none') {
              content.style.display = 'block';
              newSection.classList.remove('citizen-section-collapsed');
            } else {
              content.style.display = 'none';
              newSection.classList.add('citizen-section-collapsed');
            }
          });
        });
      }, 50); // 🔥 50ms delay is enough to let Citizen finish expanding
    });
  }
});