MediaWiki:CommonCita.js: differenze tra le versioni
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 |
||
Riga 1: | Riga 1: | ||
(function | (function () { | ||
console.log("🔍 CommonCita.js avviato"); | |||
const abstractMapByTitle = { | |||
"The epistemology of mathematical and statistical modeling: a quiet methodological revolution": ` | |||
const | |||
" | |||
<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 18: | Riga 13: | ||
}; | }; | ||
function normalize(text) { | |||
const | return text.replace(/\s+/g, ' ').trim().toLowerCase(); | ||
const | } | ||
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) { | |||
e.preventDefault(); | |||
e.stopPropagation(); | |||
document.querySelectorAll('.citation-popup-container').forEach(p => p.remove()); | |||
const href = link.getAttribute('href'); | |||
const refId = href && href.slice(1); // rimuove il # | |||
const refElement = document.getElementById(refId); | |||
if (!refElement) return; | |||
const matchedTitle = findMatchingTitle(refElement); | |||
if (!matchedTitle) return; | |||
const popup = document.createElement('div'); | |||
popup.className = 'citation-popup-container'; | |||
popup.innerHTML = abstractMapByTitle[matchedTitle]; | |||
document.body.appendChild(popup); | |||
const rect = link.getBoundingClientRect(); | |||
popup.style.top = `${rect.bottom + window.scrollY + 10}px`; | |||
popup.style.left = `${rect.left + window.scrollX}px`; | |||
}); | |||
}); | |||
document.addEventListener('click', function (e) { | |||
popup. | 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"); | |||
} | |||
// Aspetta che il DOM sia pronto e i <ref> siano renderizzati | |||
function waitForReferences() { | |||
const refs = document.querySelectorAll('sup.reference > a'); | |||
if (refs.length === 0) { | |||
return setTimeout(waitForReferences, 100); | |||
} | } | ||
}); | attachCitationPopups(); | ||
} | |||
waitForReferences(); | |||
})(); | })(); |
Versione delle 10:02, 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, suggerendo un approccio epistemologico alternativo.
</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) {
e.preventDefault();
e.stopPropagation();
document.querySelectorAll('.citation-popup-container').forEach(p => p.remove());
const href = link.getAttribute('href');
const refId = href && href.slice(1); // rimuove il #
const refElement = document.getElementById(refId);
if (!refElement) return;
const matchedTitle = findMatchingTitle(refElement);
if (!matchedTitle) return;
const popup = document.createElement('div');
popup.className = 'citation-popup-container';
popup.innerHTML = abstractMapByTitle[matchedTitle];
document.body.appendChild(popup);
const rect = link.getBoundingClientRect();
popup.style.top = `${rect.bottom + window.scrollY + 10}px`;
popup.style.left = `${rect.left + window.scrollX}px`;
});
});
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");
}
// Aspetta che il DOM sia pronto e i <ref> siano renderizzati
function waitForReferences() {
const refs = document.querySelectorAll('sup.reference > a');
if (refs.length === 0) {
return setTimeout(waitForReferences, 100);
}
attachCitationPopups();
}
waitForReferences();
})();