-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathjtk.min.js
7 lines (7 loc) · 3.12 KB
/
jtk.min.js
1
2
3
4
5
6
7
/*
* Javascript Thaana Keyboard 4.2.2
*
* Copyright (c) 2013 Jawish Hameed (jawish.org)
* Licensed under the MIT license.
*/
;var thaanaKeyboard={defaultKeyboard:"",className:"thaanaKeyboardInput",_transFrom:"qwertyuiop[]\\asdfghjkl;'zxcvbnm,./QWERTYUIOP{}|ASDFGHJKL:\"ZXCVBNM<>?()",_transToKbd:{phonetic:"\u07b0\u0787\u07ac\u0783\u078c\u0794\u07aa\u07a8\u07ae\u0795][\\\u07a6\u0790\u078b\u078a\u078e\u0780\u0796\u0786\u078d\u061b'\u0792\xd7\u0797\u0788\u0784\u0782\u0789\u060c./\u07a4\u07a2\u07ad\u079c\u0793\u07a0\u07ab\u07a9\u07af\xf7}{|\u07a7\u0781\u0791\ufdf2\u07a3\u0799\u079b\u079a\u0785:\"\u07a1\u0798\u079d\u07a5\u079e\u078f\u079f><\u061f)(","phonetic-hh":"\u07a4\u07a6\u07ac\u0783\u078c\u0794\u07aa\u07a8\u07ae\u0795][\\\u0787\u0790\u078b\u078a\u078e\u0780\u0796\u0786\u078d\u061b'\u0792\u079d\u07b0\u0788\u0784\u0782\u0789\u060c./\ufdf2\u07a7\u07ad\u079c\u0793\u07a0\u07ab\u07a9\u07af\u0795}{|\u07a2\u0781\u0791\u079f\u07a3\u0799\u079b\u079a\u0785:\"\u07a1\u0798\u0797\u07a5\u079e\u078f\u0789><\u061f)(",typewriter:'\u07ab\u07ae\u07a7\u07a9\u07ad\u078e\u0783\u0789\u078c\u0780\u078d[]\u07a8\u07aa\u07b0\u07a6\u07ac\u0788\u0787\u0782\u0786\u078a\ufdf2\u0792\u0791\u0790\u0794\u0785\u078b\u0784\u0781\u0793\u07af\xd7\u2019\u201c/:\u07a4\u079c\u07a3\u07a0\u0799\xf7{}<>.\u060c"\u07a5\u07a2\u0798\u079a\u07a1\u061b\u0796\u0795\u078f\u0797\u079f\u079b\u079d\\\u079e\u061f)('},init:function(){this.setHandlerByClass(this.className,"enable")},setHandlerByElement:function(a,b){switch(b){case"enable":a.onkeypress=this.handleKey;break;case"disable":a.onkeypress=null}},setHandlerById:function(a,b){var c=document.getElementById(a);this.setHandlerByElement(c,b)},setHandlerByClass:function(a,b){var c=new RegExp("\\b"+a+"\\b"),d=document.all||document.getElementsByTagName("*");for(n=0;n<d.length;n++)c.test(d[n].className)&&this.setHandlerByElement(d[n],b)},handleKey:function(a){if(!a)var a=window.event;if(null==a.which)keycode=a.keyCode;else{if(!(a.which>0))return!0;if(keycode=a.which,window.opera&&1==[45,46,35,36].indexOf(keycode))return!0}if(a.modifier)var b=a.modifiers&Event.CONTROL_MASK;else if("undefined"!=typeof a.ctrlKey)var b=a.ctrlKey;try{var c=thaanaKeyboard._transFrom.indexOf(String.fromCharCode(keycode));if(-1==c||b)return!0;var d=thaanaKeyboard.defaultKeyboard,e=document.getElementsByName(this.id+"_thaanaKeyboardState");if(e)for(i=0;i<e.length;i++)if("radio"==e[i].type||"checkbox"==e[i].type){if(1==e[i].checked){d=e[i].value;break}}else{if("select-one"==e[i].type){d=e[i].options[e[i].selectedIndex].value;break}if("hidden"==e[i].type||"text"==e[i].type){d=e[i].value;break}}var f=thaanaKeyboard._transToKbd[d].substr(c,1)}catch(g){return}"function"==typeof a.preventDefault?a.preventDefault():a.returnValue=!1;var h=this.scrollTop;if(this.selectionStart){var j=this.selectionStart+1;this.value=this.value.substring(0,this.selectionStart)+f+this.value.substring(this.selectionEnd,this.value.length),this.setSelectionRange(j,j),this.focus()}else document.selection?(sel=document.selection.createRange(),sel.text=f,this.focus()):this.value+=f;this.scrollTop=h}},old=window.onload?window.onload:function(){};window.onload=function(){old(),thaanaKeyboard.init()};