13693261870
2022-09-16 354b3dbfbffb3df45212a2a44dbbf48b4acc2594
1
2
3
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>The source code</title>
  <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  <style type="text/css">
    .highlight { display: block; background-color: #ddd; }
  </style>
  <script type="text/javascript">
    function highlight() {
      document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
    }
  </script>
</head>
<body onload="prettyPrint(); highlight();">
  <pre class="prettyprint lang-js"><span id='Ext-rtl-AbstractComponent'>/**
</span> * This override adds RTL support and the `rtl` config option to AbstactComponent.
 */
Ext.define('Ext.rtl.AbstractComponent', {
    override: 'Ext.AbstractComponent',
 
<span id='Ext-AbstractComponent-cfg-rtl'>    /**
</span>     * @cfg {Boolean} rtl
     * True to layout this component and its descendants in &quot;rtl&quot; (right-to-left) mode.
     * Can be explicitly set to false to override a true value inherited from an ancestor.
     */
    
    initStyles: function(){
        if (this.getHierarchyState().rtl) {
            this.horizontalPosProp = 'right';
        }
        this.callParent(arguments);
    },
 
<span id='Ext-AbstractComponent-method-convertPositionSpec'>    convertPositionSpec: function(posSpec) {
</span>        // Since anchoring is done based on page level coordinates, we need to invert
        // left and right in the position spec when the direction of the compoent being
        // aligned is not the same as the direction of the viewport/body
        if ((Ext.rootHierarchyState.rtl || false) !== (this.getHierarchyState().rtl || false)) {
            posSpec = posSpec.replace(/l/g, 'tmp').replace(/r/g, 'l').replace(/tmp/g, 'r');
        }
        return posSpec;
    },
 
<span id='Ext-rtl-AbstractComponent-method-getAnchorToXY'>    getAnchorToXY: function(el, anchor, local, mySize) {
</span>        var doc = document,
            pos, scroll, extraX, extraY;
 
        if (el.dom == doc.body || el.dom == doc) {
            // anchor the element using the same coordinate system as the viewport or body
            scroll = Ext.rootHierarchyState.rtl ? el.rtlGetScroll() : el.getScroll();
            extraX = scroll.left;
            extraY = scroll.top;
        } else {
            pos = el.getXY();
            extraX = local ? 0 : pos[0];
            extraY = local ? 0 : pos[1];
        }
 
        return el.calculateAnchorXY(anchor, extraX, extraY, mySize);
    },
 
<span id='Ext-rtl-AbstractComponent-method-getBorderPadding'>    getBorderPadding: function() {
</span>        var borderPadding = this.el.getBorderPadding(),
            xBegin;
                
        if (this.isParentRtl()) {
            xBegin = borderPadding.xBegin;
            borderPadding.xBegin = borderPadding.xEnd;
            borderPadding.xEnd = xBegin;
        }
 
        return borderPadding;
    },
 
<span id='Ext-rtl-AbstractComponent-method-getLocalX'>    getLocalX: function() {
</span>        return this.isLocalRtl() ? this.el.rtlGetLocalX() : this.el.getLocalX();
    },
 
<span id='Ext-rtl-AbstractComponent-method-getLocalXY'>    getLocalXY: function() {
</span>        return this.isLocalRtl() ? this.el.rtlGetLocalXY() : this.el.getLocalXY();
    },
    
<span id='Ext-rtl-AbstractComponent-method-unitizeBox'>    unitizeBox: function(box) {
</span>        if (this.getHierarchyState().rtl) {
            return Ext.dom.Element.rtlUnitizeBox(box); 
        } else {
            return this.callParent(arguments);
        } 
    },
    
<span id='Ext-rtl-AbstractComponent-method-parseBox'>    parseBox: function(box) {
</span>        if (this.getHierarchyState().rtl) {
            return Ext.dom.Element.rtlParseBox(box); 
        } else {
            return this.callParent(arguments);
        }
    },
 
<span id='Ext-rtl-AbstractComponent-method-initHierarchyState'>    initHierarchyState: function(hierarchyState) {
</span>        this.callParent(arguments);
        var rtl = this.rtl;
 
        if (rtl !== undefined) {
            // unlike the other hierarchical properties which should always
            // be inherited from the hierarchy unless true, rtl should only
            // be inherited if undefined, that is if this component instance
            // does not have rtl specified as true or false.
            hierarchyState.rtl = rtl;
        }
    },
 
<span id='Ext-AbstractComponent-method-isLocalRtl'>    /**
</span>     * Returns true if this component's local coordinate system is rtl. For normal
     * components this equates to the value of isParentRtl().  Floaters are a bit different
     * because a floater's element can be a childNode of something other than its
     * parent component's element.  For floaters we have to read the dom to see if the
     * component's element's parentNode has a css direction value of &quot;rtl&quot;.
     * @return {Boolean}
     * @private
     */
    isLocalRtl: function() {
        var me = this,
            rtl, offsetParent, doc;
 
        if (me.floating) {
            if (me._isOffsetParentRtl === undefined) {
                
                // position:fixed elements do not report an offsetParent, so fall back to parentNode
                offsetParent = this.el.dom.offsetParent || this.el.dom.parentNode;
                if (offsetParent) {
                    doc = document;
                    if (offsetParent === doc.documentElement) {
                        // the default offsetParent is the body in most browsers,
                        // in IE7 strict it is the document element.  If this is the case
                        // test the body's style, since its direction style is what
                        // determines if the page-level coordinate system is rtl.
                        offsetParent = doc.body;
                    }
                    me._isOffsetParentRtl =
                        Ext.fly(offsetParent, '_isLocalRtl').isStyle('direction', 'rtl');
                }
            }
            rtl = !!me._isOffsetParentRtl;
        } else {
            rtl = this.isParentRtl();
        }
 
        return rtl;
    },
 
<span id='Ext-AbstractComponent-method-isParentRtl'>    /**
</span>     * Returns true if this component's parent container is rtl. Used by rtl positioning
     * methods to determine if the component should be positioned using a right-to-left
     * coordinate system.
     * @return {Boolean}
     * @private
     */
    isParentRtl: function() {
        var me = this,
            hierarchyState = me.getHierarchyState(),
            isRtl = false,
            myRtl;
 
        if (hierarchyState.hasOwnProperty('rtl')) {
            // Temporarily remove this component's rtl property so we can see what the rtl
            // value is on the prototype.  A component is only rtl positioned if it is
            // inside of an rtl coordinate system (if one of it's ancestors is rtl). We
            // can't just use ownerCt/floatParent hierarchyState, because components may
            // not have a container, but might still be part of a rtl coordinate system by
            // virtue of the viewport.  These components will inherit the correct rtl
            // value from the prototype becuase all hierarchy states inherit from
            // Ext.rootHierarchyState
            myRtl = hierarchyState.rtl;
            delete hierarchyState.rtl;
        }
 
        if (hierarchyState.rtl) {
            isRtl = true;
        }
 
        if (myRtl !== undefined) {
            // restore this component's original hierarchyState rtl property
            hierarchyState.rtl = myRtl;
        }
 
        return isRtl;
    },
 
<span id='Ext-rtl-AbstractComponent-method-setLocalX'>    setLocalX: function(x) {
</span>        return this.isLocalRtl() ? this.el.rtlSetLocalX(x) : this.el.setLocalX(x);
    },
 
<span id='Ext-rtl-AbstractComponent-method-setLocalXY'>    setLocalXY: function(x, y) {
</span>        return this.isLocalRtl() ? this.el.rtlSetLocalXY(x, y) : this.el.setLocalXY(x, y);
    },
    
<span id='Ext-AbstractComponent-method-isOppositeRootDirection'>    isOppositeRootDirection: function(){
</span>        return !this.getHierarchyState().rtl !== !Ext.rootHierarchyState.rtl;
    }
}, function() {
    Ext.on({
        ready: function() {
            // If the document or body has &quot;direction:rtl&quot; then we set the rtl flag in the
            // root hierarchy state so that the page-level coordinate system will be
            // right-based (similar to using a Viewport with &quot;rtl: true&quot;).
            if ((Ext.fly(document.documentElement).isStyle('direction', 'rtl')) ||
                (Ext.getBody().isStyle('direction', 'rtl'))) {
                Ext.rootHierarchyState.rtl = true;
            }
        },
        single: true,
        priority: 1000
    });
});
 
</pre>
</body>
</html>