|
|
| വരി 6: |
വരി 6: |
| 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.indexOf('https://tile.openstreetmap.org/v4/marker/') === 0 |
| | ) { |
| img.src = img.src.replace( | | img.src = img.src.replace( |
| 'https://tile.openstreetmap.org/v4/marker/', | | 'https://tile.openstreetmap.org/v4/marker/', |
| വരി 39: |
വരി 41: |
|
| |
|
| sources.forEach(function (srcEl) { | | sources.forEach(function (srcEl) { |
|
| |
| var filename = srcEl.dataset.file; | | var filename = srcEl.dataset.file; |
| var captionText = srcEl.dataset.caption || ''; | | var captionText = srcEl.dataset.caption || ''; |
| വരി 61: |
വരി 62: |
| }) | | }) |
| .then(function (data) { | | .then(function (data) { |
|
| |
| if (!data || !data.query || !data.query.pages) return; | | if (!data || !data.query || !data.query.pages) return; |
|
| |
|
| var page = | | var page = |
| data.query.pages[Object.keys(data.query.pages)[0]]; | | data.query.pages[Object.keys(data.query.pages)[0]]; |
|
| |
| if (!page || !page.imageinfo) return; | | if (!page || !page.imageinfo) return; |
|
| |
|
| വരി 96: |
വരി 95: |
| img.loading = 'lazy'; | | img.loading = 'lazy'; |
| img.style.width = '100%'; | | img.style.width = '100%'; |
| img.style.display = 'block';
| |
|
| |
|
| /* Lightbox data */ | | /* Lightbox data (use responsive size, not original) */ |
| img.dataset.fullsrc = info.url; | | var lightboxSrc = info.url; |
| | if (info.responsiveUrls) { |
| | if (window.devicePixelRatio > 1 && info.responsiveUrls['2']) { |
| | lightboxSrc = info.responsiveUrls['2']; |
| | } else if (info.responsiveUrls['1.5']) { |
| | lightboxSrc = info.responsiveUrls['1.5']; |
| | } |
| | } |
| | |
| | img.dataset.fullsrc = lightboxSrc; |
| img.dataset.caption = | | img.dataset.caption = |
| (captionText ? captionText + '<br>' : '') + | | (captionText ? captionText + '<br>' : '') + |
| വരി 113: |
വരി 120: |
| figcaption.style.fontSize = '0.75em'; | | figcaption.style.fontSize = '0.75em'; |
| figcaption.style.textAlign = 'center'; | | figcaption.style.textAlign = 'center'; |
| | | figcaption.innerHTML = img.dataset.caption; |
| figcaption.innerHTML = | |
| (captionText ? captionText + '<br>' : '') +
| |
| '© ' + artist +
| |
| (licenseUrl
| |
| ? ' – <a href="' + licenseUrl +
| |
| '" target="_blank">' + license + '</a>'
| |
| : '');
| |
|
| |
|
| figure.appendChild(figcaption); | | figure.appendChild(figcaption); |
| വരി 132: |
വരി 132: |
| ); | | ); |
| }); | | }); |
|
| |
| }); | | }); |
|
| |
|
| /* Hide source placeholders */ | | /* Hide placeholder spans */ |
| sources.forEach(function (el) { | | sources.forEach(function (el) { |
| el.style.display = 'none'; | | el.style.display = 'none'; |
| വരി 141: |
വരി 140: |
| }); | | }); |
| }); | | }); |
|
| |
|
| |
|
| /* ============================================================ | | /* ============================================================ |
| വരി 182: |
വരി 180: |
| document.addEventListener('keydown', function (e) { | | document.addEventListener('keydown', function (e) { |
| if (!overlay.classList.contains('active')) return; | | if (!overlay.classList.contains('active')) return; |
|
| |
| if (e.key === 'Escape') closeLightbox(); | | if (e.key === 'Escape') closeLightbox(); |
| if (e.key === 'ArrowLeft') showPrev(); | | if (e.key === 'ArrowLeft') showPrev(); |
| വരി 197: |
വരി 194: |
| showImage(currentIndex); | | showImage(currentIndex); |
|
| |
|
| document.getElementById('commons-lightbox') | | document.getElementById('commons-lightbox').classList.add('active'); |
| .classList.add('active');
| |
| document.body.style.overflow = 'hidden'; | | document.body.style.overflow = 'hidden'; |
| } | | } |
| വരി 218: |
വരി 214: |
|
| |
|
| function showPrev() { | | function showPrev() { |
| if (currentIndex > 0) { | | if (currentIndex > 0) showImage(currentIndex - 1); |
| showImage(currentIndex - 1);
| |
| }
| |
| } | | } |
|
| |
|
| വരി 232: |
വരി 226: |
| var overlay = document.getElementById('commons-lightbox'); | | var overlay = document.getElementById('commons-lightbox'); |
| if (!overlay) return; | | if (!overlay) return; |
|
| |
| overlay.classList.remove('active'); | | overlay.classList.remove('active'); |
| document.body.style.overflow = ''; | | document.body.style.overflow = ''; |
| } | | } |
|
| |
|
| /* Event delegation for async gallery */ | | /* Event delegation (single, correct) */ |
| document.addEventListener('click', function (e) {
| |
| var img = e.target;
| |
| if (img && img.matches('.commons-gallery-item img')) {
| |
| openLightbox(img);
| |
| }
| |
| });
| |
| | |
| })();
| |
| | |
| /* ========================================================
| |
| Event delegation for dynamically loaded gallery images
| |
| ======================================================== */
| |
| document.addEventListener('click', function (e) { | | document.addEventListener('click', function (e) { |
| var img = e.target; | | var img = e.target; |
|
| |
| if (img && img.matches('.commons-gallery-item img')) { | | if (img && img.matches('.commons-gallery-item img')) { |
| img.style.cursor = 'zoom-in';
| |
| openLightbox(img); | | openLightbox(img); |
| } | | } |
| വരി 260: |
വരി 239: |
|
| |
|
| })(); | | })(); |
|
| |
|
| |
| /* ============================================================
| |
| Load images from Wikimedia Commons using template
| |
| ============================================================ */
| |
| 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 = el.dataset.width || 300;
| |
| var align = el.dataset.align || 'none';
| |
| var caption = 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) { return r.json(); })
| |
| .then(function (data) {
| |
|
| |
| if (!data.query || !data.query.pages) {
| |
| el.textContent = 'Error loading image';
| |
| return;
| |
| }
| |
|
| |
| var pages = data.query.pages;
| |
| var page = pages[Object.keys(pages)[0]];
| |
|
| |
| if (!page.imageinfo) {
| |
| el.textContent = 'Image not found on Wikimedia Commons';
| |
| 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 = caption || filename;
| |
| img.loading = 'lazy';
| |
| img.style.width = '100%';
| |
|
| |
| figure.appendChild(img);
| |
|
| |
| if (caption || license) {
| |
| var figcaption = document.createElement('figcaption');
| |
| figcaption.style.fontSize = '0.8em';
| |
| figcaption.style.textAlign = 'center';
| |
|
| |
| figcaption.innerHTML =
| |
| caption +
| |
| '<br>© ' + artist +
| |
| (licenseUrl
| |
| ? ' – <a href="' + licenseUrl +
| |
| '" target="_blank">' + license + '</a>'
| |
| : '');
| |
|
| |
| figure.appendChild(figcaption);
| |
| }
| |
|
| |
| el.replaceWith(figure);
| |
| })
| |
| .catch(function () {
| |
| el.textContent = 'Error loading image from Wikimedia Commons';
| |
| });
| |
| });
| |
| });
| |
|
| |
|
| |
| /* ============================================================
| |
| Editing tools
| |
| ============================================================ */
| |
| if (
| |
| mw.config.get('wgAction') === 'edit' ||
| |
| mw.config.get('wgAction') === 'submit' ||
| |
| mw.config.get('wgCanonicalSpecialPageName') === 'Upload'
| |
| ) {
| |
| mw.loader.load(
| |
| '/index.php?title=മീഡിയവിക്കി:Common.js/edit.js&action=raw&ctype=text/javascript'
| |
| );
| |
| }
| |
|
| |
|
| |
| /* ============================================================
| |
| Special characters subset menu
| |
| ============================================================ */
| |
| function addCharSubsetMenu() {
| |
| if ($('#editpage-specialchars').length > 0) {
| |
|
| |
| var s = parseInt($.cookie('edittoolscharsubset'), 10);
| |
| if (isNaN(s)) s = 0;
| |
|
| |
| var $menu = $('<select />')
| |
| .attr('id', 'charSubsetControl')
| |
| .css('display', 'inline')
| |
| .change(chooseCharSubset)
| |
| .data('previousSelectedIndex', s)
| |
| .append($('<option />').text('ഫലകങ്ങൾ'))
| |
| .append($('<option />').text('വിക്കിവിന്യാസങ്ങൾ'))
| |
| .append($('<option />').text('അനുമതിപത്രങ്ങൾ'))
| |
| .append($('<option />').text('മലയാളം'))
| |
| .append($('<option />').text('കൊറിയൻ'))
| |
| .append($('<option />').text('ലത്തീൻ'))
| |
| .append($('<option />').text('ഐ.പി.എ.'))
| |
| .append($('<option />').text('പലവക'))
| |
| .append($('<option />').text('അറബി'))
| |
| .append($('<option />').text('ദേവനാഗരി'))
| |
| .append($('<option />').text('ഹിബ്രു'))
| |
| .append($('<option />').text('പഴയ ഇംഗ്ലീഷ്'));
| |
|
| |
| $('#editpage-specialchars').prepend($menu);
| |
| $('#charSubsetControl')[0].selectedIndex = s;
| |
|
| |
| $('p', '#editpage-specialchars').each(function (index) {
| |
| $(this).css({
| |
| display: index === s ? 'inline' : 'none',
| |
| visibility: index === s ? 'visible' : 'hidden'
| |
| });
| |
| });
| |
| }
| |
| }
| |
|
| |
| function chooseCharSubset() {
| |
| var selectedIndex = $(this).find(':selected').index();
| |
| $('p', '#editpage-specialchars').each(function (index) {
| |
| $(this).css({
| |
| display: index === selectedIndex ? 'inline' : 'none',
| |
| visibility: index === selectedIndex ? 'visible' : 'hidden'
| |
| });
| |
| });
| |
| $.cookie('edittoolscharsubset', selectedIndex);
| |
| }
| |
|
| |
| $(addCharSubsetMenu);
| |
|
| |
|
| |
| /* ============================================================
| |
| Navigation bars
| |
| ============================================================ */
| |
| var NavigationBarHide = 'മറയ്ക്കുക';
| |
| var NavigationBarShow = 'പ്രദർശിപ്പിക്കുക';
| |
| var indexNavigationBar = 0;
| |
|
| |
| window.toggleNavigationBar = function (index, event) {
| |
| var NavToggle = document.getElementById('NavToggle' + index);
| |
| var NavFrame = document.getElementById('NavFrame' + index);
| |
| if (!NavFrame || !NavToggle) return;
| |
|
| |
| var show = NavToggle.firstChild.data === NavigationBarShow;
| |
| NavToggle.firstChild.data = show ? NavigationBarHide : NavigationBarShow;
| |
|
| |
| var children = NavFrame.children;
| |
| for (var i = 0; i < children.length; i++) {
| |
| if ($(children[i]).hasClass('NavContent') ||
| |
| $(children[i]).hasClass('NavPic')) {
| |
| children[i].style.display = show ? 'block' : 'none';
| |
| }
| |
| }
| |
| event.preventDefault();
| |
| };
| |
|
| |
| mw.hook('wikipage.content').add(function ($content) {
| |
| $content.find('div.NavFrame').each(function () {
| |
| indexNavigationBar++;
| |
| var NavFrame = this;
| |
| var NavHead = $(NavFrame).find('.NavHead').first();
| |
| if (!NavHead.length) return;
| |
|
| |
| var NavToggle = $('<a href="#" class="NavToggle"></a>')
| |
| .attr('id', 'NavToggle' + indexNavigationBar)
| |
| .text(NavigationBarHide)
| |
| .on('click', function (e) {
| |
| toggleNavigationBar(indexNavigationBar, e);
| |
| });
| |
|
| |
| NavFrame.id = 'NavFrame' + indexNavigationBar;
| |
| NavHead.append(NavToggle);
| |
| });
| |
| });
| |
|
| |
|
| |
| /* ============================================================
| |
| Collapsible tables
| |
| ============================================================ */
| |
| var autoCollapse = 2;
| |
| var collapseCaption = "മറയ്ക്കുക";
| |
| var expandCaption = "പ്രദർശിപ്പിക്കുക";
| |
|
| |
| function collapseTable(tableIndex) {
| |
| var Button = document.getElementById("collapseButton" + tableIndex);
| |
| var Table = document.getElementById("collapsibleTable" + tableIndex);
| |
| if (!Table || !Button) return;
| |
|
| |
| var Rows = Table.rows;
| |
| var hide = Button.firstChild.data === collapseCaption;
| |
|
| |
| for (var i = 1; i < Rows.length; i++) {
| |
| Rows[i].style.display = hide ? "none" : "";
| |
| }
| |
| Button.firstChild.data = hide ? expandCaption : collapseCaption;
| |
| }
| |
|
| |
| $(function () {
| |
| var tableIndex = 0;
| |
| $('table.collapsible').each(function () {
| |
| var $table = $(this);
| |
| var $header = $table.find('tr:first th:first');
| |
| if (!$header.length) return;
| |
|
| |
| $table.attr('id', 'collapsibleTable' + tableIndex);
| |
|
| |
| var $button = $('<span class="collapseButton">[</span>');
| |
| var $link = $('<a href="#"></a>')
| |
| .attr('id', 'collapseButton' + tableIndex)
| |
| .text(collapseCaption)
| |
| .on('click', function (e) {
| |
| e.preventDefault();
| |
| collapseTable(tableIndex);
| |
| });
| |
|
| |
| $button.append($link).append(']');
| |
| $header.prepend($button);
| |
|
| |
| tableIndex++;
| |
| });
| |
| });
| |