1 <!DOCTYPE html><html><head><title>Sencha Documentation Project</title><link rel="stylesheet" href="../reset.css" type="text/css"><link rel="stylesheet" href="../prettify.css" type="text/css"><link rel="stylesheet" href="../prettify_sa.css" type="text/css"><script type="text/javascript" src="../prettify.js"></script></head><body onload="prettyPrint()"><pre class="prettyprint"><pre><span id='Ext-ZIndexManager-method-constructor'><span id='Ext-ZIndexManager'>/**
2 </span></span> * @class Ext.ZIndexManager
3 * <p>A class that manages a group of {@link Ext.Component#floating} Components and provides z-order management,
4 * and Component activation behavior, including masking below the active (topmost) Component.</p>
5 * <p>{@link Ext.Component#floating Floating} Components which are rendered directly into the document (Such as {@link Ext.window.Window Window}s which are
6 * {@link Ext.Component#show show}n are managed by a {@link Ext.WindowManager global instance}.</p>
7 * <p>{@link Ext.Component#floating Floating} Components which are descendants of {@link Ext.Component#floating floating} <i>Containers</i>
8 * (For example a {Ext.view.BoundList BoundList} within an {@link Ext.window.Window Window}, or a {@link Ext.menu.Menu Menu}),
9 * are managed by a ZIndexManager owned by that floating Container. So ComboBox dropdowns within Windows will have managed z-indices
10 * guaranteed to be correct, relative to the Window.</p>
13 Ext.define('Ext.ZIndexManager', {
15 alternateClassName: 'Ext.WindowGroup',
21 constructor: function(container) {
30 // This is the ZIndexManager for an Ext.container.Container, base its zseed on the zIndex of the Container's element
31 if (container.isContainer) {
32 container.on('resize', me._onContainerResize, me);
33 me.zseed = Ext.Number.from(container.getEl().getStyle('zIndex'), me.getNextZSeed());
34 // The containing element we will be dealing with (eg masking) is the content target
35 me.targetEl = container.getTargetEl();
36 me.container = container;
38 // This is the ZIndexManager for a DOM element
40 Ext.EventManager.onWindowResize(me._onContainerResize, me);
41 me.zseed = me.getNextZSeed();
42 me.targetEl = Ext.get(container);
45 // No container passed means we are the global WindowManager. Our target is the doc body.
46 // DOM must be ready to collect that ref.
48 Ext.EventManager.onWindowResize(me._onContainerResize, me);
49 me.zseed = me.getNextZSeed();
50 Ext.onDocumentReady(function() {
51 me.targetEl = Ext.getBody();
56 getNextZSeed: function() {
57 return (Ext.ZIndexManager.zBase += 10000);
60 setBase: function(baseZIndex) {
61 this.zseed = baseZIndex;
62 return this.assignZIndices();
66 assignZIndices: function() {
67 var a = this.zIndexStack,
73 for (; i < len; i++) {
75 if (comp && !comp.hidden) {
77 // Setting the zIndex of a Component returns the topmost zIndex consumed by
79 // If it's just a plain floating Component such as a BoundList, then the
80 // return value is the passed value plus 10, ready for the next item.
81 // If a floating *Container* has its zIndex set, it re-orders its managed
82 // floating children, starting from that new base, and returns a value 10000 above
83 // the highest zIndex which it allocates.
84 zIndex = comp.setZIndex(zIndex);
92 _setActiveChild: function(comp) {
93 if (comp != this.front) {
96 this.front.setActive(false, comp);
100 comp.setActive(true);
102 this._showModalMask(comp.el.getStyle('zIndex') - 4);
109 _activateLast: function(justHidden) {
111 lastActivated = false,
114 // Go down through the z-index stack.
115 // Activate the next visible one down.
116 // Keep going down to find the next visible modal one to shift the modal mask down under
117 for (i = this.zIndexStack.length-1; i >= 0; --i) {
118 comp = this.zIndexStack[i];
120 if (!lastActivated) {
121 this._setActiveChild(comp);
122 lastActivated = true;
125 // Move any modal mask down to just under the next modal floater down the stack
127 this._showModalMask(comp.el.getStyle('zIndex') - 4);
133 // none to activate, so there must be no modal mask.
134 // And clear the currently active property
135 this._hideModalMask();
136 if (!lastActivated) {
137 this._setActiveChild(null);
141 _showModalMask: function(zIndex) {
143 this.mask = this.targetEl.createChild({
144 cls: Ext.baseCSSPrefix + 'mask'
146 this.mask.setVisibilityMode(Ext.core.Element.DISPLAY);
147 this.mask.on('click', this._onMaskClick, this);
149 Ext.getBody().addCls(Ext.baseCSSPrefix + 'body-masked');
150 this.mask.setSize(this.targetEl.getViewSize(true));
151 this.mask.setStyle('zIndex', zIndex);
155 _hideModalMask: function() {
157 Ext.getBody().removeCls(Ext.baseCSSPrefix + 'body-masked');
162 _onMaskClick: function() {
168 _onContainerResize: function() {
169 if (this.mask && this.mask.isVisible()) {
170 this.mask.setSize(this.targetEl.getViewSize(true));
174 <span id='Ext-ZIndexManager-method-register'> /**
175 </span> * <p>Registers a floating {@link Ext.Component} with this ZIndexManager. This should not
176 * need to be called under normal circumstances. Floating Components (such as Windows, BoundLists and Menus) are automatically registered
177 * with a {@link Ext.Component#zIndexManager zIndexManager} at render time.</p>
178 * <p>Where this may be useful is moving Windows between two ZIndexManagers. For example,
179 * to bring the Ext.MessageBox dialog under the same manager as the Desktop's
180 * ZIndexManager in the desktop sample app:</p><code><pre>
181 MyDesktop.getDesktop().getManager().register(Ext.MessageBox);
182 </pre></code>
183 * @param {Component} comp The Component to register.
185 register : function(comp) {
186 if (comp.zIndexManager) {
187 comp.zIndexManager.unregister(comp);
189 comp.zIndexManager = this;
191 this.list[comp.id] = comp;
192 this.zIndexStack.push(comp);
193 comp.on('hide', this._activateLast, this);
196 <span id='Ext-ZIndexManager-method-unregister'> /**
197 </span> * <p>Unregisters a {@link Ext.Component} from this ZIndexManager. This should not
198 * need to be called. Components are automatically unregistered upon destruction.
199 * See {@link #register}.</p>
200 * @param {Component} comp The Component to unregister.
202 unregister : function(comp) {
203 delete comp.zIndexManager;
204 if (this.list && this.list[comp.id]) {
205 delete this.list[comp.id];
206 comp.un('hide', this._activateLast);
207 Ext.Array.remove(this.zIndexStack, comp);
209 // Destruction requires that the topmost visible floater be activated. Same as hiding.
210 this._activateLast(comp);
214 <span id='Ext-ZIndexManager-method-get'> /**
215 </span> * Gets a registered Component by id.
216 * @param {String/Object} id The id of the Component or a {@link Ext.Component} instance
217 * @return {Ext.Component}
220 return typeof id == "object" ? id : this.list[id];
223 <span id='Ext-ZIndexManager-method-bringToFront'> /**
224 </span> * Brings the specified Component to the front of any other active Components in this ZIndexManager.
225 * @param {String/Object} comp The id of the Component or a {@link Ext.Component} instance
226 * @return {Boolean} True if the dialog was brought to the front, else false
227 * if it was already in front
229 bringToFront : function(comp) {
230 comp = this.get(comp);
231 if (comp != this.front) {
232 Ext.Array.remove(this.zIndexStack, comp);
233 this.zIndexStack.push(comp);
234 this.assignZIndices();
238 Ext.getBody().addCls(Ext.baseCSSPrefix + 'body-masked');
239 this.mask.setSize(Ext.core.Element.getViewWidth(true), Ext.core.Element.getViewHeight(true));
245 <span id='Ext-ZIndexManager-method-sendToBack'> /**
246 </span> * Sends the specified Component to the back of other active Components in this ZIndexManager.
247 * @param {String/Object} comp The id of the Component or a {@link Ext.Component} instance
248 * @return {Ext.Component} The Component
250 sendToBack : function(comp) {
251 comp = this.get(comp);
252 Ext.Array.remove(this.zIndexStack, comp);
253 this.zIndexStack.unshift(comp);
254 this.assignZIndices();
258 <span id='Ext-ZIndexManager-method-hideAll'> /**
259 </span> * Hides all Components managed by this ZIndexManager.
261 hideAll : function() {
262 for (var id in this.list) {
263 if (this.list[id].isComponent && this.list[id].isVisible()) {
264 this.list[id].hide();
269 <span id='Ext-ZIndexManager-method-hide'> /**
271 * Temporarily hides all currently visible managed Components. This is for when
272 * dragging a Window which may manage a set of floating descendants in its ZIndexManager;
273 * they should all be hidden just for the duration of the drag.
277 ln = this.zIndexStack.length,
280 this.tempHidden = [];
281 for (; i < ln; i++) {
282 comp = this.zIndexStack[i];
283 if (comp.isVisible()) {
284 this.tempHidden.push(comp);
290 <span id='Ext-ZIndexManager-method-show'> /**
292 * Restores temporarily hidden managed Components to visibility.
296 ln = this.tempHidden.length,
301 for (; i < ln; i++) {
302 comp = this.tempHidden[i];
306 comp.setPosition(x, y);
308 delete this.tempHidden;
311 <span id='Ext-ZIndexManager-method-getActive'> /**
312 </span> * Gets the currently-active Component in this ZIndexManager.
313 * @return {Ext.Component} The active Component
315 getActive : function() {
319 <span id='Ext-ZIndexManager-method-getBy'> /**
320 </span> * Returns zero or more Components in this ZIndexManager using the custom search function passed to this method.
321 * The function should accept a single {@link Ext.Component} reference as its only argument and should
322 * return true if the Component matches the search criteria, otherwise it should return false.
323 * @param {Function} fn The search function
324 * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the function is executed. Defaults to the Component being tested.
325 * that gets passed to the function if not specified)
326 * @return {Array} An array of zero or more matching windows
328 getBy : function(fn, scope) {
331 len = this.zIndexStack.length,
334 for (; i < len; i++) {
335 comp = this.zIndexStack[i];
336 if (fn.call(scope||comp, comp) !== false) {
343 <span id='Ext-ZIndexManager-method-each'> /**
344 </span> * Executes the specified function once for every Component in this ZIndexManager, passing each
345 * Component as the only parameter. Returning false from the function will stop the iteration.
346 * @param {Function} fn The function to execute for each item
347 * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the function is executed. Defaults to the current Component in the iteration.
349 each : function(fn, scope) {
351 for (var id in this.list) {
352 comp = this.list[id];
353 if (comp.isComponent && fn.call(scope || comp, comp) === false) {
359 <span id='Ext-ZIndexManager-method-eachBottomUp'> /**
360 </span> * Executes the specified function once for every Component in this ZIndexManager, passing each
361 * Component as the only parameter. Returning false from the function will stop the iteration.
362 * The components are passed to the function starting at the bottom and proceeding to the top.
363 * @param {Function} fn The function to execute for each item
364 * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the function
365 * is executed. Defaults to the current Component in the iteration.
367 eachBottomUp: function (fn, scope) {
369 stack = this.zIndexStack,
372 for (i = 0, n = stack.length ; i < n; i++) {
374 if (comp.isComponent && fn.call(scope || comp, comp) === false) {
380 <span id='Ext-ZIndexManager-method-eachTopDown'> /**
381 </span> * Executes the specified function once for every Component in this ZIndexManager, passing each
382 * Component as the only parameter. Returning false from the function will stop the iteration.
383 * The components are passed to the function starting at the top and proceeding to the bottom.
384 * @param {Function} fn The function to execute for each item
385 * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the function
386 * is executed. Defaults to the current Component in the iteration.
388 eachTopDown: function (fn, scope) {
390 stack = this.zIndexStack,
393 for (i = stack.length ; i-- > 0; ) {
395 if (comp.isComponent && fn.call(scope || comp, comp) === false) {
401 destroy: function() {
402 delete this.zIndexStack;
404 delete this.container;
405 delete this.targetEl;
408 <span id='Ext-WindowManager'> /**
409 </span> * @class Ext.WindowManager
410 * @extends Ext.ZIndexManager
411 * <p>The default global floating Component group that is available automatically.</p>
412 * <p>This manages instances of floating Components which were rendered programatically without
413 * being added to a {@link Ext.container.Container Container}, and for floating Components which were added into non-floating Containers.</p>
414 * <p><i>Floating</i> Containers create their own instance of ZIndexManager, and floating Components added at any depth below
415 * there are managed by that ZIndexManager.</p>
418 Ext.WindowManager = Ext.WindowMgr = new this();
420 </pre></pre></body></html>