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

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

Schoolwiki സംരംഭത്തിൽ നിന്ന്
No edit summary
optimize js
 
(3 ഉപയോക്താക്കൾ ചെയ്ത ഇടയ്ക്കുള്ള 77 നാൾപ്പതിപ്പുകൾ പ്രദർശിപ്പിക്കുന്നില്ല)
വരി 1: വരി 1:
/**
//mw.loader.load('//en.wikipedia.org/w/index.php?title=User:Joeytje50/JWB.js/load.js&action=raw&ctype=text/javascript');
* Modifie Special:Search pour pouvoir utiliser différents moteurs de recherche,
* disponibles dans une boîte déroulante.
* Auteurs : Jakob Voss, Guillaume, importé depuis la Wiki allemande
*
*/


function externalSearchEngines() {
/* ============================================================
if (typeof SpecialSearchEnhanced2Disabled != 'undefined') return;
  OpenStreetMap marker URL fix
  ============================================================ */
window.addEventListener('load', function () {
    document.querySelectorAll('img').forEach(function (img) {
        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
  ============================================================ */
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 mainNode = document.getElementById("powersearch");
        var width = 300;
if (!mainNode) mainNode = document.getElementById("search");
        var grid = document.createElement('div');
if (!mainNode) return;
        grid.className = 'commons-gallery-grid';
        container.appendChild(grid);


var beforeNode = document.getElementById("mw-search-top-table");
        sources.forEach(function (srcEl) {
if (!beforeNode) return;
            var filename = srcEl.dataset.file;
beforeNode = beforeNode.nextSibling;
            var captionText = srcEl.dataset.caption || '';
if (!beforeNode) return;
            if (!filename) return;
var firstEngine = "mediawiki";
var choices = document.createElement("div");
choices.setAttribute("id","searchengineChoices");
choices.style.textAlign = "center";


var lsearchbox = document.getElementById("searchText");
            var apiUrl =
if (lsearchbox == null) {
                'https://commons.wikimedia.org/w/api.php' +
lsearchbox = document.getElementById("powerSearchText");
                '?action=query' +
}
                '&format=json' +
var initValue = lsearchbox.value;
                '&prop=imageinfo' +
                '&iiprop=url|extmetadata' +
var space = "";
                '&iiurlwidth=' + width +
                '&titles=File:' + encodeURIComponent(filename) +
                '&origin=*';


for (var id in searchEngines) {
            fetch(apiUrl)
var engine = searchEngines[id];
                .then(function (r) {
if(engine.ShortName)
                    if (!r.ok) throw new Error('HTTP ' + r.status);
{
                    return r.json();
if (space) choices.appendChild(space);
                })
space = document.createTextNode(" ");
                .then(function (data) {
                    if (!data || !data.query || !data.query.pages) return;
var attr = {
                    var page = data.query.pages[Object.keys(data.query.pages)[0]];
type: "radio",
                    if (!page || !page.imageinfo) return;
name: "searchengineselect",
value: id,
onFocus: "changeSearchEngine(this.value)",
id: "searchengineRadio-"+id
};
var html = "<input";
for (var a in attr) html += " " + a + "='" + attr[a] + "'";
html += " />";
var span = document.createElement("span");
span.innerHTML = html;
choices.appendChild( span );
var label
if (engine.Template.indexOf('http') == 0 || engine.Template.indexOf('//') == 0) {
label = document.createElement("a");
label.href = engine.Template.replace("{searchTerms}", initValue).replace("{language}", "fr");
} else {
label = document.createElement("label");
}
 
label.appendChild( document.createTextNode( engine.ShortName ) );
choices.appendChild( label );
}
}
mainNode.insertBefore(choices, beforeNode);
var input = document.createElement("input");
input.id = "searchengineextraparam";
input.type = "hidden";
mainNode.insertBefore(input, beforeNode);


changeSearchEngine(firstEngine, initValue);
                    var info = page.imageinfo[0];
}
                    var imgUrl = info.thumburl || info.url;
                    var meta = info.extmetadata || {};
                    var artist = (meta.Artist && meta.Artist.value) || 'Unknown';
                    var license = (meta.LicenseShortName && meta.LicenseShortName.value) || '';
                    var licenseUrl = (meta.LicenseUrl && meta.LicenseUrl.value) || '';
                    var commonsUrl = info.descriptionurl || '';


function changeSearchEngine(selectedId, searchTerms) {
                    /* Prefer responsive URL for high-DPI screens */
                    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'];
                        }
                    }


var currentId = document.getElementById("searchengineChoices").currentChoice;
                    var captionHtml =
if (selectedId == currentId) return;
                        (captionText ? captionText + '<br>' : '') +
                        '© ' + artist +
document.getElementById("searchengineChoices").currentChoice = selectedId;
                        (licenseUrl
var radio = document.getElementById('searchengineRadio-' + selectedId);
                            ? ' – <a href="' + licenseUrl + '" target="_blank" rel="noopener noreferrer">' + license + '</a>'
radio.checked = "checked";
                            : '') +
                        (commonsUrl
var engine = searchEngines[selectedId];
                            ? '<br><a href="' + commonsUrl + '" target="_blank" rel="noopener noreferrer">View on Wikimedia Commons</a>'
var p = engine.Template.indexOf('?');
                            : '');
var params = engine.Template.substr(p+1);
var form;
if (document.forms["search"]) {
form = document.forms["search"];
} else {
form = document.getElementById("powersearch");
}
form.setAttribute("action", engine.Template.substr(0,p));
var l = ("" + params).split("&");
for (var idx = 0;idx < l.length;idx++) {
var p = l[idx].split("=");
var pValue = p[1];
if (pValue == "{language}") {
} else if (pValue == "{searchTerms}") {
$('#searchText').attr('name',p[0]);
} else {
$('#searchengineextraparam').attr('name',p[0]).val(pValue);
}
}
}


if (mw.config.get('wgCanonicalSpecialPageName') == "Search") {
                    var figure = document.createElement('figure');
var searchEngines = {
                    figure.className = 'commons-gallery-item';
mediawiki: {
ShortName: "ആഭ്യന്തര അന്വേഷണം",
Template: "/w/index.php?search={searchTerms}"
},
techterms: {
ShortName: "സാങ്കേതികപദസൂചി",
Template: "//ml.wikipedia.org/w/index.php?search={searchTerms} prefix:വിക്കിപീഡിയ:വിക്കിപദ്ധതി/സാങ്കേതികപദാവലി/മേഖലകൾ&fulltext=Search"
},
wikiwix: {
ShortName: "വിക്കിവിക്സ്",
Template: "http://ml.wikiwix.com/index.php?action={searchTerms}&lang={language}"
},
google: {
ShortName: "ഗൂഗിൾ",
Template: "http://www.google.com/search?as_sitesearch=ml.wikipedia.org&hl={language}&q={searchTerms}"
},
wlive: {
ShortName: "വിൻഡോസ് ലൈവ്",
Template: "http://search.live.com/results.aspx?q={searchTerms}&q1=site:http://ml.wikipedia.org"
},
yahoo: {
ShortName: "യാഹൂ!",
Template: "http://search.yahoo.com/search?p={searchTerms}&vs=ml.wikipedia.org"
},
exalead: {
ShortName: "എക്സാലീഡ്",
Template: "http://www.exalead.com/wikipedia/results?q={searchTerms}&language=ml"
},
globalwpsearch: {
ShortName: "ഗ്ലോബൽ ഡബ്ല്യൂപി",
Template: "http://vs.aka-online.de/cgi-bin/globalwpsearch.pl?timeout=120&search={searchTerms}"
}
};
$(externalSearchEngines);
}


/*ടൂൾബാറിൽ അവലംബം ചേർക്കാനുള്ള സൗകര്യം കൂട്ടിച്ചേർക്കുന്നതിനായി */
                    var img = document.createElement('img');
if ( mw.config.get( 'wgAction' ) === 'edit' || mw.config.get( 'wgAction' ) === 'submit' || mw.config.get( 'wgCanonicalSpecialPageName' ) === 'Upload' ) {
                    img.src = imgUrl;
    /* scripts specific to editing pages */
                    img.alt = captionText || filename;
    importScript( 'മീഡിയവിക്കി:Common.js/edit.js' );
                    img.loading = 'lazy';
}
                    img.dataset.fullsrc = lightboxSrc;
                    img.dataset.caption = captionHtml;


/** Interwiki links to featured articles ***************************************
                    var figcaption = document.createElement('figcaption');
*
                    figcaption.innerHTML = captionHtml;
*  Description: Highlights interwiki links to featured articles (or
*              equivalents) by changing the bullet before the interwiki link
*              into a star.
*  Maintainers: [[User:Junaidpv]] (updated to use jQuery)
*/
function LinkFA()
{
$('li', '#p-lang').each(function(){
var idPrefix = '#'+$(this).attr('class');
if($(idPrefix+'-fa').length>0 && !$(this).hasClass('badge-featuredarticle')) {
$(this).addClass('FA');
$(this).attr('title', 'ഈ ഭാഷയിൽ ഈ ലേഖനം തിരഞ്ഞെടുക്കപ്പെട്ടതാണ്‌.');
}else if($(idPrefix+'-ga').length>0 && !$(this).hasClass('badge-goodarticle')) {
$(this).addClass('GA');
$(this).attr('title', 'ഈ ഭാഷയിൽ ഇതൊരു മികച്ച ലേഖനമാണ്.');
}
});
}
$( LinkFA );


/** Main Page layout fixes *********************************************************
                    figure.appendChild(img);
*
                    figure.appendChild(figcaption);
*  Description:        Various layout fixes for the main page, including an
                    grid.appendChild(figure);
*                      additional link to the complete list of languages available
                })
*                      and the renaming of the 'Article' to to 'Main Page'.
                .catch(function (err) {
*  Maintainers:       User:AzaToth, User:R. Koot
                    console.warn('Commons gallery image failed:', filename, err.message);
*/
                });
        });


mw.loader.using(['mediawiki.util']).then(function () {
        sources.forEach(function (el) { el.style.display = 'none'; });
if (mw.config.get('wgIsMainPage') || mw.config.get('wgPageName') == 'സംവാദം:പ്രധാന_താൾ') {
    });
$(function () {
mw.util.addPortletLink('p-lang', '//meta.wikimedia.org/wiki/List_of_Wikipedias',
'പൂർണ്ണമായ പട്ടിക', 'interwiki-completelist', 'വിക്കിപീഡിയകളുടെ പൂർണ്ണമായ പട്ടിക');
var nstab = document.getElementById('ca-nstab-main');
if (nstab && mw.config.get('wgUserLanguage')=='ml') {
while (nstab.firstChild) {
nstab = nstab.firstChild;
}
nstab.nodeValue = 'പ്രധാന താൾ';
}else if (nstab) {
while (nstab.firstChild) nstab = nstab.firstChild
nstab.nodeValue = 'Main Page'
}
});
}
});
});


/* ============================================================
  Commons Gallery Lightbox (keyboard + touch swipe)
  ============================================================ */
(function () {
    var galleryImages = [];
    var currentIndex = -1;
    var touchStartX = 0;
    function collectImages() {
        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">&#8249;</button>' +
                '<button class="clb-next" aria-label="Next">&#8250;</button>' +
                '<button class="clb-close" aria-label="Close">&times;</button>' +
                '<img class="clb-image" alt="">' +
                '<div class="clb-caption"></div>' +
            '</div>';
        document.body.appendChild(overlay);


/**
        overlay.querySelector('.clb-backdrop').addEventListener('click', closeLightbox);
* Dynamic Navigation Bars (experimental)
        overlay.querySelector('.clb-close').addEventListener('click', closeLightbox);
*
        overlay.querySelector('.clb-prev').addEventListener('click', showPrev);
* Description: See [[Wikipedia:NavFrame]].
        overlay.querySelector('.clb-next').addEventListener('click', showNext);
* Maintainers: UNMAINTAINED
*/


/* set up the words in your language */
        /* Keyboard navigation */
var NavigationBarHide = 'മറയ്ക്കുക';
        document.addEventListener('keydown', function (e) {
var NavigationBarShow = 'പ്രദർശിപ്പിക്കുക';
            if (!document.getElementById('commons-lightbox').classList.contains('active')) return;
var indexNavigationBar = 0;
            if (e.key === 'Escape') closeLightbox();
            if (e.key === 'ArrowLeft') showPrev();
            if (e.key === 'ArrowRight') showNext();
        });


/**
        /* Touch swipe navigation */
* Shows and hides content and picture (if available) of navigation bars
        overlay.addEventListener('touchstart', function (e) {
* Parameters:
            touchStartX = e.changedTouches[0].clientX;
*    indexNavigationBar: the index of navigation bar to be toggled
        }, { passive: true });
**/
window.toggleNavigationBar = function ( indexNavigationBar, event ) {
    var NavToggle = document.getElementById( 'NavToggle' + indexNavigationBar );
    var NavFrame = document.getElementById( 'NavFrame' + indexNavigationBar );
    var NavChild;


    if ( !NavFrame || !NavToggle ) {
        overlay.addEventListener('touchend', function (e) {
         return false;
            var dx = e.changedTouches[0].clientX - touchStartX;
            if (Math.abs(dx) > 50) {
                if (dx < 0) showNext(); else showPrev();
            }
         }, { passive: true });
     }
     }


     /* if shown now */
     function openLightbox(img) {
    if ( NavToggle.firstChild.data === NavigationBarHide ) {
         collectImages();
         for ( NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling ) {
        currentIndex = galleryImages.indexOf(img);
            if ( $( NavChild ).hasClass( 'NavContent' ) || $( NavChild ).hasClass( 'NavPic' ) ) {
        if (currentIndex === -1) return;
                NavChild.style.display = 'none';
            }
        }
    NavToggle.firstChild.data = NavigationBarShow;


    /* if hidden now */
        createLightbox();
    } else if ( NavToggle.firstChild.data === NavigationBarShow ) {
         showImage(currentIndex);
         for ( NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling ) {
        document.getElementById('commons-lightbox').classList.add('active');
            if ( $( NavChild ).hasClass( 'NavContent' ) || $( NavChild ).hasClass( 'NavPic' ) ) {
        document.body.style.overflow = 'hidden';
                NavChild.style.display = 'block';
            }
        }
        NavToggle.firstChild.data = NavigationBarHide;
     }
     }


     event.preventDefault();
     function showImage(index) {
};
        var overlay = document.getElementById('commons-lightbox');
        var img = galleryImages[index];
        if (!img) return;
 
        overlay.querySelector('.clb-image').src = img.dataset.fullsrc || img.src;
        overlay.querySelector('.clb-image').alt = img.alt || '';
        overlay.querySelector('.clb-caption').innerHTML = img.dataset.caption || '';
 
        /* Show/hide nav arrows at ends */
        overlay.querySelector('.clb-prev').style.visibility = index > 0 ? '' : 'hidden';
        overlay.querySelector('.clb-next').style.visibility = index < galleryImages.length - 1 ? '' : 'hidden';


/* adds show/hide-button to navigation bars */
        currentIndex = index;
function createNavigationBarToggleButton( $content ) {
     }
    var NavChild;
    /* iterate over all < div >-elements */
    var $divs = $content.find( 'div' );
     $divs.each( function ( i, NavFrame ) {
        /* if found a navigation bar */
        if ( $( NavFrame ).hasClass( 'NavFrame' ) ) {


            indexNavigationBar++;
    function showPrev() { if (currentIndex > 0) showImage(currentIndex - 1); }
            var NavToggle = document.createElement( 'a' );
    function showNext() { if (currentIndex < galleryImages.length - 1) showImage(currentIndex + 1); }
            NavToggle.className = 'NavToggle';
            NavToggle.setAttribute( 'id', 'NavToggle' + indexNavigationBar );
            NavToggle.setAttribute( 'href', '#' );
            $( NavToggle ).on( 'click', $.proxy( window.toggleNavigationBar, window, indexNavigationBar ) );


            var isCollapsed = $( NavFrame ).hasClass( 'collapsed' );
    function closeLightbox() {
            /**
        var overlay = document.getElementById('commons-lightbox');
            * Check if any children are already hidden.  This loop is here for backwards compatibility:
        if (!overlay) return;
            * the old way of making NavFrames start out collapsed was to manually add style="display:none"
        overlay.classList.remove('active');
            * to all the NavPic/NavContent elements.  Since this was bad for accessibility (no way to make
        document.body.style.overflow = '';
            * 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) */
    document.addEventListener('click', function (e) {
            for( var j = 0; j < NavFrame.childNodes.length; j++ ) {
        if (e.target && e.target.matches('.commons-gallery-item img')) {
                if ( $( NavFrame.childNodes[j] ).hasClass( 'NavHead' ) ) {
            openLightbox(e.target);
                    NavToggle.style.color = NavFrame.childNodes[j].style.color;
                    NavFrame.childNodes[j].appendChild( NavToggle );
                }
            }
            NavFrame.setAttribute( 'id', 'NavFrame' + indexNavigationBar );
         }
         }
     } );
     });
 
})();
 
/* ============================================================
  Editing tools (load only on edit/upload pages)
  ============================================================ */
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'
    );
}
}


mw.hook( 'wikipage.content' ).add( createNavigationBarToggleButton );
/* ============================================================
  Special characters subset menu
  ============================================================ */
function addCharSubsetMenu() {
    if ($('#editpage-specialchars').length === 0) return;


/*END OF NAVIGATION BARS*/
    var s = parseInt(mw.cookie.get('edittoolscharsubset'), 10);
    if (isNaN(s)) s = 0;


    var options = [
        'ഫലകങ്ങൾ', 'വിക്കിവിന്യാസങ്ങൾ', 'അനുമതിപത്രങ്ങൾ', 'മലയാളം',
        'കൊറിയൻ', 'ലത്തീൻ', 'ഐ.പി.എ.', 'പലവക',
        'അറബി', 'ദേവനാഗരി', 'ഹിബ്രു', 'പഴയ ഇംഗ്ലീഷ്'
    ];


/*
    var $menu = $('<select />')
==addCharSubsetMenu==
        .attr('id', 'charSubsetControl')
*/
        .css('display', 'inline')
        .change(chooseCharSubset)
        .data('previousSelectedIndex', s);


/* add menu for selecting subsets of secial characters  */
    options.forEach(function (label) {
/***** must match MediaWiki:Edittools *****/
        $menu.append($('<option />').text(label));
function addCharSubsetMenu() {
    });
if($('#editpage-specialchars').length>0) {
 
/* default subset from cookie */
    $('#editpage-specialchars').prepend($menu);
var s = parseInt( $.cookie('edittoolscharsubset') );
    $('#charSubsetControl')[0].selectedIndex = s;
if ( isNaN(s) ) s = 0;
 
var $menu = $('<select />')
    $('p', '#editpage-specialchars').each(function (index) {
.attr('id', 'charSubsetControl')
        $(this).css({
.css('display', 'inline');
            display: index === s ? 'inline' : 'none',
$menu.change(chooseCharSubset)
            visibility: index === s ? 'visible' : 'hidden'
.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');
    mw.cookie.set('edittoolscharsubset', selectedIndex);
}
});
$.cookie('edittoolscharsubset', selectedIndex);
$(this).data('previousSelectedIndex', selectedIndex);
}
}


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


function customizeWikipedia() {
/* ============================================================
addCharSubsetMenu();
  Navigation bars (NavFrame show/hide)
}
  ============================================================ */
var NavigationBarHide = 'മറയ്ക്കുക';
$(customizeWikipedia);
var NavigationBarShow = 'പ്രദർശിപ്പിക്കുക';
var indexNavigationBar = 0;


/*HERE STARTS THE WORKING-CODE OF "METABOXES"*/
window.toggleNavigationBar = function (index, event) {
    var NavToggle = document.getElementById('NavToggle' + index);
    var NavFrame = document.getElementById('NavFrame' + index);
    if (!NavFrame || !NavToggle) return;


/* Funcionament de la Plantilla:Metacaixa
    var show = NavToggle.firstChild.data === NavigationBarShow;
Implementat per: Usuari:Peleguer.
    NavToggle.firstChild.data = show ? NavigationBarHide : NavigationBarShow;
Actualitzat per Joanjoc seguint les indicacions d'en Martorell
*/


function MetaCaixaInit(){
    Array.prototype.forEach.call(NavFrame.children, function (child) {
//S'executa al carregar-se la pàgina, si hi ha metacaixes,
        if (child.classList.contains('NavContent') || child.classList.contains('NavPic')) {
// s'assignen els esdeveniments als botons
            child.style.display = show ? 'block' : 'none';
//alert("MetaCaixaInit");
        }
 
    });
var i=0      //Inicialitzem comptador de caixes
    event.preventDefault();
for (i=0;i<=9;i++){
};
var vMc = document.getElementById("mc"+i);
if (!vMc) break;
//alert("MetaCaixaInit, trobada Metacaixa mc"+i);
   
var j=1    //Inicialitzem comptador de botons dins de la caixa
var vPsIni = 0  //Pestanya visible inicial
for (j=1;j<=9;j++){
var vBt = document.getElementById("mc"+i+"bt"+j);
if (!vBt) break;
//alert("MetaCaixaInit, trobat botó mc"+i+"bt"+j);
vBt.onclick = MetaCaixaMostraPestanya;          //A cada botó assignem l'esdeveniment onclick
//alert (vBt.className);
if (vBt.className=="mcBotoSel") vPsIni=j;  //Si tenim un botó seleccionat, en guardem l'index
}
//alert ("mc="+i+", ps="+j+", psini="+vPsIni );
if (vPsIni == 0) { //Si no tenim cap botó seleccionat, n'agafem un aleatòriament
vPsIni = 1+Math.floor((j-1)*Math.random()) ;
//alert ("Activant Pestanya a l'atzar; _mc"+i+"bt"+vPsIni +"_");
document.getElementById("mc"+i+"ps"+vPsIni).style.display = "block";
document.getElementById("mc"+i+"ps"+vPsIni).style.visibility = "visible";
document.getElementById("mc"+i+"bt"+vPsIni).className="mcBotoSel";
}
}
}
 
function MetaCaixaMostraPestanya(){
//S'executa al clicar una pestanya,
//aquella es fa visible i les altres s'oculten
var vMcNom = this.id.substr(0,3); //A partir del nom del botó, deduïm el nom de la caixa
var vIndex = this.id.substr(5,1); //I l'index
 
var i=1
for (i=1;i<=9;i++){        //busquem totes les pestanyes d'aquella caixa
//alert(vMcNom+"ps"+i);
var vPsElem = document.getElementById(vMcNom+"ps"+i);
if (!vPsElem) break;
if (vIndex==i){ //Si és la pestanya bona la mostrem i canviem la classe de botó
vPsElem.style.display = "block";
vPsElem.style.visibility = "visible";
document.getElementById(vMcNom+"bt"+i).className="mcBotoSel";
} else {            //Sinó, l'ocultem i canviem la classe de botó
vPsElem.style.display = "none";
vPsElem.style.visibility = "hidden";
document.getElementById(vMcNom+"bt"+i).className="mcBoto";
}
}
return false; //evitem la recàrrega de la pàgina
}
$(MetaCaixaInit);


/*HERE FINISHES THE WORKING-CODE OF "METABOXES"*/
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;


/** WikiMiniAtlas *******************************************************
        var idx = indexNavigationBar;
  *
        var $NavToggle = $('<a href="#" class="NavToggle"></a>')
  *  Description: WikiMiniAtlas is a popup click and drag world map.
            .attr('id', 'NavToggle' + idx)
  *              This script causes all of our coordinate links to display the WikiMiniAtlas popup button.
            .text(NavigationBarHide)
  *              The script itself is located on meta because it is used by many projects.
            .on('click', function (e) {
  *              See [[Meta:WikiMiniAtlas]] for more information.  
                toggleNavigationBar(idx, e);
  *  Maintainers: [[User:Dschwen]]
            });
  */


mw.loader.load('//meta.wikimedia.org/w/index.php?title=MediaWiki:Wikiminiatlas.js&action=raw&ctype=text/javascript&smaxage=21600&maxage=86400');
        NavFrame.id = 'NavFrame' + idx;
        $NavHead.append($NavToggle);
    });
});


/** Collapsible tables *********************************************************
/* ============================================================
*
  Collapsible tables
*  Description: Allows tables to be collapsed, showing only the header. See
  ============================================================ */
*              [[Wikipedia:NavFrame]].
*  Maintainers: [[User:R. Koot]]
*/
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 ) {
    var hide = Button.firstChild.data === collapseCaption;
return false;
    Array.prototype.forEach.call(Table.rows, function (row, i) {
}
        if (i > 0) row.style.display = hide ? 'none' : '';
    });
var Rows = Table.rows;
    Button.firstChild.data = hide ? expandCaption : collapseCaption;
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()
$(function () {
{
    var tableIndex = 0;
var tableIndex = 0;
    $('table.collapsible').each(function () {
var NavigationBoxes = new Object();
        var $table = $(this);
var Tables = document.getElementsByTagName( "table" );
        var $header = $table.find('tr:first th:first');
        if (!$header.length) return;
for ( var i = 0; i < Tables.length; i++ ) {
 
if ( $(Tables[i]).hasClass( "collapsible" ) ) {
        var idx = tableIndex;
        $table.attr('id', 'collapsibleTable' + idx);
/* only add button and increment count if there is a header row to work with */
 
var HeaderRow = Tables[i].getElementsByTagName( "tr" )[0];
        var $link = $('<a href="#"></a>')
if (!HeaderRow) continue;
            .attr('id', 'collapseButton' + idx)
var Header = HeaderRow.getElementsByTagName( "th" )[0];
            .text(collapseCaption)
if (!Header) continue;
            .on('click', function (e) {
                e.preventDefault();
NavigationBoxes[ tableIndex ] = Tables[i];
                collapseTable(idx);
Tables[i].setAttribute( "id", "collapsibleTable" + tableIndex );
            });
 
var Button    = document.createElement( "span" );
        $header.prepend($('<span class="collapseButton">[</span>').append($link).append(']'));
var ButtonLink = document.createElement( "a" );
        tableIndex++;
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 );

23:26, 29 മേയ് 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.addEventListener('load', function () {
    document.querySelectorAll('img').forEach(function (img) {
        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
   ============================================================ */
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';
        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 meta = info.extmetadata || {};
                    var artist = (meta.Artist && meta.Artist.value) || 'Unknown';
                    var license = (meta.LicenseShortName && meta.LicenseShortName.value) || '';
                    var licenseUrl = (meta.LicenseUrl && meta.LicenseUrl.value) || '';
                    var commonsUrl = info.descriptionurl || '';

                    /* Prefer responsive URL for high-DPI screens */
                    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'];
                        }
                    }

                    var captionHtml =
                        (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>'
                            : '');

                    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.dataset.fullsrc = lightboxSrc;
                    img.dataset.caption = captionHtml;

                    var figcaption = document.createElement('figcaption');
                    figcaption.innerHTML = captionHtml;

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

        sources.forEach(function (el) { el.style.display = 'none'; });
    });
});

/* ============================================================
   Commons Gallery Lightbox (keyboard + touch swipe)
   ============================================================ */
(function () {

    var galleryImages = [];
    var currentIndex = -1;
    var touchStartX = 0;

    function collectImages() {
        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">&#8249;</button>' +
                '<button class="clb-next" aria-label="Next">&#8250;</button>' +
                '<button class="clb-close" aria-label="Close">&times;</button>' +
                '<img class="clb-image" alt="">' +
                '<div class="clb-caption"></div>' +
            '</div>';

        document.body.appendChild(overlay);

        overlay.querySelector('.clb-backdrop').addEventListener('click', closeLightbox);
        overlay.querySelector('.clb-close').addEventListener('click', closeLightbox);
        overlay.querySelector('.clb-prev').addEventListener('click', showPrev);
        overlay.querySelector('.clb-next').addEventListener('click', showNext);

        /* Keyboard navigation */
        document.addEventListener('keydown', function (e) {
            if (!document.getElementById('commons-lightbox').classList.contains('active')) return;
            if (e.key === 'Escape') closeLightbox();
            if (e.key === 'ArrowLeft') showPrev();
            if (e.key === 'ArrowRight') showNext();
        });

        /* Touch swipe navigation */
        overlay.addEventListener('touchstart', function (e) {
            touchStartX = e.changedTouches[0].clientX;
        }, { passive: true });

        overlay.addEventListener('touchend', function (e) {
            var dx = e.changedTouches[0].clientX - touchStartX;
            if (Math.abs(dx) > 50) {
                if (dx < 0) showNext(); else showPrev();
            }
        }, { passive: true });
    }

    function openLightbox(img) {
        collectImages();
        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 img = galleryImages[index];
        if (!img) return;

        overlay.querySelector('.clb-image').src = img.dataset.fullsrc || img.src;
        overlay.querySelector('.clb-image').alt = img.alt || '';
        overlay.querySelector('.clb-caption').innerHTML = img.dataset.caption || '';

        /* Show/hide nav arrows at ends */
        overlay.querySelector('.clb-prev').style.visibility = index > 0 ? '' : 'hidden';
        overlay.querySelector('.clb-next').style.visibility = index < galleryImages.length - 1 ? '' : 'hidden';

        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 = '';
    }

    document.addEventListener('click', function (e) {
        if (e.target && e.target.matches('.commons-gallery-item img')) {
            openLightbox(e.target);
        }
    });

})();

/* ============================================================
   Editing tools (load only on edit/upload pages)
   ============================================================ */
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) return;

    var s = parseInt(mw.cookie.get('edittoolscharsubset'), 10);
    if (isNaN(s)) s = 0;

    var options = [
        'ഫലകങ്ങൾ', 'വിക്കിവിന്യാസങ്ങൾ', 'അനുമതിപത്രങ്ങൾ', 'മലയാളം',
        'കൊറിയൻ', 'ലത്തീൻ', 'ഐ.പി.എ.', 'പലവക',
        'അറബി', 'ദേവനാഗരി', 'ഹിബ്രു', 'പഴയ ഇംഗ്ലീഷ്'
    ];

    var $menu = $('<select />')
        .attr('id', 'charSubsetControl')
        .css('display', 'inline')
        .change(chooseCharSubset)
        .data('previousSelectedIndex', s);

    options.forEach(function (label) {
        $menu.append($('<option />').text(label));
    });

    $('#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'
        });
    });
    mw.cookie.set('edittoolscharsubset', selectedIndex);
}

$(addCharSubsetMenu);

/* ============================================================
   Navigation bars (NavFrame show/hide)
   ============================================================ */
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;

    Array.prototype.forEach.call(NavFrame.children, function (child) {
        if (child.classList.contains('NavContent') || child.classList.contains('NavPic')) {
            child.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 idx = indexNavigationBar;
        var $NavToggle = $('<a href="#" class="NavToggle"></a>')
            .attr('id', 'NavToggle' + idx)
            .text(NavigationBarHide)
            .on('click', function (e) {
                toggleNavigationBar(idx, e);
            });

        NavFrame.id = 'NavFrame' + idx;
        $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 hide = Button.firstChild.data === collapseCaption;
    Array.prototype.forEach.call(Table.rows, function (row, i) {
        if (i > 0) row.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;

        var idx = tableIndex;
        $table.attr('id', 'collapsibleTable' + idx);

        var $link = $('<a href="#"></a>')
            .attr('id', 'collapseButton' + idx)
            .text(collapseCaption)
            .on('click', function (e) {
                e.preventDefault();
                collapseTable(idx);
            });

        $header.prepend($('<span class="collapseButton">[</span>').append($link).append(']'));
        tableIndex++;
    });
});
"https://schoolwiki.in/index.php?title=മീഡിയവിക്കി:Common.js&oldid=2989107" എന്ന താളിൽനിന്ന് ശേഖരിച്ചത്