مدیاویکی:Common.js: تفاوت میان نسخهها
از ویکییاد
بدون خلاصۀ ویرایش |
بدون خلاصۀ ویرایش |
||
| خط ۱: | خط ۱: | ||
/** | /** | ||
* Gallery to background-cover: | * Gallery to background-cover: set img src as background on .thumb div + hide img | ||
*/ | */ | ||
(function () { | (function () { | ||
function processGalleries() { | function processGalleries() { | ||
document.querySelectorAll('li.gallerybox').forEach(function (box) { | document.querySelectorAll('li.gallerybox').forEach(function (box) { | ||
// Find the img inside | // Find the .thumb div and the img inside it | ||
const | const thumbDiv = box.querySelector('div.thumb'); | ||
const img = thumbDiv ? thumbDiv.querySelector('img.mw-file-element') : null; | |||
if (img && img.src && ! | if (thumbDiv && img && img.src && !thumbDiv.dataset.backgroundApplied) { | ||
// Apply background | // Apply background to the .thumb div | ||
thumbDiv.style.backgroundImage = 'url(' + img.src + ')'; | |||
thumbDiv.style.backgroundSize = 'cover'; | |||
thumbDiv.style.backgroundPosition = 'center center'; | |||
thumbDiv.style.backgroundRepeat = 'no-repeat'; | |||
// Hide original | // Hide the original <img> tag | ||
img.style.display = 'none'; | img.style.display = 'none'; | ||
// Mark as processed | // Mark as processed | ||
thumbDiv.dataset.backgroundApplied = 'true'; | |||
console.log('Applied background to | console.log('Applied background to thumb div:', img.src); | ||
} | } | ||
}); | }); | ||
| خط ۲۹: | خط ۳۰: | ||
document.addEventListener('DOMContentLoaded', processGalleries); | document.addEventListener('DOMContentLoaded', processGalleries); | ||
// Watch for dynamic | // Watch for dynamic additions (DPL may insert later) | ||
const observer = new MutationObserver(processGalleries); | const observer = new MutationObserver(processGalleries); | ||
observer.observe(document.body, { childList: true, subtree: true }); | observer.observe(document.body, { childList: true, subtree: true }); | ||
// | // Extra fallback runs | ||
setTimeout(processGalleries, | setTimeout(processGalleries, 1000); | ||
setTimeout(processGalleries, | setTimeout(processGalleries, 2500); | ||
})(); | })(); | ||
نسخهٔ ۲۳ ژانویهٔ ۲۰۲۶، ساعت ۱۹:۴۱
/**
* Gallery to background-cover: set img src as background on .thumb div + hide img
*/
(function () {
function processGalleries() {
document.querySelectorAll('li.gallerybox').forEach(function (box) {
// Find the .thumb div and the img inside it
const thumbDiv = box.querySelector('div.thumb');
const img = thumbDiv ? thumbDiv.querySelector('img.mw-file-element') : null;
if (thumbDiv && img && img.src && !thumbDiv.dataset.backgroundApplied) {
// Apply background to the .thumb div
thumbDiv.style.backgroundImage = 'url(' + img.src + ')';
thumbDiv.style.backgroundSize = 'cover';
thumbDiv.style.backgroundPosition = 'center center';
thumbDiv.style.backgroundRepeat = 'no-repeat';
// Hide the original <img> tag
img.style.display = 'none';
// Mark as processed
thumbDiv.dataset.backgroundApplied = 'true';
console.log('Applied background to thumb div:', img.src);
}
});
}
// Run once DOM is ready
document.addEventListener('DOMContentLoaded', processGalleries);
// Watch for dynamic additions (DPL may insert later)
const observer = new MutationObserver(processGalleries);
observer.observe(document.body, { childList: true, subtree: true });
// Extra fallback runs
setTimeout(processGalleries, 1000);
setTimeout(processGalleries, 2500);
})();
