ഉള്ളടക്കത്തിലേക്ക് പോവുക

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

Schoolwiki സംരംഭത്തിൽ നിന്ന്
(ചെ.)No edit summary
No edit summary
 
(3 ഉപയോക്താക്കൾ ചെയ്ത ഇടയ്ക്കുള്ള 43 നാൾപ്പതിപ്പുകൾ പ്രദർശിപ്പിക്കുന്നില്ല)
വരി 1: വരി 1:
// mw.loader.load('//en.wikipedia.org/w/index.php?title=User:Joeytje50/JWB.js/load.js&action=raw&ctype=text/javascript');
mw.loader.load('//en.wikipedia.org/w/index.php?title=User:Joeytje50/JWB.js/load.js&action=raw&ctype=text/javascript');


/* document.addEventListener("DOMContentLoaded", function () {
/* ============================================================
     console.log("Script loaded and DOM is ready.");
  OpenStreetMap marker URL fix
   
  ============================================================ */
    setInterval(function () {
window.onload = function () {
         console.log("Checking for images...");
    var images = document.querySelectorAll('img');
          
    for (var i = 0; i < images.length; i++) {
         var markerImages = document.querySelectorAll('img[src="https://tile.openstreetmap.org/v4/marker/pin-m+7e7e7e@2x.png"]');
        var img = images[i];
         console.log("Found " + markerImages.length + " marker(s).");
        if (
            img.src &&
            img.src.startsWith("https://tile.openstreetmap.org/v4/marker/")
        ) {
            img.src = img.src.replace(
                'https://tile.openstreetmap.org/v4/marker/',
                'https://maps.wikimedia.org/v4/marker/'
            );
        }
};
};
 
/* ============================================================
  Wikimedia Commons Gallery Loader (Template-based, MULTILINE SAFE)
  ============================================================ */
mw.hook('wikipage.content').add(function ($content) {
 
     $content.find('.commons-gallery').each(function () {
        var container = this;
 
        var sources = container.querySelectorAll('.commons-gallery-source');
        if (!sources.length) return;
 
        var width = 300;
 
         var grid = document.createElement('div');
        grid.className = 'commons-gallery-grid';
        grid.style.display = 'grid';
        grid.style.gridTemplateColumns =
            'repeat(auto-fill, minmax(' + width + 'px, 1fr))';
        grid.style.gap = '8px';
 
         container.appendChild(grid);
 
         sources.forEach(function (srcEl) {
            var filename = srcEl.dataset.file;
            var captionText = srcEl.dataset.caption || '';
 
            if (!filename) return;
 
            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) return;
 
                    var page =
                        data.query.pages[Object.keys(data.query.pages)[0]];
                    if (!page || !page.imageinfo) return;
 
                    var info = page.imageinfo[0];
                    var imgUrl = info.thumburl || info.url;
 
                    var artist = 'Unknown';
                    var license = '';
                    var licenseUrl = '';
                    var commonsUrl = info.descriptionurl || '';
 
                    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.className = 'commons-gallery-item';
 
                    var img = document.createElement('img');
                    img.src = imgUrl;
                    img.alt = captionText || filename;
                    img.loading = 'lazy';
                    img.style.width = '100%';
 
                    /* Lightbox source: responsive, not original */
                    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 =
                        (captionText ? captionText + '<br>' : '') +
                        '© ' + artist +
                        (licenseUrl
                            ? ' – <a href="' + licenseUrl +
                              '" 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);
                    grid.appendChild(figure);
                })
                .catch(function (err) {
                    console.warn(
                        'Commons gallery image failed:',
                        filename,
                        err.message
                    );
                });
        });
 
        /* Hide source placeholders */
        sources.forEach(function (el) {
            el.style.display = 'none';
        });
    });
});
 
/* ============================================================
  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;


         for (var i = 0; i < markerImages.length; i++) {
         lbImg.src = img.dataset.fullsrc || img.src;
            markerImages[i].src = "https://schoolwiki.in/extensions/Kartographer/lib/external/mapbox/images/marker-icon-2x.png";
        lbImg.alt = img.alt || '';
             console.log("Replaced image " + (i + 1));
        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);
         }
         }
     }, 500);
     }
});


*/
    function closeLightbox() {
        var overlay = document.getElementById('commons-lightbox');
        if (!overlay) return;
        overlay.classList.remove('active');
        document.body.style.overflow = '';
    }


document.addEventListener("DOMContentLoaded", function () {
    /* Event delegation (single, correct) */
    alert("Page Loaded Successfully!");
    document.addEventListener('click', function (e) {
});
        var img = e.target;
        if (img && img.matches('.commons-gallery-item img')) {
            openLightbox(img);
        }
    });


//Quick Edit Box
})();
// [[User:BrandonXLF/QuickEdit.js]]
//mw.loader.load('https://en.wikipedia.org/w/index.php?title=User:BrandonXLF/QuickEdit.js&action=raw&ctype=text/javascript');
//mw.loader.load( '/index.php?title=മീഡിയവിക്കി:Common.js/QuickEdit.js&action=raw&ctype=text/javascript' );


/*ടൂൾബാറിൽ അവലംബം ചേർക്കാനുള്ള സൗകര്യം കൂട്ടിച്ചേർക്കുന്നതിനായി */
/* ============================================================
if ( mw.config.get( 'wgAction' ) === 'edit' || mw.config.get( 'wgAction' ) === 'submit' || mw.config.get( 'wgCanonicalSpecialPageName' ) === 'Upload' ) {
  Editing tools
    /* scripts specific to editing pages */
  ============================================================ */
/*    importScript( 'മീഡിയവിക്കി:Common.js/edit.js' ); */
if (
     mw.loader.load( '/index.php?title=മീഡിയവിക്കി:Common.js/edit.js&action=raw&ctype=text/javascript' );
    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);
==addCharSubsetMenu==
        $('#charSubsetControl')[0].selectedIndex = s;
*/


/* add menu for selecting subsets of secial characters  */
        $('p', '#editpage-specialchars').each(function (index) {
/***** must match MediaWiki:Edittools *****/
            $(this).css({
function addCharSubsetMenu() {
                display: index === s ? 'inline' : 'none',
if($('#editpage-specialchars').length>0) {
                visibility: index === s ? 'visible' : 'hidden'
/* default subset from cookie */
            });
var s = parseInt( $.cookie('edittoolscharsubset') );
        });
if ( isNaN(s) ) s = 0;
    }
var $menu = $('<select />')
.attr('id', 'charSubsetControl')
.css('display', 'inline');
$menu.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);
/* update dropdown control to value of cookie */
$('#charSubsetControl')[0].selectedIndex = s;
$('p', '#editpage-specialchars').each(function(index) {
if(index==s) {
$(this).css('display', 'inline');
$(this).css('visibility', 'visible');
} else {
$(this).css('display', 'none');
$(this).css('visibility', 'hidden');
}
});
}
}
}


/*
===chooseCharSubsetMenu===
*/
/* select subsection of special characters */
function chooseCharSubset() {
function chooseCharSubset() {
var selectedIndex = $(this).find(':selected').index();
    var selectedIndex = $(this).find(':selected').index();
$('p', '#editpage-specialchars').each(function(index) {
    $('p', '#editpage-specialchars').each(function (index) {
if(index==selectedIndex) {
        $(this).css({
$(this).css('display', 'inline');
            display: index === selectedIndex ? 'inline' : 'none',
$(this).css('visibility', 'visible');
            visibility: index === selectedIndex ? 'visible' : 'hidden'
}else {
        });
$(this).css('display', 'none');
    });
$(this).css('visibility', 'hidden');
    $.cookie('edittoolscharsubset', selectedIndex);
}
});
$.cookie('edittoolscharsubset', selectedIndex);
$(this).data('previousSelectedIndex', selectedIndex);
}
}


/*
$(addCharSubsetMenu);
== customizeWikipedia ==
*/


function customizeWikipedia() {
/* ============================================================
addCharSubsetMenu();
  Navigation bars
}
  ============================================================ */
$(customizeWikipedia);
 
/**
* Dynamic Navigation Bars (experimental)
*
* Description: See [[Wikipedia:NavFrame]].
* Maintainers: UNMAINTAINED
*/
 
/* set up the words in your language */
var NavigationBarHide = 'മറയ്ക്കുക';
var NavigationBarHide = 'മറയ്ക്കുക';
var NavigationBarShow = 'പ്രദർശിപ്പിക്കുക';
var NavigationBarShow = 'പ്രദർശിപ്പിക്കുക';
var indexNavigationBar = 0;
var indexNavigationBar = 0;


/**
window.toggleNavigationBar = function (index, event) {
* Shows and hides content and picture (if available) of navigation bars
     var NavToggle = document.getElementById('NavToggle' + index);
* Parameters:
     var NavFrame = document.getElementById('NavFrame' + index);
*    indexNavigationBar: the index of navigation bar to be toggled
     if (!NavFrame || !NavToggle) return;
**/
window.toggleNavigationBar = function ( indexNavigationBar, event ) {
     var NavToggle = document.getElementById( 'NavToggle' + indexNavigationBar );
     var NavFrame = document.getElementById( 'NavFrame' + indexNavigationBar );
     var NavChild;


     if ( !NavFrame || !NavToggle ) {
     var show = NavToggle.firstChild.data === NavigationBarShow;
        return false;
     NavToggle.firstChild.data = show ? NavigationBarHide : NavigationBarShow;
     }


     /* if shown now */
     var children = NavFrame.children;
     if ( NavToggle.firstChild.data === NavigationBarHide ) {
     for (var i = 0; i < children.length; i++) {
        for ( NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling ) {
        if ($(children[i]).hasClass('NavContent') ||
            if ( $( NavChild ).hasClass( 'NavContent' ) || $( NavChild ).hasClass( 'NavPic' ) ) {
            $(children[i]).hasClass('NavPic')) {
                NavChild.style.display = 'none';
            children[i].style.display = show ? 'block' : 'none';
            }
         }
         }
    NavToggle.firstChild.data = NavigationBarShow;
    /* if hidden now */
    } else if ( NavToggle.firstChild.data === NavigationBarShow ) {
        for ( NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling ) {
            if ( $( NavChild ).hasClass( 'NavContent' ) || $( NavChild ).hasClass( 'NavPic' ) ) {
                NavChild.style.display = 'block';
            }
        }
        NavToggle.firstChild.data = NavigationBarHide;
     }
     }
     event.preventDefault();
     event.preventDefault();
};
};


/* adds show/hide-button to navigation bars */
mw.hook('wikipage.content').add(function ($content) {
function createNavigationBarToggleButton( $content ) {
     $content.find('div.NavFrame').each(function () {
     var NavChild;
        indexNavigationBar++;
    /* iterate over all < div >-elements */
        var NavFrame = this;
    var $divs = $content.find( 'div' );
        var NavHead = $(NavFrame).find('.NavHead').first();
    $divs.each( function ( i, NavFrame ) {
         if (!NavHead.length) return;
         /* if found a navigation bar */
 
        if ( $( NavFrame ).hasClass( 'NavFrame' ) ) {
        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 = 'പ്രദർശിപ്പിക്കുക';


            indexNavigationBar++;
function collapseTable(tableIndex) {
            var NavToggle = document.createElement( 'a' );
    var Button = document.getElementById('collapseButton' + tableIndex);
            NavToggle.className = 'NavToggle';
    var Table = document.getElementById('collapsibleTable' + tableIndex);
            NavToggle.setAttribute( 'id', 'NavToggle' + indexNavigationBar );
    if (!Table || !Button) return;
            NavToggle.setAttribute( 'href', '#' );
            $( NavToggle ).on( 'click', $.proxy( window.toggleNavigationBar, window, indexNavigationBar ) );


            var isCollapsed = $( NavFrame ).hasClass( 'collapsed' );
    var Rows = Table.rows;
            /**
    var hide = Button.firstChild.data === collapseCaption;
            * Check if any children are already hidden.  This loop is here for backwards compatibility:
            * the old way of making NavFrames start out collapsed was to manually add style="display:none"
            * to all the NavPic/NavContent elements.  Since this was bad for accessibility (no way to make
            * the content visible without JavaScript support), the new recommended way is to add the class
            * "collapsed" to the NavFrame itself, just like with collapsible tables.
            */
            for ( NavChild = NavFrame.firstChild; NavChild != null && !isCollapsed; NavChild = NavChild.nextSibling ) {
                if ( $( NavChild ).hasClass( 'NavPic' ) || $( NavChild ).hasClass( 'NavContent' ) ) {
                    if ( NavChild.style.display === 'none' ) {
                        isCollapsed = true;
                    }
                }
            }
            if ( isCollapsed ) {
                for ( NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling ) {
                    if ( $( NavChild ).hasClass( 'NavPic' ) || $( NavChild ).hasClass( 'NavContent' ) ) {
                        NavChild.style.display = 'none';
                    }
                }
            }
            var NavToggleText = document.createTextNode( isCollapsed ? NavigationBarShow : NavigationBarHide );
            NavToggle.appendChild( NavToggleText );


            /* Find the NavHead and attach the toggle link (Must be this complicated because Moz's firstChild handling is borked) */
    for (var i = 1; i < Rows.length; i++) {
            for( var j = 0; j < NavFrame.childNodes.length; j++ ) {
        Rows[i].style.display = hide ? 'none' : '';
                if ( $( NavFrame.childNodes[j] ).hasClass( 'NavHead' ) ) {
    }
                    NavToggle.style.color = NavFrame.childNodes[j].style.color;
     Button.firstChild.data = hide ? expandCaption : collapseCaption;
                    NavFrame.childNodes[j].appendChild( NavToggle );
                }
            }
            NavFrame.setAttribute( 'id', 'NavFrame' + indexNavigationBar );
        }
     } );
}
}


mw.hook( 'wikipage.content' ).add( createNavigationBarToggleButton );
$(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);
            });


/*END OF NAVIGATION BARS*/
        $button.append($link).append(']');
        $header.prepend($button);


/** Collapsible tables *********************************************************
        tableIndex++;
*
     });
*  Description: Allows tables to be collapsed, showing only the header. See
});
*              [[Wikipedia:NavFrame]].
*  Maintainers: [[User:R. Koot]]
*/
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 false;
}
var Rows = Table.rows;
if ( Button.firstChild.data == collapseCaption ) {
for ( var i = 1; i < Rows.length; i++ ) {
Rows[i].style.display = "none";
}
Button.firstChild.data = expandCaption;
} else {
for ( var i = 1; i < Rows.length; i++ ) {
Rows[i].style.display = Rows[0].style.display;
}
Button.firstChild.data = collapseCaption;
}
}
function createCollapseButtons()
{
var tableIndex = 0;
var NavigationBoxes = new Object();
var Tables = document.getElementsByTagName( "table" );
for ( var i = 0; i < Tables.length; i++ ) {
if ( $(Tables[i]).hasClass( "collapsible" ) ) {
/* only add button and increment count if there is a header row to work with */
var HeaderRow = Tables[i].getElementsByTagName( "tr" )[0];
if (!HeaderRow) continue;
var Header = HeaderRow.getElementsByTagName( "th" )[0];
if (!Header) continue;
NavigationBoxes[ tableIndex ] = Tables[i];
Tables[i].setAttribute( "id", "collapsibleTable" + tableIndex );
var Button     = document.createElement( "span" );
var ButtonLink = document.createElement( "a" );
var ButtonText = document.createTextNode( collapseCaption );
Button.className = "collapseButton";  //Styles are declared in Common.css
ButtonLink.style.color = Header.style.color;
ButtonLink.setAttribute( "id", "collapseButton" + tableIndex );
ButtonLink.setAttribute( "href", "javascript:collapseTable(" + tableIndex + ");" );
ButtonLink.appendChild( ButtonText );
Button.appendChild( document.createTextNode( "[" ) );
Button.appendChild( ButtonLink );
Button.appendChild( document.createTextNode( "]" ) );
Header.insertBefore( Button, Header.childNodes[0] );
tableIndex++;
}
}
for ( var i = 0;  i < tableIndex; i++ ) {
if ( $(NavigationBoxes[i]).hasClass( "collapsed" ) || ( tableIndex >= autoCollapse && $(NavigationBoxes[i]).hasClass( "autocollapse" ) ) ) {
collapseTable( i );
}
else if ( $(NavigationBoxes[i]).hasClass( "innercollapse" ) ) {
var element = NavigationBoxes[i];
while (element = element.parentNode) {
if ( $(element).hasClass( "outercollapse" ) ) {
collapseTable ( i );
break;
}
}
}
}
}
$( createCollapseButtons );

12:03, 17 ജനുവരി 2026-നു നിലവിലുള്ള രൂപം

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
   ============================================================ */
window.onload = function () {
    var images = document.querySelectorAll('img');
    for (var i = 0; i < images.length; i++) {
        var img = images[i];
        if (
            img.src &&
            img.src.startsWith("https://tile.openstreetmap.org/v4/marker/")
        ) {
            img.src = img.src.replace(
                'https://tile.openstreetmap.org/v4/marker/',
                'https://maps.wikimedia.org/v4/marker/'
            );
        }
};
};

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

    $content.find('.commons-gallery').each(function () {
        var container = this;

        var sources = container.querySelectorAll('.commons-gallery-source');
        if (!sources.length) return;

        var width = 300;

        var grid = document.createElement('div');
        grid.className = 'commons-gallery-grid';
        grid.style.display = 'grid';
        grid.style.gridTemplateColumns =
            'repeat(auto-fill, minmax(' + width + 'px, 1fr))';
        grid.style.gap = '8px';

        container.appendChild(grid);

        sources.forEach(function (srcEl) {
            var filename = srcEl.dataset.file;
            var captionText = srcEl.dataset.caption || '';

            if (!filename) return;

            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) return;

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

                    var info = page.imageinfo[0];
                    var imgUrl = info.thumburl || info.url;

                    var artist = 'Unknown';
                    var license = '';
                    var licenseUrl = '';
                    var commonsUrl = info.descriptionurl || '';

                    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.className = 'commons-gallery-item';

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

                    /* Lightbox source: responsive, not original */
                    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 =
                        (captionText ? captionText + '<br>' : '') +
                        '© ' + artist +
                        (licenseUrl
                            ? ' – <a href="' + licenseUrl +
                              '" 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);
                    grid.appendChild(figure);
                })
                .catch(function (err) {
                    console.warn(
                        'Commons gallery image failed:',
                        filename,
                        err.message
                    );
                });
        });

        /* Hide source placeholders */
        sources.forEach(function (el) {
            el.style.display = 'none';
        });
    });
});

/* ============================================================
   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);
        }
    });

})();

/* ============================================================
   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++;
    });
});
"https://schoolwiki.in/index.php?title=മീഡിയവിക്കി:Common.js&oldid=2934538" എന്ന താളിൽനിന്ന് ശേഖരിച്ചത്