MediaWiki:Common.js: Difference between revisions

No edit summary
No edit summary
 
(6 intermediate revisions by the same user not shown)
Line 1: Line 1:
importScriptURI('https://code.jquery.com/jquery-3.5.1.min.js');
/* Load Popper.js */
importScriptURI('https://cdn.jsdelivr.net/npm/@popperjs/core@2.5.4/dist/umd/popper.min.js');
mw.loader.load('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 */
     var count = 0;
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) {
     document.querySelectorAll('.btn.btn-primary.places-button').forEach(function(button) {
         var uniqueId = 'details-' + Date.now() + '-' + count++;
         var uniqueId = 'details-places-' + count;
         var collapseDiv = button.parentElement.nextElementSibling;
         var collapseDiv = button.parentElement.nextElementSibling;
         if (collapseDiv) {
         if (collapseDiv) {
Line 13: Line 15:
             button.setAttribute('aria-controls', uniqueId);
             button.setAttribute('aria-controls', uniqueId);
             count++;
             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();
    });
}