"മീഡിയവിക്കി:Common.js" എന്ന താളിന്റെ പതിപ്പുകൾ തമ്മിലുള്ള വ്യത്യാസം

No edit summary
No edit summary
 
(2 ഉപയോക്താക്കൾ ചെയ്ത ഇടയ്ക്കുള്ള 18 നാൾപ്പതിപ്പുകൾ പ്രദർശിപ്പിക്കുന്നില്ല)
വരി 1: വരി 1:
mw.loader.load('//en.wikipedia.org/w/index.php?title=User:Joeytje50/JWB.js/load.js&action=raw&ctype=text/javascript');
/* ============================================================
/* ============================================================
   OpenStreetMap marker URL fix
   OpenStreetMap marker URL fix
   ============================================================ */
   ============================================================ */
mw.hook('wikipage.content').add(function () {
window.onload = function () {
     var images = document.querySelectorAll('img');
     var images = document.querySelectorAll('img');
     for (var i = 0; i < images.length; i++) {
     for (var i = 0; i < images.length; i++) {
         var img = images[i];
         var img = images[i];
         if (img.src &&
         if (
             img.src.indexOf('https://tile.openstreetmap.org/v4/marker/') === 0) {
            img.src &&
             img.src.startsWith("https://tile.openstreetmap.org/v4/marker/")
        ) {
             img.src = img.src.replace(
             img.src = img.src.replace(
                 'https://tile.openstreetmap.org/v4/marker/',
                 'https://tile.openstreetmap.org/v4/marker/',
വരി 13: വരി 17:
             );
             );
         }
         }
    }
};
});
};
 


/* ============================================================
/* ============================================================
   Load images from Wikimedia Commons using template
   Wikimedia Commons Gallery Loader (Template-based, MULTILINE SAFE)
   ============================================================ */
   ============================================================ */
mw.hook('wikipage.content').add(function ($content) {
mw.hook('wikipage.content').add(function ($content) {


     $content.find('.commons-image').each(function () {
     $content.find('.commons-gallery').each(function () {
         var el = this;
         var container = this;
         var filename = el.dataset.filename;
 
         if (!filename) return;
         var sources = container.querySelectorAll('.commons-gallery-source');
         if (!sources.length) return;


         var width = el.dataset.width || 300;
         var width = 300;
        var align = el.dataset.align || 'none';
        var caption = el.dataset.caption || '';


         var apiUrl =
         var grid = document.createElement('div');
            'https://commons.wikimedia.org/w/api.php' +
        grid.className = 'commons-gallery-grid';
            '?action=query' +
        grid.style.display = 'grid';
            '&format=json' +
        grid.style.gridTemplateColumns =
            '&prop=imageinfo' +
             'repeat(auto-fill, minmax(' + width + 'px, 1fr))';
            '&iiprop=url|extmetadata' +
        grid.style.gap = '8px';
             '&iiurlwidth=' + width +
            '&titles=File:' + encodeURIComponent(filename) +
            '&origin=*';


         fetch(apiUrl)
         container.appendChild(grid);
            .then(function (r) { return r.json(); })
            .then(function (data) {


                if (!data.query || !data.query.pages) {
        sources.forEach(function (srcEl) {
                    el.textContent = 'Error loading image';
            var filename = srcEl.dataset.file;
                    return;
            var captionText = srcEl.dataset.caption || '';
                }


                var pages = data.query.pages;
            if (!filename) return;
                var page = pages[Object.keys(pages)[0]];


                 if (!page.imageinfo) {
            var apiUrl =
                    el.textContent = 'Image not found on Wikimedia Commons';
                 'https://commons.wikimedia.org/w/api.php' +
                    return;
                '?action=query' +
                 }
                '&format=json' +
                '&prop=imageinfo' +
                '&iiprop=url|extmetadata' +
                '&iiurlwidth=' + width +
                '&titles=File:' + encodeURIComponent(filename) +
                 '&origin=*';


                 var info = page.imageinfo[0];
            fetch(apiUrl)
                 var imgUrl = info.thumburl || info.url;
                 .then(function (r) {
                    if (!r.ok) throw new Error('HTTP ' + r.status);
                    return r.json();
                 })
                .then(function (data) {
                    if (!data || !data.query || !data.query.pages) return;


                var artist = 'Unknown';
                    var page =
                var license = '';
                        data.query.pages[Object.keys(data.query.pages)[0]];
                var licenseUrl = '';
                    if (!page || !page.imageinfo) return;


                if (info.extmetadata) {
                     var info = page.imageinfo[0];
                     if (info.extmetadata.Artist) {
                     var imgUrl = info.thumburl || info.url;
                        artist = info.extmetadata.Artist.value;
                     }
                    if (info.extmetadata.LicenseShortName) {
                        license = info.extmetadata.LicenseShortName.value;
                    }
                    if (info.extmetadata.LicenseUrl) {
                        licenseUrl = info.extmetadata.LicenseUrl.value;
                    }
                }


                var figure = document.createElement('figure');
                    var artist = 'Unknown';
                figure.style.maxWidth = width + 'px';
                    var license = '';
                    var licenseUrl = '';
                    var commonsUrl = info.descriptionurl || '';


                if (align === 'right') figure.style.float = 'right';
                    if (info.extmetadata) {
                if (align === 'left') figure.style.float = 'left';
                        if (info.extmetadata.Artist) {
                if (align === 'center') {
                            artist = info.extmetadata.Artist.value;
                    figure.style.marginLeft = 'auto';
                        }
                     figure.style.marginRight = 'auto';
                        if (info.extmetadata.LicenseShortName) {
                }
                            license = info.extmetadata.LicenseShortName.value;
                        }
                        if (info.extmetadata.LicenseUrl) {
                            licenseUrl = info.extmetadata.LicenseUrl.value;
                        }
                     }


                var img = document.createElement('img');
                    var figure = document.createElement('figure');
                img.src = imgUrl;
                    figure.className = 'commons-gallery-item';
                img.alt = caption || filename;
                img.loading = 'lazy';
                img.style.width = '100%';


                figure.appendChild(img);
                    var img = document.createElement('img');
                    img.src = imgUrl;
                    img.alt = captionText || filename;
                    img.loading = 'lazy';
                    img.style.width = '100%';


                if (caption || license) {
                    /* Lightbox source: responsive, not original */
                    var figcaption = document.createElement('figcaption');
                    var lightboxSrc = info.url;
                    figcaption.style.fontSize = '0.8em';
                    if (info.responsiveUrls) {
                    figcaption.style.textAlign = 'center';
                        if (window.devicePixelRatio > 1 && info.responsiveUrls['2']) {
                            lightboxSrc = info.responsiveUrls['2'];
                        } else if (info.responsiveUrls['1.5']) {
                            lightboxSrc = info.responsiveUrls['1.5'];
                        }
                    }


                     figcaption.innerHTML =
                     img.dataset.fullsrc = lightboxSrc;
                        caption +
                    img.dataset.caption =
                         '<br>© ' + artist +
                         (captionText ? captionText + '<br>' : '') +
                        '© ' + artist +
                         (licenseUrl
                         (licenseUrl
                             ? ' – <a href="' + licenseUrl +
                             ? ' – <a href="' + licenseUrl +
                               '" target="_blank">' + license + '</a>'
                               '" target="_blank" rel="noopener noreferrer">' +
                              license + '</a>'
                            : '') +
                        (commonsUrl
                            ? '<br><a href="' + commonsUrl +
                              '" target="_blank" rel="noopener noreferrer">' +
                              'View on Wikimedia Commons</a>'
                             : '');
                             : '');
                    figure.appendChild(img);
                    var figcaption = document.createElement('figcaption');
                    figcaption.style.fontSize = '0.75em';
                    figcaption.style.textAlign = 'center';
                    figcaption.innerHTML = img.dataset.caption;


                     figure.appendChild(figcaption);
                     figure.appendChild(figcaption);
                 }
                    grid.appendChild(figure);
                 })
                .catch(function (err) {
                    console.warn(
                        'Commons gallery image failed:',
                        filename,
                        err.message
                    );
                });
        });


                el.replaceWith(figure);
        /* Hide source placeholders */
            })
        sources.forEach(function (el) {
            .catch(function () {
            el.style.display = 'none';
                el.textContent = 'Error loading image from Wikimedia Commons';
        });
            });
     });
     });
});
});


/* ============================================================
  Commons Gallery Lightbox Viewer (with navigation)
  ============================================================ */
(function () {
    var galleryImages = [];
    var currentIndex = -1;
    function collectGalleryImages() {
        galleryImages = Array.prototype.slice.call(
            document.querySelectorAll('.commons-gallery-item img')
        );
    }
    function createLightbox() {
        if (document.getElementById('commons-lightbox')) return;
        var overlay = document.createElement('div');
        overlay.id = 'commons-lightbox';
        overlay.innerHTML =
            '<div class="clb-backdrop"></div>' +
            '<div class="clb-content">' +
                '<button class="clb-prev" aria-label="Previous">‹</button>' +
                '<button class="clb-next" aria-label="Next">›</button>' +
                '<button class="clb-close" aria-label="Close">×</button>' +
                '<img class="clb-image" alt="">' +
                '<div class="clb-caption"></div>' +
            '</div>';
        document.body.appendChild(overlay);
        overlay.querySelector('.clb-backdrop').onclick = closeLightbox;
        overlay.querySelector('.clb-close').onclick = closeLightbox;
        overlay.querySelector('.clb-prev').onclick = showPrev;
        overlay.querySelector('.clb-next').onclick = showNext;
        document.addEventListener('keydown', function (e) {
            if (!overlay.classList.contains('active')) return;
            if (e.key === 'Escape') closeLightbox();
            if (e.key === 'ArrowLeft') showPrev();
            if (e.key === 'ArrowRight') showNext();
        });
    }
    function openLightbox(img) {
        collectGalleryImages();
        currentIndex = galleryImages.indexOf(img);
        if (currentIndex === -1) return;
        createLightbox();
        showImage(currentIndex);
        document.getElementById('commons-lightbox').classList.add('active');
        document.body.style.overflow = 'hidden';
    }
    function showImage(index) {
        var overlay = document.getElementById('commons-lightbox');
        var lbImg = overlay.querySelector('.clb-image');
        var caption = overlay.querySelector('.clb-caption');
        var img = galleryImages[index];
        if (!img) return;
        lbImg.src = img.dataset.fullsrc || img.src;
        lbImg.alt = img.alt || '';
        caption.innerHTML = img.dataset.caption || '';
        currentIndex = index;
    }
    function showPrev() {
        if (currentIndex > 0) showImage(currentIndex - 1);
    }
    function showNext() {
        if (currentIndex < galleryImages.length - 1) {
            showImage(currentIndex + 1);
        }
    }
    function closeLightbox() {
        var overlay = document.getElementById('commons-lightbox');
        if (!overlay) return;
        overlay.classList.remove('active');
        document.body.style.overflow = '';
    }
    /* Event delegation (single, correct) */
    document.addEventListener('click', function (e) {
        var img = e.target;
        if (img && img.matches('.commons-gallery-item img')) {
            openLightbox(img);
        }
    });
})();


/* ============================================================
/* ============================================================
വരി 132: വരി 261:
     );
     );
}
}


/* ============================================================
/* ============================================================
വരി 185: വരി 313:


$(addCharSubsetMenu);
$(addCharSubsetMenu);


/* ============================================================
/* ============================================================
വരി 230: വരി 357:
     });
     });
});
});


/* ============================================================
/* ============================================================
വരി 236: വരി 362:
   ============================================================ */
   ============================================================ */
var autoCollapse = 2;
var autoCollapse = 2;
var collapseCaption = "മറയ്ക്കുക";
var collapseCaption = 'മറയ്ക്കുക';
var expandCaption = "പ്രദർശിപ്പിക്കുക";
var expandCaption = 'പ്രദർശിപ്പിക്കുക';


function collapseTable(tableIndex) {
function collapseTable(tableIndex) {
     var Button = document.getElementById("collapseButton" + tableIndex);
     var Button = document.getElementById('collapseButton' + tableIndex);
     var Table = document.getElementById("collapsibleTable" + tableIndex);
     var Table = document.getElementById('collapsibleTable' + tableIndex);
     if (!Table || !Button) return;
     if (!Table || !Button) return;


വരി 248: വരി 374:


     for (var i = 1; i < Rows.length; i++) {
     for (var i = 1; i < Rows.length; i++) {
         Rows[i].style.display = hide ? "none" : "";
         Rows[i].style.display = hide ? 'none' : '';
     }
     }
     Button.firstChild.data = hide ? expandCaption : collapseCaption;
     Button.firstChild.data = hide ? expandCaption : collapseCaption;
"https://schoolwiki.in/മീഡിയവിക്കി:Common.js" എന്ന താളിൽനിന്ന് ശേഖരിച്ചത്