]> git.wh0rd.org - tt-rss.git/blob - lib/dijit/_BidiSupport.js.uncompressed.js
modify dojo rebuild script to remove uncompressed files
[tt-rss.git] / lib / dijit / _BidiSupport.js.uncompressed.js
1 define("dijit/_BidiSupport", ["./_WidgetBase"], function(_WidgetBase){
2
3 // module:
4 // dijit/_BidiSupport
5
6 /*=====
7 return function(){
8 // summary:
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.
12 // description:
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".
17 };
18 =====*/
19
20 _WidgetBase.extend({
21
22 getTextDir: function(/*String*/ text){
23 // summary:
24 // Gets the right direction of text.
25 // description:
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.
29 // tags:
30 // protected.
31 return this.textDir == "auto" ? this._checkContextual(text) : this.textDir;
32 },
33
34 _checkContextual: function(text){
35 // summary:
36 // Finds the first strong (directional) character, return ltr if isLatin
37 // or rtl if isBidiChar.
38 // tags:
39 // private.
40
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";
45 },
46
47 applyTextDir: function(/*Object*/ element, /*String*/ text){
48 // summary:
49 // Set element.dir according to this.textDir
50 // element:
51 // The text element to be set. Should have dir property.
52 // text:
53 // Used in case this.textDir is "auto", for calculating the right transformation
54 // description:
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.
58 // tags:
59 // protected.
60
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;
65 }
66 },
67 enforceTextDirWithUcc: function(option, text){
68 // summary:
69 // Wraps by UCC (Unicode control characters) option's text according to this.textDir
70 // option:
71 // The element (`<option>`) we wrapping the text for.
72 // text:
73 // The text to be wrapped.
74 // description:
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.
81 if(this.textDir){
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;
85 }
86 return text;
87 },
88 restoreOriginalText: function(origObj){
89 // summary:
90 // Restores the text of origObj, if needed, after enforceTextDirWithUcc, e.g. set("textDir", textDir).
91 // origObj:
92 // The element (`<option>`) to restore.
93 // description:
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;
99 }
100 return origObj;
101 }
102 });
103
104 // UCC - constants that will be used by bidi support.
105 var bidi_const = {
106 LRM : '\u200E',
107 LRE : '\u202A',
108 PDF : '\u202C',
109 RLM : '\u200f',
110 RLE : '\u202B'
111 };
112 return _WidgetBase;
113 });