Aller au contenu

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

De AECFC
Aucun résumé des modifications
Balise : Révocation manuelle
Aucun résumé des modifications
 
(12 versions intermédiaires par le même utilisateur non affichées)
Ligne 3 : Ligne 3 :
$(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');
});
});
*/
*/
Ligne 11 : Ligne 11 :
     'use strict';
     'use strict';


     function configureAecfcLogo() {
     function restoreAecfcLink() {
         const mainLink = 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 (!mainLink) {
    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;


         // Évite une seconde initialisation.
    var historyMenuItem = mw.util.addPortletLink(
         if (mainLink.dataset.aecfcRouting === '1') {
        'p-tb',
            return;
         historyLink.href,
         }
         historyLink.textContent.trim() || "Voir l'historique",
        't-page-history',
        "Voir l'historique de cette page",
        null,
         firstTool
    );


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


        /*
$.when(
        * Supprime le titre et le sous-titre natifs,
    mw.loader.using( 'mediawiki.util' ),
        * mais conserve l'image du logo.
    $.ready
        */
).then( function () {
        const nativeText = mainLink.querySelector('.mw-logo-container');


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


        /*
    var leftNavigation = document.getElementById( 'left-navigation' );
        * Création des deux textes affichés à droite du logo.
    var rightNavigation = document.getElementById( 'right-navigation' );
        * 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');
    var viewsPortlet = document.getElementById( 'p-views' );
        accueilText.className = 'aecfc-accueil-text';
    var associatedPagesPortlet = document.getElementById( 'p-associated-pages' );
        accueilText.textContent = 'Accueil';
    var toolsDropdown = document.getElementById(
         accueilText.title = 'Accueil du wiki';
         'vector-page-tools-dropdown'
    );


         const devoirsText = document.createElement('span');
    if (
         devoirsText.className = 'aecfc-devoirs-text';
        !leftNavigation ||
         devoirsText.textContent = 'Devoirs';
         !rightNavigation ||
         devoirsText.title = 'Consulter les devoirs';
         !viewsPortlet ||
         !associatedPagesPortlet
    ) {
         return;
    }


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


        /*
    /*
        * Le lien par défaut du bloc reste l'accueil du wiki.
    * 2. Déplacer également le menu Outils à gauche
        */
    */
         mainLink.href = 'https://wiki.aecfc.org/wiki/Accueil';
    if ( toolsDropdown ) {
         mainLink.title = '';
         var toolsBlock = toolsDropdown.closest( 'nav' ) || toolsDropdown;
         leftNavigation.appendChild( toolsBlock );
    }


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


         if (logoIcon) {
    if ( associatedList ) {
             logoIcon.title = 'Site officiel de l’AECFC';
         while ( associatedList.firstChild ) {
             associatedList.removeChild( associatedList.firstChild );
         }
         }
    }


        /*
    /*
        * Comme Vector utilise un seul lien parent,
    * 4. Déplacer ce bloc vide à droite
        * on choisit la destination selon la zone cliquée.
    */
        */
    var associatedPagesBlock =
         mainLink.addEventListener(
         associatedPagesPortlet.closest( 'nav' ) ||
            'click',
        associatedPagesPortlet;
            function (event) {
                const target =
                    event.target instanceof Element
                        ? event.target
                        : event.target.parentElement;


                if (!target) {
    rightNavigation.appendChild( associatedPagesBlock );
                    return;
                }


                // Clic sur le logo graphique → site aecfc.org
    /*
                if (target.closest('.mw-logo-icon')) {
    * 5. Ajouter Accueil et Devoirs dans la partie droite
                    event.preventDefault();
    */
                    event.stopImmediatePropagation();
    mw.util.addPortletLink(
                    window.location.assign('https://aecfc.org/');
        'p-associated-pages',
                    return;
        mw.util.getUrl( 'Accueil' ),
                }
        'Accueil',
        'ca-aecfc-accueil',
        "Aller à la page d'accueil"
    );


                // Clic sur Devoirs → page Devoirs
    mw.util.addPortletLink(
                if (target.closest('.aecfc-devoirs-text')) {
        'p-associated-pages',
                    event.preventDefault();
        mw.util.getUrl( 'Devoirs_2026-2027' ),
                    event.stopImmediatePropagation();
        'Devoirs',
                    window.location.assign(
        'ca-aecfc-devoirs',
                        'https://wiki.aecfc.org/wiki/Devoirs'
        'Aller à la page des devoirs'
                    );
    );
                    return;
                }


                /*
/*
                * Clic sur Accueil, ou sur le reste du bloc :
* Déplacer « Voir l'historique » dans le menu Outils
                * le comportement normal du lien parent est conservé.
*/
                */
var historyTab = document.getElementById( 'ca-history' );
            },
var historyLink = historyTab
            true
    ? 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();
     }
     }
}


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

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

} );