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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
<!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-resizer-SplitterTracker'>/**
</span> * Private utility class for Ext.Splitter.
 * @private
 */
Ext.define('Ext.resizer.SplitterTracker', {
    extend: 'Ext.dd.DragTracker',
    requires: ['Ext.util.Region'],
<span id='Ext-resizer-SplitterTracker-property-enabled'>    enabled: true,
</span>    
<span id='Ext-resizer-SplitterTracker-property-overlayCls'>    overlayCls: Ext.baseCSSPrefix + 'resizable-overlay',
</span>
<span id='Ext-resizer-SplitterTracker-method-createDragOverlay'>    createDragOverlay: function () {
</span>        var overlay;
 
        overlay = this.overlay =  Ext.getBody().createChild({
            cls: this.overlayCls, 
            html: '&amp;#160;'
        });
 
        overlay.unselectable();
        overlay.setSize(Ext.Element.getViewWidth(true), Ext.Element.getViewHeight(true));
        overlay.show();
    },
 
<span id='Ext-resizer-SplitterTracker-method-getPrevCmp'>    getPrevCmp: function() {
</span>        var splitter = this.getSplitter();
        return splitter.previousSibling(':not([hidden])');
    },
 
<span id='Ext-resizer-SplitterTracker-method-getNextCmp'>    getNextCmp: function() {
</span>        var splitter = this.getSplitter();
        return splitter.nextSibling(':not([hidden])');
    },
 
<span id='Ext-resizer-SplitterTracker-method-onBeforeStart'>    // ensure the tracker is enabled, store boxes of previous and next
</span>    // components and calculate the constrain region
    onBeforeStart: function(e) {
        var me = this,
            prevCmp = me.getPrevCmp(),
            nextCmp = me.getNextCmp(),
            collapseEl = me.getSplitter().collapseEl,
            target = e.getTarget(),
            box;
            
        if (!prevCmp || !nextCmp) {
            return false;
        }
 
        if (collapseEl &amp;&amp; target === me.getSplitter().collapseEl.dom) {
            return false;
        }
 
        // SplitterTracker is disabled if any of its adjacents are collapsed.
        if (nextCmp.collapsed || prevCmp.collapsed) {
            return false;
        }
 
        // store boxes of previous and next
        me.prevBox  = prevCmp.getEl().getBox();
        me.nextBox  = nextCmp.getEl().getBox();
        me.constrainTo = box = me.calculateConstrainRegion();
 
        if (!box) {
            return false;
        }
 
        return box;
    },
 
<span id='Ext-resizer-SplitterTracker-method-onStart'>    // We move the splitter el. Add the proxy class.
</span>    onStart: function(e) {
        var splitter = this.getSplitter();
        this.createDragOverlay();
        splitter.addCls(splitter.baseCls + '-active');
    },
 
<span id='Ext-resizer-SplitterTracker-method-calculateConstrainRegion'>    // calculate the constrain Region in which the splitter el may be moved.
</span>    calculateConstrainRegion: function() {
        var me         = this,
            splitter   = me.getSplitter(),
            splitWidth = splitter.getWidth(),
            defaultMin = splitter.defaultSplitMin,
            orient     = splitter.orientation,
            prevBox    = me.prevBox,
            prevCmp    = me.getPrevCmp(),
            nextBox    = me.nextBox,
            nextCmp    = me.getNextCmp(),
            // prev and nextConstrainRegions are the maximumBoxes minus the
            // minimumBoxes. The result is always the intersection
            // of these two boxes.
            prevConstrainRegion, nextConstrainRegion, constrainOptions;
 
        // vertical splitters, so resizing left to right
        if (orient === 'vertical') {
            constrainOptions = {
                prevCmp: prevCmp,
                nextCmp: nextCmp,
                prevBox: prevBox,
                nextBox: nextBox,
                defaultMin: defaultMin,
                splitWidth: splitWidth
            };
            // Region constructor accepts (top, right, bottom, left)
            // anchored/calculated from the left
            prevConstrainRegion = new Ext.util.Region(
                prevBox.y,
                me.getVertPrevConstrainRight(constrainOptions),
                prevBox.bottom,
                me.getVertPrevConstrainLeft(constrainOptions)
            );
            // anchored/calculated from the right
            nextConstrainRegion = new Ext.util.Region(
                nextBox.y,
                me.getVertNextConstrainRight(constrainOptions),
                nextBox.bottom,
                me.getVertNextConstrainLeft(constrainOptions)
            );
        } else {
            // anchored/calculated from the top
            prevConstrainRegion = new Ext.util.Region(
                prevBox.y + (prevCmp.minHeight || defaultMin),
                prevBox.right,
                // Bottom boundary is y + maxHeight if there IS a maxHeight.
                // Otherwise it is calculated based upon the minWidth of the next Component
                (prevCmp.maxHeight ? prevBox.y + prevCmp.maxHeight : nextBox.bottom - (nextCmp.minHeight || defaultMin)) + splitWidth,
                prevBox.x
            );
            // anchored/calculated from the bottom
            nextConstrainRegion = new Ext.util.Region(
                // Top boundary is bottom - maxHeight if there IS a maxHeight.
                // Otherwise it is calculated based upon the minHeight of the previous Component
                (nextCmp.maxHeight ? nextBox.bottom - nextCmp.maxHeight : prevBox.y + (prevCmp.minHeight || defaultMin)) - splitWidth,
                nextBox.right,
                nextBox.bottom - (nextCmp.minHeight || defaultMin),
                nextBox.x
            );
        }
 
        // intersection of the two regions to provide region draggable
        return prevConstrainRegion.intersect(nextConstrainRegion);
    },
 
<span id='Ext-resizer-SplitterTracker-method-performResize'>    // Performs the actual resizing of the previous and next components
</span>    performResize: function(e, offset) {
        var me        = this,
            splitter  = me.getSplitter(),
            orient    = splitter.orientation,
            prevCmp   = me.getPrevCmp(),
            nextCmp   = me.getNextCmp(),
            owner     = splitter.ownerCt,
            flexedSiblings = owner.query('&gt;[flex]'),
            len       = flexedSiblings.length,
            vertical  = orient === 'vertical',
            i         = 0,
            dimension = vertical ? 'width' : 'height',
            totalFlex = 0,
            item, size;
 
        // Convert flexes to pixel values proportional to the total pixel width of all flexes.
        for (; i &lt; len; i++) {
            item = flexedSiblings[i];
            size = vertical ? item.getWidth() : item.getHeight();
            totalFlex += size;
            item.flex = size;
        }
 
        offset = vertical ? offset[0] : offset[1];
 
        if (prevCmp) {
            size = me.prevBox[dimension] + offset;
            if (prevCmp.flex) {
                prevCmp.flex = size;
            } else {
                prevCmp[dimension] = size;
            }
        }
        if (nextCmp) {
            size = me.nextBox[dimension] - offset;
            if (nextCmp.flex) {
                nextCmp.flex = size;
            } else {
                nextCmp[dimension] = size;
            }
        }
 
        owner.updateLayout();
    },
 
<span id='Ext-resizer-SplitterTracker-method-endDrag'>    // Cleans up the overlay (if we have one) and calls the base. This cannot be done in
</span>    // onEnd, because onEnd is only called if a drag is detected but the overlay is created
    // regardless (by onBeforeStart).
    endDrag: function () {
        var me = this;
 
        if (me.overlay) {
             me.overlay.remove();
             delete me.overlay;
        }
 
        me.callParent(arguments); // this calls onEnd
    },
 
<span id='Ext-resizer-SplitterTracker-method-onEnd'>    // perform the resize and remove the proxy class from the splitter el
</span>    onEnd: function(e) {
        var me = this,
            splitter = me.getSplitter();
            
        splitter.removeCls(splitter.baseCls + '-active');
        me.performResize(e, me.getResizeOffset());
    },
 
<span id='Ext-resizer-SplitterTracker-method-onDrag'>    // Track the proxy and set the proper XY coordinates
</span>    // while constraining the drag
    onDrag: function(e) {
        var me        = this,
            offset    = me.getOffset('dragTarget'),
            splitter  = me.getSplitter(),
            splitEl   = splitter.getEl(),
            orient    = splitter.orientation;
 
        if (orient === &quot;vertical&quot;) {
            splitEl.setX(me.startRegion.left + offset[0]);
        } else {
            splitEl.setY(me.startRegion.top + offset[1]);
        }
    },
 
<span id='Ext-resizer-SplitterTracker-method-getSplitter'>    getSplitter: function() {
</span>        return this.splitter;
    },
 
<span id='Ext-resizer-SplitterTracker-method-getVertPrevConstrainRight'>    getVertPrevConstrainRight: function(o) {
</span>        // Right boundary is x + maxWidth if there IS a maxWidth.
        // Otherwise it is calculated based upon the minWidth of the next Component
        return (o.prevCmp.maxWidth ? o.prevBox.x + o.prevCmp.maxWidth :
            o.nextBox.right - (o.nextCmp.minWidth || o.defaultMin)) + o.splitWidth;
    },
 
<span id='Ext-resizer-SplitterTracker-method-getVertPrevConstrainLeft'>    getVertPrevConstrainLeft: function(o) {
</span>        return o.prevBox.x + (o.prevCmp.minWidth || o.defaultMin);
    },
 
 
<span id='Ext-resizer-SplitterTracker-method-getVertNextConstrainRight'>    getVertNextConstrainRight: function(o) {
</span>        return o.nextBox.right - (o.nextCmp.minWidth || o.defaultMin);
    },
 
<span id='Ext-resizer-SplitterTracker-method-getVertNextConstrainLeft'>    getVertNextConstrainLeft: function(o) {
</span>        // Left boundary is right - maxWidth if there IS a maxWidth.
        // Otherwise it is calculated based upon the minWidth of the previous Component
        return (o.nextCmp.maxWidth ? o.nextBox.right - o.nextCmp.maxWidth :
            o.prevBox.x + (o.prevBox.minWidth || o.defaultMin)) - o.splitWidth;
    },
 
<span id='Ext-resizer-SplitterTracker-method-getResizeOffset'>    getResizeOffset: function() {
</span>        return this.getOffset('dragTarget');
    }
});</pre>
</body>
</html>