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

De WikiMetz : Encyclopédie sur l'Histoire de Metz, l'encyclopédie de Metz
Aucun résumé des modifications
Balise : Révoqué
Aucun résumé des modifications
Balise : Révoqué
Ligne 29 : Ligne 29 :
});
});


document.addEventListener("click", function(e){
document.addEventListener("DOMContentLoaded", function(){
   if(e.target.classList.contains("mw-inline-cats-toggle")){
   document.querySelectorAll(".mw-inline-cats-wrapper").forEach(function(wrapper){
     const box = e.target.closest(".mw-inline-cats-wrapper");
     const text = wrapper.querySelector(".mw-inline-cats-text");
     box.classList.toggle("expanded");
     if (text.scrollWidth > text.clientWidth) {
      const btn = document.createElement("button");
      btn.className = "mw-inline-cats-toggle";
      btn.textContent = "afficher";
      wrapper.appendChild(btn);


    e.target.textContent =
      btn.addEventListener("click", function(){
      box.classList.contains("expanded") ? "masquer" : "afficher";
        wrapper.classList.toggle("expanded");
   }
        btn.textContent = wrapper.classList.contains("expanded") ? "masquer" : "afficher";
      });
    }
   });
});
});

Version du 9 mars 2026 à 20:55

/* Tout JavaScript présent ici sera exécuté par tous les utilisateurs à chaque chargement de page. */
mw.loader.using('user', function () {
    document.addEventListener('copy', function (e) {
        const selection = window.getSelection().toString();
        const copyrightNotice = '\n— Source : WikiMetz (https://www.wikimetz.fr)';
        const copyText = selection + copyrightNotice;

        e.preventDefault();

        if (e.clipboardData) {
            e.clipboardData.setData('text/plain', copyText);
        } else if (window.clipboardData) {
            window.clipboardData.setData('Text', copyText);
        }
    });
});

$(function () {

    // uniquement namespace File
    if (mw.config.get('wgCanonicalNamespace') !== 'File') return;

    // désactive clic droit sur l’image principale
    $('.fullImageLink img').on('contextmenu', function (e) {
        e.preventDefault();
        return false;
    });

});

document.addEventListener("DOMContentLoaded", function(){
  document.querySelectorAll(".mw-inline-cats-wrapper").forEach(function(wrapper){
    const text = wrapper.querySelector(".mw-inline-cats-text");
    if (text.scrollWidth > text.clientWidth) {
      const btn = document.createElement("button");
      btn.className = "mw-inline-cats-toggle";
      btn.textContent = "afficher";
      wrapper.appendChild(btn);

      btn.addEventListener("click", function(){
        wrapper.classList.toggle("expanded");
        btn.textContent = wrapper.classList.contains("expanded") ? "masquer" : "afficher";
      });
    }
  });
});