]> git.wh0rd.org - tt-rss.git/blob - lib/dijit/_BidiSupport.js.uncompressed.js
make precache_headlines_idle() start slower
[tt-rss.git] / lib / dijit / _BidiSupport.js.uncompressed.js
1 define("dijit/_BidiSupport", ["./_WidgetBase"], function(_WidgetBase){
2
3 /*=====
4 var _WidgetBase = dijit._WidgetBase;
5 ====*/
6
7 // module:
8 // dijit/_BidiSupport
9 // summary:
10 // Module that deals with BIDI, special with the auto
11 // direction if needed without changing the GUI direction.
12 // Including this module will extend _WidgetBase with BIDI related methods.
13 // description:
14 // There's a special need for displaying BIDI text in rtl direction
15 // in ltr GUI, sometimes needed auto support.
16 // In creation of widget, if it's want to activate this class,
17 // the widget should define the "textDir".
18
19 _WidgetBase.extend({
20
21 getTextDir: function(/*String*/ text){
22 // summary:
23 // Gets the right direction of text.
24 // description:
25 // If textDir is ltr or rtl returns the value.
26 // If it's auto, calls to another function that responsible
27 // for checking the value, and defining the direction.
28 // tags:
29 // protected.
30 return this.textDir == "auto" ? this._checkContextual(text) : this.textDir;
31 },
32
33 _checkContextual: function(text){
34 // summary:
35 // Finds the first strong (directional) character, return ltr if isLatin
36 // or rtl if isBidiChar.
37 // tags:
38 // private.
39
40 // look for strong (directional) characters
41 var fdc = /[A-Za-z\u05d0-\u065f\u066a-\u06ef\u06fa-\u07ff\ufb1d-\ufdff\ufe70-\ufefc]/.exec(text);
42 // if found return the direction that defined by the character, else return widgets dir as defult.
43 return fdc ? ( fdc[0] <= 'z' ? "ltr" : "rtl" ) : this.dir ? this.dir : this.isLeftToRight() ? "ltr" : "rtl";
44 },
45
46 applyTextDir: function(/*Object*/ element, /*String*/ text){
47 // summary:
48 // Set element.dir according to this.textDir
49 // element:
50 // The text element to be set. Should have dir property.
51 // text:
52 // Used in case this.textDir is "auto", for calculating the right transformation
53 // description:
54 // If textDir is ltr or rtl returns the value.
55 // If it's auto, calls to another function that responsible
56 // for checking the value, and defining the direction.
57 // tags:
58 // protected.
59
60 var textDir = this.textDir == "auto" ? this._checkContextual(text) : this.textDir;
61 // update only when there's a difference
62 if(element.dir != textDir){
63 element.dir = textDir;
64 }
65 }
66 });
67
68 return _WidgetBase;
69 });