مدیاویکی:Common.js: تفاوت میان نسخهها
از ویکییاد
بدون خلاصۀ ویرایش |
بدون خلاصۀ ویرایش |
||
| خط ۱: | خط ۱: | ||
/** | /** | ||
* Gallery | * Gallery to background-cover: extract img src → set as box background + hide img | ||
*/ | */ | ||
(function () { | |||
document.querySelectorAll('.gallerybox').forEach(function (box) { | function processGalleries() { | ||
document.querySelectorAll('li.gallerybox').forEach(function (box) { | |||
// Find the img inside thumb | |||
const img = box.querySelector('.thumb img.mw-file-element'); | |||
// Hide | if (img && img.src && !box.dataset.backgroundApplied) { | ||
// Apply background | |||
} | box.style.backgroundImage = 'url(' + img.src + ')'; | ||
}); | box.style.backgroundSize = 'cover'; | ||
}); | box.style.backgroundPosition = 'center center'; | ||
box.style.backgroundRepeat = 'no-repeat'; | |||
// Hide original image | |||
img.style.display = 'none'; | |||
// Mark as processed to avoid re-running | |||
box.dataset.backgroundApplied = 'true'; | |||
console.log('Applied background to gallery box:', img.src); | |||
} | |||
}); | |||
} | |||
// Run once DOM is ready | |||
document.addEventListener('DOMContentLoaded', processGalleries); | |||
// Watch for dynamic content added by DPL (important!) | |||
const observer = new MutationObserver(processGalleries); | |||
observer.observe(document.body, { childList: true, subtree: true }); | |||
// Fallback: run again after 1–2 seconds in case DPL is very slow | |||
setTimeout(processGalleries, 1500); | |||
setTimeout(processGalleries, 3000); | |||
})(); | |||
نسخهٔ ۲۳ ژانویهٔ ۲۰۲۶، ساعت ۱۹:۳۸
/**
* Gallery to background-cover: extract img src → set as box background + hide img
*/
(function () {
function processGalleries() {
document.querySelectorAll('li.gallerybox').forEach(function (box) {
// Find the img inside thumb
const img = box.querySelector('.thumb img.mw-file-element');
if (img && img.src && !box.dataset.backgroundApplied) {
// Apply background
box.style.backgroundImage = 'url(' + img.src + ')';
box.style.backgroundSize = 'cover';
box.style.backgroundPosition = 'center center';
box.style.backgroundRepeat = 'no-repeat';
// Hide original image
img.style.display = 'none';
// Mark as processed to avoid re-running
box.dataset.backgroundApplied = 'true';
console.log('Applied background to gallery box:', img.src);
}
});
}
// Run once DOM is ready
document.addEventListener('DOMContentLoaded', processGalleries);
// Watch for dynamic content added by DPL (important!)
const observer = new MutationObserver(processGalleries);
observer.observe(document.body, { childList: true, subtree: true });
// Fallback: run again after 1–2 seconds in case DPL is very slow
setTimeout(processGalleries, 1500);
setTimeout(processGalleries, 3000);
})();
