Creata pagina con "(function waitForReferencesAndInit() { const references = document.querySelectorAll('sup.reference > a'); if (references.length === 0) { return setTimeout(waitForReferencesAndInit, 100); } console.log("✅ CommonCita.js attivo"); const abstractData = { "Rodgers2010": ` <strong>Rodgers JL</strong><br> <em>The epistemology of mathematical and statistical modeling: a quiet methodological revolution</em><br> <small><span style="color:#99..."
 
Nessun oggetto della modifica
 
(2 versioni intermedie di uno stesso utente non sono mostrate)
Riga 1: Riga 1:
(function waitForReferencesAndInit() {
(function () {
  const references = document.querySelectorAll('sup.reference > a');
   console.log("🔍 CommonCita.js avviato");
  if (references.length === 0) {
    return setTimeout(waitForReferencesAndInit, 100);
  }
 
   console.log("CommonCita.js attivo");


   const abstractData = {
   const abstractMapByTitle = {
     "Rodgers2010": `
     "The epistemology of mathematical and statistical modeling: a quiet methodological revolution": `
       <strong>Rodgers JL</strong><br>
       <strong>Rodgers JL</strong><br>
       <em>The epistemology of mathematical and statistical modeling: a quiet methodological revolution</em><br>
       <em>The epistemology of mathematical and statistical modeling: a quiet methodological revolution</em><br>
Riga 14: Riga 9:
       <hr>
       <hr>
       <div class="citation-popup-abstract">
       <div class="citation-popup-abstract">
         Questo articolo propone un cambiamento radicale nella valutazione statistica, suggerendo un approccio epistemologico alternativo.
         Questo articolo propone un cambiamento radicale nella valutazione statistica.
       </div>`
       </div>`
   };
   };


   references.forEach(link => {
   function normalize(text) {
     const href = link.getAttribute('href');
     return text.replace(/\s+/g, ' ').trim().toLowerCase();
    const match = href && href.match(/#cite_note-(.+?)(?:-\d+)?$/);
  }
    if (!match) return;


     const refId = match[1];
  function findMatchingTitle(refContent) {
     if (!abstractData[refId]) return;
     const refText = normalize(refContent.textContent || '');
     for (const title in abstractMapByTitle) {
      if (refText.includes(normalize(title))) {
        return title;
      }
    }
    return null;
  }


     link.style.cursor = "pointer";
  function attachCitationPopups() {
     document.querySelectorAll('sup.reference > a').forEach(link => {
      link.addEventListener('click', function (e) {
        const href = link.getAttribute('href');
        const refId = href && href.slice(1);
        const refElement = document.getElementById(refId);
        if (!refElement) return;


    link.addEventListener('click', function (e) {
        const matchedTitle = findMatchingTitle(refElement);
      e.preventDefault();
        if (!matchedTitle) return;
      e.stopPropagation();


      document.querySelectorAll('.citation-popup-container').forEach(p => p.remove());
        e.preventDefault(); // blocca salto alla bibliografia
        e.stopPropagation();


      const popup = document.createElement('div');
        // Rimuove popup precedenti
      popup.className = 'citation-popup-container';
        document.querySelectorAll('.citation-popup-container').forEach(p => p.remove());
      popup.innerHTML = abstractData[refId];
      document.body.appendChild(popup);


      const rect = link.getBoundingClientRect();
        const popup = document.createElement('div');
      popup.style.top = `${rect.bottom + window.scrollY + 10}px`;
        popup.className = 'citation-popup-container';
      popup.style.left = `${rect.left + window.scrollX}px`;
        popup.innerHTML = abstractMapByTitle[matchedTitle];
        document.body.appendChild(popup);
 
        const rect = link.getBoundingClientRect();
        popup.style.position = 'absolute';
        popup.style.top = `${rect.bottom + window.scrollY + 10}px`;
        popup.style.left = `${rect.left + window.scrollX}px`;
        popup.style.padding = '10px 15px';
        popup.style.background = 'white';
        popup.style.border = '1px solid silver';
        popup.style.borderRadius = '10px';
        popup.style.boxShadow = '0 0 60px 25px rgba(0,0,0,0.4)';
        popup.style.zIndex = 9999;
        popup.style.maxWidth = '400px';
      });
     });
     });
  });


  document.addEventListener('click', function (e) {
    document.addEventListener('click', function (e) {
    if (!e.target.closest('.citation-popup-container') && !e.target.closest('sup.reference')) {
      if (!e.target.closest('.citation-popup-container') && !e.target.closest('sup.reference')) {
      document.querySelectorAll('.citation-popup-container').forEach(p => p.remove());
        document.querySelectorAll('.citation-popup-container').forEach(p => p.remove());
      }
    });
 
    console.log("✅ Tooltip attivo per citazioni con abstract noti");
  }
 
  function waitForReferences(attempts = 0) {
    const refs = document.querySelectorAll('sup.reference > a');
    if (refs.length === 0 && attempts < 20) {
      return setTimeout(() => waitForReferences(attempts + 1), 300);
    }
    if (refs.length === 0) {
      console.warn("❌ Nessuna citazione trovata.");
      return;
     }
     }
   });
    console.log(`🔎 Trovate ${refs.length} citazioni`);
    attachCitationPopups();
   }
 
  waitForReferences();
})();
})();

Versione attuale delle 11:08, 25 apr 2025

(function () {
  console.log("🔍 CommonCita.js avviato");

  const abstractMapByTitle = {
    "The epistemology of mathematical and statistical modeling: a quiet methodological revolution": `
      <strong>Rodgers JL</strong><br>
      <em>The epistemology of mathematical and statistical modeling: a quiet methodological revolution</em><br>
      <small><span style="color:#999">Am Psychol, 2010</span></small>
      <hr>
      <div class="citation-popup-abstract">
        Questo articolo propone un cambiamento radicale nella valutazione statistica.
      </div>`
  };

  function normalize(text) {
    return text.replace(/\s+/g, ' ').trim().toLowerCase();
  }

  function findMatchingTitle(refContent) {
    const refText = normalize(refContent.textContent || '');
    for (const title in abstractMapByTitle) {
      if (refText.includes(normalize(title))) {
        return title;
      }
    }
    return null;
  }

  function attachCitationPopups() {
    document.querySelectorAll('sup.reference > a').forEach(link => {
      link.addEventListener('click', function (e) {
        const href = link.getAttribute('href');
        const refId = href && href.slice(1);
        const refElement = document.getElementById(refId);
        if (!refElement) return;

        const matchedTitle = findMatchingTitle(refElement);
        if (!matchedTitle) return;

        e.preventDefault(); // blocca salto alla bibliografia
        e.stopPropagation();

        // Rimuove popup precedenti
        document.querySelectorAll('.citation-popup-container').forEach(p => p.remove());

        const popup = document.createElement('div');
        popup.className = 'citation-popup-container';
        popup.innerHTML = abstractMapByTitle[matchedTitle];
        document.body.appendChild(popup);

        const rect = link.getBoundingClientRect();
        popup.style.position = 'absolute';
        popup.style.top = `${rect.bottom + window.scrollY + 10}px`;
        popup.style.left = `${rect.left + window.scrollX}px`;
        popup.style.padding = '10px 15px';
        popup.style.background = 'white';
        popup.style.border = '1px solid silver';
        popup.style.borderRadius = '10px';
        popup.style.boxShadow = '0 0 60px 25px rgba(0,0,0,0.4)';
        popup.style.zIndex = 9999;
        popup.style.maxWidth = '400px';
      });
    });

    document.addEventListener('click', function (e) {
      if (!e.target.closest('.citation-popup-container') && !e.target.closest('sup.reference')) {
        document.querySelectorAll('.citation-popup-container').forEach(p => p.remove());
      }
    });

    console.log("✅ Tooltip attivo per citazioni con abstract noti");
  }

  function waitForReferences(attempts = 0) {
    const refs = document.querySelectorAll('sup.reference > a');
    if (refs.length === 0 && attempts < 20) {
      return setTimeout(() => waitForReferences(attempts + 1), 300);
    }
    if (refs.length === 0) {
      console.warn("❌ Nessuna citazione trovata.");
      return;
    }
    console.log(`🔎 Trovate ${refs.length} citazioni`);
    attachCitationPopups();
  }

  waitForReferences();
})();