X-Git-Url: http://git.ithinksw.org/extjs.git/blobdiff_plain/7a654f8d43fdb43d78b63d90528bed6e86b608cc..3789b528d8dd8aad4558e38e22d775bcab1cbd36:/src/window/Window.js diff --git a/src/window/Window.js b/src/window/Window.js index d9879016..2a73270e 100644 --- a/src/window/Window.js +++ b/src/window/Window.js @@ -353,7 +353,15 @@ Ext.define('Ext.window.Window', { if (me.closable) { keyMap = me.getKeyMap(); keyMap.on(27, me.onEsc, me); - keyMap.disable(); + + //if (hidden) { ? would be consistent w/before/afterShow... + keyMap.disable(); + //} + } + + if (!hidden) { + me.syncMonitorWindowResize(); + me.doConstrain(); } }, @@ -370,33 +378,40 @@ Ext.define('Ext.window.Window', { if (!me.header) { me.updateHeader(true); } + + /* + * Check the header here again. If for whatever reason it wasn't created in + * updateHeader (preventHeader) then we'll just ignore the rest since the + * header acts as the drag handle. + */ + if (me.header) { + ddConfig = Ext.applyIf({ + el: me.el, + delegate: '#' + me.header.id + }, me.draggable); + + // Add extra configs if Window is specified to be constrained + if (me.constrain || me.constrainHeader) { + ddConfig.constrain = me.constrain; + ddConfig.constrainDelegate = me.constrainHeader; + ddConfig.constrainTo = me.constrainTo || me.container; + } - ddConfig = Ext.applyIf({ - el: me.el, - delegate: '#' + me.header.id - }, me.draggable); - - // Add extra configs if Window is specified to be constrained - if (me.constrain || me.constrainHeader) { - ddConfig.constrain = me.constrain; - ddConfig.constrainDelegate = me.constrainHeader; - ddConfig.constrainTo = me.constrainTo || me.container; + /** + *

If this Window is configured {@link #draggable}, this property will contain + * an instance of {@link Ext.util.ComponentDragger} (A subclass of {@link Ext.dd.DragTracker DragTracker}) + * which handles dragging the Window's DOM Element, and constraining according to the {@link #constrain} + * and {@link #constrainHeader} .

+ *

This has implementations of onBeforeStart, onDrag and onEnd + * which perform the dragging action. If extra logic is needed at these points, use + * {@link Ext.Function#createInterceptor createInterceptor} or {@link Ext.Function#createSequence createSequence} to + * augment the existing implementations.

+ * @type Ext.util.ComponentDragger + * @property dd + */ + me.dd = Ext.create('Ext.util.ComponentDragger', this, ddConfig); + me.relayEvents(me.dd, ['dragstart', 'drag', 'dragend']); } - - /** - *

If this Window is configured {@link #draggable}, this property will contain - * an instance of {@link Ext.util.ComponentDragger} (A subclass of {@link Ext.dd.DragTracker DragTracker}) - * which handles dragging the Window's DOM Element, and constraining according to the {@link #constrain} - * and {@link #constrainHeader} .

- *

This has implementations of onBeforeStart, onDrag and onEnd - * which perform the dragging action. If extra logic is needed at these points, use - * {@link Ext.Function#createInterceptor createInterceptor} or {@link Ext.Function#createSequence createSequence} to - * augment the existing implementations.

- * @type Ext.util.ComponentDragger - * @property dd - */ - me.dd = Ext.create('Ext.util.ComponentDragger', this, ddConfig); - me.relayEvents(me.dd, ['dragstart', 'drag', 'dragend']); }, // private @@ -484,8 +499,7 @@ Ext.define('Ext.window.Window', { // private afterShow: function(animateTarget) { - var me = this, - size; + var me = this; // Perform superclass's afterShow tasks // Which might include animating a proxy from an animTarget @@ -495,10 +509,9 @@ Ext.define('Ext.window.Window', { me.fitContainer(); } - if (me.monitorResize || me.constrain || me.constrainHeader) { - Ext.EventManager.onWindowResize(me.onWindowResize, me); - } + me.syncMonitorWindowResize(); me.doConstrain(); + if (me.keyMap) { me.keyMap.enable(); } @@ -523,9 +536,7 @@ Ext.define('Ext.window.Window', { var me = this; // No longer subscribe to resizing now that we're hidden - if (me.monitorResize || me.constrain || me.constrainHeader) { - Ext.EventManager.removeResizeListener(me.onWindowResize, me); - } + me.syncMonitorWindowResize(); // Turn off keyboard handling once window is hidden if (me.keyMap) { @@ -613,6 +624,7 @@ Ext.define('Ext.window.Window', { me.el.addCls(Ext.baseCSSPrefix + 'window-maximized'); me.container.addCls(Ext.baseCSSPrefix + 'window-maximized-ct'); + me.syncMonitorWindowResize(); me.setPosition(0, 0); me.fitContainer(); me.fireEvent('maximize', me); @@ -665,12 +677,40 @@ Ext.define('Ext.window.Window', { me.container.removeCls(Ext.baseCSSPrefix + 'window-maximized-ct'); + me.syncMonitorWindowResize(); me.doConstrain(); me.fireEvent('restore', me); } return me; }, + /** + * Synchronizes the presence of our listener for window resize events. This method + * should be called whenever this status might change. + * @private + */ + syncMonitorWindowResize: function () { + var me = this, + currentlyMonitoring = me._monitoringResize, + // all the states where we should be listening to window resize: + yes = me.monitorResize || me.constrain || me.constrainHeader || me.maximized, + // all the states where we veto this: + veto = me.hidden || me.destroying || me.isDestroyed; + + if (yes && !veto) { + // we should be listening... + if (!currentlyMonitoring) { + // but we aren't, so set it up + Ext.EventManager.onWindowResize(me.onWindowResize, me); + me._monitoringResize = true; + } + } else if (currentlyMonitoring) { + // we should not be listening, but we are, so tear it down + Ext.EventManager.removeResizeListener(me.onWindowResize, me); + me._monitoringResize = false; + } + }, + /** * A shortcut method for toggling between {@link #maximize} and {@link #restore} based on the current maximized * state of the window.