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

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

از ویکی‌یاد
Adminwki (بحث | مشارکت‌ها)
جز «مدیاویکی:Common.js» را محافظت کرد ([ویرایش=تنها مدیران] (بی‌پایان) [انتقال=تنها مدیران] (بی‌پایان))
Adminwki (بحث | مشارکت‌ها)
بدون خلاصۀ ویرایش
خط ۱: خط ۱:
/* Any JavaScript here will be loaded for all users on every page load. */
/**
 
* Gallery boxes: use the image as full-cover background instead of <img> tag
// Make gallery boxes use their img src as background-cover
* Runs after page is loaded
document.addEventListener('DOMContentLoaded', function() {
*/
  document.querySelectorAll('.gallerybox').forEach(function(box) {
document.addEventListener('DOMContentLoaded', function () {
    const img = box.querySelector('img');
    document.querySelectorAll('.gallerybox').forEach(function (box) {
    if (img && img.src) {
        // Find the <img> inside this box
      box.style.backgroundImage = 'url(' + img.src + ')';
        const img = box.querySelector('img.mw-file-element');
      box.style.backgroundSize = 'cover';
       
      box.style.backgroundPosition = 'center';
        if (img && img.src) {
      box.style.backgroundRepeat = 'no-repeat';
            // Set background using the exact src of the thumbnail
      // Optional: hide original img
            box.style.backgroundImage = 'url(' + img.src + ')';
      img.style.display = 'none';
            box.style.backgroundSize = 'cover';
    }
            box.style.backgroundPosition = 'center center';
  });
            box.style.backgroundRepeat = 'no-repeat';
           
            // Hide the original <img> tag
            img.style.display = 'none';
        }
    });
});
});

نسخهٔ ۲۳ ژانویهٔ ۲۰۲۶، ساعت ۱۹:۳۴

/**
 * Gallery boxes: use the image as full-cover background instead of <img> tag
 * Runs after page is loaded
 */
document.addEventListener('DOMContentLoaded', function () {
    document.querySelectorAll('.gallerybox').forEach(function (box) {
        // Find the <img> inside this box
        const img = box.querySelector('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
            img.style.display = 'none';
        }
    });
});