SplitterTracker.html
8.68 KB
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
<!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'],
enabled: true,
overlayCls: Ext.baseCSSPrefix + 'resizable-overlay',
createDragOverlay: function () {
var overlay;
overlay = this.overlay = Ext.getBody().createChild({
cls: this.overlayCls,
html: '&#160;'
});
overlay.unselectable();
overlay.setSize(Ext.Element.getViewWidth(true), Ext.Element.getViewHeight(true));
overlay.show();
},
getPrevCmp: function() {
var splitter = this.getSplitter();
return splitter.previousSibling();
},
getNextCmp: function() {
var splitter = this.getSplitter();
return splitter.nextSibling();
},
// ensure the tracker is enabled, store boxes of previous and next
// 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 (collapseEl && 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;
}
me.createDragOverlay();
return box;
},
// We move the splitter el. Add the proxy class.
onStart: function(e) {
var splitter = this.getSplitter();
splitter.addCls(splitter.baseCls + '-active');
},
// calculate the constrain Region in which the splitter el may be moved.
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;
// vertical splitters, so resizing left to right
if (orient === 'vertical') {
// Region constructor accepts (top, right, bottom, left)
// anchored/calculated from the left
prevConstrainRegion = new Ext.util.Region(
prevBox.y,
// Right boundary is x + maxWidth if there IS a maxWidth.
// Otherwise it is calculated based upon the minWidth of the next Component
(prevCmp.maxWidth ? prevBox.x + prevCmp.maxWidth : nextBox.right - (nextCmp.minWidth || defaultMin)) + splitWidth,
prevBox.bottom,
prevBox.x + (prevCmp.minWidth || defaultMin)
);
// anchored/calculated from the right
nextConstrainRegion = new Ext.util.Region(
nextBox.y,
nextBox.right - (nextCmp.minWidth || defaultMin),
nextBox.bottom,
// Left boundary is right - maxWidth if there IS a maxWidth.
// Otherwise it is calculated based upon the minWidth of the previous Component
(nextCmp.maxWidth ? nextBox.right - nextCmp.maxWidth : prevBox.x + (prevBox.minWidth || defaultMin)) - splitWidth
);
} 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);
},
// Performs the actual resizing of the previous and next components
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('>[flex]'),
len = flexedSiblings.length,
i = 0,
dimension,
size,
totalFlex = 0;
// Convert flexes to pixel values proportional to the total pixel width of all flexes.
for (; i < len; i++) {
size = flexedSiblings[i].getWidth();
totalFlex += size;
flexedSiblings[i].flex = size;
}
offset = offset || me.getOffset('dragTarget');
if (orient === 'vertical') {
offset = offset[0];
dimension = 'width';
} else {
dimension = 'height';
offset = 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();
},
// Cleans up the overlay (if we have one) and calls the base. This cannot be done in
// 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
},
// perform the resize and remove the proxy class from the splitter el
onEnd: function(e) {
var me = this,
splitter = me.getSplitter();
splitter.removeCls(splitter.baseCls + '-active');
me.performResize(e, me.getOffset('dragTarget'));
},
// Track the proxy and set the proper XY coordinates
// 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 === "vertical") {
splitEl.setX(me.startRegion.left + offset[0]);
} else {
splitEl.setY(me.startRegion.top + offset[1]);
}
},
getSplitter: function() {
return this.splitter;
}
});</pre>
</body>
</html>