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

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


/*<pre><nowiki>
/* ============================================================
ടൂള്‍ ബാര്‍ ബട്ടണുകള്‍ അടുക്കിപ്പെറുക്കി വയ്ക്കാനുള്ള സ്ക്രിപ്റ്റ്‌
  OpenStreetMap marker URL fix
Maintainer : [[User:Tux the penguin]]
  ============================================================ */
*/
window.addEventListener('load', function () {
function lija_rearrange()
     document.querySelectorAll('img').forEach(function (img) {
{
         if (img.src && img.src.startsWith('https://tile.openstreetmap.org/v4/marker/')) {
var def,ext;
            img.src = img.src.replace(
if(mwEditButtons)
                'https://tile.openstreetmap.org/v4/marker/',
def=mwEditButtons;
                'https://maps.wikimedia.org/v4/marker/'
 
            );
if(mwCustomEditButtons)
ext=mwCustomEditButtons;
 
if(def!=null && ext!=null)
{
var defc=def.slice();
var extc=ext.slice();
try
  {
def[2]=extc[1];
def[3]=defc[4];
def[4]=extc[8];
def[5]=extc[5];
def[6]=extc[9];
def[7]=extc[2];
def[8]=defc[10];
def[9]=extc[6];
def[10]=defc[8];
def[def.length]={
    "imageFile": "http://upload.wikimedia.org/wikipedia/commons/8/88/Btn_toolbar_enum.png",
    "speedTip": "എണ്ണമിട്ട പട്ടിക",
    "tagOpen": "\n#",
    "tagClose": "\n#രണ്ടാമത്തെ ഇനം\n#മൂന്നാമത്തെ ഇനം",
    "sampleText": "ഒന്നാമത്തെ ഇനം"};
def[def.length]={
    "imageFile": "http://upload.wikimedia.org/wikipedia/commons/1/11/Btn_toolbar_liste.png",
    "speedTip": "എണ്ണമിടാത്ത പട്ടിക",
    "tagOpen": "\n*",
    "tagClose": "\n*രണ്ടാമത്തെ ഇനം\n*മൂന്നാമത്തെ ഇനം",
    "sampleText": "ഒന്നാമത്തെ ഇനം"};
def[def.length]={
    "imageFile": "http://upload.wikimedia.org/wikipedia/commons/b/b4/Button_category03.png",
    "speedTip": "സൂചിക ചേര്ക്കുക",
    "tagOpen": "[[Category:",
    "tagClose": "]]",
    "sampleText": "ഉള്ളടക്കം"};
 
ext[0]=defc[2];
ext[1]=defc[3];
ext[2]=defc[5];
ext[3]=defc[6];
ext[4]=extc[7];
ext[5]=defc[7];
ext[6]=extc[3];
ext[7]=extc[4];
ext[8]=extc[0];
ext[9]=extc[10];
ext[10]=extc[11];
ext[11]=defc[9];
}
catch(ex)
{
//എറര്‍ ഉണ്ടായാല്‍..... സഹിക്കുക. അല്ലാണ്ടെന്തു ചെയ്യാന്‍ ?
}
}
 
 
}
 
addOnloadHook(lija_rearrange);
//****************************************************************************************************************
//ടൂള്‍ ബാര്‍ സ്ക്രിപ്റ്റ്‌ ഇവിടെ അവസാനിയ്ക്കുന്നു.
//****************************************************************************************************************
/*</nowiki></pre>*/
 
 
/*
<nowiki><pre>
 
    This script is a modified version of Alex benenson's cyrillic translitarator and this version was created by [[User:Peringz|Peringz]]
*/
 
var consonants = {"ക":"ക","ഖ":"ഖ","ഗ":"ഗ","ഘ":"ഘ","ങ":"ങ","ച":"ച","ഛ":"ഛ","ജ":"ജ","ഝ":"ഝ","ഞ":"ഞ","ട":"ട","ഠ":"ഠ","ഡ":"ഡ","ഢ":"ഢ","ണ":"ണ","ത":"ത","ഥ":"ഥ","ദ":"ദ","ധ":"ധ","ന":"ന","പ":"പ","ഫ":"ഫ","ബ":"ബ","ഭ":"ഭ","മ":"മ","യ":"യ","ര":"ര","ല":"ല","വ":"വ","ശ":"ശ","ഷ":"ഷ","സ":"സ","ഹ":"ഹ","ള":"ള","ഴ":"ഴ","റ":"റ","റ്റ":"റ്റ"};
var chillaksharam = {"ണ്‍":"ണ","ന്‍":"ന","ം":"മ","ര്‍":"ര","ല്‍":"ല","ള്‍":"ള","്\\u200D":""};
 
var vowels = '"്a":"","്e":"െ","്i":"ി","്o":"ൊ","്u":"ു","്A":"ാ","്E":"േ","്I":"ീ","്O":"ോ","്U":"ൂ","്Y":"ൈ","െe":"ീ","ൊo":"ൂ","ിi":"ീ","ിe":"ീ","ുu":"ൂ","ുo":"ൂ","്r":"്ര്",';
var roman = '"k":"ക്","ക്h":"ഖ്","g":"ഗ്","ഗ്h":"ഘ്","ന്‍g":"ങ്","c":"ക്\\u200D","ക്\\u200Dh":"ച്","ച്h":"ഛ്","j":"ജ്","ജ്h":"ഝ്","ന്‍j":"ഞ്","ന്‍h":"ഞ്","T":"ട്","ട്h":"ഠ്","D":"ഡ്","ഡ്h":"ഢ്","റ്റ്h":"ത്","ത്h":"ഥ്","d":"ദ്","ദ്h":"ധ്","p":"പ്","പ്h":"ഫ്","f":"ഫ്","b":"ബ്","ബ്h":"ഭ്","y":"യ്","v":"വ്","w":"വ്","z":"ശ്","S":"ശ്","സ്h":"ഷ്","s":"സ്","h":"ഹ്","ശ്h":"ഴ്","x":"ക്ഷ്","R":"റ്","t":"റ്റ്",';
var chill = '"N":"ണ്‍","n":"ന്‍","m":"ം","r":"ര്‍","l":"ല്‍","L":"ള്‍",';
var swaram = '"a":"അ","അa":"ആ","A":"ആ","e":"എ","E":"ഏ","എe":"ഈ","i":"ഇ","ഇi":"ഈ","ഇe":"ഈ","അi":"ഐ","I":"ഐ","o":"ഒ","ഒo":"ഊ","O":"ഓ","അu":"ഔ","ഒu":"ഔ","u":"ഉ","ഉu":"ഊ","U":"ഊ","H":"ഃ","റ്h":"ഋ","ര്‍^":"ഋ","ഋ^":"ൠ","ല്‍^":"ഌ","ഌ^":"ൡ",';
//var numerals = '"1":"൧","2":"൨","3":"൩","4":"൪","5":"൫","6":"൬","7":"൭","8":"൮","9":"൯","0":"൦",';
var conjuncts = '"ന്‍t":"ന്റ്","ന്റ്h":"ന്ത്","ന്‍k":"ങ്ക്","ന്‍n":"ന്ന്","ണ്‍N":"ണ്ണ്","ള്‍L":"ള്ള്","ല്‍l":"ല്ല്","ംm":"മ്മ്","ന്‍m":"ന്മ്","ന്ന്g":"ങ്ങ്","ന്‍d":"ന്ദ്","ണ്‍m":"ണ്മ്","ല്‍p":"ല്പ്","ംp":"മ്പ്","റ്റ്t":"ട്ട്","ന്‍T":"ണ്ട്","ണ്‍T":"ണ്ട്","്ര്^":"ൃ","ന്‍c":"ന്‍\\u200D","ന്‍\\u200Dh":"ഞ്ച്","ണ്‍D":"ണ്ഡ്",';
var others = '"്L":"്ല്","~":"്\\u200C","്~":"്\\u200C","\\u200C~":"\\u200C","ം~":"മ്","ക്\\u200Dc":"ക്ക്\\u200D","ക്ക്\\u200Dh":"ച്ച്","q":"ക്യൂ",';
var caps = '"B":"ബ്ബ്","C":"ക്ക്\\u200D","F":"ഫ്","G":"ഗ്ഗ്","J":"ജ്ജ്","K":"ക്ക്","M":"മ്മ്","P":"പ്പ്","Q":"ക്യൂ","V":"വ്വ്","W":"വ്വ്","X":"ക്ഷ്","Y":"യ്യ്","Z":"ശ്ശ്",';
var ZWNJ = '"_":"\\u200C"';
 
// for compatibility with bookmarklets
function cyr_translit(src) {
    return to_cyrillic(src);
}
 
var conversionHash = undefined;
var maxcyrlength = 0;
 
function getConversionHash() {
    if (conversionHash == undefined) {
        // TODO
        var opr = "{" + vowels + roman + chill + swaram +  conjuncts + caps + others;
        for (var consonant in consonants) {
        opr += '"' + consonant + 'a":"' + consonant + 'ാ",';
        opr += '"' + consonant + 'e":"' + consonant + 'േ",';
        opr += '"' + consonant + 'i":"' + consonant + 'ൈ",';
        opr += '"' + consonant + 'o":"' + consonant + 'ോ",';
        opr += '"' + consonant + 'u":"' + consonant + 'ൗ",';
        }
        for (var chk in chillaksharam) {
            opr += '"' + chk + 'a":"' + chillaksharam[chk] + '",';
            opr += '"' + chk + 'e":"' + chillaksharam[chk] + 'െ",';
            opr += '"' + chk + 'i":"' + chillaksharam[chk] + 'ി",';
            opr += '"' + chk + 'o":"' + chillaksharam[chk] + 'ൊ",';
            opr += '"' + chk + 'u":"' + chillaksharam[chk] + 'ു",';
            opr += '"' + chk + 'A":"' + chillaksharam[chk] + 'ാ",';
            opr += '"' + chk + 'E":"' + chillaksharam[chk] + 'േ",';
            opr += '"' + chk + 'I":"' + chillaksharam[chk] + 'ീ",';
            opr += '"' + chk + 'O":"' + chillaksharam[chk] + 'ോ",';
            opr += '"' + chk + 'U":"' + chillaksharam[chk] + 'ൂ",';
            opr += '"' + chk + 'Y":"' + chillaksharam[chk] + 'ൈ",';
            opr += '"' + chk + 'r":"' + chillaksharam[chk] + '്ര്",';
            opr += '"' + chk + 'y":"' + chillaksharam[chk] + '്യ്",';
            opr += '"' + chk + 'v":"' + chillaksharam[chk] + '്വ്",';
            opr += '"' + chk + 'w":"' + chillaksharam[chk] + '്വ്",';
            opr += '"' + chk + '~":"' + chillaksharam[chk] + '്\\u200C",';
        }
        opr += ZWNJ + "}";
        // var tb = document.getElementById('wpTextbox1');
        // tb.value = opr;
        conversionHash = eval("("+opr+")");
        maxcyrlength=6;
    }
 
    return conversionHash;
}
 
function to_cyrillic(src, output, chunks) {
    if (src == undefined || src == "" || src == null)
        return src;
    if (output == undefined)
        output = new String();
 
     var hash = getConversionHash();
    var location = 0;
    while (location < src.length) {
         var len = Math.min(maxcyrlength, src.length - location);
        var arr = undefined;
        var sub;
        while (len > 0) {
        sub = src.substr(location, len);
        arr = hash[sub];
        if (arr != undefined)
        break;
        else
        len--;
        }
        // need this for translit on the fly
        if (chunks != undefined)
        chunks[chunks.length] = sub;
        if (arr == undefined) {
        output += sub;
        location ++;
         }
         }
        else {
    });
 
});
        // case analysis
        var newChar = arr;
        if (sub.toLowerCase() == sub.toUpperCase() && arr.length > 1 && arr[1] && (newChar.toUpperCase() != newChar.toLowerCase())) {
        // need translit hash to determine if previous character (and possibly the one before it)
        // were converted and are in upper case
        // set prevDud to true previous is not a translated character or simply a blank
        // set prevCap to true if previous was translated and was upper case
 
        var prevCh = output.length == 0 ? null : output.substr(output.length - 1, 1);
        var prevDud = !prevCh || !getTranslitString(prevCh);
        var prevCap = (!prevDud && prevCh == prevCh.toUpperCase());


        // sub is caseless but result isn't. case will depend on lookbehind and lookahead
/* ============================================================
        if (prevDud || !prevCap) {
  Wikimedia Commons Gallery Loader
        output += newChar.toLowerCase();
  ============================================================ */
        prevCap = false;
mw.hook('wikipage.content').add(function ($content) {
        }
        else {
        var next = " ";
        if (location + len < src.length)
        next = src.substr(location + len, 1);


        if (next != next.toUpperCase() && next == next.toLowerCase() ) {
    $content.find('.commons-gallery').each(function () {
        //next is lowercase (and not caseless)
        var container = this;
        output += newChar.toLowerCase();
        var sources = container.querySelectorAll('.commons-gallery-source');
        }
        if (!sources.length) return;
        else if (next == next.toUpperCase() && next != next.toLowerCase() ) {
        // next is uppercase (and not caseless)
        output += newChar.toUpperCase();
        }
        else {
        // next is caseless. output case determined by the case of output[length - 2]
        var pprevCh = output.length == 1 ? null : output.substr(output.length - 2, 1);
        var pprevDud = !pprevCh || !getTranslitString(pprevCh);
        if (!pprevDud && (pprevCh == pprevCh.toUpperCase())) {
        //pre-prev is in upper case. output is also uppercase
        output += newChar.toUpperCase();
        }
        else {
            output += newChar.toLowerCase();
        }
        }
        }
        }
        else if ((sub.toLowerCase() == sub.toUpperCase()) && (arr.length < 2 || !arr[1])) {
        // literal treatment of newChar
        output += newChar;


        }
        var width = 300;
        else if (sub != sub.toLowerCase()) {
        var grid = document.createElement('div');
        grid.className = 'commons-gallery-grid';
        // sub not all-lowercase
         container.appendChild(grid);
        output += newChar.toUpperCase();
        }
        else {
        // sub is lowercase
            output += newChar.toLowerCase();
        }
        location += len;
         }
    }
    return output;
}


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


function convertIt(src,converter){
            fetch(apiUrl)
var resultbuffer="";  
                .then(function (r) {
    for(var i=0;i<src.length;i++){
                    if (!r.ok) throw new Error('HTTP ' + r.status);
    resultbuffer=converter(resultbuffer+src[i]);
                    return r.json();
    }
                })
        return converter(resultbuffer);
                .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 translitHash = undefined;
                    var figure = document.createElement('figure');
                    figure.className = 'commons-gallery-item';


function initTranslit() {
                    var img = document.createElement('img');
    if (translitHash == undefined) {
                    img.src = imgUrl;
        translitHash = new Array();
                    img.alt = captionText || filename;
                    img.loading = 'lazy';
                    img.dataset.fullsrc = lightboxSrc;
                    img.dataset.caption = captionHtml;


        for (var i = 0; i < conversionHash.length; i++) {
                    var figcaption = document.createElement('figcaption');
        var ch = conversionHash[i][1];
                    figcaption.innerHTML = captionHtml;
        // if the translit string is not caseless, convert cyr string to upper case
        // otherwise maintain its case
        if (conversionHash[i][0].toUpperCase() != conversionHash[i][0].toLowerCase())
        ch = ch.toUpperCase();
        if (translitHash[ch] == undefined)
        translitHash[ch] = conversionHash[i][0];
        }
    }
}


                    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 () {


//-- translit on-the-fly --  
    var galleryImages = [];
    var currentIndex = -1;
    var touchStartX = 0;


function replaceValue(node, value, stepback) {
    function collectImages() {
    if (stepback == undefined)
         galleryImages = Array.prototype.slice.call(
         stepback = 0;
            document.querySelectorAll('.commons-gallery-item img')
         );
    if (isExplorer()) {
        var range = document.selection.createRange();
        range.moveStart("character", -stepback);
        range.text = value;
        range.collapse(false);
        range.select();
    }
    else {
        var scrollTop = node.scrollTop;
         var cursorLoc =  node.selectionStart;
        node.value = node.value.substring(0, node.selectionStart - stepback) + value +
                node.value.substring(node.selectionEnd, node.value.length);
        node.scrollTop = scrollTop;
        node.selectionStart = cursorLoc + value.length - stepback;
        node.selectionEnd = cursorLoc + value.length - stepback;
     }
     }
}
// compare positions
function positionIsEqual(other) {
    if (isExplorer())
        return this.position.isEqual(other.position);
    else
        return this.position == other.position;
 
}


function Position(node) {
    function createLightbox() {
  if (node.selectionStart != undefined)
        if (document.getElementById('commons-lightbox')) return;
    this.position = node.selectionStart;
  else if (document.selection && document.selection.createRange())
    this.position = document.selection.createRange();
   
  this.isEqual = positionIsEqual;
}


function resetState() {
        var overlay = document.createElement('div');
    this.position = new Position(this.node);
        overlay.id = 'commons-lightbox';
    this.transBuffer = "";
        overlay.innerHTML =
    this.cyrBuffer = "";
            '<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>';


function StateObject(node) {
        document.body.appendChild(overlay);
    this.node = node;
    this.reset = resetState;
    this.cyrBuffer = "";
    this.transBuffer = "";
    this.position = new Position(node);
}


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


var stateHash = new Array();
        /* 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();
        });


function isExplorer() {
        /* Touch swipe navigation */
  return (document.selection != undefined && document.selection.createRange().isEqual != undefined);
        overlay.addEventListener('touchstart', function (e) {
}
            touchStartX = e.changedTouches[0].clientX;
        }, { passive: true });


function pressedKey(event) {
        overlay.addEventListener('touchend', function (e) {
  if (isExplorer())
            var dx = e.changedTouches[0].clientX - touchStartX;
    return event.keyCode;
            if (Math.abs(dx) > 50) {
  else
                if (dx < 0) showNext(); else showPrev();
    return event.which;
            }
}
         }, { passive: true });
 
function transliterateKey(event) {
    /*
    if ((event.keyCode == 255 && event.charCode > 0) || event.keyCode == 8) {
        return;
    }
    */
   
    if (event == undefined)
        event = window.event;
   
    var node = null;
    if (event.target) {
        node = event.target;
        }
    else if (event.srcElement) {
        node = event.srcElement;
         }
    // initialize state
    var state = stateHash[node];
    if (state == null) {
        state = new StateObject(node);
        stateHash[node] = state;
     }
     }
    if ( (pressedKey(event) > 20) && !event.ctrlKey && !event.altKey && !event.metaKey) {
        var c = String.fromCharCode(pressedKey(event));


        // process input
    function openLightbox(img) {
         var result = process_translit(state, c);
         collectImages();
         // finish up
         currentIndex = galleryImages.indexOf(img);
        if (c != result.out || result.replace != 0) {
        if (currentIndex === -1) return;
          if (isExplorer())
        event.returnValue = false;
          else
            event.preventDefault();
 
          replaceValue(node, result.out, result.replace);
 
          state.position = new Position(node);


         }
         createLightbox();
        showImage(currentIndex);
        document.getElementById('commons-lightbox').classList.add('active');
        document.body.style.overflow = 'hidden';
     }
     }
}


function TranslitResult() {
    function showImage(index) {
    this.out = "";
        var overlay = document.getElementById('commons-lightbox');
    this.replace = 0;
        var img = galleryImages[index];
}
        if (!img) return;


function process_translit(state, c) {
        overlay.querySelector('.clb-image').src = img.dataset.fullsrc || img.src;
    // reset state if position changed
         overlay.querySelector('.clb-image').alt = img.alt || '';
    if (!state.position.isEqual(new Position(state.node)))
        overlay.querySelector('.clb-caption').innerHTML = img.dataset.caption || '';
         state.reset();
    var result = new TranslitResult();
    // initial backbuffer. Add to it as characters are converted
    var backbuffer = getBackBuffer(state.node, state.cyrBuffer.length, 2);
    var chunks = new Array();
    state.transBuffer = state.transBuffer+ c


    var str = to_cyrillic(state.cyrBuffer+c, backbuffer, chunks);
        /* 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';


    // remove backbuffer from output
         currentIndex = index;
    str = str.substr(backbuffer.length);
    result.out = str;
    /* str is now left alone - it has the output matching contents of chunks and
      will be used to reinitialize backbuffers, along with chunks and state.transBuffer
    */
    // get the difference between state.cyrBuffer and output
    for (var i = 0; i < Math.min(state.cyrBuffer.length, result.out.length); i++) {
        if (state.cyrBuffer.substr(i, 1) != result.out.substr(i, 1)) {
        result.replace = state.cyrBuffer.length - i;
        result.out = result.out.substr(i);
        break;
        }
    }
    if (result.replace == 0) {
              if(result.out.length<state.cyrBuffer.length)
        result.replace=state.cyrBuffer.length- result.out.length;
        result.out = result.out.substr(Math.min(state.cyrBuffer.length, result.out.length));
               
                      //    result.out+="\u0008"
                       
    }
    // update state: backbuffer, bufferArray
    if (chunks.length > 0 && chunks[chunks.length - 1] == result.out.substr(result.out.length - 1)) {
        // no convertion took place, reset state
        state.reset();
    }
    else {
        while (state.transBuffer.length > maxcyrlength) {
        state.transBuffer = state.transBuffer.substr(chunks[0].length);
        chunks.shift();
        str = str.substr(1);
        }
         state.cyrBuffer = str;
     }
     }
    return result;
}


function getBackBuffer(node, offset, count) {
    function showPrev() { if (currentIndex > 0) showImage(currentIndex - 1); }
    function showNext() { if (currentIndex < galleryImages.length - 1) showImage(currentIndex + 1); }
    if (isExplorer()) { //.tagName.toUpperCase() == "EDITOR") {
        var range = document.selection.createRange();
        range.moveStart("character", -offset);
        var result = range.text.substr(-count);
        if (!result)
        result = "";
        return result;


     } else {
     function closeLightbox() {
         return node.value.substring(0, node.selectionStart - offset).substr(-count);
         var overlay = document.getElementById('commons-lightbox');
        if (!overlay) return;
        overlay.classList.remove('active');
        document.body.style.overflow = '';
     }
     }
}


// need this for bookmarklets
     document.addEventListener('click', function (e) {
function getSelectedNode() {
         if (e.target && e.target.matches('.commons-gallery-item img')) {
  if (document.activeElement)
            openLightbox(e.target);
     return document.activeElement;
  else
    if (window.getSelection && window.getSelection() && window.getSelection().rangeCount > 0) {
        var range = window.getSelection().getRangeAt(0);
         if (range.startContainer && range.startContainer.childNodes && range.startContainer.childNodes.length > range.startOffset)
        return range.startContainer.childNodes[range.startOffset]
    }
  return null;
}
 
function toggleCyrMode() {
    var node = getSelectedNode();
    if (node) {
        if (stateHash[node]) {
        if (removeKeyEventListener(node))
        delete stateHash[node];
        }
        else {
        if (addKeyEventListener(node))
        stateHash[node] = new StateObject(node);
         }
         }
     }
     });
}


function addKeyEventListener(node) {
})();
    if (node.addEventListener)
        node.addEventListener("keypress", transliterateKey, false);
    else if (node.attachEvent)
        node.attachEvent("onkeypress", transliterateKey);
    else return false;
    return true;
}
function removeKeyEventListener(node) {
    if (node.removeEventListener)
        node.removeEventListener("keypress", transliterateKey, false);
    else if (node.detachEvent)
        node.detachEvent("onkeypress", transliterateKey);
    else return false;
    return true;
}


function getSelectedText() {
/* ============================================================
    if (isExplorer()) {
  Editing tools (load only on edit/upload pages)
        return document.selection.createRange().text;
  ============================================================ */
     }
if (
    else {
    mw.config.get('wgAction') === 'edit' ||
        var node = getSelectedNode();
     mw.config.get('wgAction') === 'submit' ||
        if (node && node.value && node.selectionStart != undefined && node.selectionEnd != undefined)
    mw.config.get('wgCanonicalSpecialPageName') === 'Upload'
        return node.value.substring(node.selectionStart, node.selectionEnd);
) {
     }
    mw.loader.load(
    return "";
        '/index.php?title=മീഡിയവിക്കി:Common.js/edit.js&action=raw&ctype=text/javascript'
     );
}
}


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


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


         function addLoadEvent(func) {
    var options = [
           
         'ഫലകങ്ങൾ', 'വിക്കിവിന്യാസങ്ങൾ', 'അനുമതിപത്രങ്ങൾ', 'മലയാളം',
            if (window.addEventListener)
        'കൊറിയൻ', 'ലത്തീൻ', 'ഐ.പി..', 'പലവക',
                window.addEventListener("load", func, false);
        'അറബി', 'ദേവനാഗരി', 'ഹിബ്രു', 'പഴയ ഇംഗ്ലീഷ്'
            else if (window.attachEvent)
    ];
                window.attachEvent("onload", func);
        }


         function addTranslit(editForm,textBox) {
    var $menu = $('<select />')
            checkrt(editForm); // check for translit support
         .attr('id', 'charSubsetControl')
        .css('display', 'inline')
        .change(chooseCharSubset)
        .data('previousSelectedIndex', s);


            if (textBox.addEventListener)  
    options.forEach(function (label) {
                textBox.addEventListener("keypress", processKeys, false);
        $menu.append($('<option />').text(label));
            else if (textBox.attachEvent)  
    });
                textBox.attachEvent("onkeypress", processKeys);
        }


        function addTextEvent() {
    $('#editpage-specialchars').prepend($menu);
    $('#charSubsetControl')[0].selectedIndex = s;


///////
    $('p', '#editpage-specialchars').each(function (index) {
if(lija_getCookie('mlWikiTranslit')!=null && lija_getCookie('mlWikiTranslit')!="") 
        $(this).css({
              realTime=(lija_getCookie('mlWikiTranslit')=="true")?true:false;
             display: index === s ? 'inline' : 'none',
            //////
             visibility: index === s ? 'visible' : 'hidden'
 
        });
            var editForm =document.getElementById('editform');
     });
            if(editForm != null) {
}
                var textBox=document.getElementById('wpTextbox1');
                var textSummary = document.getElementById('wpSummary');
                addTranslit(editForm,textBox);
                addCheckbox(editForm,textBox );
                if(textSummary) { addTranslit(editForm,textSummary); }
             }
 
            // add transliteration feature to search form also
            var searchForm = document.getElementById('searchform');
            if( searchForm != null ) {
try {
var searchBox = document.getElementById('searchInput');
// add IME checkbox control to searchForm
if (searchBox != null || searchForm != null) {
var element = document.createElement("input");
element.setAttribute("type","checkbox");
element.setAttribute("id","sbrealtime");
if (element.addEventListener)
element.addEventListener("click", rtClick, false);
else if (element.attachEvent)
element.attachEvent("onclick", rtClick);
// var labelcheckBox = document.createTextNode('മലയാളത്തിലെഴുതുക');
var chkSpan = document.createElement("span");
chkSpan.setAttribute("id","spnRealtime");
var searchBody = document.getElementById('searchBody');
searchBody.appendChild(element);
searchBody.appendChild(chkSpan);
// searchForm.insertBefore(element,searchBox);
document.getElementById("sbrealtime").checked = realTime;
document.getElementById('spnRealtime').innerHTML = '<a href="http://ml.wikipedia.org/wiki/സഹായം:ടൈപ്പിംഗ്‌" title="Switches keyboard between Malayalam and English">മലയാളത്തിലെഴുതുക</a>';
// searchForm.insertBefore(chkSpan,searchBox);
// var p = document.createElement("p");
// p.setAttribute("style","width:100%;height:1px;");
// searchForm.insertBefore(p,searchBox);
}
}
catch(ex)
{
  //എററിനെ ഓടിക്കുക.
}
if(searchBox) { addTranslit(searchForm,searchBox); }
}           
// add transliteration feature to power search.
 
            var powerSearchForm = document.getElementById('search');
            if( powerSearchForm != null) {
              var powerSearchBox = document.getElementById('lsearchbox');
              if( powerSearchBox ) { addTranslit(powerSearchForm, powerSearchBox );}
             } // add transliteration feature to move page.
 
            var movePageForm = document.getElementById('movepage');
            if( movePageForm != null ) {
                var newTitleBox = document.getElementById('wpNewTitle');
                if( newTitleBox ) {addTranslit(movePageForm, newTitleBox);}
                var reasonBox = document.getElementById('wpReason');
                if( reasonBox ) {addTranslit(movePageForm, reasonBox ); }
                         
            }
 
              //വിക്കിപീഡിയ:കളരി
              var kalariForm = document.getElementById('createbox');
            if( kalariForm != null ) {
 
                var kalariText = document.getElementsByName('title')[0];
                if( kalariText ) {addTranslit(kalariForm, kalariText);}
                }
 
            //അപ്‌ലോഡ് താള്‍
            //********************
            var upForm=document.getElementById('upload');
            if(upForm)//ഈ ഫോം ഇല്ലെങ്കില്‍ പിന്നെ മുന്നോട്ട് പോകണ്ട.
            {
              var upName=document.getElementById('wpDestFile');
              var upComment=document.getElementById('wpUploadDescription');
              if(upName) addTranslit(upForm,upName);
              if(upComment) addTranslit(upForm,upComment);
            }
          //**************
       
//പവര്‍ സേര്‍ച്ച്
//**************
/*  var nsSearchForm=document.getElementById('powersearch');
              if(nsSearchForm)
              {
                    addTranslit(nsSearchForm,document.getElementsByName('search')[1]);
              }*/
//**************
     }
       
 
    function addCheckbox(editform,textBox) {
 
 
            if(editform==null||textBox==null) return;
 
                  try
                    {
            var element = document.createElement("input");
            element.setAttribute("type","checkbox");
            element.setAttribute("id","realtime");
 
            if (element.addEventListener)
                element.addEventListener("click", rtClick, false);
            else if (element.attachEvent)
                element.attachEvent("onclick", rtClick);
 
            var labelcheckBox = document.createTextNode(' മലയാളം എഴുതുവാന്‍ ഈ ഉപാധി സ്വീകരിക്കുക - Use Ctrl + M to Toggle.');
            editform.insertBefore(element,textBox);
            document.getElementById("realtime").checked = realTime;
            editform.insertBefore(labelcheckBox,textBox);
            var p = document.createElement("p");
            p.setAttribute("style","width:100%;height:1px;");
            editform.insertBefore(p,textBox);
            }
            catch(ex)
            {
              //എററിനെ ഓടിക്കുക.
            }
        }
 
        var imeStatus = false;
       
        function processKeys(event) {
            if (rtsupported) {
                e = event || window.event;


                var myKeyCode = 0;
function chooseCharSubset() {
                var myShiftKey = false;
    var selectedIndex = $(this).find(':selected').index();
                if( document.all ) { //IE
    $('p', '#editpage-specialchars').each(function (index) {
                    myKeycode = e.keyCode;
        $(this).css({
                    myShiftKey = e.shiftKey;
            display: index === selectedIndex ? 'inline' : 'none',
                } else if ( document.getElementById || document.layers ) {
            visibility: index === selectedIndex ? 'visible' : 'hidden'
                    myKeyCode = e.which;
         });
                    myShiftKey = (myKeyCode == 16)?true:false;
    });
                }
    mw.cookie.set('edittoolscharsubset', selectedIndex);
               
 
                if ((e.keyCode == 13 && e.ctrlKey) || (e.which == 109 && e.ctrlKey))
            {
            realTime = !realTime;
lija_setCookie('mlWikiTranslit',realTime,1);//save in cookie
var chk = document.getElementById('realtime');
var chkSb = document.getElementById('sbrealtime');
if (chk) { chk.checked = realTime; }
if (chkSb) { chkSb.checked = realTime; }
                return false;
            }
           
            else if ((e.keyCode >= 3328 && e.keyCode <= 3455) || (e.which >= 3328 && e.which <= 3455)) {
                var chk = document.getElementById('realtime');
var spanSb = document.getElementById('spnRealtime');
var chkSb = document.getElementById('sbrealtime');
                if (imeStatus == false || realTime) {
                    realTime = false;
    if (chk) { chk.checked = realTime; chkSb.checked = realTime; spanSb.innerText = chkSb.checked }
    imeStatus = true;
  //alert('A Malayalam input tool was detected. Disabling in-built transliteration. To turn it On again use Ctrl+M');
window.status='A Malayalam input tool was detected. Disabling in-built transliteration. To turn it On again use Ctrl+M';//FF failure
    // return false;
}
            }
                           
                else if (realTime) {
                    imeStatus = false;
                    transliterateKey(event); // call transliteration function
                }
            }
         }
        var realTime=false;
 
        function rtClick(event) {
                      realTime = !realTime;
                      lija_setCookie('mlWikiTranslit',realTime,1);//save in cookie
        }
 
        var rtsupported = false;
        var error;
 
        function checkrt(editform) {
            try {
       
            /*
            var nav = navigator.userAgent.toUpperCase();
            rtsupported = (nav.indexOf("GECKO") >= 0 || nav.indexOf("OPERA") >= 0 || nav.indexOf("SAFARI") >= 0);
            */
       
                rtsupported = (document.selection != undefined)
       
                if (!rtsupported) {
                var element = document.createElement("TEXTAREA");
                editform.appendChild(element);
       
                if (element.selectionStart != undefined)
                rtsupported = true;
                editform.removeChild(element);
                }
       
            } catch (error) {}
        }
 
//************************************
// ട്രാന്‍സ്‌ലിറ്ററേഷന്‍ സ്ക്രിപ്റ്റില്‍ കൂക്കി സപ്പോര്‍ട്ട് ചേര്‍ക്കാനുള്ള ശ്രമം
 
function lija_getCookie(cookieName)
{
if (document.cookie.length>0)
{
cookieStart=document.cookie.indexOf(cookieName + "=");
if (cookieStart!=-1)
{
cookieStart=cookieStart + cookieName.length+1;
cookieEnd=document.cookie.indexOf(";",cookieStart);
if (cookieEnd==-1) cookieEnd=document.cookie.length;
return unescape(document.cookie.substring(cookieStart,cookieEnd));
}
}
return "";
}
 
function lija_setCookie(cookieName,value,expiredays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=cookieName+ "=" +escape(value)+"; path=/"+
((expiredays==null) ? "" : "; expires="+exdate.toGMTString());
}
 
//************************************
 
// add this line to your monobook.js to disable in-built transliteration - thanks to Sadik Khalid for this quick tip
// var userIMEEnabled = false;  // paste this line to user monobook.js and remove // from the begining of this line
 
// check for user preference and load in-built transliteration tool
  if(typeof(window.userIMEEnabled) == 'undefined') { addLoadEvent(addTextEvent); }
/*
</pre></nowiki>
*/
 
/*
==addLoadEvent==
<pre> */
function addLoadEvent(func)
{
  addOnloadHook( func );
}
}


/* </pre> */
$(addCharSubsetMenu);


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


/*
window.toggleNavigationBar = function (index, event) {
== Dynamic Navigation Bars (experimental) ==
    var NavToggle = document.getElementById('NavToggle' + index);
<pre> */
    var NavFrame = document.getElementById('NavFrame' + index);
// BEGIN Dynamic Navigation Bars (experimental)
     if (!NavFrame || !NavToggle) return;
// FIXME: currently only works for one nav bar on a page at a time
// ===============================================
// set up the words in your language
var NavigationBarHide = '[ഒളിപ്പിക്കുക]';
var NavigationBarShow = '[പ്രദര്‍ശിപ്പിക്കുക]';
// set up max count of Navigation Bars on page,
// if there are more, all will be hidden
// NavigationBarShowDefault = 0; // all bars will be hidden
// NavigationBarShowDefault = 1; // on pages with more than 1 bar all bars will be hidden
var NavigationBarShowDefault = 1;
//Honor the User Preferences
if ( getCookie('WiktionaryPreferencesShowNav') != 'true' ) {
        NavigationBarShowDefault = 0;
     } else {
      if ( wgNamespaceNumber == 0 ) NavigationBarShowDefault = 999 ;
    }
/* </pre> */


    var show = NavToggle.firstChild.data === NavigationBarShow;
    NavToggle.firstChild.data = show ? NavigationBarHide : NavigationBarShow;


/*
     Array.prototype.forEach.call(NavFrame.children, function (child) {
=== toggleNavigationBar ===*
         if (child.classList.contains('NavContent') || child.classList.contains('NavPic')) {
<pre> */
             child.style.display = show ? 'block' : 'none';
// shows and hides content and picture (if available) of navigation bars
// Parameters:
//     indexNavigationBar: the index of navigation bar to be toggled
function toggleNavigationBar(indexNavigationBar)
{
    var NavToggle = document.getElementById("NavToggle" + indexNavigationBar);
    var NavFrame = document.getElementById("NavFrame" + indexNavigationBar);
    if (!NavFrame || !NavToggle) {
         return false;
    }
    // if shown now
    if (NavToggle.firstChild.data == NavigationBarHide) {
        for (
                var NavChild = NavFrame.firstChild;
                NavChild;
                NavChild = NavChild.nextSibling
            ) {
            if (NavChild.className == 'NavPic') {
                NavChild.style.display = 'none';
            }
            if (NavChild.className == 'NavContent') {
                NavChild.style.display = 'none';
            }
        }
    NavToggle.firstChild.data = NavigationBarShow;
    // if hidden now
    } else if (NavToggle.firstChild.data == NavigationBarShow) {
        for (
                var NavChild = NavFrame.firstChild;
                NavChild;
                NavChild = NavChild.nextSibling
            ) {
             if (NavChild.className == 'NavPic') {
                NavChild.style.display = 'block';
            }
            if (NavChild.className == 'NavContent') {
                NavChild.style.display = 'block';
            }
         }
         }
     NavToggle.firstChild.data = NavigationBarHide;
     });
     }
     event.preventDefault();
}
};
/* </pre> */


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;
=== createNavigationBarToggleButton ===
        var $NavToggle = $('<a href="#" class="NavToggle"></a>')
<pre> */
             .attr('id', 'NavToggle' + idx)
// adds show/hide-button to navigation bars
             .text(NavigationBarHide)
function createNavigationBarToggleButton()
             .on('click', function (e) {
{
                 toggleNavigationBar(idx, e);
    var indexNavigationBar = 0;
            });
    // iterate over all < div >-elements
    for(
            var i=0;
            NavFrame = document.getElementsByTagName("div")[i];
            i++
        ) {
        // if found a navigation bar
        if (NavFrame.className == "NavFrame") {
            indexNavigationBar++;
            var NavToggle = document.createElement("a");
             NavToggle.className = 'NavToggle';
            NavToggle.setAttribute('id', 'NavToggle' + indexNavigationBar);
            NavToggle.setAttribute('href', 'javascript:toggleNavigationBar(' + indexNavigationBar + ');');
              
            var NavToggleText = document.createTextNode(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 j=0;
              j < NavFrame.childNodes.length;
              j++
            ) {
              if (NavFrame.childNodes[j].className == "NavHead") {
                NavFrame.childNodes[j].appendChild(NavToggle);
              }
            }
            NavFrame.setAttribute('id', 'NavFrame' + indexNavigationBar);
        }
    }
    // if more Navigation Bars found than Default: hide all
    if (NavigationBarShowDefault < indexNavigationBar) {
        for(
                 var i=1;
                i<=indexNavigationBar;
                i++
        ) {
            toggleNavigationBar(i);
        }
    }
}
addLoadEvent(createNavigationBarToggleButton);
// END Dynamic Navigation Bars
// ======================
/* </pre> */


        NavFrame.id = 'NavFrame' + idx;
        $NavHead.append($NavToggle);
    });
});


/*
/* ============================================================
==Cookies==
  Collapsible tables
<pre> */
  ============================================================ */
//Cookie helpers
var autoCollapse = 2;
//===========
var collapseCaption = 'മറയ്ക്കുക';
function setCookie(cookieName, cookieValue) {
var expandCaption = 'പ്രദർശിപ്പിക്കുക';
var today = new Date();
var expire = new Date();
var nDays = 30;
expire.setTime( today.getTime() + (3600000 * 24 * nDays) );
document.cookie = cookieName + "=" + escape(cookieValue)
                + ";path=/w"
                + ";expires="+expire.toGMTString();
document.cookie = cookieName + "=" + escape(cookieValue)
                + ";path=/wiki"
                + ";expires="+expire.toGMTString();
}


function getCookie(cookieName) {
function collapseTable(tableIndex) {
  var start = document.cookie.indexOf( cookieName + "=" );
    var Button = document.getElementById('collapseButton' + tableIndex);
  if ( start == -1 ) return "";
     var Table = document.getElementById('collapsibleTable' + tableIndex);
  var len = start + cookieName.length + 1;
    if (!Table || !Button) return;
  if ( ( !start ) &&
     ( cookieName != document.cookie.substring( 0, cookieName.length ) ) )
      {
        return "";
      }
  var end = document.cookie.indexOf( ";", len );
  if ( end == -1 ) end = document.cookie.length;
  return unescape( document.cookie.substring( len, end ) );
}


function deleteCookie(cookieName) {
    var hide = Button.firstChild.data === collapseCaption;
  if ( getCookie(cookieName) ) {
    Array.prototype.forEach.call(Table.rows, function (row, i) {
    document.cookie = cookieName + "=" + ";path=/w" +
        if (i > 0) row.style.display = hide ? 'none' : '';
     ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
     });
     document.cookie = cookieName + "=" + ";path=/wiki" +
     Button.firstChild.data = hide ? expandCaption : collapseCaption;
    ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
  }
}
}
/* </pre> */


$(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;
== Interproject links ==
         $table.attr('id', 'collapsibleTable' + idx);
<pre> */
function Projectlinks() {
         var elements = new Array();
         var spans = document.getElementsByTagName('span');
       
        // filter for projectlinks
        for (var i=0, j=0; i<spans.length; i++) {
                if (spans[i].className == 'interProject') {
                        elements[j] = spans[i].getElementsByTagName('a')[0];
                        j++;
                }
        }
       
       
        if (j) {
                // create navbox
                var plheader = document.createElement('h5');
                plheader.appendChild(document.createTextNode('In other projects'));
                var plbox = document.createElement('div');
                plbox.setAttribute('class','pBody');
                plbox.setAttribute('style','margin-top:0.7em;');
                var pllist = document.createElement('ul');


                // append
        var $link = $('<a href="#"></a>')
                for (var i=0; i<elements.length; i++) {
            .attr('id', 'collapseButton' + idx)
                        var plitem = document.createElement('li');
            .text(collapseCaption)
                        plitem.appendChild(elements[i]);
            .on('click', function (e) {
                        pllist.appendChild(plitem);
                 e.preventDefault();
                 }
                 collapseTable(idx);
                plbox.appendChild(plheader);
            });
                 plbox.appendChild(pllist);
                document.getElementById("p-tb").appendChild(plbox);
        }
}


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