Aller au contenu

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

De Wikiquestia
Aucun résumé des modifications
Aucun résumé des modifications
 
(3 versions intermédiaires par le même utilisateur non affichées)
Ligne 1 : Ligne 1 :
document.addEventListener('DOMContentLoaded', function () {
(function () {
   document.querySelectorAll('.copy-button').forEach(button => {
   try {
     button.addEventListener('click', function () {
     if (window.__copySyntaxInit) return;
      const targetId = this.getAttribute('data-copy-target');
    window.__copySyntaxInit = true;
      const target = document.getElementById(targetId);


       if (!target) return;
    document.addEventListener('click', function (e) {
      var btn = e.target.closest('.copy-syntax-btn');
       if (!btn) return;


       // 👇 Force le focus avant de copier
       var wrapper = btn.closest('.syntax-copy-wrapper');
       window.focus();
       if (!wrapper) return;


       const text = target.innerText || target.textContent;
       var pre = wrapper.querySelector('.syntax-to-copy');
      if (!pre) return;


       navigator.clipboard.writeText(text).then(() => {
      var text = pre.innerText;
         this.textContent = '✅ Copié';
 
         setTimeout(() => this.textContent = '📋 Copier', 2000);
       navigator.clipboard.writeText(text).then(function () {
      }).catch(err => {
         btn.textContent = '✅ Copié';
        console.error("Erreur de copie :", err);
         setTimeout(function () {
        this.textContent = '❌ Erreur';
          btn.textContent = '📋 Copier la syntaxe';
        }, 1500);
       });
       });
     });
     });
   });
   } catch (err) {
});
    console.error('CopierSyntaxe error:', err);
  }
})();

Dernière version du 17 janvier 2026 à 22:20

(function () {
  try {
    if (window.__copySyntaxInit) return;
    window.__copySyntaxInit = true;

    document.addEventListener('click', function (e) {
      var btn = e.target.closest('.copy-syntax-btn');
      if (!btn) return;

      var wrapper = btn.closest('.syntax-copy-wrapper');
      if (!wrapper) return;

      var pre = wrapper.querySelector('.syntax-to-copy');
      if (!pre) return;

      var text = pre.innerText;

      navigator.clipboard.writeText(text).then(function () {
        btn.textContent = '✅ Copié';
        setTimeout(function () {
          btn.textContent = '📋 Copier la syntaxe';
        }, 1500);
      });
    });
  } catch (err) {
    console.error('CopierSyntaxe error:', err);
  }
})();