]>
git.wh0rd.org - tt-rss.git/blob - lib/dijit/_BidiSupport.js.uncompressed.js
1 define("dijit/_BidiSupport", ["./_WidgetBase"], function(_WidgetBase
){
9 // Module that deals with BIDI, special with the auto
10 // direction if needed without changing the GUI direction.
11 // Including this module will extend _WidgetBase with BIDI related methods.
13 // There's a special need for displaying BIDI text in rtl direction
14 // in ltr GUI, sometimes needed auto support.
15 // In creation of widget, if it's want to activate this class,
16 // the widget should define the "textDir".
22 getTextDir: function(/*String*/ text
){
24 // Gets the right direction of text.
26 // If textDir is ltr or rtl returns the value.
27 // If it's auto, calls to another function that responsible
28 // for checking the value, and defining the direction.
31 return this.textDir
== "auto" ? this._checkContextual(text
) : this.textDir
;
34 _checkContextual: function(text
){
36 // Finds the first strong (directional) character, return ltr if isLatin
37 // or rtl if isBidiChar.
41 // look for strong (directional) characters
42 var fdc
= /[A-Za-z\u05d0-\u065f\u066a-\u06ef\u06fa-\u07ff\ufb1d-\ufdff\ufe70-\ufefc]/.exec(text
);
43 // if found return the direction that defined by the character, else return widgets dir as defult.
44 return fdc
? ( fdc
[0] <= 'z' ? "ltr" : "rtl" ) : this.dir
? this.dir
: this.isLeftToRight() ? "ltr" : "rtl";
47 applyTextDir: function(/*Object*/ element
, /*String*/ text
){
49 // Set element.dir according to this.textDir
51 // The text element to be set. Should have dir property.
53 // Used in case this.textDir is "auto", for calculating the right transformation
55 // If textDir is ltr or rtl returns the value.
56 // If it's auto, calls to another function that responsible
57 // for checking the value, and defining the direction.
61 var textDir
= this.textDir
== "auto" ? this._checkContextual(text
) : this.textDir
;
62 // update only when there's a difference
63 if(element
.dir
!= textDir
){
64 element
.dir
= textDir
;
67 enforceTextDirWithUcc: function(option
, text
){
69 // Wraps by UCC (Unicode control characters) option's text according to this.textDir
71 // The element (`<option>`) we wrapping the text for.
73 // The text to be wrapped.
75 // There's a dir problem with some HTML elements. For some elements (e.g. `<option>`, `<select>`)
76 // defining the dir in different direction then the GUI orientation, won't display correctly.
77 // FF 3.6 will change the alignment of the text in option - this doesn't follow the bidi standards (static text
78 // should be aligned following GUI direction). IE8 and Opera11.10 completely ignore dir setting for `<option>`.
79 // Therefore the only solution is to use UCC (Unicode control characters) to display the text in correct orientation.
80 // This function saves the original text value for later restoration if needed, for example if the textDir will change etc.
82 option
.originalText
= text
;
83 var dir
= this.textDir
== "auto" ? this._checkContextual(text
) : this.textDir
;
84 return (dir
== "ltr" ? bidi_const
.LRE
: bidi_const
.RLE
) + text
+ bidi_const
.PDF
;
88 restoreOriginalText: function(origObj
){
90 // Restores the text of origObj, if needed, after enforceTextDirWithUcc, e.g. set("textDir", textDir).
92 // The element (`<option>`) to restore.
94 // Sets the text of origObj to origObj.originalText, which is the original text, without the UCCs.
95 // The function than removes the originalText from origObj!
96 if(origObj
.originalText
){
97 origObj
.text
= origObj
.originalText
;
98 delete origObj
.originalText
;
104 // UCC - constants that will be used by bidi support.