Rar!ϐs st &SgSgMg:90 him.js/* * H.I.M JavaScript Vietnamese Input Method Source File dated 03-12-2005 * * Copyright (C) 2004 Hieu Tran Dang * Website: http://hieu.acunett.com * http://rhos.sf.net * * You are allowed to use this software in any way you want providing: * 1. You must retain this copyright notice at all time * 2. You must not claim that you or any other third party is the author * of this software in any way. */ var va="".split(',') //Put the ID of the fields you DON'T want to let users type Vietnamese in, multiple fields allowed, separated by a comma (,) var fID="vB_Editor_QR_iframe,vB_Editor_QE_1_iframe,vB_Editor_001_iframe".split(',') //Put the ID of the iframes you want to let users type Vietnamese in separated by a comma (,) var method=0 //Default input method, 0=AUTO, 1=TELEX, 2=VNI, 3=VIQR var on_off=1 //Start H.I.M on var dockspell=1 //Start H.I.M with spell checking on var dauCu=1 //Start H.I.M with old way of marking accent (o`a, o`e, u`y) var useCookie=1 //Set this to 0 to NOT use cookies var radioID=new Array("him_auto","him_telex","him_vni","him_viqr","him_viqr2","him_off","him_ckspell","him_daucu") var agt=navigator.userAgent.toLowerCase(),alphabet="QWERTYUIOPASDFGHJKLZXCVBNM\ ",them,spellerr,setCookie,getCookie var is_ie=((agt.indexOf("msie")!=-1)&&(agt.indexOf("opera")==-1)),S,F,J,R,X,D,oc,sk,saveStr,wi,frame,is_opera=false,D2 var ver=0,support=true,changed=false,uni,uni2,g,h,SFJRX,DAWEO,Z,AEO,moc,trang,kl=0,tw5,range=null,doc var skey=new Array(97,226,259,101,234,105,111,244,417,117,432,121,65,194,258,69,202,73,79,212,416,85,431,89) var skey2="a,a,a,e,e,i,o,o,o,u,u,y,A,A,A,E,E,I,O,O,O,U,U,Y".split(','),A,E,O,whit=false var english=fcc(272)+fcc(194)+fcc(258)+fcc(416)+fcc(431)+fcc(202)+fcc(212),ds1=new Array('d','D'),db1=new Array(273,272) var os1=new Array('o','O',417,416,243,211,242,210,7885,7884,7887,7886,245,213,7898,7900,7906,7902,7904) var ob1=new Array(244,212,244,212,7889,7888,7891,7890,7897,7896,7893,7892,7895,7894,7888,7890,7896,7892,7894) var mocs1=new Array('o','O',244,212,'u','U',243,211,242,210,7885,7884,7887,7886,245,213,250,218,249,217,7909,7908,7911,7910,361,360,7888,7890,7896,7892,7894) var mocb1=new Array(417,416,417,416,432,431,7899,7898,7901,7900,7907,7906,7903,7902,7905,7904,7913,7912,7915,7914,7921,7920,7917,7916,7919,7918,7898,7900,7906,7902,7904) var trangs1=new Array('a','A',226,194,225,193,224,192,7841,7840,7843,7842,227,195,7844,7846,7852,7848,7850) var trangb1=new Array(259,258,259,258,7855,7854,7857,7856,7863,7862,7859,7858,7861,7860,7854,7856,7862,7858,7860) var as1=new Array('a','A',259,258,225,193,224,192,7841,7840,7843,7842,227,195,7854,7856,7862,7858,7860,7870,7872,7878,7874,7876) var ab1=new Array(226,194,226,194,7845,7844,7847,7846,7853,7852,7849,7848,7851,7850,7844,7846,7852,7848,7850,201,200,7864,7866,7868) var es1=new Array('e','E',233,201,232,200,7865,7864,7867,7866,7869,7868),eb1=new Array(234,202,7871,7870,7873,7872,7879,7878,7875,7874,7877,7876) var arA="á,à,ả,ã,ạ,a,Á,À,Ả,Ã,Ạ,A".split(','),mocrA="ó,ò,ỏ,õ,ọ,o,ú,ù,ủ,ũ,ụ,u,Ó,Ò,Ỏ,Õ,Ọ,O,Ú,Ù,Ủ,Ũ,Ụ,U".split(','),erA="é,è,ẻ,ẽ,ẹ,e,É,È,Ẻ,Ẽ,Ẹ,E".split(','),orA="ó,ò,ỏ,õ,ọ,o,Ó,Ò,Ỏ,Õ,Ọ,O".split(',') var aA="ấ,ầ,ẩ,ẫ,ậ,â,Ấ,Ầ,Ẩ,Ẫ,Ậ,Â".split(','),mocA="ớ,ờ,ở,ỡ,ợ,ơ,ứ,ừ,ử,ữ,ự,ư,Ớ,Ờ,Ở,Ỡ,Ợ,Ơ,Ứ,Ừ,Ử,Ữ,Ự,Ư".split(','),trangA="ắ,ằ,ẳ,ẵ,ặ,ă,Ắ,Ằ,Ẳ,Ẵ,Ặ,Ă".split(','),eA="ế,ề,ể,ễ,ệ,ê,Ế,Ề,Ể,Ễ,Ệ,Ê".split(','),oA="ố,ồ,ổ,ỗ,ộ,ô,Ố,Ồ,Ổ,Ỗ,Ộ,Ô".split(',') function notWord(w) { var str="\ \r\n#,\\;.:-_()<>+-*/=?!\"$%{}[]\'~|^\@\&\t"+fcc(160) return (str.indexOf(w)>=0) } function mozGetText(obj) { var v,pos,w="";g=1 v=(obj.data)?obj.data:obj.value if(v.length<=0) return false if(!obj.data) { if(!obj.setSelectionRange) return false pos=obj.selectionStart } else pos=obj.pos if(obj.selectionStart!=obj.selectionEnd) return new Array("",pos) while(1) { if(pos-g<0) break else if(notWord(v.substr(pos-g,1))) { if(v.substr(pos-g,1)=="\\") w=v.substr(pos-g,1)+w; break } else w=v.substr(pos-g,1)+w; g++ } return new Array(w,pos) } function start(obj,key) { var w="";oc=obj;uni2=false;fixed=false if(method==0) { uni="D,A,E,O,W,W".split(','); uni2="9,6,6,6,7,8".split(','); D2="DAWEO6789" } else if(method==1) { uni="D,A,E,O,W,W".split(','); D2="DAWEO" } else if(method==2) { uni="9,6,6,6,7,8".split(','); D2="6789" } else if(method==3) { uni="D,^,^,^,+,(".split(','); D2="D^+(" } else if(method==4) { uni="D,^,^,^,*,(".split(','); D2="D^*(" } if(!is_ie) { key=fcc(key.which) w=mozGetText(obj) if((!w)||(obj.sel)) return main(w[0],key,w[1],uni) if(!dockspell) w=mozGetText(obj) if((w)&&(uni2)&&(!changed)) main(w[0],key,w[1],uni2) } else { obj=ieGetText(obj) if(obj) { var sT=obj.cW.text w=main(obj.cW.text,key,0,uni) if((uni2)&&((w==sT)||(typeof(w)=='undefined'))) w=main(obj.cW.text,key,0,uni2) if(w) obj.cW.text=w } } if(D2.indexOf(key.toUpperCase())>=0) { if(!is_ie) { w=mozGetText(obj) if(!w) return normC(w[0],key,w[1]) } else if(typeof(obj)=="object") { obj=ieGetText(obj) if(obj) { w=obj.cW.text if(!changed) { w+=key; changed=true } obj.cW.text=w w=normC(w,key,0) if(w) { obj=ieGetText(obj); obj.cW.text=w } } } } } function ieGetText(obj) { var caret=obj.document.selection.createRange(),w="" if(caret.text) caret.text="" else { while(1) { caret.moveStart("character",-1) if(w.length==caret.text.length) break w=caret.text if(notWord(w.charAt(0))) { if(w.charCodeAt(0)==13) w=w.substr(2) else if(w.charAt(0)!="\\") w=w.substr(1) break } } } if(w.length) { caret.collapse(false) caret.moveStart("character",-w.length) obj.cW=caret.duplicate() return obj } else return false } function ie_replaceChar(w,pos,c) { var r="",uc=0 if(isNaN(c)) uc=c.toUpperCase() if((whit)&&(w.substr(w.length-pos-1,1).toUpperCase()=='U')&&(pos!=1)&&(w.substr(w.length-pos-2,1).toUpperCase()!='Q')) { whit=false if((unV(fcc(c)).toUpperCase()=="Ơ")||(uc=="O")) { if(w.substr(w.length-pos-1,1)=='u') r=fcc(432) else r=fcc(431) } if(uc=="O") { if(c=="o") c=417 else c=416 } } if(!isNaN(c)) { changed=true;r+=fcc(c) return w.substr(0,w.length-pos-r.length+1)+r+w.substr(w.length-pos+1) } else return w.substr(0,w.length-pos)+c+w.substr(w.length-pos+1) } function tr(k,w,by,sf,i) { var r,pos=findC(w,k,sf) if(pos) { if(pos[1]) { if(is_ie) return ie_replaceChar(w,pos[0],pos[1]) else return replaceChar(oc,i-pos[0],pos[1]) } else { var c,pC;r=sf;pC=w.substr(w.length-pos,1) for(g=0;g=0) { var ret=sr(w,k,i); got=true if(ret) return ret } else if(uk==Z) { sf=repSign(null) for(h=0;h=0)||(Z.indexOf(uk)>=0)) return tr(k,w,by,sf,i) } function normC(w,k,i) { var uk=k.toUpperCase(),u=repSign(null),fS,c,j,space=(k.charCodeAt(0)==32)?true:false if((!is_ie)&&(space)) return for(j=1;j<=w.length;j++) { for(h=0;h=0) for(a=0;a=0) return true for(b=0;b=0) next=false if((next)&&((gi.indexOf(notViet[b])<0)||(a<=0)||(uw2.substr(a-1,1)!='G'))) return true } } } for(b=0;b=0) return true } } test=tw.substr(0,1) if((t==3)&&((test=="A")||(test=="O")||(test=="U")||(test=="Y"))) return true if((t==5)&&((test=="E")||(test=="I")||(test=="Y"))) return true uw2=unV2(tw) if(uw2==notV2) return true if(tw!=twE) for(z=0;z0)&&(uk=='E')) check=false if((them.indexOf(uk)>=0)&&(check)) { for(a=0;a=0) return true if(uk!=trang) if(uw2==noAOE) return true if((uk==trang)&&(trang!='W')) if(uw2==noT) return true if(uk==moc) for(a=0;a4) return true } else if(uw2.length>3) return true return false } function DAWEOF(cc,k) { var ret=new Array(),kA=new Array(A,moc,trang,E,O),z,a;ret[0]=g var ccA=new Array(aA,mocA,trangA,eA,oA),ccrA=new Array(arA,mocrA,arA,erA,orA) for(a=0;a=0) { if(uk==moc) { if((w2.indexOf("UU")>=0)&&(tw5!=dont[1])) { if(w2.indexOf("UU")==(w.length-2)) res=2 else return false } else if(w2.indexOf("UOU")>=0) { if(w2.indexOf("UOU")==(w.length-3)) res=2 else return false } } if(!res) { for(g=1;g<=w.length;g++) { cc=w.substr(w.length-g,1) pc=w.substr(w.length-g-1,1).toUpperCase() uc=cc.toUpperCase() for(h=0;h=0) { if(((uk==moc)&&(unV(uc)=="U")&&(unV(w.substr(w.length-g+1,1)).toUpperCase()=="A"))||((uk==trang)&&(unV(uc)=='A')&&(unV(pc)=='U'))) { if(unV(uc)=="U") tv=1 else tv=2 ccc=w.substr(w.length-g-tv,1).toUpperCase() if(ccc!="Q") res=g+tv-1 else if(uk==trang) res=g else if(moc!=trang) return false } else res=g if((!whit)||(uw.indexOf("Ư")<0)||(uw.indexOf("W")<0)) break } else if(DAWEOFA.indexOf(uc)>=0) { if(uk==D) { if(cc=="đ") res=new Array(g,'d') else if(cc=="Đ") res=new Array(g,'D') } else res=DAWEOF(cc,uk) if(res) break } } } } if((uk!=Z)&&(DAWEO.indexOf(uk)<0)) { var tEC=retKC(uk); for (g=0;g=0) { if(cc=='U') { if(pc!='Q') { c++;vowA[vowA.length]=g } } else if(cc=='I') { if((pc!='G')||(c<=0)) { c++;vowA[vowA.length]=g } } else { c++;vowA[vowA.length]=g } } else if(uk!=Z) { for(h=0;h=0)) return g else if(tE.indexOf(w.substr(w.length-g,1))>=0) { for(h=0;h=0) { c2++;fdconsonant=true if(dc[g]!='NGH') h++ else h+=2 } } if(!fdconsonant) { if(sc.indexOf(w.substr(w.length-h,1).toUpperCase())>=0) c2++ else break } } if((c2==1)||(c2==2)) return vowA[0] else return vowA[1] } else if(c==3) return vowA[1] else return false } function unV(w) { var u=repSign(null),b,a for(a=1;a<=w.length;a++) { for(b=0;b=8) is_opera=true else { operaV=operaV[0].split("/") if(parseInt(operaV[1])>=8) is_opera=true } } } if((is_ie)||(ver>=1.3)||(is_opera)) { getCookie() if(on_off==0) setMethod(-1) else setMethod(method) setSpell(dockspell);setDauCu(dauCu);statusMessage() } else support=false document.onkeydown=function(e) { onKeyDown(e) } document.onkeypress=function(e) { if(!support) return if(!is_ie) { var el=e.target,code=e.which; if(e.ctrlKey) return; if((e.altKey)&&(code!=92)&&(code!=126)) return } else { var el=window.event.srcElement,code=window.event.keyCode; if((event.ctrlKey)&&(code!=92)&&(code!=126)) return } if(((el.type!='textarea')&&(el.type!='text'))||checkCode(code)) return sk=fcc(code); for(i=0;i0)) return if(!is_ie) start(el,e) else start(el,sk) if(changed) { changed=false; return false } } function findF() { for(g=0;g0)) { for(g=0;g={@