/[drupal]/contributions/modules/unisaraswati/marathi.js
ViewVC logotype

Contents of /contributions/modules/unisaraswati/marathi.js

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.1 - (show annotations) (download) (as text)
Thu May 31 11:27:54 2007 UTC (2 years, 5 months ago) by tusharvjoshi
Branch: MAIN
CVS Tags: DRUPAL-5--1-0, HEAD
Branch point for: DRUPAL-5
File MIME type: text/javascript
UniSaraswati Devnagari Transliterator Module

This module provides facility of typing in devnagari Indian script.  It makes one block available for changing the typing mode.  It works with all the edit-* elements of the nodes, except the edit-email and edit-recipents elements.
1 /*
2 ##############################################################################
3 # UniSarasvati Devnagari Transliterator Version 1.0 Beta
4 # Creator: Prasad Shirgaonkar prasad.shir@gmail.com
5 # Created 20/08/2004 Last Modified 10/03/2007
6 # This program comes on AS IS basis, without any warranty &/or support of any sort.
7 # You are free to use and distribute this program freely!
8 ##############################################################################
9 */
10 document.onkeydown = toggleKBMode;
11
12 document.onkeypress = eventCaptured;
13
14 //variable iexplore will be set if the browser is Internet Explorer
15 var iexplore = !window.opera && (window.event || document.all);
16
17 function eventCaptured(evt)
18 {
19 //alert("eventCaptured");
20
21 var target,event;
22
23 if(iexplore) { //if the browser is IE
24 event = window.event;
25 target = window.event.srcElement;
26 }
27 else { //for other browsers
28 event = evt;
29 target = evt.target;
30 }
31 //alert(target)
32 if(target.type!="password")
33 {
34 if(!(target.id=="edit-mail" || target.id=="edit-recipients" || target.id=="edit-yemail"))
35 {
36 convertThis(event,target);
37 }
38 //event handler function of specific file corresponding
39 //to specific keyboard layout
40 }
41 }
42
43
44
45 var vyanjan = ['क','ख','ग','घ','ङ','च','छ','ज','झ','ञ','ट','ठ','ड','ढ','ण','त','थ','द','ध','न','प','फ','ब','भ','म','य','र','र','ल','ळ','व','स','श','ऽ','ष','ह','क्ष','ज्ञ','ॐ']
46 var halanta = ['क्','ख्','ग्','घ्','ङ्','च्','छ्','ज्','झ्','ञ्','ट्','ठ्','ड्','ढ्','ण्','त्','थ्','द्','ध्','न्','प्','फ्','ब्','भ्','म्','य्','र्','र्‍','ल्','ळ्','व्','स्','श्','ऽ','ष्','ह्','क्ष्', 'ज्ञ्','ॐ']
47 var input = ['k','क्h','g','ग्h','~N','ch','च्h','j','ज्h','Y','T','ट्h','D','ड्h','N','t','त्h','d','द्h','n','p','प्h','b','ब्h','m','y','r','R','l','L','v','s','स्h','S','ऽh','h','x','द्Y','ऑM']
48 var rhasva_swar = ['ि', 'ु', 'े', 'ृ' , 'ॅ' ,'ॅ' , 'ँ' , 'ं', 'ः','ा','ी','ू','ॉ']
49 var rhasva_swar_input = ['i', 'u', 'e','q', 'E','_', '^', 'M', 'H','A','I','U','O' ]
50 var all_swar = ['ँ', 'ं', 'ः', 'अ', 'आ', 'आ', 'इ', 'ई', 'ई', 'उ', 'ऊ', 'ऋ', 'ऌ', 'ए', 'ऐ', 'ऑ', 'ओ', 'औ','ऍ']
51 var all_swar_input = ['^','M', 'H','a','अअ','A','i','I','इइ','u','U','Q','Lu','e','अइ','O','o','अउ','E']
52 var punctuation_marks =['.','!','\,','\'','\"','\?','\;','\(','\)']
53 var chnbin = "\u094D";
54 var ugar = "\u0941";
55 var uugar = "\u0942";
56
57 function replTxt(txt)
58 {
59 prvlen = txt.length;
60
61
62 //Pre Processing
63
64 txt = txt.replace(/B/g, "b");
65 txt = txt.replace(/C/g, "ch");
66 txt = txt.replace(/F/gi, "ph");
67 txt = txt.replace(/G/g, "g");
68 txt = txt.replace(/J/g, "j");
69 txt = txt.replace(/K/g, "k");
70 txt = txt.replace(/P/g, "p");
71 // txt = txt.replace(/Q/g, "k");
72 // txt = txt.replace(/q/g, "k");
73 txt = txt.replace(/V/g, "v");
74 txt = txt.replace(/W/gi, "v");
75 txt = txt.replace(/X/g, "x");
76 txt = txt.replace(/Z/gi, "jh");
77
78
79 //Actual Processing
80 //phonetic string typing converts to halanta
81 for (i=0;i<input.length;i++)
82 {txt = txt.replace(input[i], unescape(halanta[i]));}
83
84 //halanta followed by 'a' converts to vyanjana
85 for (i=0;i<halanta.length;i++)
86 {txt = txt.replace(halanta[i]+'a', unescape(vyanjan[i]));}
87
88 //halanta followed by 'space' converts to vyanjana
89 for (i=0;i<halanta.length;i++)
90 {txt = txt.replace(halanta[i]+' ', unescape(vyanjan[i]+' '));}
91
92 //halanta followed by punctuation mark converts to vyanjana with punctuation mark
93 for (i=0;i<halanta.length;i++)
94 for (k=0;k<punctuation_marks.length;k++)
95 {txt = txt.replace(halanta[i]+punctuation_marks[k], unescape(vyanjan[i]+punctuation_marks[k]));}
96
97
98 //kaanaa
99 for (i=0;i<halanta.length;i++)
100 {txt = txt.replace(vyanjan[i]+'a', unescape(vyanjan[i]+'ा'));}
101
102 //halanta followed by rhasva swar converts to vyanjana with rhasva swar
103 for (i=0;i<halanta.length;i++)
104 for (j=0;j<rhasva_swar.length;j++)
105 {txt = txt.replace(halanta[i]+rhasva_swar_input[j], unescape(vyanjan[i]+rhasva_swar[j]));}
106
107 //ikaarant to eekaarant
108 //for (i=0;i<halanta.length;i++)
109 //{txt = txt.replace(vyanjan[i]+'ि'+'i', unescape(vyanjan[i]+'ी'));}
110 {txt = txt.replace('ि'+'i', unescape('ी'));}
111 {txt = txt.replace('े'+'e', unescape('ी'));}
112
113 //ukaaraant to ookaarant
114 //for (i=0;i<halanta.length;i++)
115 //{txt = txt.replace(vyanjan[i]+'ु'+'u', unescape(vyanjan[i]+'ू'));}
116 {txt = txt.replace('ु'+'u', unescape('ू'));}
117 {txt = txt.replace('ो'+'o', unescape('ू'));}
118
119 //halanta followed by 'ai' converts to 'ai' kar
120 for (i=0;i<halanta.length;i++)
121 {txt = txt.replace(vyanjan[i]+'i', unescape(vyanjan[i]+'ै'));}
122
123 //okaar
124 for (i=0;i<halanta.length;i++)
125 {txt = txt.replace(halanta[i]+'o', unescape(vyanjan[i]+'ो'));}
126
127 //'au' kaar
128 for (i=0;i<halanta.length;i++)
129 {txt = txt.replace(vyanjan[i]+'u', unescape(vyanjan[i]+'ौ'));}
130
131 //logic for inputting swars as characters
132 for (i=0;i<all_swar.length;i++)
133 {txt = txt.replace(all_swar_input[i], unescape(all_swar[i]));}
134
135 txt = replaceEngNums(txt);
136 sPos += (txt.length -prvlen +1);
137 return txt;
138 }
139
140
141 function replaceEngNums(txt)
142 {
143 txt = txt.replace(/1/g, "\u0967");
144 txt = txt.replace(/2/g, "\u0968");
145 txt = txt.replace(/3/g, "\u0969");
146 txt = txt.replace(/4/g, "\u096A");
147 txt = txt.replace(/5/g, "\u096B");
148 txt = txt.replace(/6/g, "\u096C");
149 txt = txt.replace(/7/g, "\u096D");
150 txt = txt.replace(/8/g, "\u096E");
151 txt = txt.replace(/9/g, "\u096F");
152 txt = txt.replace(/0/g, "\u0966");
153
154 return txt;
155 }
156
157 //CORE PROCESSING CODE
158
159 var isIE = document.all?true:false;
160 var myimg = new Image();
161 var sPos = 0;
162 var isTh = false;
163 var isNg = false;
164 var kbmode = "roman";
165 var pkbmode = "roman";
166 var SplKeys = new Array();
167 //var myFieldID = "edit-comment1"
168
169 SplKeys["ZR"] = 0;
170 SplKeys["BS"] = 8;
171 SplKeys["CR"] = 13;
172
173 function convertThis(e, tar)
174 {
175 if (!isIE)
176 Key = e.which;
177 else
178 Key = e.keyCode;
179 Char = String.fromCharCode(Key);
180 // myField = document.getElementById(id);
181 myField = tar;
182 //myField = this();
183 //alert(myField)
184 if( isIE )
185 {
186 myField.caretPos = document.selection.createRange().duplicate();
187 prevChar = myField.caretPos.text;
188 if(prevChar.length != 0)
189 document.selection.clear();
190 if(myField.value.length != 0)
191 myField.caretPos.moveStart('character',-1);
192 prevChar = myField.caretPos.text;
193 if(prevChar == chnbin)
194 {
195 myField.caretPos.moveStart('character',-1);
196 prevChar = myField.caretPos.text;
197 }
198 if(prevChar == "" && myField.value.length != 0)
199 prevChar = "\u000A";
200 if(Key == 13)
201 Char = "\u000A";
202 myField.caretPos.text = getLang(prevChar,Char, 0)
203 e.cancelBubble = true;
204 e.returnValue = false;
205
206 }
207 else if( myField.selectionStart >= 0)
208 {
209 if(isSplKey(Key) || e.ctrlKey )
210 return true;
211 var startPos = myField.selectionStart;
212 var endPos = myField.selectionEnd;
213 txtTop = myField.scrollTop;
214 if(myField.value.length == 0)
215 {
216 prevChar = "";
217 myField.value = getLang(prevChar,Char, startPos)
218 }
219 else
220 {
221 prevChar = myField.value.substring(startPos-1,startPos);
222 prevStr = myField.value.substring(0,startPos -1);
223 if(prevChar == chnbin)
224 {
225 prevChar = myField.value.substring(startPos-2,startPos);
226 prevStr = myField.value.substring(0,startPos - 2);
227 }
228 myField.value = prevStr + getLang(prevChar,Char, myField.selectionStart)
229 + myField.value.substring(endPos, myField.value.length);
230 }
231 myField.selectionStart = sPos ;
232 myField.selectionEnd = sPos;
233 if((myField.scrollHeight+4)+"px" != myField.style.height)
234 myField.scrollTop = txtTop;
235 e.stopPropagation();
236 e.preventDefault();
237 }
238 }
239
240 function toggleT(obj)
241 {
242 isTh = obj.checked;
243 }
244
245 function toggleG(obj)
246 {
247 isNg = obj.checked;
248 }
249
250 function toggleKBMode(e,obj)
251 {
252 if(obj != null)
253 {
254 pkbmode = kbmode;
255 kbmode = obj.value;
256 if(kbmode == "typewriter")
257 myimg.src = "images/tw.png";
258 else
259 myimg.src = "images/"+"lang"+".png";
260 }
261 else
262 {
263 if (!isIE)
264 key = e.which;
265 else
266 key = window.event.keyCode;
267 if (key == 123)
268 {
269 if(kbmode != "english")
270 {
271 pkbmode = kbmode;
272 kbmode = "english";
273 document.keybdsel.keybrd[1].checked = true;
274 }
275 else
276 {
277 kbmode = pkbmode;
278 pkbmode = "english";
279 document.keybdsel.keybrd[0].checked = true;
280 }
281 }
282
283 }
284 }
285
286 function isSplKey(keynum)
287 {
288 retVal = false;
289 for(i in SplKeys)
290 {
291 if(keynum == SplKeys[i])
292 retVal = true;
293 }
294 return retVal;
295 }
296
297 function getLang(prv, txt, sP, mod)
298 {
299 sPos = sP;
300 if(kbmode == "english")
301 {
302 retTxt = prv+txt;
303 sPos ++;
304 }
305 else if(kbmode == "typewriter")
306 {
307 if(prv == ugar && mapLangTw(txt,sP) == uugar)
308 retTxt = mapLangTw(prv+txt,sP,mod);
309 else
310 {
311 retTxt = prv+mapLangTw(txt,sP,mod);
312 }
313 }
314 else
315 {
316 if(pkbmode == "english")
317 {
318 retTxt = prv+replTxt(txt);
319 pkbmode = "roman";
320 }
321 else
322 retTxt = replTxt(prv+txt);
323 }
324 return retTxt;
325 }
326
327

  ViewVC Help
Powered by ViewVC 1.1.2