User:Automatik/common.js

//for testing User:Conrad.Irwin/editor.js via User:Automatik/editor.js //importScript('User:Automatik/test.js');

( function ( mw, $ ) { // Closure closed at the very end of the script

///////////////////// SpecialChars /////////////////////// /////////////// char sequences replacement ///////////////

// disable it on JS or CSS files var title = mw.config.get( 'wgTitle' ); var P3 = title.substring( title.length-3 ); var P4 = title.substring( title.length-4 ); var namespace = mw.config.get('wgNamespaceNumber'); if ( (P3 !== ".js") && (P4 !== ".css") || (P3 === ".js" || P4 === ".css") && namespace%2 === 1 ) { $(SpecChar_Main); } function SpecChar_Main { var tb = document.getElementById("wpTextbox1"); if (!tb) return; tb.onkeyup = function(e) { var key = (window.event) ? event.keyCode : e.keyCode; startPos = tb.selectionStart; endPos = tb.selectionEnd; if ( endPos==startPos && (key>=12 && key<=255) ) { var m = tb.value.substring(startPos-2, startPos); var m3 = tb.value.substring(startPos-3, startPos); var f = tb.value.substring(startPos); var todo = true; var i = 2; var goback = -1; switch (m) { //treatment of 2-letter char sequences case "$s":m="ſ";break; case "$à":m="À";break; case "$é":m="É";break; case "$è":m="È";break; case "$ç":m="Ç";break; case "$-":m="– ";break; case "$_":m="— ";break; case "<<":m="« ";break; case ">>":m=" »";break; case "$ù":m="Ù";break; case "$$":m=" — " + "";break; case "$t":m="====Translations====\n\n* French: {"+"{t+|fr|}}\n\n\n";goback=34;break; case "$p":m="===Pronunciation===\n\n";break; default:todo=false; }			   if (!todo) {     //treatment of 2-letter char sequences 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 "$aa":m="ā";break; case "$ii":m="ī";break; case "$ee":m="ē";break; case "$uu":m="ū";break; case "$oo":m="ō";break; case "$AA":m="Ā";break; case "$II":m="Ī";break; case "$EE":m="Ē";break; case "$UU":m="Ū";break; case "$OO":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; if (goback != -1) { tb.selectionStart = tb.selectionStart - goback; tb.selectionEnd = tb.selectionEnd - goback; }					tb.scrollTop = textScroll; }		  }	  }; } } ( mediaWiki, jQuery ) ); // End of the closure