| 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 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
lang.extend(_Grid, { |
| 34 |
|
| 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 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 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 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 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 |
|
| 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 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 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 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 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, '&').replace(/</g, '<') : v; |
| 145 |
o = o.replace ? o.replace(/&/g, '&').replace(/</g, '<') : 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 |
}); |