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

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

از ویکی‌یاد
Adminwki (بحث | مشارکت‌ها)
بدون خلاصۀ ویرایش
Adminwki (بحث | مشارکت‌ها)
بدون خلاصۀ ویرایش
خط ۱: خط ۱:
/**
/**
  * Gallery to background-cover: extract img src → set as box background + hide img
  * 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 thumb
             // Find the .thumb div and the img inside it
             const img = box.querySelector('.thumb img.mw-file-element');
             const thumbDiv = box.querySelector('div.thumb');
            const img = thumbDiv ? thumbDiv.querySelector('img.mw-file-element') : null;
              
              
             if (img && img.src && !box.dataset.backgroundApplied) {
             if (thumbDiv && img && img.src && !thumbDiv.dataset.backgroundApplied) {
                 // Apply background
                 // Apply background to the .thumb div
                 box.style.backgroundImage = 'url(' + img.src + ')';
                 thumbDiv.style.backgroundImage = 'url(' + img.src + ')';
                 box.style.backgroundSize = 'cover';
                 thumbDiv.style.backgroundSize = 'cover';
                 box.style.backgroundPosition = 'center center';
                 thumbDiv.style.backgroundPosition = 'center center';
                 box.style.backgroundRepeat = 'no-repeat';
                 thumbDiv.style.backgroundRepeat = 'no-repeat';
                  
                  
                 // Hide original image
                 // Hide the original <img> tag
                 img.style.display = 'none';
                 img.style.display = 'none';
                  
                  
                 // Mark as processed to avoid re-running
                 // Mark as processed
                 box.dataset.backgroundApplied = 'true';
                 thumbDiv.dataset.backgroundApplied = 'true';
                  
                  
                 console.log('Applied background to gallery box:', img.src);
                 console.log('Applied background to thumb div:', img.src);
             }
             }
         });
         });
خط ۲۹: خط ۳۰:
     document.addEventListener('DOMContentLoaded', processGalleries);
     document.addEventListener('DOMContentLoaded', processGalleries);


     // Watch for dynamic content added by DPL (important!)
     // 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 });


     // Fallback: run again after 1–2 seconds in case DPL is very slow
     // Extra fallback runs
     setTimeout(processGalleries, 1500);
     setTimeout(processGalleries, 1000);
     setTimeout(processGalleries, 3000);
     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);
})();