MediaWiki:Common.js: Difference between revisions

No edit summary
No edit summary
 
(11 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. */
/* Load Popper.js */
importScriptURI('https://code.jquery.com/jquery-3.5.1.min.js');
mw.loader.load('https://cdn.jsdelivr.net/npm/@popperjs/core@2.5.4/dist/umd/popper.min.js');
importScriptURI('https://cdn.jsdelivr.net/npm/@popperjs/core@2.5.4/dist/umd/popper.min.js');
importScriptURI('https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js');


document.addEventListener("DOMContentLoaded", function() {
/* Load Bootstrap JS */
     let count = 0;
mw.loader.load('https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js');
     document.querySelectorAll('.btn.btn-primary.places-button').forEach(button => {
 
         const uniqueId = 'details-' + Date.now() + '-' + count++;
function initializePlacesButtons() {
         const collapseDiv = button.parentElement.nextElementSibling;
     var count = 1;
     document.querySelectorAll('.btn.btn-primary.places-button').forEach(function(button) {
         var uniqueId = 'details-places-' + count;
         var collapseDiv = button.parentElement.nextElementSibling;
         if (collapseDiv) {
         if (collapseDiv) {
             collapseDiv.id = uniqueId;
             collapseDiv.id = uniqueId;
             button.setAttribute('data-target', '#' + uniqueId);
             button.setAttribute('data-target', '#' + uniqueId);
             button.setAttribute('aria-controls', uniqueId);
             button.setAttribute('aria-controls', uniqueId);
         }
            count++;
         }  
    });
}
 
if (document.readyState !== 'loading') {
    initializePlacesButtons();
} else {
    document.addEventListener('DOMContentLoaded', function () {
        initializePlacesButtons();
     });
     });
});
}

Latest revision as of 07:26, 29 June 2024

/* Load Popper.js */
mw.loader.load('https://cdn.jsdelivr.net/npm/@popperjs/core@2.5.4/dist/umd/popper.min.js');

/* Load Bootstrap JS */
mw.loader.load('https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js');

function initializePlacesButtons() {
    var count = 1;
    document.querySelectorAll('.btn.btn-primary.places-button').forEach(function(button) {
        var uniqueId = 'details-places-' + count;
        var collapseDiv = button.parentElement.nextElementSibling;
        if (collapseDiv) {
            collapseDiv.id = uniqueId;
            button.setAttribute('data-target', '#' + uniqueId);
            button.setAttribute('aria-controls', uniqueId);
            count++;
        } 
    });
}

if (document.readyState !== 'loading') {
    initializePlacesButtons();
} else {
    document.addEventListener('DOMContentLoaded', function () {
        initializePlacesButtons();
    });
}