MediaWiki:Common.js: Difference between revisions
(Created page with "→Any JavaScript here will be loaded for all users on every page load.: importScriptURI('https://code.jquery.com/jquery-3.5.1.slim.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');") |
No edit summary |
||
| (13 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
/* | /* 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(); | |||
}); | |||
} | |||
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();
});
}