User:Alex Smotrov/createEditTools

From Wikipedia, the free encyclopedia

//

//basic set of tags and symbols
var charinsert = 'Insert: –—…°≈≠≤≥±−×÷←→·§ _ _ Sign_your_username: ~~~~+ ___ ' +
'Wiki_markup: {{+}} |+ [+]  [[+]] [[Category:+]] #REDIRECT_[[+]]  <s>+</s> <sup>+</sup> <sub>+</sub> <code>+</code> <blockquote>+</blockquote> <ref>+</ref> {{Reflist}}+ <references/>+ <includeonly>+</includeonly> <noinclude>+</noinclude> {{DEFAULTSORT:+}} <nowiki>+ __ ' +
'Symbols: ~|¡¿†‡↔↑↓•¶ #¹²³½⅓⅔¼¾⅛⅜⅝⅞∞ ‘“’” ¢$€₦£¥ ♠♣♥♦ __ ';


function createEditTools(){

        var box = document.getElementById('editpage-specialchars');
        if (!box) return;

        //additional sets of symbols
        if (!window.noAdditionalChars){
        charinsert += 'Characters: ÁáĆćÉéÍíĹĺŃńÓóŔশÚúÝýŹź ÀàÈèÌìÒòÙù ÂâĈĉÊêĜĝĤĥÎîĴĵÔôŜŝÛûŴŵŶŷ ÄäËëÏïÖöÜüŸÿ ß ÃãẼẽĨĩÑñÕõŨũỸỹ ÇçĢģĶķĻļŅņŖŗŞşŢţ Đđ Ůů ǍǎČčĎďĚěǏǐĽľŇňǑǒŘřŠšŤťǓǔŽž ĀāĒēĪīŌōŪūȲȳǢǣ ǖǘǚǜ ĂăĔĕĞğĬĭŎŏŬŭ ĊċĖėĠġİıŻż ĄąĘęĮįǪǫŲų ḌḍḤḥḶḷḸḹṂṃṆṇṚṛṜṝṢṣṬṭ Łł ŐőŰű Ŀŀ Ħħ ÐðÞþ Œœ ÆæØøÅå Əə _• {{Unicode|+}} __ ';
        charinsert += 'Greek: ΆάΈέΉήΊίΌόΎύΏώ ΑαΒβΓγΔδ ΕεΖζΗηΘθ ΙιΚκΛλΜμ ΝνΞξΟοΠπ ΡρΣσςΤτΥυ ΦφΧχΨψΩω _• {{Polytonic|+}} __ ';
        charinsert += 'Cyrillic: АаБбВвГг ҐґЃѓДдЂђ ЕеЁёЄєЖж ЗзЅѕИиІі ЇїЙйЈјКк ЌќЛлЉљМм НнЊњОоПп РрСсТтЋћ УуЎўФфХх ЦцЧчЏџШш ЩщЪъЫыЬь ЭэЮюЯя __ ';  
        charinsert += 'IPA: _ t̪+ d̪+ ʈɖɟɡɢʡʔ ɸʃʒɕʑʂʐʝɣʁʕʜʢɦ ɱɳɲŋɴ ʋɹɻɰ ʙʀɾɽ ɫɬɮɺɭʎʟ ɥʍɧ ɓɗʄɠʛ ʘǀǃǂǁ ɨʉɯ ɪʏʊ ɘɵɤ əɚ ɛɜɝɞʌɔ ɐɶɑɒ ʰʷʲˠˤⁿˡ ˈˌːˑ̪ _•  {{IPA|+}} __ '
        }

        //remove current Edittools -  for demonstration only 
        while (box.firstChild) box.removeChild(box.firstChild);
        
        var tokens, i, token, n
        var paragraph = document.createElement('small');
        tokens = charinsert.split(' ');
        for (i in tokens) {
                token = tokens[i];
                n = token.indexOf('+');
                if (n >= 0){ //a tag 
                        addInsLink(paragraph, token.substring(0,n), token.substring(n+1));
                        addnbsp(paragraph);     
                }else if (token == '_')
                        addnbsp(paragraph);     
                else if (token == '__')
                        paragraph.appendChild(document.createElement('br'))
                else if (token == '___')
                        paragraph.appendChild(document.createElement('hr'))
                else if (token.charAt(token.length-1) == ':')  // : at the end means just text
                        addBoldText(paragraph, token)
                else if (token.charAt(0) == '_')  //_ in the beginning also means text
                        addBoldText(paragraph, token.substring(1))
                else{ //a string of  characters
                                for (var i=0; i < token.length; i++)
                                        addInsLink(paragraph, token.charAt(i), '');
                                addnbsp(paragraph);     
                }                       
                paragraph.appendChild(document.createTextNode(' '));
        }
        box.appendChild(paragraph);
}

function addInsLink(parent, tagOpen, tagClose){
        tagOpen = tagOpen.replace(/_/g,' ');
        var a = document.createElement('a');
        a.appendChild(document.createTextNode(tagOpen + tagClose));
        a.href = "javascript:insertTags('" + tagOpen + "','" + tagClose + "','')";
        parent.appendChild(a);
        parent.appendChild(document.createTextNode(' '));
}       

function addBoldText(parent, text){
        var b = document.createElement('b'); 
        b.appendChild(document.createTextNode(text.replace(/_/g,' ')));
        parent.appendChild(b);
        parent.appendChild(document.createTextNode(' '));
}       

function addnbsp(parent){
        parent.appendChild(document.createTextNode(' \u00a0 '));
}

addOnloadHook(createEditTools);

if (document.editform) createEditTools(); //for demonstration only

//</nowiki>