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

No edit summary
No edit summary
വരി 74: വരി 74:
                     var license = '';
                     var license = '';
                     var licenseUrl = '';
                     var licenseUrl = '';
                    var commonsUrl = info.descriptionurl || '';


                     if (info.extmetadata) {
                     if (info.extmetadata) {
വരി 96: വരി 97:
                     img.style.width = '100%';
                     img.style.width = '100%';


                     /* Lightbox data (use responsive size, not original) */
                     /* Lightbox source: responsive, not original */
                     var lightboxSrc = info.url;
                     var lightboxSrc = info.url;
                     if (info.responsiveUrls) {
                     if (info.responsiveUrls) {
വരി 112: വരി 113:
                         (licenseUrl
                         (licenseUrl
                             ? ' – <a href="' + licenseUrl +
                             ? ' – <a href="' + licenseUrl +
                               '" target="_blank">' + license + '</a>'
                               '" target="_blank" rel="noopener noreferrer">' +
                             : '')+
                              license + '</a>'
    (commonsUrl
                             : '') +
        ? '<br><a href="' + commonsUrl +
                        (commonsUrl
          '" target="_blank" rel="noopener noreferrer">View on Wikimedia Commons</a>'
                            ? '<br><a href="' + commonsUrl +
        : '');
                              '" target="_blank" rel="noopener noreferrer">' +
                              'View on Wikimedia Commons</a>'
                            : '');


                     figure.appendChild(img);
                     figure.appendChild(img);
വരി 138: വരി 141:
         });
         });


         /* Hide placeholder spans */
         /* Hide source placeholders */
         sources.forEach(function (el) {
         sources.forEach(function (el) {
             el.style.display = 'none';
             el.style.display = 'none';
വരി 243: വരി 246:


})();
})();
/* ============================================================
  Wikimedia Commons Single Image Loader (CommonsImage)
  ============================================================ */
mw.hook('wikipage.content').add(function ($content) {
    $content.find('.commons-image').each(function () {
        var el = this;
        var filename = el.dataset.filename;
        if (!filename) return;
        var width = parseInt(el.dataset.width, 10) || 300;
        var align = el.dataset.align || 'none';
        var captionText = el.dataset.caption || '';
        var apiUrl =
            'https://commons.wikimedia.org/w/api.php' +
            '?action=query' +
            '&format=json' +
            '&prop=imageinfo' +
            '&iiprop=url|extmetadata' +
            '&iiurlwidth=' + width +
            '&titles=File:' + encodeURIComponent(filename) +
            '&origin=*';
        fetch(apiUrl)
            .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) {
                    el.textContent = 'Error loading image';
                    return;
                }
                var page =
                    data.query.pages[Object.keys(data.query.pages)[0]];
                if (!page || !page.imageinfo) {
                    el.textContent = 'Image not found';
                    return;
                }
                var info = page.imageinfo[0];
                var imgUrl = info.thumburl || info.url;
                var artist = 'Unknown';
                var license = '';
                var licenseUrl = '';
                if (info.extmetadata) {
                    if (info.extmetadata.Artist) {
                        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');
                figure.style.maxWidth = width + 'px';
                if (align === 'right') figure.style.float = 'right';
                if (align === 'left') figure.style.float = 'left';
                if (align === 'center') {
                    figure.style.marginLeft = 'auto';
                    figure.style.marginRight = 'auto';
                }
                var img = document.createElement('img');
                img.src = imgUrl;
                img.alt = captionText || filename;
                img.loading = 'lazy';
                img.style.width = '100%';
                figure.appendChild(img);
                if (captionText || license) {
                    var figcaption = document.createElement('figcaption');
                    figcaption.style.fontSize = '0.8em';
                    figcaption.style.textAlign = 'center';
                    figcaption.innerHTML =
                        (captionText ? captionText + '<br>' : '') +
                        '© ' + artist +
                        (licenseUrl
                            ? ' – <a href="' + licenseUrl +
                              '" target="_blank">' + license + '</a>'
                            : '')+
    (commonsUrl
        ? '<br><a href="' + commonsUrl +
          '" target="_blank" rel="noopener noreferrer">View on Wikimedia Commons</a>'
        : '');
                    figure.appendChild(figcaption);
                }
                el.replaceWith(figure);
            })
            .catch(function () {
                el.textContent = 'Error loading image from Commons';
            });
    });
});


/* ============================================================
/* ============================================================
വരി 365: വരി 259:
     );
     );
}
}


/* ============================================================
/* ============================================================
വരി 418: വരി 311:


$(addCharSubsetMenu);
$(addCharSubsetMenu);


/* ============================================================
/* ============================================================
വരി 463: വരി 355:
     });
     });
});
});


/* ============================================================
/* ============================================================
വരി 469: വരി 360:
   ============================================================ */
   ============================================================ */
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;


വരി 481: വരി 372:


     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" എന്ന താളിൽനിന്ന് ശേഖരിച്ചത്