« MediaWiki:Common.js » : différence entre les versions
Apparence
Aucun résumé des modifications Balise : Révoqué |
Aucun résumé des modifications Balise : Révocation manuelle |
||
| Ligne 8 : | Ligne 8 : | ||
*/ | */ | ||
(function () { | |||
'use strict'; | |||
function configureAecfcLogo() { | |||
. | const mainLink = document.querySelector('a.mw-logo'); | ||
if (!mainLink) { | |||
return; | |||
} | |||
// Évite une seconde initialisation. | |||
if (mainLink.dataset.aecfcRouting === '1') { | |||
return; | |||
} | |||
mainLink.dataset.aecfcRouting = '1'; | |||
/* | /* | ||
. | * Supprime le titre et le sous-titre natifs, | ||
* mais conserve l'image du logo. | |||
*/ | |||
const nativeText = mainLink.querySelector('.mw-logo-container'); | |||
if (nativeText) { | |||
nativeText.remove(); | |||
} | |||
/* | |||
* Création des deux textes affichés à droite du logo. | |||
* Ce sont volontairement des <span>, pas des liens imbriqués. | |||
*/ | |||
const textBlock = document.createElement('span'); | |||
textBlock.className = 'aecfc-logo-texts'; | |||
const accueilText = document.createElement('span'); | |||
. | accueilText.className = 'aecfc-accueil-text'; | ||
.aecfc-accueil- | accueilText.textContent = 'Accueil'; | ||
accueilText.title = 'Accueil du wiki'; | |||
const devoirsText = document.createElement('span'); | |||
. | devoirsText.className = 'aecfc-devoirs-text'; | ||
.aecfc-devoirs- | devoirsText.textContent = 'Devoirs'; | ||
devoirsText.title = 'Consulter les devoirs'; | |||
.aecfc- | textBlock.appendChild(accueilText); | ||
.aecfc-devoirs- | textBlock.appendChild(devoirsText); | ||
mainLink.appendChild(textBlock); | |||
} | |||
/* | |||
* Le lien par défaut du bloc reste l'accueil du wiki. | |||
*/ | |||
mainLink.href = 'https://wiki.aecfc.org/wiki/Accueil'; | |||
mainLink.title = ''; | |||
const logoIcon = mainLink.querySelector('.mw-logo-icon'); | |||
if (logoIcon) { | |||
logoIcon.title = 'Site officiel de l’AECFC'; | |||
} | |||
/* | |||
* Comme Vector utilise un seul lien parent, | |||
* on choisit la destination selon la zone cliquée. | |||
*/ | |||
mainLink.addEventListener( | |||
'click', | |||
function (event) { | |||
const target = | |||
event.target instanceof Element | |||
? event.target | |||
: event.target.parentElement; | |||
if (!target) { | |||
return; | |||
} | |||
// Clic sur le logo graphique → site aecfc.org | |||
if (target.closest('.mw-logo-icon')) { | |||
event.preventDefault(); | |||
event.stopImmediatePropagation(); | |||
window.location.assign('https://aecfc.org/'); | |||
return; | |||
} | |||
// Clic sur Devoirs → page Devoirs | |||
if (target.closest('.aecfc-devoirs-text')) { | |||
event.preventDefault(); | |||
event.stopImmediatePropagation(); | |||
window.location.assign( | |||
'https://wiki.aecfc.org/wiki/Devoirs' | |||
); | |||
return; | |||
} | |||
/* | |||
* Clic sur Accueil, ou sur le reste du bloc : | |||
* le comportement normal du lien parent est conservé. | |||
*/ | |||
}, | |||
true | |||
); | |||
} | |||
if (document.readyState === 'loading') { | |||
document.addEventListener( | |||
'DOMContentLoaded', | |||
configureAecfcLogo, | |||
{ once: true } | |||
); | |||
} else { | |||
configureAecfcLogo(); | |||
} | |||
})(); | |||
Version du 2 juillet 2026 à 16:48
/* Tout JavaScript présent ici sera exécuté par tous les utilisateurs à chaque chargement de page.
$(function () {
$('a.mw-wiki-logo, a.mw-logo')
.attr('href', 'Accueil')
.attr('title', 'Retour a l'accueil');
});
*/
(function () {
'use strict';
function configureAecfcLogo() {
const mainLink = document.querySelector('a.mw-logo');
if (!mainLink) {
return;
}
// Évite une seconde initialisation.
if (mainLink.dataset.aecfcRouting === '1') {
return;
}
mainLink.dataset.aecfcRouting = '1';
/*
* Supprime le titre et le sous-titre natifs,
* mais conserve l'image du logo.
*/
const nativeText = mainLink.querySelector('.mw-logo-container');
if (nativeText) {
nativeText.remove();
}
/*
* Création des deux textes affichés à droite du logo.
* Ce sont volontairement des <span>, pas des liens imbriqués.
*/
const textBlock = document.createElement('span');
textBlock.className = 'aecfc-logo-texts';
const accueilText = document.createElement('span');
accueilText.className = 'aecfc-accueil-text';
accueilText.textContent = 'Accueil';
accueilText.title = 'Accueil du wiki';
const devoirsText = document.createElement('span');
devoirsText.className = 'aecfc-devoirs-text';
devoirsText.textContent = 'Devoirs';
devoirsText.title = 'Consulter les devoirs';
textBlock.appendChild(accueilText);
textBlock.appendChild(devoirsText);
mainLink.appendChild(textBlock);
/*
* Le lien par défaut du bloc reste l'accueil du wiki.
*/
mainLink.href = 'https://wiki.aecfc.org/wiki/Accueil';
mainLink.title = '';
const logoIcon = mainLink.querySelector('.mw-logo-icon');
if (logoIcon) {
logoIcon.title = 'Site officiel de l’AECFC';
}
/*
* Comme Vector utilise un seul lien parent,
* on choisit la destination selon la zone cliquée.
*/
mainLink.addEventListener(
'click',
function (event) {
const target =
event.target instanceof Element
? event.target
: event.target.parentElement;
if (!target) {
return;
}
// Clic sur le logo graphique → site aecfc.org
if (target.closest('.mw-logo-icon')) {
event.preventDefault();
event.stopImmediatePropagation();
window.location.assign('https://aecfc.org/');
return;
}
// Clic sur Devoirs → page Devoirs
if (target.closest('.aecfc-devoirs-text')) {
event.preventDefault();
event.stopImmediatePropagation();
window.location.assign(
'https://wiki.aecfc.org/wiki/Devoirs'
);
return;
}
/*
* Clic sur Accueil, ou sur le reste du bloc :
* le comportement normal du lien parent est conservé.
*/
},
true
);
}
if (document.readyState === 'loading') {
document.addEventListener(
'DOMContentLoaded',
configureAecfcLogo,
{ once: true }
);
} else {
configureAecfcLogo();
}
})();