اطلاعیه: از همه ایران دوستان عزیز دعوت می‌کنیم در ایجاد و به‌روزرسانی صفحات جاویدنامان همیاری نمایند. در حال حاضر میتوانید بدون عضویت در ثبت تاریخ کمک نمایید.

مدیاویکی:Common.js: تفاوت میان نسخه‌ها

از ویکی‌یاد
Adminwki (بحث | مشارکت‌ها)
بدون خلاصۀ ویرایش
Adminwki (بحث | مشارکت‌ها)
بدون خلاصۀ ویرایش
خط ۱: خط ۱:
/**
/**
  * Gallery boxes: use the image as full-cover background instead of <img> tag
  * Gallery to background-cover: extract img src → set as box background + hide img
* Runs after page is loaded
  */
  */
document.addEventListener('DOMContentLoaded', function () {
(function () {
     document.querySelectorAll('.gallerybox').forEach(function (box) {
     function processGalleries() {
        // Find the <img> inside this box
        document.querySelectorAll('li.gallerybox').forEach(function (box) {
        const img = box.querySelector('img.mw-file-element');
            // Find the img inside thumb
       
            const img = box.querySelector('.thumb img.mw-file-element');
        if (img && img.src) {
            // Set background using the exact src of the thumbnail
            box.style.backgroundImage = 'url(' + img.src + ')';
            box.style.backgroundSize = 'cover';
            box.style.backgroundPosition = 'center center';
            box.style.backgroundRepeat = 'no-repeat';
              
              
             // Hide the original <img> tag
             if (img && img.src && !box.dataset.backgroundApplied) {
            img.style.display = 'none';
                // 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);
})();