Debian Codegraph @

dojox/grid/bidi/_BidiMixin.js

raw symbols SCIP
1 define(["../../main", "dojo/_base/lang", "../_Builder", "dijit/_BidiSupport",
2 "../_Grid", "../cells/_base", "../cells/dijit"],
3 function(dojox, lang, _Builder, _BidiSupport, _Grid, BaseCell, cellsDijit){
4 // module:
5 // dojox/grid/bidi/BidiMixin
6
7 /*=====
8 return {
9 // summary:
10 // Module that deals with BIDI for Grid
11 // description:
12 // There's a special need for displaying BIDI text in rtl direction in ltr GUI, or sometimes needed auto support.
13 // "textDir" attribute should be set on Grid so that this class can be activated and responsible for text direction
14 // Allowed values:
15 // 1. "ltr"
16 // 2. "rtl"
17 // 3. "auto" - contextual the direction of a text defined by first strong letter.
18 // By default the same as the page direction.
19
20 // Arabic, Hebrew, Urdu, and Farsi (Persian) are written from right to left,
21 // while numbers and segments of Latin (or Cyrillic or Greek) text are embedded in
22 // this text from left to right. The dual directionality aspects of such
23 // bidirectional (bidi) text are posing challenges to the way this text is processed and presented in computer applications.
24 // The Unicode Bidirectional Algorithm, which is commonly used for preparation of Bidi text for display,
25 // is not capable to reliably identify the natural base text direction for a given text.
26 // Only a human reader can unfailingly recognize the natural base text direction for a given text.
27 // Support for enforcing the base text direction is provided out of the box by most platforms / technologies,
28 // but very often the default settings do not guarantee proper display of English and Arabic/Hebrew text in the
29 // same application. See for reference:http://w3-03.ibm.com/globalization/page/publish/4353
30 };
31 =====*/
32
33 lang.extend(_Grid, {
34 /*this.textDir = textDir*/
35 setCellNodeTextDirection: function(inColIndex, inRowIndex, textDir){
36 this.getCell(inColIndex).getNode(inRowIndex).style.direction = textDir || "";
37 },
38 getCellNodeTextDirection: function(inColIndex, inRowIndex){
39 return this.getCell(inColIndex).getNode(inRowIndex).style.direction;
40 },
41 _setTextDirAttr: function(textDir){
42 this.textDir = textDir;
43 this.render();
44 }
45 });
46
47 lang.extend(_Builder._ContentBuilder, {
48 _getTextDirStyle: function(textDir, inCell, inRowIndex){
49 // summary:
50 // Returns input text direction related attributes.
51 // textDir:
52 // Cell text direction
53 // inCell:
54 // Cell under processing
55 // inRowIndex:
56 // Row index
57 var item = this.grid.getItem(inRowIndex), ret = "";
58 if(textDir === "auto"){
59 var name = inCell.get ? inCell.get(inRowIndex, item) : (inCell.value || inCell.defaultValue);
60 if(name){
61 textDir = _BidiSupport.prototype._checkContextual(name);
62 }
63 }
64 ret = " direction:" + textDir + ";";
65 return ret;
66 }
67 });
68
69 lang.extend(_Builder._HeaderBuilder, {
70 _getTextDirStyle: function(textDir, inCell, inValue){
71 // summary:
72 // Returns input text direction related attributes.
73 // textDir:
74 // Cell text direction
75 // inCell:
76 // Cell under processing
77 // inValue:
78 // Header cell content
79 if(textDir === "auto"){
80 var name = inValue || inCell.name || inCell.grid.getCellName(inCell);
81 if(name){
82 textDir = _BidiSupport.prototype._checkContextual(name);
83 }
84 }
85 return (' direction:' + textDir + '; ');
86 }
87 });
88
89 lang.extend(BaseCell.Cell, {
90 // text direction UCC constants
91 LRE: '\u202A',
92 RLE: '\u202B',
93 PDF: '\u202C',
94 KEY_HANDLER: "onkeyup=' javascript:(function(){" +
95 "var target; if (event.target) target = event.target; else if (event.srcElement) target = event.srcElement; if(!target) return;" +
96 "var regExMatch = /[A-Za-z\u05d0-\u065f\u066a-\u06ef\u06fa-\u07ff\ufb1d-\ufdff\ufe70-\ufefc]/.exec(target.value);" +
97 "target.dir = regExMatch ? ( regExMatch[0] <= \"z\" ? \"ltr\" : \"rtl\" ) : target.dir ? target.dir : \"ltr\"; })();'",
98 _getTextDirMarkup: function(inDatum){
99 // summary:
100 // Returns input text direction related attributes.
101 // textDir:
102 // The control text direction
103 // inDatum:
104 // Control text value.
105 var textDirMarkup = "", textDir = this.textDir || this.grid.textDir;
106 if(textDir){
107 if(textDir === "auto"){
108 textDirMarkup = this.KEY_HANDLER;
109 textDir = _BidiSupport.prototype._checkContextual(inDatum);
110 }
111 textDirMarkup += " dir='" + textDir + "'; ";
112 }
113 return textDirMarkup;
114 },
115 formatEditing: function(inDatum, inRowIndex){
116 this.needFormatNode(inDatum, inRowIndex);
117 return '<input class="dojoxGridInput" ' + this._getTextDirMarkup(inDatum) + ' type="text" value="' + inDatum + '">';
118 },
119 _enforceTextDirWithUcc: function(textDir, text){
120 // summary:
121 // Wraps by UCC (Unicode control characters) option's text according to textDir
122 // textDir:
123 // The control text direction
124 // text:
125 // The text to be wrapped.
126 textDir = (textDir === "auto") ? _BidiSupport.prototype._checkContextual(text) : textDir;
127 return (textDir === "rtl" ? this.RLE : this.LRE) + text + this.PDF;
128 }
129 });
130
131 lang.extend(BaseCell.Select, {
132 _getValueCallOrig: dojox.grid.cells.Select.prototype.getValue,
133 getValue: function(inRowIndex){
134 var ret = this._getValueCallOrig(inRowIndex);
135 if(ret && (this.textDir || this.grid.textDir)){
136 ret = ret.replace(/\u202A|\u202B|\u202C/g, "");
137 }
138 return ret;
139 },
140 formatEditing: function(inDatum, inRowIndex){
141 this.needFormatNode(inDatum, inRowIndex);
142 var h = [ '<select dir = \"' + (this.grid.isLeftToRight() ? 'ltr' : 'rtl') + '\" class="dojoxGridSelect">' ];
143 for(var i = 0, o, v; ((o = this.options[i]) !== undefined) && ((v = this.values[i]) !== undefined); i++){
144 v = v.replace ? v.replace(/&/g, '&amp;').replace(/</g, '&lt;') : v;
145 o = o.replace ? o.replace(/&/g, '&amp;').replace(/</g, '&lt;') : o;
146 if(this.textDir || this.grid.textDir){
147 o = this._enforceTextDirWithUcc(this.textDir || this.grid.textDir, o);
148 }
149 h.push("<option", (inDatum == v ? ' selected' : ''), ' value = "' + v + '"', ">", o, "</option>");
150 }
151 h.push('</select>');
152 return h.join('');
153 }
154 });
155
156 lang.extend(cellsDijit.ComboBox, {
157 getWidgetPropsCallOrig: dojox.grid.cells.ComboBox.prototype.getWidgetProps,
158 getWidgetProps: function(inDatum){
159 var ret = this.getWidgetPropsCallOrig(inDatum);
160 if(this.textDir || this.grid.textDir){
161 ret.textDir = this.textDir || this.grid.textDir;
162 }
163 return ret;
164 }
165 });
166
167 lang.extend(cellsDijit._Widget, {
168 getWidgetPropsCallOrig: dojox.grid.cells._Widget.prototype.getWidgetProps,
169 getWidgetProps: function(inDatum){
170 var ret = this.getWidgetPropsCallOrig(inDatum);
171 if(this.textDir || this.grid.textDir){
172 ret.textDir = this.textDir || this.grid.textDir;
173 }
174 return ret;
175 }
176 });
177 });