MediaWiki:JSScripts/TableUnicode

Un livre de Wikilivres.

/*

Ce script ajoute un bouton pour l'insertion de caractères Unicode. Ce bouton ouvre une nouvelle fenêtre affichant les caractères Unicode par page de 256. Un clic sur un caractère l'insère dans la fenêtre d'édition à la position du curseur.

Utilisation

Ajoutez la ligne suivante dans votre monobook.js :

obtenir('TableUnicode');

Source

*/

/**
 * Retourne un caractère unicode.
 * @author: fr:user:DavidL
 * @version: 0.1
 */
function char(n)
{
    if (n<65536) return String.fromCharCode(n);
    n-=65536;
    return String.fromCharCode(0xD800+(n>>10),0xDC00+(n&0x3FF));
}

/**
 * Table unicode
 * @author: fr:user:DavidL
 * @version: 0.1
 */
function generateChar(numChar) {
    insertTags(char(numChar),'',''); 
}

/**
 * Ouvre une fenêtre affichant la table des caractères Unicode. 
 * Un clic sur le caractère l'insère dans la fenêtre d'édition.
 * @author: fr:user:DavidL
 * @version: 0.1
 */
function popupUnicode() {
    var popup = window.open('','name','height=692,width=550');

    popup.document.write('<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" />'+
        '<title>Table Unicode</title><script type="text\/javascript">'+
        '\nwgBreakFrames=1;\nvar stylepath = "'+stylepath+'";\nvar wgContentLanguage = "fr";\n</script>'+
        '<script type="text\/javascript" src="'+stylepath+'\/common\/wikibits.js"><!-- wikibits js --><\/script>'+
        '<style type="text\/css" media="screen,projection">/*<![CDATA[*/ @import "'+stylepath+'\/monobook\/main.css"; /*]]>*/<\/style>'+
        '<style type="text\/css">'+
        '\nbody, td { font-size: 12pt; }'+
        '\nul, li { margin-top: 0;margin-bottom:0; }'+
        '\ntable.uc { border-collapse:collapse; }'+
        '\ntable.uc td { cursor: default;text-align:center; '+
        'font-family: Arial; width:30px; height:30px; border: solid 1px black; }'+
        '\ntable.uc td:hover { background-color: #aaaaff; color:white; }'+
        '\ntable.nc td { vertical-align:top; }'+
        '\n.npg { text-align:center;width:100px; }'+
        '\n.sp { width:100px; }'+
        '\n.char { width:200px; height:100px; font-size:96pt; '+
        'border: solid 1px black;text-align:center; }'+
        '<\/style><script type="text\/javascript">\n'+

        'var uranges=['+ // http://www.unicode.org/Public/UNIDATA/Blocks.txt
        '[0,127,"Basic Latin"],'+
        '[128,255,"Latin-1 Supplement"],'+
        '[256,383,"Latin Extended-A"],'+
        '[384,591,"Latin Extended-B"],'+
        '[592,687,"IPA Extensions"],'+
        '[688,767,"Spacing Modifier Letters"],'+
        '[768,879,"Combining Diacritical Marks"],'+
        '[880,1023,"Greek and Coptic"],'+
        '[1024,1279,"Cyrillic"],'+
        '[1280,1327,"Cyrillic Supplement"],'+
        '[1328,1423,"Armenian"],'+
        '[1424,1535,"Hebrew"],'+
        '[1536,1791,"Arabic"],'+
        '[1792,1871,"Syriac"],'+
        '[1872,1919,"Arabic Supplement"],'+
        '[1920,1983,"Thaana"],'+
        '[1984,2047,"NKo"],'+
        '[2304,2431,"Devanagari"],'+
        '[2432,2559,"Bengali"],'+
        '[2560,2687,"Gurmukhi"],'+
        '[2688,2815,"Gujarati"],'+
        '[2816,2943,"Oriya"],'+
        '[2944,3071,"Tamil"],'+
        '[3072,3199,"Telugu"],'+
        '[3200,3327,"Kannada"],'+
        '[3328,3455,"Malayalam"],'+
        '[3456,3583,"Sinhala"],'+
        '[3584,3711,"Thai"],'+
        '[3712,3839,"Lao"],'+
        '[3840,4095,"Tibetan"],'+
        '[4096,4255,"Myanmar"],'+
        '[4256,4351,"Georgian"],'+
        '[4352,4607,"Hangul Jamo"],'+
        '[4608,4991,"Ethiopic"],'+
        '[4992,5023,"Ethiopic Supplement"],'+
        '[5024,5119,"Cherokee"],'+
        '[5120,5759,"Unified Canadian Aboriginal Syllabics"],'+
        '[5760,5791,"Ogham"],'+
        '[5792,5887,"Runic"],'+
        '[5888,5919,"Tagalog"],'+
        '[5920,5951,"Hanunoo"],'+
        '[5952,5983,"Buhid"],'+
        '[5984,6015,"Tagbanwa"],'+
        '[6016,6143,"Khmer"],'+
        '[6144,6319,"Mongolian"],'+
        '[6400,6479,"Limbu"],'+
        '[6480,6527,"Tai Le"],'+
        '[6528,6623,"New Tai Lue"],'+
        '[6624,6655,"Khmer Symbols"],'+
        '[6656,6687,"Buginese"],'+
        '[6912,7039,"Balinese"],'+
        '[7040,7103,"Sundanese"],'+
        '[7168,7247,"Lepcha"],'+
        '[7248,7295,"Ol Chiki"],'+
        '[7424,7551,"Phonetic Extensions"],'+
        '[7552,7615,"Phonetic Extensions Supplement"],'+
        '[7616,7679,"Combining Diacritical Marks Supplement"],'+
        '[7680,7935,"Latin Extended Additional"],'+
        '[7936,8191,"Greek Extended"],'+
        '[8192,8303,"General Punctuation"],'+
        '[8304,8351,"Superscripts and Subscripts"],'+
        '[8352,8399,"Currency Symbols"],'+
        '[8400,8447,"Combining Diacritical Marks for Symbols"],'+
        '[8448,8527,"Letterlike Symbols"],'+
        '[8528,8591,"Number Forms"],'+
        '[8592,8703,"Arrows"],'+
        '[8704,8959,"Mathematical Operators"],'+
        '[8960,9215,"Miscellaneous Technical"],'+
        '[9216,9279,"Control Pictures"],'+
        '[9280,9311,"Optical Character Recognition"],'+
        '[9312,9471,"Enclosed Alphanumerics"],'+
        '[9472,9599,"Box Drawing"],'+
        '[9600,9631,"Block Elements"],'+
        '[9632,9727,"Geometric Shapes"],'+
        '[9728,9983,"Miscellaneous Symbols"],'+
        '[9984,10175,"Dingbats"],'+
        '[10176,10223,"Miscellaneous Mathematical Symbols-A"],'+
        '[10224,10239,"Supplemental Arrows-A"],'+
        '[10240,10495,"Braille Patterns"],'+
        '[10496,10623,"Supplemental Arrows-B"],'+
        '[10624,10751,"Miscellaneous Mathematical Symbols-B"],'+
        '[10752,11007,"Supplemental Mathematical Operators"],'+
        '[11008,11263,"Miscellaneous Symbols and Arrows"],'+
        '[11264,11359,"Glagolitic"],'+
        '[11360,11391,"Latin Extended-C"],'+
        '[11392,11519,"Coptic"],'+
        '[11520,11567,"Georgian Supplement"],'+
        '[11568,11647,"Tifinagh"],'+
        '[11648,11743,"Ethiopic Extended"],'+
        '[11744,11775,"Cyrillic Extended-A"],'+
        '[11776,11903,"Supplemental Punctuation"],'+
        '[11904,12031,"CJK Radicals Supplement"],'+
        '[12032,12255,"Kangxi Radicals"],'+
        '[12272,12287,"Ideographic Description Characters"],'+
        '[12288,12351,"CJK Symbols and Punctuation"],'+
        '[12352,12447,"Hiragana"],'+
        '[12448,12543,"Katakana"],'+
        '[12544,12591,"Bopomofo"],'+
        '[12592,12687,"Hangul Compatibility Jamo"],'+
        '[12688,12703,"Kanbun"],'+
        '[12704,12735,"Bopomofo Extended"],'+
        '[12736,12783,"CJK Strokes"],'+
        '[12784,12799,"Katakana Phonetic Extensions"],'+
        '[12800,13055,"Enclosed CJK Letters and Months"],'+
        '[13056,13311,"CJK Compatibility"],'+
        '[13312,19903,"CJK Unified Ideographs Extension A"],'+
        '[19904,19967,"Yijing Hexagram Symbols"],'+
        '[19968,40959,"CJK Unified Ideographs"],'+
        '[40960,42127,"Yi Syllables"],'+
        '[42128,42191,"Yi Radicals"],'+
        '[42240,42559,"Vai"],'+
        '[42560,42655,"Cyrillic Extended-B"],'+
        '[42752,42783,"Modifier Tone Letters"],'+
        '[42784,43007,"Latin Extended-D"],'+
        '[43008,43055,"Syloti Nagri"],'+
        '[43072,43135,"Phags-pa"],'+
        '[43136,43231,"Saurashtra"],'+
        '[43264,43311,"Kayah Li"],'+
        '[43312,43359,"Rejang"],'+
        '[43520,43615,"Cham"],'+
        '[44032,55215,"Hangul Syllables"],'+
        '[55296,56191,"High Surrogates"],'+
        '[56192,56319,"High Private Use Surrogates"],'+
        '[56320,57343,"Low Surrogates"],'+
        '[57344,63743,"Private Use Area"],'+
        '[63744,64255,"CJK Compatibility Ideographs"],'+
        '[64256,64335,"Alphabetic Presentation Forms"],'+
        '[64336,65023,"Arabic Presentation Forms-A"],'+
        '[65024,65039,"Variation Selectors"],'+
        '[65040,65055,"Vertical Forms"],'+
        '[65056,65071,"Combining Half Marks"],'+
        '[65072,65103,"CJK Compatibility Forms"],'+
        '[65104,65135,"Small Form Variants"],'+
        '[65136,65279,"Arabic Presentation Forms-B"],'+
        '[65280,65519,"Halfwidth and Fullwidth Forms"],'+
        '[65520,65535,"Specials"],'+
        '[65536,65663,"Linear B Syllabary"],'+
        '[65664,65791,"Linear B Ideograms"],'+
        '[65792,65855,"Aegean Numbers"],'+
        '[65856,65935,"Ancient Greek Numbers"],'+
        '[65936,65999,"Ancient Symbols"],'+
        '[66000,66047,"Phaistos Disc"],'+
        '[66176,66207,"Lycian"],'+
        '[66208,66271,"Carian"],'+
        '[66304,66351,"Old Italic"],'+
        '[66352,66383,"Gothic"],'+
        '[66432,66463,"Ugaritic"],'+
        '[66464,66527,"Old Persian"],'+
        '[66560,66639,"Deseret"],'+
        '[66640,66687,"Shavian"],'+
        '[66688,66735,"Osmanya"],'+
        '[67584,67647,"Cypriot Syllabary"],'+
        '[67840,67871,"Phoenician"],'+
        '[67872,67903,"Lydian"],'+
        '[68096,68191,"Kharoshthi"],'+
        '[73728,74751,"Cuneiform"],'+
        '[74752,74879,"Cuneiform Numbers and Punctuation"],'+
        '[118784,119039,"Byzantine Musical Symbols"],'+
        '[119040,119295,"Musical Symbols"],'+
        '[119296,119375,"Ancient Greek Musical Notation"],'+
        '[119552,119647,"Tai Xuan Jing Symbols"],'+
        '[119648,119679,"Counting Rod Numerals"],'+
        '[119808,120831,"Mathematical Alphanumeric Symbols"],'+
        '[126976,127023,"Mahjong Tiles"],'+
        '[127024,127135,"Domino Tiles"],'+
        '[131072,173791,"CJK Unified Ideographs Extension B"],'+
        '[194560,195103,"CJK Compatibility Ideographs Supplement"],'+
        '[917504,917631,"Tags"],'+
        '[917760,917999,"Variation Selectors Supplement"],'+
        '[983040,1048575,"Supplementary Private Use Area-A"],'+
        '[1048576,1114111,"Supplementary Private Use Area-B"]'+

        '];\nfunction findUChar(num)'+
        '{for(var i=0;i<uranges.length;i++) if ((num>=uranges[i][0])&&(num<=uranges[i][1]))'+
        ' return i;\nreturn -1;}\nfunction showUR(num){var i=findUChar(num);'+
        'if (i>=0) document.getElementById("_urange").selectedIndex=1+i;}'+
        '\nfunction putchar(n){window.opener.generateChar(n);}'+
        '\nvar hexch="0123456789ABCDEF"\nfunction hchar(n){ return '+
        'hexch.charAt((n>>20)&15)+hexch.charAt((n>>16)&15)+hexch.charAt((n>>12)&15)+'+
        'hexch.charAt((n>>8)&15)+hexch.charAt((n>>4)&15)+hexch.charAt(n&15); }'+
        '\nfunction char(n){ if (n<65536) return String.fromCharCode(n);'+
        'n-=65536;return String.fromCharCode(0xD800+(n>>10),0xDC00+(n&0x3FF)); }'+
        '\nfunction zoomchar(n)'+
        '{document.getElementById("nchar").innerHTML=char(n);'+
        'document.getElementById("numchar").innerHTML=hchar(n);showUR(n);}'+
        '\nvar offset = 0;'+
        '\nfunction loadPage(ofs){if (ofs<0) ofs=0;if (ofs>1113856) ofs=1113856;'+
        '\nhh = document.getElementsByTagName("td");offset=ofs;'+
        '\ndocument.getElementById("npage").innerHTML=hchar(ofs)+"-"+hchar(ofs+255);'+
        '\nfor(var el=0;(el<hh.length)&&(el<256);el++){'+
        '\nvar n = hh.item(el);var ttd=document.createElement("td");'+
        '\nttd.setAttribute("onmouseover","zoomchar("+(ofs+el)+");");'+
        '\nttd.setAttribute("onclick","putchar("+(ofs+el)+");");'+
        (document.all?'\neval("ttd.onclick=function(){putchar("+(ofs+el)+");return false;}");':'')+
        '\nttd.appendChild( document.createTextNode( char(ofs+el) ) );'+
        '\nvar p=n.parentNode;p.replaceChild(ttd,n);}}'+
        '\nfunction showPage(dp){loadPage(offset+dp*256);}'+
        '\nfunction goPage(p){loadPage(p*256);return false;}'+
        '\nfunction goUBlock(){var i=document.getElementById("_urange").selectedIndex;'+
        '\nif (i>0) goPage(uranges[i-1][0]>>8);}'+
        '\nfunction getUnicodeBlocks(){'+
        'var res="Bloc de caractères Unicode :<br />'+
        '<select id=\\"_urange\\" name=\\"urange\\" onchange=\\"goUBlock();\\">'+
        '<option value=\\"\\" style=\\"font-weight:bold;\\">Select the Unicode Block ...<\/option>";'+
        '\nfor(var i=0;i<uranges.length;i++) res+="<option value=\\""+uranges[i][0]+"\\">"'+
        '+hchar(uranges[i][0])+"-"+hchar(uranges[i][1])+" : "+uranges[i][2]+"<\/option>";'+
        '\ndocument.getElementById("_ub").innerHTML=res+"<\/select><p />'+
        'Cliquez une case pour insérer le caractère.";}'+
        '\nfunction initAll(){showPage(0);getUnicodeBlocks();}'+
    '\n<\/script><\/head><body onload="initAll();"><table class="uc">'+
        '<tr><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td></tr>'+
        '<tr><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td></tr>'+
        '<tr><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td></tr>'+
        '<tr><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td></tr>'+
        '<tr><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td></tr>'+
        '<tr><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td></tr>'+
        '<tr><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td></tr>'+
        '<tr><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td></tr>'+
        '<tr><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td></tr>'+
        '<tr><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td></tr>'+
        '<tr><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td></tr>'+
        '<tr><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td></tr>'+
        '<tr><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td></tr>'+
        '<tr><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td></tr>'+
        '<tr><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td></tr>'+
        '<tr><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td></tr>'+
    '<\/table><hr><form name="nav"><table class="nc"><tr>'+
    '<td><nobr><input type="button" value=" &lt;&lt;&lt; " onclick="showPage(-256);"><\/input>'+
    '<input type="button" value=" &lt;&lt; " onclick="showPage(-16);"><\/input>'+
    '<input type="button" value=" &lt; " onclick="showPage(-1);"><\/input></nobr><\/td>'+
    '<td class="npg"><span id="npage">0<\/span><\/td>'+
    '<td><nobr><input type="button" value=" &gt; " onclick="showPage(1);"><\/input>'+
    '<input type="button" value=" &gt;&gt; " onclick="showPage(16);"><\/input>'+
    '<input type="button" value=" &gt;&gt;&gt; " onclick="showPage(256);"><\/input></nobr><\/td>'+
    '<td class="sp">&nbsp;</td><td rowspan="2" class="char"><span id="nchar">.<\/span><\/td>'+
    '<\/tr><tr><td colspan="4" rowspan="2"><span id=\"_ub\">'+
    '<i>Chargement blocs Unicode en cours ...</i><ul>'+
    '<li><a href="javascript:void(0)" onclick="return goPage(0);">Ascii</a>'+
    '<li><a href="javascript:void(0)" onclick="return goPage(33);">Flèches</a>'+
    '<li><a href="javascript:void(0)" onclick="return goPage(37);">Graphiques 1</a>'+
    '<li><a href="javascript:void(0)" onclick="return goPage(224);">Graphiques 2</a>'+
    '<li><a href="javascript:void(0)" onclick="return goPage(248);">Graphiques 3</a>'+
    '<\/ul><\/span><\/td><\/tr><tr><td><span id="numchar">.<\/span><\/td><\/tr>'+
    '<\/table><\/form><\/body><\/html>');
    popup.document.close();
}

//Ressemble à la fonction de /skins-1.5/commons/wikibits.js pour insérer un autre lien que insertTags
function boutonUnicode() {
    var toolbar = document.getElementById('toolbar');
    if (!toolbar) return false;

    var textbox = document.getElementById('wpTextbox1');

    if (!textbox) return false;
 
    if (!document.selection && textbox.selectionStart == null) return false;
 
    var image = document.createElement("img");
    image.width = 23;
    image.height = 22;
    image.src = '//upload.wikimedia.org/wikipedia/commons/4/41/Btn_toolbar_unicode.png';
    image.border = 0;
    image.alt = 'Table unicode';
    image.title = 'Table unicode';
    image.style.cursor = "pointer";
    image.onclick = function() {
        popupUnicode();
        return false;
    }
    toolbar.appendChild(image);
}

addOnloadHook(boutonUnicode);
//