User:VIGNERON/common.js

From translatewiki.net
Jump to: navigation, search
/*
 Replacement de certains caractères spéciaux lors de l'édition
 Uniquement sous firefox.
 Auteur: ThomasV
*/
 
function keycheck() {
   tb = document.getElementById("wpTextbox1")
   if( tb && wgNamespaceNumber!=8 ) {
 
       tb.onkeyup=function(e) {
       var key = (window.event) ? event.keyCode : e.keyCode;
 
       startPos = tb.selectionStart;
       endPos = tb.selectionEnd;
       if( endPos==startPos && ( (key>=65 && key<=90) || key==222 || key==190) ) {
 
           m = tb.value.substring(startPos-2, startPos);
           m3 = tb.value.substring(startPos-3, startPos);
 
           f = tb.value.substring(startPos);
           todo=true; i=2;
           if(m[1]=="'"){
              m = m[0]+"’"; 
              if(m=="’’") m="''"; 
              if(m=="'’") m="''"; 
           } else switch(m) {
              case "^s" : m = "ſ"; break;
              case "`A" : m = "À"; break;
              case "`E" : m = "È"; break;
              case "`U" : m = "Ù"; break;
              case "'E" : m = "É"; break;
              case "~a" : m = "ã"; break;
              case "~e" : m = "ẽ"; break;
              case "~i" : m = "ĩ"; break;
              case "~o" : m = "õ"; break;
              case "~n" : m = "ñ"; break;
              case "~u" : m = "ũ"; break;
              case "=a" : m = "ā"; break;
              case "=e" : m = "ē"; break;
              case "=i" : m = "ī"; break;
              case "=o" : m = "ō"; break;
              case "=u" : m = "ū"; break;
              case "=y" : m = "ȳ"; break;
              case "=A" : m = "Ā"; break;
              case "=E" : m = "Ē"; break;
              case "=I" : m = "Ī"; break;
              case "=O" : m = "Ō"; break;
              case "=U" : m = "Ū"; break;
              case "=Y" : m = "Ȳ"; break;
              default : todo = false;
           }
           if(!todo) {
             m=m3; todo=true; i=3;
             switch(m) {
              case "^oe" : m="œ"; break;
              case "^ae" : m = "æ"; break;
              case "^OE" : m = "Œ"; break;
              case "^AE" : m = "Æ"; break;
              case "..." : m = "…"; break;
              default : todo = false;
           }}
 
           if(todo) {
		var textScroll = tb.scrollTop;
                h = tb.value.substring(0, startPos-i);
                tb.value = h+m+f;
		tb.selectionStart = startPos-i + m.length;
		tb.selectionEnd = tb.selectionStart;
		tb.scrollTop = textScroll;
           }
       }
     }
 }
 
}
addOnloadHook(keycheck);