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

MediaWiki:Common.js: Difference between revisions

MediaWiki interface page
No edit summary
Tag: Reverted
No edit summary
Tag: Reverted
Line 71: Line 71:
     document.body.removeChild(a);  // Clean up
     document.body.removeChild(a);  // Clean up
}
}
document.addEventListener("DOMContentLoaded", function () {
document.addEventListener("DOMContentLoaded", function () {
   // Find the sidebar menu button (or other reference element)
   // Find the header element with the specified class
   var menuButton = document.querySelector(".mw-citizen-sidebar-button");
   var headerElement = document.querySelector(".mw-header.citizen-header");


   if (menuButton) {
   if (headerElement) {
     // Create a new div element
     // Create a new div element with the required classes
     var newDiv = document.createElement("div");
     var newDiv = document.createElement("div");
     newDiv.className = "citizen-drawer citizen-header__item citizen-dropdown";
     newDiv.className = "citizen-drawer citizen-header__item citizen-dropdown";


     // Optionally, add some content or attributes to the new div
     // Optionally, add content inside the div (customize as needed)
     newDiv.innerHTML = "<p>Custom content here</p>"; // Replace with your desired content
     newDiv.innerHTML = "<p>Injected dropdown content</p>"; // Replace or remove content


     // Inject the new div directly after the menu button
     // Append the new div as the last child inside the header
     menuButton.parentNode.insertBefore(newDiv, menuButton.nextSibling);
     headerElement.appendChild(newDiv);
   }
   }
});
});

Revision as of 09:27, 5 January 2025

/* Any JavaScript here will be loaded for all users on every page load. */
 $(function(){
  $('.card').on('mousenter', function(event){
    event.preventDefault();
    $(this).toggleClass('hovered');
  });
   $('.card').on('mouseleave', function(event){
    event.preventDefault();
    $(this).toggleClass('hovered');
  });
});
document.querySelectorAll('.sub-card').forEach(card => {
    card.addEventListener('click', function(event) {
        event.stopPropagation(); // Prevent event bubbling

        // Toggle the expanded state of the clicked card
        const isExpanded = card.getAttribute('data-expanded') === 'true';
        
        // Flip the current sub-card
        card.setAttribute('data-expanded', isExpanded ? 'false' : 'true');

        // Hide all other sub-cards
        document.querySelectorAll('.sub-card').forEach(otherCard => {
            if (otherCard !== card) {
                otherCard.setAttribute('data-expanded', 'false');
            }
        });
    });
});

document.querySelectorAll('.card').forEach(card => {
    card.addEventListener('mouseleave', function() {
        // Collapse all sub-cards when mouse leaves the main card
        document.querySelectorAll('.sub-card').forEach(subCard => {
            subCard.setAttribute('data-expanded', 'false');
        });
    });
});

$(document).ready(function() {
    // Click event for the header or the arrow
    $('.mw-collapsible-header').click(function() {
        var parentDiv = $(this).closest('.mw-collapsible');
        var content = parentDiv.find('.mw-collapsible-content');
        
        // Toggle the collapse/expand state
        parentDiv.toggleClass('mw-collapsed');
        
        // Toggle visibility of the content
        content.stop(true, true).slideToggle(); // Stop any ongoing animation before toggling visibility
    });

    // Ensure that the arrow starts pointing up for expanded sections by default
    $('.mw-collapsible').each(function() {
        var parentDiv = $(this);
        var content = parentDiv.find('.mw-collapsible-content');
        
        if (!parentDiv.hasClass('mw-collapsed')) {
            content.show(); // Ensure content is visible
        }
    });
});

// Function to trigger file download when the image is clicked
function downloadFile(filePath) {
    var a = document.createElement('a');
    a.href = filePath;
    a.download = '';  // This triggers the download
    document.body.appendChild(a);
    a.click();
    document.body.removeChild(a);  // Clean up
}

document.addEventListener("DOMContentLoaded", function () {
  // Find the header element with the specified class
  var headerElement = document.querySelector(".mw-header.citizen-header");

  if (headerElement) {
    // Create a new div element with the required classes
    var newDiv = document.createElement("div");
    newDiv.className = "citizen-drawer citizen-header__item citizen-dropdown";

    // Optionally, add content inside the div (customize as needed)
    newDiv.innerHTML = "<p>Injected dropdown content</p>"; // Replace or remove content

    // Append the new div as the last child inside the header
    headerElement.appendChild(newDiv);
  }
});
Cookies help us deliver our services. By using our services, you agree to our use of cookies.