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-window.Window-method-constructor'><span id='Ext-window.Window'>/**
2 </span></span> * @class Ext.window.Window
3 * @extends Ext.panel.Panel
4 * <p>A specialized panel intended for use as an application window. Windows are floated, {@link #resizable}, and
5 * {@link #draggable} by default. Windows can be {@link #maximizable maximized} to fill the viewport,
6 * restored to their prior size, and can be {@link #minimize}d.</p>
7 * <p>Windows can also be linked to a {@link Ext.ZIndexManager} or managed by the {@link Ext.WindowManager} to provide
8 * grouping, activation, to front, to back and other application-specific behavior.</p>
9 * <p>By default, Windows will be rendered to document.body. To {@link #constrain} a Window to another element
10 * specify {@link Ext.Component#renderTo renderTo}.</p>
11 * <p><b>As with all {@link Ext.container.Container Container}s, it is important to consider how you want the Window
12 * to size and arrange any child Components. Choose an appropriate {@link #layout} configuration which lays out
13 * child Components in the required manner.</b></p>
14 * {@img Ext.window.Window/Ext.window.Window.png Window component}
15 * Example:<code><pre>
16 Ext.create('Ext.window.Window', {
21 items: { // Let's put an empty grid in just to illustrate fit layout
24 columns: [{header: 'World'}], // One header just for show. There's no data,
25 store: Ext.create('Ext.data.ArrayStore', {}) // A dummy empty data store
28 </pre></code>
30 * @param {Object} config The config object
33 Ext.define('Ext.window.Window', {
34 extend: 'Ext.panel.Panel',
36 alternateClassName: 'Ext.Window',
38 requires: ['Ext.util.ComponentDragger', 'Ext.util.Region', 'Ext.EventManager'],
40 alias: 'widget.window',
42 <span id='Ext-window.Window-cfg-x'> /**
43 </span> * @cfg {Number} x
44 * The X position of the left edge of the window on initial showing. Defaults to centering the Window within
45 * the width of the Window's container {@link Ext.core.Element Element) (The Element that the Window is rendered to).
47 <span id='Ext-window.Window-cfg-y'> /**
48 </span> * @cfg {Number} y
49 * The Y position of the top edge of the window on initial showing. Defaults to centering the Window within
50 * the height of the Window's container {@link Ext.core.Element Element) (The Element that the Window is rendered to).
52 <span id='Ext-window.Window-cfg-modal'> /**
53 </span> * @cfg {Boolean} modal
54 * True to make the window modal and mask everything behind it when displayed, false to display it without
55 * restricting access to other UI elements (defaults to false).
57 <span id='Ext-window.Window-cfg-animateTarget'> /**
58 </span> * @cfg {String/Element} animateTarget
59 * Id or element from which the window should animate while opening (defaults to null with no animation).
61 <span id='Ext-window.Window-cfg-defaultFocus'> /**
62 </span> * @cfg {String/Number/Component} defaultFocus
63 * <p>Specifies a Component to receive focus when this Window is focused.</p>
64 * <p>This may be one of:</p><div class="mdetail-params"><ul>
65 * <li>The index of a footer Button.</li>
66 * <li>The id or {@link Ext.AbstractComponent#itemId} of a descendant Component.</li>
67 * <li>A Component.</li>
68 * </ul></div>
70 <span id='Ext-window.Window-cfg-onEsc'> /**
71 </span> * @cfg {Function} onEsc
72 * Allows override of the built-in processing for the escape key. Default action
73 * is to close the Window (performing whatever action is specified in {@link #closeAction}.
74 * To prevent the Window closing when the escape key is pressed, specify this as
75 * Ext.emptyFn (See {@link Ext#emptyFn Ext.emptyFn}).
77 <span id='Ext-window.Window-cfg-collapsed'> /**
78 </span> * @cfg {Boolean} collapsed
79 * True to render the window collapsed, false to render it expanded (defaults to false). Note that if
80 * {@link #expandOnShow} is true (the default) it will override the <code>collapsed</code> config and the window
81 * will always be expanded when shown.
83 <span id='Ext-window.Window-cfg-maximized'> /**
84 </span> * @cfg {Boolean} maximized
85 * True to initially display the window in a maximized state. (Defaults to false).
88 <span id='Ext-window.Window-cfg-baseCls'> /**
89 </span> * @cfg {String} baseCls
90 * The base CSS class to apply to this panel's element (defaults to 'x-window').
92 baseCls: Ext.baseCSSPrefix + 'window',
94 <span id='Ext-window.Window-cfg-resizable'> /**
95 </span> * @cfg {Mixed} resizable
96 * <p>Specify as <code>true</code> to allow user resizing at each edge and corner of the window, false to disable
97 * resizing (defaults to true).</p>
98 * <p>This may also be specified as a config object to </p>
102 <span id='Ext-window.Window-cfg-draggable'> /**
103 </span> * @cfg {Boolean} draggable
104 * <p>True to allow the window to be dragged by the header bar, false to disable dragging (defaults to true). Note
105 * that by default the window will be centered in the viewport, so if dragging is disabled the window may need
106 * to be positioned programmatically after render (e.g., myWindow.setPosition(100, 100);).<p>
110 <span id='Ext-window.Window-cfg-constrain'> /**
111 </span> * @cfg {Boolean} constrain
112 * True to constrain the window within its containing element, false to allow it to fall outside of its
113 * containing element. By default the window will be rendered to document.body. To render and constrain the
114 * window within another element specify {@link #renderTo}.
115 * (defaults to false). Optionally the header only can be constrained using {@link #constrainHeader}.
119 <span id='Ext-window.Window-cfg-constrainHeader'> /**
120 </span> * @cfg {Boolean} constrainHeader
121 * True to constrain the window header within its containing element (allowing the window body to fall outside
122 * of its containing element) or false to allow the header to fall outside its containing element (defaults to
123 * false). Optionally the entire window can be constrained using {@link #constrain}.
125 constrainHeader: false,
127 <span id='Ext-window.Window-cfg-plain'> /**
128 </span> * @cfg {Boolean} plain
129 * True to render the window body with a transparent background so that it will blend into the framing
130 * elements, false to add a lighter background color to visually highlight the body element and separate it
131 * more distinctly from the surrounding frame (defaults to false).
135 <span id='Ext-window.Window-cfg-minimizable'> /**
136 </span> * @cfg {Boolean} minimizable
137 * True to display the 'minimize' tool button and allow the user to minimize the window, false to hide the button
138 * and disallow minimizing the window (defaults to false). Note that this button provides no implementation --
139 * the behavior of minimizing a window is implementation-specific, so the minimize event must be handled and a
140 * custom minimize behavior implemented for this option to be useful.
144 <span id='Ext-window.Window-cfg-maximizable'> /**
145 </span> * @cfg {Boolean} maximizable
146 * True to display the 'maximize' tool button and allow the user to maximize the window, false to hide the button
147 * and disallow maximizing the window (defaults to false). Note that when a window is maximized, the tool button
148 * will automatically change to a 'restore' button with the appropriate behavior already built-in that will
149 * restore the window to its previous size.
159 <span id='Ext-window.Window-cfg-expandOnShow'> /**
160 </span> * @cfg {Boolean} expandOnShow
161 * True to always expand the window when it is displayed, false to keep it in its current state (which may be
162 * {@link #collapsed}) when displayed (defaults to true).
166 // inherited docs, same default
169 <span id='Ext-window.Window-cfg-closable'> /**
170 </span> * @cfg {Boolean} closable
171 * <p>True to display the 'close' tool button and allow the user to close the window, false to
172 * hide the button and disallow closing the window (defaults to <code>true</code>).</p>
173 * <p>By default, when close is requested by either clicking the close button in the header
174 * or pressing ESC when the Window has focus, the {@link #close} method will be called. This
175 * will <i>{@link Ext.Component#destroy destroy}</i> the Window and its content meaning that
176 * it may not be reused.</p>
177 * <p>To make closing a Window <i>hide</i> the Window so that it may be reused, set
178 * {@link #closeAction} to 'hide'.</p>
182 <span id='Ext-window.Window-cfg-hidden'> /**
183 </span> * @cfg {Boolean} hidden
184 * Render this Window hidden (default is <code>true</code>). If <code>true</code>, the
185 * {@link #hide} method will be called internally.
189 // Inherit docs from Component. Windows render to the body on first show.
192 // Inherit docs from Component. Windows hide using visibility.
193 hideMode: 'visibility',
195 <span id='Ext-window.Window-cfg-floating'> /** @cfg {Boolean} floating @hide Windows are always floating*/
196 </span> floating: true,
198 ariaRole: 'alertdialog',
200 itemCls: 'x-window-item',
204 ignoreHeaderBorderManagement: true,
207 initComponent: function() {
211 <span id='Ext-window.Window-event-activate'> /**
212 </span> * @event activate
213 * Fires after the window has been visually activated via {@link #setActive}.
214 * @param {Ext.window.Window} this
216 <span id='Ext-window.Window-event-deactivate'> /**
217 </span> * @event deactivate
218 * Fires after the window has been visually deactivated via {@link #setActive}.
219 * @param {Ext.window.Window} this
221 <span id='Ext-window.Window-event-resize'> /**
222 </span> * @event resize
223 * Fires after the window has been resized.
224 * @param {Ext.window.Window} this
225 * @param {Number} width The window's new width
226 * @param {Number} height The window's new height
229 <span id='Ext-window.Window-event-maximize'> /**
230 </span> * @event maximize
231 * Fires after the window has been maximized.
232 * @param {Ext.window.Window} this
235 <span id='Ext-window.Window-event-minimize'> /**
236 </span> * @event minimize
237 * Fires after the window has been minimized.
238 * @param {Ext.window.Window} this
241 <span id='Ext-window.Window-event-restore'> /**
242 </span> * @event restore
243 * Fires after the window has been restored to its original size after being maximized.
244 * @param {Ext.window.Window} this
250 me.addClsWithUI('plain');
254 me.ariaRole = 'dialog';
261 initStateEvents: function(){
262 var events = this.stateEvents;
263 // push on stateEvents if they don't exist
264 Ext.each(['maximize', 'restore', 'resize', 'dragend'], function(event){
265 if (Ext.Array.indexOf(events, event)) {
272 getState: function() {
274 state = me.callParent() || {},
275 maximized = !!me.maximized;
277 state.maximized = maximized;
279 size: maximized ? me.restoreSize : me.getSize(),
280 pos: maximized ? me.restorePos : me.getPosition()
285 applyState: function(state){
289 me.maximized = state.maximized;
291 me.hasSavedRestore = true;
292 me.restoreSize = state.size;
293 me.restorePos = state.pos;
296 width: state.size.width,
297 height: state.size.height,
306 onMouseDown: function () {
313 onRender: function(ct, position) {
315 me.callParent(arguments);
318 // Double clicking a header will toggleMaximize
319 if (me.maximizable) {
322 fn: me.toggleMaximize,
331 afterRender: function() {
337 // Component's afterRender sizes and positions the Component
341 // Create the proxy after the size has been applied in Component.afterRender
342 me.proxy = me.getProxy();
345 me.mon(me.el, 'mousedown', me.onMouseDown, me);
349 me.maximized = false;
354 keyMap = me.getKeyMap();
355 keyMap.on(27, me.onEsc, me);
360 <span id='Ext-window.Window-method-initDraggable'> /**
363 * Override Component.initDraggable.
364 * Window uses the header element as the delegate.
366 initDraggable: function() {
371 me.updateHeader(true);
374 ddConfig = Ext.applyIf({
376 delegate: '#' + me.header.id
379 // Add extra configs if Window is specified to be constrained
380 if (me.constrain || me.constrainHeader) {
381 ddConfig.constrain = me.constrain;
382 ddConfig.constrainDelegate = me.constrainHeader;
383 ddConfig.constrainTo = me.constrainTo || me.container;
386 <span id='Ext-window.Window-property-dd'> /**
387 </span> * <p>If this Window is configured {@link #draggable}, this property will contain
388 * an instance of {@link Ext.util.ComponentDragger} (A subclass of {@link Ext.dd.DragTracker DragTracker})
389 * which handles dragging the Window's DOM Element, and constraining according to the {@link #constrain}
390 * and {@link #constrainHeader} .</p>
391 * <p>This has implementations of <code>onBeforeStart</code>, <code>onDrag</code> and <code>onEnd</code>
392 * which perform the dragging action. If extra logic is needed at these points, use
393 * {@link Ext.Function#createInterceptor createInterceptor} or {@link Ext.Function#createSequence createSequence} to
394 * augment the existing implementations.</p>
395 * @type Ext.util.ComponentDragger
398 me.dd = Ext.create('Ext.util.ComponentDragger', this, ddConfig);
399 me.relayEvents(me.dd, ['dragstart', 'drag', 'dragend']);
403 onEsc: function(k, e) {
405 this[this.closeAction]();
409 beforeDestroy: function() {
412 delete this.animateTarget;
421 <span id='Ext-window.Window-method-addTools'> /**
424 * Contribute class-specific tools to the header.
425 * Called by Panel's initTools.
427 addTools: function() {
430 // Call Panel's initTools
433 if (me.minimizable) {
436 handler: Ext.Function.bind(me.minimize, me, [])
439 if (me.maximizable) {
442 handler: Ext.Function.bind(me.maximize, me, [])
446 handler: Ext.Function.bind(me.restore, me, []),
452 <span id='Ext-window.Window-method-getFocusEl'> /**
453 </span> * Gets the configured default focus item. If a {@link #defaultFocus} is set, it will receive focus, otherwise the
454 * Container itself will receive focus.
456 getFocusEl: function() {
459 defaultComp = me.defaultButton || me.defaultFocus,
464 if (Ext.isDefined(defaultComp)) {
465 if (Ext.isNumber(defaultComp)) {
466 f = me.query('button')[defaultComp];
467 } else if (Ext.isString(defaultComp)) {
468 f = me.down('#' + defaultComp);
473 return f || me.focusEl;
477 beforeShow: function() {
480 if (this.expandOnShow) {
486 afterShow: function(animateTarget) {
490 // Perform superclass's afterShow tasks
491 // Which might include animating a proxy from an animTarget
492 me.callParent(arguments);
498 if (me.monitorResize || me.constrain || me.constrainHeader) {
499 Ext.EventManager.onWindowResize(me.onWindowResize, me);
508 doClose: function() {
513 me.fireEvent('close', me);
514 me[me.closeAction]();
516 // close after hiding
517 me.hide(me.animTarget, me.doClose, me);
522 afterHide: function() {
525 // No longer subscribe to resizing now that we're hidden
526 if (me.monitorResize || me.constrain || me.constrainHeader) {
527 Ext.EventManager.removeResizeListener(me.onWindowResize, me);
530 // Turn off keyboard handling once window is hidden
535 // Perform superclass's afterHide tasks.
536 me.callParent(arguments);
540 onWindowResize: function() {
541 if (this.maximized) {
547 <span id='Ext-window.Window-method-minimize'> /**
548 </span> * Placeholder method for minimizing the window. By default, this method simply fires the {@link #minimize} event
549 * since the behavior of minimizing a window is application-specific. To implement custom minimize behavior,
550 * either the minimize event can be handled or this method can be overridden.
551 * @return {Ext.window.Window} this
553 minimize: function() {
554 this.fireEvent('minimize', this);
558 afterCollapse: function() {
561 if (me.maximizable) {
562 me.tools.maximize.hide();
563 me.tools.restore.hide();
566 me.resizer.disable();
568 me.callParent(arguments);
571 afterExpand: function() {
575 me.tools.restore.show();
576 } else if (me.maximizable) {
577 me.tools.maximize.show();
582 me.callParent(arguments);
585 <span id='Ext-window.Window-method-maximize'> /**
586 </span> * Fits the window within its current container and automatically replaces
587 * the {@link #maximizable 'maximize' tool button} with the 'restore' tool button.
588 * Also see {@link #toggleMaximize}.
589 * @return {Ext.window.Window} this
591 maximize: function() {
596 if (!me.hasSavedRestore) {
597 me.restoreSize = me.getSize();
598 me.restorePos = me.getPosition(true);
600 if (me.maximizable) {
601 me.tools.maximize.hide();
602 me.tools.restore.show();
605 me.el.disableShadow();
610 if (me.collapseTool) {
611 me.collapseTool.hide();
613 me.el.addCls(Ext.baseCSSPrefix + 'window-maximized');
614 me.container.addCls(Ext.baseCSSPrefix + 'window-maximized-ct');
616 me.setPosition(0, 0);
618 me.fireEvent('maximize', me);
623 <span id='Ext-window.Window-method-restore'> /**
624 </span> * Restores a {@link #maximizable maximized} window back to its original
625 * size and position prior to being maximized and also replaces
626 * the 'restore' tool button with the 'maximize' tool button.
627 * Also see {@link #toggleMaximize}.
628 * @return {Ext.window.Window} this
630 restore: function() {
635 delete me.hasSavedRestore;
636 me.removeCls(Ext.baseCSSPrefix + 'window-maximized');
638 // Toggle tool visibility
640 tools.restore.hide();
642 if (tools.maximize) {
643 tools.maximize.show();
645 if (me.collapseTool) {
646 me.collapseTool.show();
649 // Restore the position/sizing
650 me.setPosition(me.restorePos);
651 me.setSize(me.restoreSize);
653 // Unset old position/sizing
654 delete me.restorePos;
655 delete me.restoreSize;
657 me.maximized = false;
659 me.el.enableShadow(true);
661 // Allow users to drag and drop again
666 me.container.removeCls(Ext.baseCSSPrefix + 'window-maximized-ct');
669 me.fireEvent('restore', me);
674 <span id='Ext-window.Window-method-toggleMaximize'> /**
675 </span> * A shortcut method for toggling between {@link #maximize} and {@link #restore} based on the current maximized
676 * state of the window.
677 * @return {Ext.window.Window} this
679 toggleMaximize: function() {
680 return this[this.maximized ? 'restore': 'maximize']();
683 <span id='Ext-window.Window-cfg-autoWidth'> /**
684 </span> * @cfg {Boolean} autoWidth @hide
685 * Absolute positioned element and therefore cannot support autoWidth.
686 * A width is a required configuration.
688 });</pre></pre></body></html>