User:Don Alessandro/monobook.js

/*

addLoadEvent
*/ // BEGIN function addLoadEvent function addLoadEvent(func) { if (window.addEventListener) window.addEventListener("load", func, false); else if (window.attachEvent) window.attachEvent("onload", func); }

// END function addLoadEvent /*

getToolbar
*/ function getToolbar { var toolbar = document.getElementById('toolbar'); if (!toolbar) return false; var textbox = document.getElementById('wpTextbox1'); if (!textbox) return false; // Don't generate buttons for browsers which don't fully // support it. if (!document.selection && textbox.selectionStart == null) return false; } /*

homonyme
BEGIN homonyme for conversional homonymes like Look in usage of Template:homonyme */ if (document.URL.indexOf("=edit") > 0 || document.URL.indexOf("=submit") > 0) { var noJSforEdit; } else { if (wgUserLanguage !== "crh-cyrl"){ document.write('#crh-latn {display:inline;} #crh-cyrl {display:none;}<\/style>'); } else { document.write('#crh-latn {display:none;} #crh-cyrl {display:inline;}<\/style>'); } } // END homonyme /*

Translit Code
/** * Translit(eration) on-the-fly Code * @author: kk:User:GaiJin * @version: */ /*

Init variables
var output_array = ("A|Â|B|C|Ç|D|E|F|G|Ğ|I|İ|J|K|L|M|N|Ñ|O|Ö|P|Q|R|S|Ş|T|U|Ü|V|Y|Z|a|â|b|c|ç|d|e|f|g|ğ|h|ı|i|j|k|l|m|n|ñ|o|ö|p|q|r|s|ş|t|u|ü|v|y|z|Ç|Ğ|Ş|Ç|Ğ|Ş|ç|ch|ğ|gh|ş|sh").split("|"); var input_array = ("A|A`|B|C|C`|D|E|F|G|G`|I|I`|J|K|L|M|N|N`|O|O`|P|Q|R|S|S`|T|U|U`|V|Y|Z|a|a`|b|c|c`|d|e|f|g|g`|h|i|ı`|j|k|l|m|n|n`|o|o`|p|q|r|s|s`|t|u|u`|v|y|z|CH|GH|SH|Ch|Gh|Sh|ch|cH|gh|gH|sh|sH").split("|");

//0 - english, 1 - turkic-crh (standard) var language = 1;

document.write('.translitbut {color:black; background-color:#FFFFE0; border:thin #FFA500 outset; font:bold 0.90em small-caps; text-decoration:none; width:7em; cursor:pointer; padding:0 0.1em 0.1em 0.1em; margin-left: 6px; margin-right: 0px; float: right;} .translit_helpbut {cursor:pointer; float:right;}<\/style>'); /*

add_button
*/ function add_button { getToolbar var translit_help = document.createElement("img"); translit_help.src = "http://upload.wikimedia.org/wikipedia/kk/9/9a/Suraq.gif"; translit_help.id = 'translit_help'; translit_help.title = 'Қазақша теру анықтамасы'; translit_help.className = 'translit_helpbut'; translit_help.onclick = function { openhelp; return false; } toolbar.appendChild(translit_help);

var translit = document.createElement("input"); translit.type = 'button'; translit.name = 'lang'; translit.id = 'lang'; translit.title = 'Теру үшін Ctrl+Alt пернелерін қосып басыңыз'; translit.className = 'translitbut'; translit.onclick = changelanguage; toolbar.appendChild(translit); changelanguage; } /*

AkeyIsDown
*/ document.onkeydown = function AkeyIsDown { if (event.ctrlKey && event.altKey) {changelanguage;event.returnValue=false;} } /*

changelanguage
*/ function changelanguage { var textbox = document.getElementById('wpTextbox1'); if (!textbox) return false; var lang = document.getElementById('lang'); if (language == 1) { lang.value = "English"; //lang.style.background-color="#C8E6CC"; //lang.style.border-color="#45AA50"; document.editform.wpTextbox1.focus; return language = 0; } else if (language == 0) { lang.value = "Qırımtatar"; //lang.style.background-color="#FFFFE0"; //lang.style.border-color="#FFA500"; document.editform.wpTextbox1.focus; return language = 1; } } /*

ConvertInRealTime
*/

document.onkeypress= function ConvertInRealTime { if (document.activeElement!=document.editform.wpTextbox1) return; if (!language) return;

//the entered character var code = event.keyCode; txt=String.fromCharCode(code); //make selection cursor_pos_selection = document.selection.createRange; //delete something selected before cursor_pos_selection.text=""; //get the previous character cursor_pos_selection.moveStart("character",-1); pretxt = cursor_pos_selection.text; if (pretxt.length>1) {pretxt="";} event.keyCode = 0;

result=Convert(pretxt+txt); //delete the previous symbol if it is exists (if the entered symbol is not the first one) if (pretxt!="") { cursor_pos_selection.select; cursor_pos_selection.collapse;} with(document.selection.createRange) {text = result; collapse; select} return; } /*

Convert(text)
*/ function Convert(text) { var i,text1; for(i=0;i<output_array.length;i++) if(text==input_array[i]) return output_array[i]; text1=text.substr(1,1); for(i=0;i<output_array.length;i++) if(text1==input_array[i]) return text.substr(0,1)+output_array[i]; return text; } /*

Run the code
*/ addLoadEvent(add_button);

/*