DockingContainer.html
10.2 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
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
278
279
280
281
282
283
284
285
286
287
<!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-container-DockingContainer'>/**
</span> *
*/
Ext.define('Ext.container.DockingContainer', {
/* Begin Definitions */
requires: ['Ext.util.MixedCollection', 'Ext.Element' ],
/* End Definitions */
isDockingContainer: true,
<span id='Ext-container-DockingContainer-cfg-defaultDockWeights'> /**
</span> * @cfg {Object} defaultDockWeights
* This object holds the default weights applied to dockedItems that have no weight. These start with a
* weight of 1, to allow negative weights to insert before top items and are odd numbers
* so that even weights can be used to get between different dock orders.
*
* To make default docking order match border layout, do this:
*
* Ext.panel.AbstractPanel.prototype.defaultDockWeights = { top: 1, bottom: 3, left: 5, right: 7 };
*
* Changing these defaults as above or individually on this object will effect all Panels.
* To change the defaults on a single panel, you should replace the entire object:
*
* initComponent: function () {
* // NOTE: Don't change members of defaultDockWeights since the object is shared.
* this.defaultDockWeights = { top: 1, bottom: 3, left: 5, right: 7 };
*
* this.callParent();
* }
*
* To change only one of the default values, you do this:
*
* initComponent: function () {
* // NOTE: Don't change members of defaultDockWeights since the object is shared.
* this.defaultDockWeights = Ext.applyIf({ top: 10 }, this.defaultDockWeights);
*
* this.callParent();
* }
*/
defaultDockWeights: {
top: { render: 1, visual: 1 },
left: { render: 3, visual: 5 },
right: { render: 5, visual: 7 },
bottom: { render: 7, visual: 3 }
},
// @private
// Values to decide which side of the body element docked items must go
// This overides any weight. A left/top will *always* sort before a right/bottom
// regardless of any weight value. Weights sort at either side of the "body" dividing point.
dockOrder: {
top: -1,
left: -1,
right: 1,
bottom: 1
},
<span id='Ext-container-DockingContainer-method-addDocked'> /**
</span> * Adds docked item(s) to the container.
*
* @param {Object/Object[]} component The Component or array of components to add. The components
* must include a 'dock' parameter on each component to indicate where it should be docked
* ('top', 'right', 'bottom', 'left').
* @param {Number} [pos] The index at which the Component will be added
* @return {Ext.Component[]} The added components.
*/
addDocked : function(items, pos) {
var me = this,
i = 0,
item, length;
items = me.prepareItems(items);
length = items.length;
for (; i < length; i++) {
item = items[i];
item.dock = item.dock || 'top';
if (pos !== undefined) {
me.dockedItems.insert(pos + i, item);
} else {
me.dockedItems.add(item);
}
if (item.onAdded !== Ext.emptyFn) {
item.onAdded(me, i);
}
if (me.onDockedAdd !== Ext.emptyFn) {
me.onDockedAdd(item);
}
}
if (me.rendered && !me.suspendLayout) {
me.updateLayout();
}
return items;
},
destroyDockedItems: function(){
var dockedItems = this.dockedItems,
c;
if (dockedItems) {
while ((c = dockedItems.first())) {
this.removeDocked(c, true);
}
}
},
doRenderDockedItems: function (out, renderData, after) {
// Careful! This method is bolted on to the frameTpl and renderTpl so all we get for
// context is the renderData! The "this" pointer is either the frameTpl or the
// renderTpl instance!
// Due to framing, we will be called in two different ways: in the frameTpl or in
// the renderTpl. The frameTpl version enters via doRenderFramingDockedItems which
// sets "$skipDockedItems" on the renderTpl's renderData.
//
var me = renderData.$comp,
layout = me.componentLayout,
items,
tree;
if (layout.getDockedItems && !renderData.$skipDockedItems) {
items = layout.getDockedItems('render', !after);
tree = items && layout.getItemsRenderTree(items);
if (tree) {
Ext.DomHelper.generateMarkup(tree, out);
}
}
},
<span id='Ext-container-DockingContainer-method-getDockedComponent'> /**
</span> * Finds a docked component by id, itemId or position. Also see {@link #getDockedItems}
* @param {String/Number} comp The id, itemId or position of the docked component (see {@link Ext.panel.AbstractPanel#getComponent getComponent} for details)
* @return {Ext.Component} The docked component (if found)
*/
getDockedComponent: function(comp) {
if (Ext.isObject(comp)) {
comp = comp.getItemId();
}
return this.dockedItems.get(comp);
},
<span id='Ext-container-DockingContainer-method-getDockedItems'> /**
</span> * Retrieves an array of all currently docked Components.
*
* For example to find a toolbar that has been docked at top:
*
* panel.getDockedItems('toolbar[dock="top"]');
*
* @param {String} selector A {@link Ext.ComponentQuery ComponentQuery} selector string to filter the returned items.
* @param {Boolean} beforeBody An optional flag to limit the set of items to only those
* before the body (true) or after the body (false). All components are returned by
* default.
* @return {Ext.Component[]} The array of docked components meeting the specified criteria.
*/
getDockedItems : function(selector, beforeBody) {
var dockedItems = this.getComponentLayout().getDockedItems('render', beforeBody);
if (selector && dockedItems.length) {
dockedItems = Ext.ComponentQuery.query(selector, dockedItems);
}
return dockedItems;
},
getDockingRefItems: function(deep, containerItems) {
// deep fetches the docked items and their descendants using '*' and then '* *'
var selector = deep && '*,* *',
// start with only the top/left docked items (and maybe their children)
dockedItems = this.getDockedItems(selector, true),
items;
// push container items (and maybe their children) after top/left docked items:
dockedItems.push.apply(dockedItems, containerItems);
// push right/bottom docked items (and maybe their children) after container items:
items = this.getDockedItems(selector, false);
dockedItems.push.apply(dockedItems, items);
return dockedItems;
},
initDockingItems: function() {
var me = this,
items = me.dockedItems;
me.dockedItems = new Ext.util.AbstractMixedCollection(false, me.getComponentId);
if (items) {
me.addDocked(items);
}
},
<span id='Ext-container-DockingContainer-method-insertDocked'> /**
</span> * Inserts docked item(s) to the panel at the indicated position.
* @param {Number} pos The index at which the Component will be inserted
* @param {Object/Object[]} component. The Component or array of components to add. The components
* must include a 'dock' paramater on each component to indicate where it should be docked ('top', 'right',
* 'bottom', 'left').
*/
insertDocked : function(pos, items) {
this.addDocked(items, pos);
},
// Placeholder empty functions
<span id='Ext-container-DockingContainer-method-onDockedAdd'> /**
</span> * Invoked after a docked item is added to the Panel.
* @param {Ext.Component} component
* @template
* @protected
*/
onDockedAdd : Ext.emptyFn,
<span id='Ext-container-DockingContainer-method-onDockedRemove'> /**
</span> * Invoked after a docked item is removed from the Panel.
* @param {Ext.Component} component
* @template
* @protected
*/
onDockedRemove : Ext.emptyFn,
<span id='Ext-container-DockingContainer-method-removeDocked'> /**
</span> * Removes the docked item from the panel.
* @param {Ext.Component} item. The Component to remove.
* @param {Boolean} autoDestroy (optional) Destroy the component after removal.
*/
removeDocked : function(item, autoDestroy) {
var me = this,
layout,
hasLayout;
if (!me.dockedItems.contains(item)) {
return item;
}
layout = me.componentLayout;
hasLayout = layout && me.rendered;
if (hasLayout) {
layout.onRemove(item);
}
me.dockedItems.remove(item);
item.onRemoved();
me.onDockedRemove(item);
if (autoDestroy === true || (autoDestroy !== false && me.autoDestroy)) {
item.destroy();
} else if (hasLayout) {
// not destroying, make any layout related removals
layout.afterRemove(item);
}
if (!me.destroying && !me.suspendLayout) {
me.updateLayout();
}
return item;
},
setupDockingRenderTpl: function (renderTpl) {
renderTpl.renderDockedItems = this.doRenderDockedItems;
}
});
</pre>
</body>
</html>