root / trunk / web / dojo / dojox / string / BidiComplex.js
History | View | Annotate | Download (5.35 KB)
1 | 9 | andrej.cim | /*
|
---|---|---|---|
2 | Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved.
|
||
3 | Available via Academic Free License >= 2.1 OR the modified BSD license.
|
||
4 | see: http://dojotoolkit.org/license for details
|
||
5 | */
|
||
6 | |||
7 | |||
8 | if(!dojo._hasResource["dojox.string.BidiComplex"]){ |
||
9 | dojo._hasResource["dojox.string.BidiComplex"]=true; |
||
10 | dojo.provide("dojox.string.BidiComplex");
|
||
11 | dojo.experimental("dojox.string.BidiComplex");
|
||
12 | (function(){
|
||
13 | var _1=[];
|
||
14 | dojox.string.BidiComplex.attachInput=function(_2,_3){ |
||
15 | _2.alt=_3; |
||
16 | dojo.connect(_2,"onkeydown",this,"_ceKeyDown"); |
||
17 | dojo.connect(_2,"onkeyup",this,"_ceKeyUp"); |
||
18 | dojo.connect(_2,"oncut",this,"_ceCutText"); |
||
19 | dojo.connect(_2,"oncopy",this,"_ceCopyText"); |
||
20 | _2.value=dojox.string.BidiComplex.createDisplayString(_2.value,_2.alt); |
||
21 | }; |
||
22 | dojox.string.BidiComplex.createDisplayString=function(_4,_5){ |
||
23 | _4=dojox.string.BidiComplex.stripSpecialCharacters(_4); |
||
24 | var _6=dojox.string.BidiComplex._parse(_4,_5);
|
||
25 | var _7=""+_4; |
||
26 | var _8=1; |
||
27 | dojo.forEach(_6,function(n){
|
||
28 | if(n!=null){ |
||
29 | var _9=_7.substring(0,n+_8); |
||
30 | var _a=_7.substring(n+_8,_7.length);
|
||
31 | _7=_9+""+_a;
|
||
32 | _8++; |
||
33 | } |
||
34 | }); |
||
35 | return _7;
|
||
36 | }; |
||
37 | dojox.string.BidiComplex.stripSpecialCharacters=function(_b){ |
||
38 | return _b.replace(/[\u200E\u200F\u202A-\u202E]/g,""); |
||
39 | }; |
||
40 | dojox.string.BidiComplex._ceKeyDown=function(_c){ |
||
41 | var _d=dojo.isIE?_c.srcElement:_c.target;
|
||
42 | _1=_d.value; |
||
43 | }; |
||
44 | dojox.string.BidiComplex._ceKeyUp=function(_e){ |
||
45 | var _f=""; |
||
46 | var _10=dojo.isIE?_e.srcElement:_e.target;
|
||
47 | var _11=_10.value;
|
||
48 | var _12=_e.keyCode;
|
||
49 | if((_12==dojo.keys.HOME)||(_12==dojo.keys.END)||(_12==dojo.keys.SHIFT)){
|
||
50 | return;
|
||
51 | } |
||
52 | var _13,_14;
|
||
53 | var _15=dojox.string.BidiComplex._getCaretPos(_e,_10);
|
||
54 | if(_15){
|
||
55 | _13=_15[0];
|
||
56 | _14=_15[1];
|
||
57 | } |
||
58 | if(dojo.isIE){
|
||
59 | var _16=_13,_17=_14;
|
||
60 | if(_12==dojo.keys.LEFT_ARROW){
|
||
61 | if((_11.charAt(_14-1)==_f)&&(_13==_14)){ |
||
62 | dojox.string.BidiComplex._setSelectedRange(_10,_13-1,_14-1); |
||
63 | } |
||
64 | return;
|
||
65 | } |
||
66 | if(_12==dojo.keys.RIGHT_ARROW){
|
||
67 | if(_11.charAt(_14-1)==_f){ |
||
68 | _17=_14+1;
|
||
69 | if(_13==_14){
|
||
70 | _16=_13+1;
|
||
71 | } |
||
72 | } |
||
73 | dojox.string.BidiComplex._setSelectedRange(_10,_16,_17); |
||
74 | return;
|
||
75 | } |
||
76 | }else{
|
||
77 | if(_12==dojo.keys.LEFT_ARROW){
|
||
78 | if(_11.charAt(_14-1)==_f){ |
||
79 | dojox.string.BidiComplex._setSelectedRange(_10,_13-1,_14-1); |
||
80 | } |
||
81 | return;
|
||
82 | } |
||
83 | if(_12==dojo.keys.RIGHT_ARROW){
|
||
84 | if(_11.charAt(_14-1)==_f){ |
||
85 | dojox.string.BidiComplex._setSelectedRange(_10,_13+1,_14+1); |
||
86 | } |
||
87 | return;
|
||
88 | } |
||
89 | } |
||
90 | var _18=dojox.string.BidiComplex.createDisplayString(_11,_10.alt);
|
||
91 | if(_11!=_18){
|
||
92 | window.status=_11+" c="+_14;
|
||
93 | _10.value=_18; |
||
94 | if((_12==dojo.keys.DELETE)&&(_18.charAt(_14)==_f)){
|
||
95 | _10.value=_18.substring(0,_14)+_18.substring(_14+2,_18.length); |
||
96 | } |
||
97 | if(_12==dojo.keys.DELETE){
|
||
98 | dojox.string.BidiComplex._setSelectedRange(_10,_13,_14); |
||
99 | }else{
|
||
100 | if(_12==dojo.keys.BACKSPACE){
|
||
101 | if((_1.length>=_14)&&(_1.charAt(_14-1)==_f)){ |
||
102 | dojox.string.BidiComplex._setSelectedRange(_10,_13-1,_14-1); |
||
103 | }else{
|
||
104 | dojox.string.BidiComplex._setSelectedRange(_10,_13,_14); |
||
105 | } |
||
106 | }else{
|
||
107 | if(_10.value.charAt(_14)!=_f){
|
||
108 | dojox.string.BidiComplex._setSelectedRange(_10,_13+1,_14+1); |
||
109 | } |
||
110 | } |
||
111 | } |
||
112 | } |
||
113 | }; |
||
114 | dojox.string.BidiComplex._processCopy=function(_19,_1a,_1b){ |
||
115 | if(_1a==null){ |
||
116 | if(dojo.isIE){
|
||
117 | var _1c=document.selection.createRange();
|
||
118 | _1a=_1c.text; |
||
119 | }else{
|
||
120 | _1a=_19.value.substring(_19.selectionStart,_19.selectionEnd); |
||
121 | } |
||
122 | } |
||
123 | var _1d=dojox.string.BidiComplex.stripSpecialCharacters(_1a);
|
||
124 | if(dojo.isIE){
|
||
125 | window.clipboardData.setData("Text",_1d);
|
||
126 | } |
||
127 | return true; |
||
128 | }; |
||
129 | dojox.string.BidiComplex._ceCopyText=function(_1e){ |
||
130 | if(dojo.isIE){
|
||
131 | _1e.returnValue=false;
|
||
132 | } |
||
133 | return dojox.string.BidiComplex._processCopy(_1e,null,false); |
||
134 | }; |
||
135 | dojox.string.BidiComplex._ceCutText=function(_1f){ |
||
136 | var ret=dojox.string.BidiComplex._processCopy(_1f,null,false); |
||
137 | if(!ret){
|
||
138 | return false; |
||
139 | } |
||
140 | if(dojo.isIE){
|
||
141 | document.selection.clear(); |
||
142 | }else{
|
||
143 | var _20=_1f.selectionStart;
|
||
144 | _1f.value=_1f.value.substring(0,_20)+_1f.value.substring(_1f.selectionEnd);
|
||
145 | _1f.setSelectionRange(_20,_20); |
||
146 | } |
||
147 | return true; |
||
148 | }; |
||
149 | dojox.string.BidiComplex._getCaretPos=function(_21,_22){ |
||
150 | if(dojo.isIE){
|
||
151 | var _23=0,_24=document.selection.createRange().duplicate(),_25=_24.duplicate(),_26=_24.text.length; |
||
152 | if(_22.type=="textarea"){ |
||
153 | _25.moveToElementText(_22); |
||
154 | }else{
|
||
155 | _25.expand("textedit");
|
||
156 | } |
||
157 | while(_24.compareEndPoints("StartToStart",_25)>0){ |
||
158 | _24.moveStart("character",-1); |
||
159 | ++_23; |
||
160 | } |
||
161 | return [_23,_23+_26];
|
||
162 | } |
||
163 | return [_21.target.selectionStart,_21.target.selectionEnd];
|
||
164 | }; |
||
165 | dojox.string.BidiComplex._setSelectedRange=function(_27,_28,_29){ |
||
166 | if(dojo.isIE){
|
||
167 | var _2a=_27.createTextRange();
|
||
168 | if(_2a){
|
||
169 | if(_27.type=="textarea"){ |
||
170 | _2a.moveToElementText(_27); |
||
171 | }else{
|
||
172 | _2a.expand("textedit");
|
||
173 | } |
||
174 | _2a.collapse(); |
||
175 | _2a.moveEnd("character",_29);
|
||
176 | _2a.moveStart("character",_28);
|
||
177 | _2a.select(); |
||
178 | } |
||
179 | }else{
|
||
180 | _27.selectionStart=_28; |
||
181 | _27.selectionEnd=_29; |
||
182 | } |
||
183 | }; |
||
184 | var _2b=function(c){ |
||
185 | return (c>="0"&&c<="9")||(c>"ÿ"); |
||
186 | }; |
||
187 | var _2c=function(c){ |
||
188 | return (c>="A"&&c<="Z")||(c>="a"&&c<="z"); |
||
189 | }; |
||
190 | var _2d=function(_2e,i,_2f){ |
||
191 | while(i>0){ |
||
192 | if(i==_2f){
|
||
193 | return false; |
||
194 | } |
||
195 | i--; |
||
196 | if(_2b(_2e.charAt(i))){
|
||
197 | return true; |
||
198 | } |
||
199 | if(_2c(_2e.charAt(i))){
|
||
200 | return false; |
||
201 | } |
||
202 | } |
||
203 | return false; |
||
204 | }; |
||
205 | dojox.string.BidiComplex._parse=function(str,_30){ |
||
206 | var _31=-1,_32=[]; |
||
207 | var _33={FILE_PATH:"/\\:.",URL:"/:.?=&#",XPATH:"/\\:.<>=[]",EMAIL:"<>@.,;"}[_30]; |
||
208 | switch(_30){
|
||
209 | case "FILE_PATH": |
||
210 | case "URL": |
||
211 | case "XPATH": |
||
212 | dojo.forEach(str,function(ch,i){
|
||
213 | if(_33.indexOf(ch)>=0&&_2d(str,i,_31)){ |
||
214 | _31=i; |
||
215 | _32.push(i); |
||
216 | } |
||
217 | }); |
||
218 | break;
|
||
219 | case "EMAIL": |
||
220 | var _34=false; |
||
221 | dojo.forEach(str,function(ch,i){
|
||
222 | if(ch=="\""){ |
||
223 | if(_2d(str,i,_31)){
|
||
224 | _31=i; |
||
225 | _32.push(i); |
||
226 | } |
||
227 | i++; |
||
228 | var i1=str.indexOf("\"",i); |
||
229 | if(i1>=i){
|
||
230 | i=i1; |
||
231 | } |
||
232 | if(_2d(str,i,_31)){
|
||
233 | _31=i; |
||
234 | _32.push(i); |
||
235 | } |
||
236 | } |
||
237 | if(_33.indexOf(ch)>=0&&_2d(str,i,_31)){ |
||
238 | _31=i; |
||
239 | _32.push(i); |
||
240 | } |
||
241 | }); |
||
242 | } |
||
243 | return _32;
|
||
244 | }; |
||
245 | })(); |
||
246 | } |