MediaWiki:Script/Tabber.js : Différence entre versions
(Annulation des modifications 78304 de Dexter (discussion)) (Balise : Annuler) |
|||
Ligne 32 : | Ligne 32 : | ||
var newHash = e.target.location.hash; | var newHash = e.target.location.hash; | ||
if (newHash !== '') { | if (newHash !== '') { | ||
− | var targetButton = | + | var targetButton = buttonContainer.querySelector(e.target.location.hash); |
if (targetButton !== null) { | if (targetButton !== null) { | ||
globalChange(targetButton, buttonContainer, textContainer, false, false); | globalChange(targetButton, buttonContainer, textContainer, false, false); |
Version du 12 octobre 2022 à 07:00
function changeDisplay(button, textContainer, method) {
button.classList[method]('tabber-active');
textContainer.children[button.dataset.position].classList[method]('tabber-active');
}
function globalChange(button, allButton, allText, activation, changeUrl, bool = false) {
if (button.classList.contains('button')) {
var activeButton = allButton.querySelector('.tabber-active');
if (activation || button !== activeButton) {
if (bool && changeUrl) {
var newHash = '#'+button.id;
history.pushState({}, '', newHash);
}
changeDisplay(button, allText, 'toggle');
if (button !== activeButton && activeButton !== null) {
changeDisplay(activeButton, allText, 'remove');
}
}
}
}
function updateTabber(tabber, activation, changeUrl) {
var [buttonContainer, textContainer] = tabber.children;
var targetButton = buttonContainer.querySelector(':target');
buttonContainer.addEventListener('click', function(event) {
globalChange(event.target, buttonContainer, textContainer, activation, changeUrl, true);
});
if (targetButton !== null) {
globalChange(targetButton, buttonContainer, textContainer, false, false);
}
window.addEventListener('popstate', function(e) {
var newHash = e.target.location.hash;
if (newHash !== '') {
var targetButton = buttonContainer.querySelector(e.target.location.hash);
if (targetButton !== null) {
globalChange(targetButton, buttonContainer, textContainer, false, false);
}
}
});
}
(function() {
var tabberContainer = document.querySelectorAll('div.tabber-container');
tabberContainer.forEach(function(tabber) {
updateTabber(tabber, !tabber.dataset.activation, tabber.dataset.url);
});
})();