Aller au contenu

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

De AECFC
Aucun résumé des modifications
Aucun résumé des modifications
 
(17 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');
});
});
*/
*/


mw.loader.using('mediawiki.util').then(function () {
(function () {
    'use strict';


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


         if (!logoLink) {
    if (document.readyState === 'loading') {
             return;
        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 );
         }
         }
    }


        /*
    /*
        * Supprime un éventuel ancien bloc personnalisé.
    * 4. Déplacer ce bloc vide à droite
        */
    */
         document.querySelectorAll('.aecfc-header-links').forEach(function (element) {
    var associatedPagesBlock =
            element.remove();
         associatedPagesPortlet.closest( 'nav' ) ||
        });
        associatedPagesPortlet;
 
    rightNavigation.appendChild( associatedPagesBlock );


        /*
    /*
        * Le lien du logo ne doit contenir que l'image.
    * 5. Ajouter Accueil et Devoirs dans la partie droite
        * On supprime le wordmark, le sous-titre natif
    */
        * et tout ancien texte ajouté dans ce lien.
    mw.util.addPortletLink(
        */
        'p-associated-pages',
        Array.from(logoLink.children).forEach(function (child) {
        mw.util.getUrl( 'Accueil' ),
            if (!child.classList.contains('mw-logo-icon')) {
        'Accueil',
                child.remove();
        'ca-aecfc-accueil',
            }
         "Aller à la page d'accueil"
         });
    );


        /*
    mw.util.addPortletLink(
        * Le logo graphique ouvre le site public.
        'p-associated-pages',
        */
         mw.util.getUrl( 'Devoirs_2026-2027' ),
         logoLink.href = 'https://aecfc.org/';
         'Devoirs',
         logoLink.title = 'Site officiel de l’AECFC';
         'ca-aecfc-devoirs',
         logoLink.setAttribute(
        'Aller à la page des devoirs'
            'aria-label',
    );
            'Accéder au site officiel de l’AECFC'
        );


        /*
/*
        * Nouveau bloc indépendant pour Accueil et Devoirs.
* Déplacer « Voir l'historique » dans le menu Outils
        */
*/
        const linksBlock = document.createElement('div');
var historyTab = document.getElementById( 'ca-history' );
        linksBlock.className = 'aecfc-header-links';
var historyLink = historyTab
    ? historyTab.querySelector( 'a' )
    : null;


        const accueilLink = document.createElement('a');
if (
        accueilLink.className = 'aecfc-header-home';
    historyLink &&
        accueilLink.href = mw.util.getUrl('Accueil');
    !document.getElementById( 't-page-history' )
         accueilLink.textContent = 'Accueil';
) {
        accueilLink.title = 'Accueil du wiki';
    var toolsList = document.querySelector(
         '#p-tb .vector-menu-content-list'
    );


        const devoirsLink = document.createElement('a');
    var firstTool = toolsList
         devoirsLink.className = 'aecfc-header-homework';
         ? toolsList.firstElementChild
         devoirsLink.href = mw.util.getUrl('Devoirs');
         : null;
        devoirsLink.textContent = 'Devoirs';
        devoirsLink.title = 'Consulter les devoirs';


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


        /*
    if ( historyMenuItem ) {
        * Le bloc est placé après le lien du logo,
         historyTab.remove();
        * donc il n'est pas contenu dans le même <a>.
        */
         logoLink.insertAdjacentElement('afterend', linksBlock);
     }
     }
}


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

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();
    }
}

} );