Aller au contenu

« MediaWiki:Common.js » : différence entre les versions

De AECFC
Aucun résumé des modifications
Aucun résumé des modifications
 
(16 versions intermédiaires par le même utilisateur non affichées)
Ligne 1 : Ligne 1 :
/* Tout JavaScript présent ici sera exécuté par tous les utilisateurs à chaque chargement de page. */
/* Tout JavaScript présent ici sera exécuté par tous les utilisateurs à chaque chargement de page.


$(function () {
$(function () {
     $('a.mw-wiki-logo, a.mw-logo')
     $('a.mw-wiki-logo, a.mw-logo')
         .attr('href', 'Accueil')
         .attr('href', 'https://aecfc.org')
         .attr('title', 'Retour a l'accueil');
         .attr('title', 'Retour au site d'AECFC');
});
});
*/
*/


(function () {
(function () {
     function rebuildAecfcHeader() {
     'use strict';
        /*
        * Lien global d'origine de Vector :
        * logo + titre + sous-titre.
        */
        const oldLogoLink = document.querySelector('a.mw-logo');


         if (!oldLogoLink) {
    function restoreAecfcLink() {
            return;
        document.querySelectorAll('a.mw-logo').forEach(function (link) {
         }
            link.href = 'https://aecfc.org/';
            link.title = 'Site de l’AECFC';
        });
    }
 
    if (document.readyState === 'loading') {
        document.addEventListener(
            'DOMContentLoaded',
            restoreAecfcLink,
            { once: true }
        );
    } else {
         restoreAecfcLink();
    }
})();
 
 
/*
* Déplacer « Voir l'historique » dans le menu Outils
*/
var historyTab = document.getElementById( 'ca-history' );
var historyLink = historyTab
    ? historyTab.querySelector( 'a' )
    : null;
 
if (
    historyLink &&
    !document.getElementById( 't-page-history' )
) {
    var toolsList = document.querySelector(
        '#p-tb .vector-menu-content-list'
    );
 
    var firstTool = toolsList
        ? toolsList.firstElementChild
        : null;
 
    var historyMenuItem = mw.util.addPortletLink(
        'p-tb',
        historyLink.href,
        historyLink.textContent.trim() || "Voir l'historique",
        't-page-history',
        "Voir l'historique de cette page",
        null,
        firstTool
    );
 
    /*
    * Supprimer l'onglet uniquement si son ajout
    * dans Outils a réussi
    */
    if ( historyMenuItem ) {
        historyTab.remove();
    }
}
 
$.when(
    mw.loader.using( 'mediawiki.util' ),
    $.ready
).then( function () {
 
    // Ce code concerne l'habillage Vector 2022
    if ( mw.config.get( 'skin' ) !== 'vector-2022' ) {
        return;
    }
 
    var leftNavigation = document.getElementById( 'left-navigation' );
    var rightNavigation = document.getElementById( 'right-navigation' );
 
    var viewsPortlet = document.getElementById( 'p-views' );
    var associatedPagesPortlet = document.getElementById( 'p-associated-pages' );
    var toolsDropdown = document.getElementById(
        'vector-page-tools-dropdown'
    );
 
    if (
         !leftNavigation ||
        !rightNavigation ||
        !viewsPortlet ||
        !associatedPagesPortlet
    ) {
        return;
    }
 
    /*
    * 1. Déplacer Lire, Modifier, Historique, etc. à gauche
    */
    var viewsBlock = viewsPortlet.closest( 'nav' ) || viewsPortlet;
    leftNavigation.appendChild( viewsBlock );


        /*
    /*
        * Empêche la création en double.
    * 2. Déplacer également le menu Outils à gauche
        */
    */
        if (document.querySelector('.aecfc-brand')) {
    if ( toolsDropdown ) {
            return;
        var toolsBlock = toolsDropdown.closest( 'nav' ) || toolsDropdown;
        }
        leftNavigation.appendChild( toolsBlock );
    }


        /*
    /*
        * Récupère uniquement l'image du logo.
    * 3. Vider l'ancien bloc contenant "Page"
        */
    */
        const logoImage =
    var associatedList = associatedPagesPortlet.querySelector(
            oldLogoLink.querySelector('img.mw-logo-icon') ||
        '.vector-menu-content-list'
            oldLogoLink.querySelector('img');
    );


         if (!logoImage) {
    if ( associatedList ) {
             console.warn('Image du logo AECFC introuvable');
         while ( associatedList.firstChild ) {
            return;
             associatedList.removeChild( associatedList.firstChild );
         }
         }
    }


        /*
    /*
        * Nouveau conteneur général.
    * 4. Déplacer ce bloc vide à droite
        */
    */
         const brand = document.createElement('div');
    var associatedPagesBlock =
         brand.className = 'aecfc-brand';
         associatedPagesPortlet.closest( 'nav' ) ||
         associatedPagesPortlet;


        /*
    rightNavigation.appendChild( associatedPagesBlock );
        * 1. Logo graphique → site public AECFC.
 
        */
    /*
        const logoLink = document.createElement('a');
    * 5. Ajouter Accueil et Devoirs dans la partie droite
         logoLink.className = 'mw-logo aecfc-logo-link';
    */
         logoLink.href = 'https://aecfc.org/';
    mw.util.addPortletLink(
         logoLink.title = 'Site officiel de l’AECFC';
         'p-associated-pages',
         logoLink.setAttribute(
         mw.util.getUrl( 'Accueil' ),
            'aria-label',
         'Accueil',
            'Accéder au site officiel de l’AECFC'
         'ca-aecfc-accueil',
        );
        "Aller à la page d'accueil"
        logoLink.appendChild(logoImage.cloneNode(true));
    );


        /*
    mw.util.addPortletLink(
        * Conteneur des deux liens du wiki.
        'p-associated-pages',
        */
         mw.util.getUrl( 'Devoirs_2026-2027' ),
         const textLinks = document.createElement('div');
        'Devoirs',
         textLinks.className = 'aecfc-text-links';
         'ca-aecfc-devoirs',
        'Aller à la page des devoirs'
    );


        /*
/*
        * 2. Accueil → page Accueil du wiki.
* Déplacer « Voir l'historique » dans le menu Outils
        */
*/
        const accueilLink = document.createElement('a');
var historyTab = document.getElementById( 'ca-history' );
        accueilLink.className = 'aecfc-accueil-link';
var historyLink = historyTab
        accueilLink.href = 'https://wiki.aecfc.org/wiki/Accueil';
    ? historyTab.querySelector( 'a' )
        accueilLink.textContent = 'Accueil';
    : null;
        accueilLink.title = 'Accueil du wiki';


        /*
if (
        * 3. Devoirs → page Devoirs du wiki.
    historyLink &&
        */
    !document.getElementById( 't-page-history' )
        const devoirsLink = document.createElement('a');
) {
        devoirsLink.className = 'aecfc-devoirs-link';
    var toolsList = document.querySelector(
        devoirsLink.href = 'https://wiki.aecfc.org/wiki/Devoirs';
         '#p-tb .vector-menu-content-list'
         devoirsLink.textContent = 'Devoirs';
    );
        devoirsLink.title = 'Consulter les devoirs';


         textLinks.appendChild(accueilLink);
    var firstTool = toolsList
         textLinks.appendChild(devoirsLink);
         ? toolsList.firstElementChild
         : null;


         brand.appendChild(logoLink);
    var historyMenuItem = mw.util.addPortletLink(
         brand.appendChild(textLinks);
        'p-tb',
         historyLink.href,
        historyLink.textContent.trim() || "Voir l'historique",
         't-page-history',
        "Voir l'historique de cette page",
        null,
        firstTool
    );


        /*
    if ( historyMenuItem ) {
        * Supprime entièrement l'ancien lien global
         historyTab.remove();
        * et le remplace par les trois liens indépendants.
        */
         oldLogoLink.replaceWith(brand);
     }
     }
}


    if (document.readyState === 'loading') {
} );
        document.addEventListener(
            'DOMContentLoaded',
            rebuildAecfcHeader,
            { once: true }
        );
    } else {
        rebuildAecfcHeader();
    }
})();

Dernière version du 3 juillet 2026 à 00:26

/* 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', 'https://aecfc.org')
        .attr('title', 'Retour au site d'AECFC');
});
*/

(function () {
    'use strict';

    function restoreAecfcLink() {
        document.querySelectorAll('a.mw-logo').forEach(function (link) {
            link.href = 'https://aecfc.org/';
            link.title = 'Site de l’AECFC';
        });
    }

    if (document.readyState === 'loading') {
        document.addEventListener(
            'DOMContentLoaded',
            restoreAecfcLink,
            { once: true }
        );
    } else {
        restoreAecfcLink();
    }
})();


/*
 * Déplacer « Voir l'historique » dans le menu Outils
 */
var historyTab = document.getElementById( 'ca-history' );
var historyLink = historyTab
    ? historyTab.querySelector( 'a' )
    : null;

if (
    historyLink &&
    !document.getElementById( 't-page-history' )
) {
    var toolsList = document.querySelector(
        '#p-tb .vector-menu-content-list'
    );

    var firstTool = toolsList
        ? toolsList.firstElementChild
        : null;

    var historyMenuItem = mw.util.addPortletLink(
        'p-tb',
        historyLink.href,
        historyLink.textContent.trim() || "Voir l'historique",
        't-page-history',
        "Voir l'historique de cette page",
        null,
        firstTool
    );

    /*
     * Supprimer l'onglet uniquement si son ajout
     * dans Outils a réussi
     */
    if ( historyMenuItem ) {
        historyTab.remove();
    }
}

$.when(
    mw.loader.using( 'mediawiki.util' ),
    $.ready
).then( function () {

    // Ce code concerne l'habillage Vector 2022
    if ( mw.config.get( 'skin' ) !== 'vector-2022' ) {
        return;
    }

    var leftNavigation = document.getElementById( 'left-navigation' );
    var rightNavigation = document.getElementById( 'right-navigation' );

    var viewsPortlet = document.getElementById( 'p-views' );
    var associatedPagesPortlet = document.getElementById( 'p-associated-pages' );
    var toolsDropdown = document.getElementById(
        'vector-page-tools-dropdown'
    );

    if (
        !leftNavigation ||
        !rightNavigation ||
        !viewsPortlet ||
        !associatedPagesPortlet
    ) {
        return;
    }

    /*
     * 1. Déplacer Lire, Modifier, Historique, etc. à gauche
     */
    var viewsBlock = viewsPortlet.closest( 'nav' ) || viewsPortlet;
    leftNavigation.appendChild( viewsBlock );

    /*
     * 2. Déplacer également le menu Outils à gauche
     */
    if ( toolsDropdown ) {
        var toolsBlock = toolsDropdown.closest( 'nav' ) || toolsDropdown;
        leftNavigation.appendChild( toolsBlock );
    }

    /*
     * 3. Vider l'ancien bloc contenant "Page"
     */
    var associatedList = associatedPagesPortlet.querySelector(
        '.vector-menu-content-list'
    );

    if ( associatedList ) {
        while ( associatedList.firstChild ) {
            associatedList.removeChild( associatedList.firstChild );
        }
    }

    /*
     * 4. Déplacer ce bloc vide à droite
     */
    var associatedPagesBlock =
        associatedPagesPortlet.closest( 'nav' ) ||
        associatedPagesPortlet;

    rightNavigation.appendChild( associatedPagesBlock );

    /*
     * 5. Ajouter Accueil et Devoirs dans la partie droite
     */
    mw.util.addPortletLink(
        'p-associated-pages',
        mw.util.getUrl( 'Accueil' ),
        'Accueil',
        'ca-aecfc-accueil',
        "Aller à la page d'accueil"
    );

    mw.util.addPortletLink(
        'p-associated-pages',
        mw.util.getUrl( 'Devoirs_2026-2027' ),
        'Devoirs',
        'ca-aecfc-devoirs',
        'Aller à la page des devoirs'
    );

/*
 * Déplacer « Voir l'historique » dans le menu Outils
 */
var historyTab = document.getElementById( 'ca-history' );
var historyLink = historyTab
    ? historyTab.querySelector( 'a' )
    : null;

if (
    historyLink &&
    !document.getElementById( 't-page-history' )
) {
    var toolsList = document.querySelector(
        '#p-tb .vector-menu-content-list'
    );

    var firstTool = toolsList
        ? toolsList.firstElementChild
        : null;

    var historyMenuItem = mw.util.addPortletLink(
        'p-tb',
        historyLink.href,
        historyLink.textContent.trim() || "Voir l'historique",
        't-page-history',
        "Voir l'historique de cette page",
        null,
        firstTool
    );

    if ( historyMenuItem ) {
        historyTab.remove();
    }
}

} );