4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../prettify/prettify.js"></script>
8 <style type="text/css">
9 .highlight { display: block; background-color: #ddd; }
11 <script type="text/javascript">
12 function highlight() {
13 document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
17 <body onload="prettyPrint(); highlight();">
18 <pre class="prettyprint lang-js"><span id='Ext-window-Window-method-constructor'><span id='Ext-window-Window'>/**
19 </span></span> * @class Ext.window.Window
20 * @extends Ext.panel.Panel
21 * <p>A specialized panel intended for use as an application window. Windows are floated, {@link #resizable}, and
22 * {@link #draggable} by default. Windows can be {@link #maximizable maximized} to fill the viewport,
23 * restored to their prior size, and can be {@link #minimize}d.</p>
24 * <p>Windows can also be linked to a {@link Ext.ZIndexManager} or managed by the {@link Ext.WindowManager} to provide
25 * grouping, activation, to front, to back and other application-specific behavior.</p>
26 * <p>By default, Windows will be rendered to document.body. To {@link #constrain} a Window to another element
27 * specify {@link Ext.Component#renderTo renderTo}.</p>
28 * <p><b>As with all {@link Ext.container.Container Container}s, it is important to consider how you want the Window
29 * to size and arrange any child Components. Choose an appropriate {@link #layout} configuration which lays out
30 * child Components in the required manner.</b></p>
31 * {@img Ext.window.Window/Ext.window.Window.png Window component}
32 * Example:<code><pre>
33 Ext.create('Ext.window.Window', {
38 items: { // Let's put an empty grid in just to illustrate fit layout
41 columns: [{header: 'World'}], // One header just for show. There's no data,
42 store: Ext.create('Ext.data.ArrayStore', {}) // A dummy empty data store
45 </pre></code>
47 * @param {Object} config The config object
50 Ext.define('Ext.window.Window', {
51 extend: 'Ext.panel.Panel',
53 alternateClassName: 'Ext.Window',
55 requires: ['Ext.util.ComponentDragger', 'Ext.util.Region', 'Ext.EventManager'],
57 alias: 'widget.window',
59 <span id='Ext-window-Window-cfg-x'> /**
60 </span> * @cfg {Number} x
61 * The X position of the left edge of the window on initial showing. Defaults to centering the Window within
62 * the width of the Window's container {@link Ext.core.Element Element) (The Element that the Window is rendered to).
64 <span id='Ext-window-Window-cfg-y'> /**
65 </span> * @cfg {Number} y
66 * The Y position of the top edge of the window on initial showing. Defaults to centering the Window within
67 * the height of the Window's container {@link Ext.core.Element Element) (The Element that the Window is rendered to).
69 <span id='Ext-window-Window-cfg-modal'> /**
70 </span> * @cfg {Boolean} modal
71 * True to make the window modal and mask everything behind it when displayed, false to display it without
72 * restricting access to other UI elements (defaults to false).
74 <span id='Ext-window-Window-cfg-animateTarget'> /**
75 </span> * @cfg {String/Element} animateTarget
76 * Id or element from which the window should animate while opening (defaults to null with no animation).
78 <span id='Ext-window-Window-cfg-defaultFocus'> /**
79 </span> * @cfg {String/Number/Component} defaultFocus
80 * <p>Specifies a Component to receive focus when this Window is focused.</p>
81 * <p>This may be one of:</p><div class="mdetail-params"><ul>
82 * <li>The index of a footer Button.</li>
83 * <li>The id or {@link Ext.AbstractComponent#itemId} of a descendant Component.</li>
84 * <li>A Component.</li>
85 * </ul></div>
87 <span id='Ext-window-Window-cfg-onEsc'> /**
88 </span> * @cfg {Function} onEsc
89 * Allows override of the built-in processing for the escape key. Default action
90 * is to close the Window (performing whatever action is specified in {@link #closeAction}.
91 * To prevent the Window closing when the escape key is pressed, specify this as
92 * Ext.emptyFn (See {@link Ext#emptyFn Ext.emptyFn}).
94 <span id='Ext-window-Window-cfg-collapsed'> /**
95 </span> * @cfg {Boolean} collapsed
96 * True to render the window collapsed, false to render it expanded (defaults to false). Note that if
97 * {@link #expandOnShow} is true (the default) it will override the <code>collapsed</code> config and the window
98 * will always be expanded when shown.
100 <span id='Ext-window-Window-cfg-maximized'> /**
101 </span> * @cfg {Boolean} maximized
102 * True to initially display the window in a maximized state. (Defaults to false).
105 <span id='Ext-window-Window-cfg-baseCls'> /**
106 </span> * @cfg {String} baseCls
107 * The base CSS class to apply to this panel's element (defaults to 'x-window').
109 baseCls: Ext.baseCSSPrefix + 'window',
111 <span id='Ext-window-Window-cfg-resizable'> /**
112 </span> * @cfg {Mixed} resizable
113 * <p>Specify as <code>true</code> to allow user resizing at each edge and corner of the window, false to disable
114 * resizing (defaults to true).</p>
115 * <p>This may also be specified as a config object to </p>
119 <span id='Ext-window-Window-cfg-draggable'> /**
120 </span> * @cfg {Boolean} draggable
121 * <p>True to allow the window to be dragged by the header bar, false to disable dragging (defaults to true). Note
122 * that by default the window will be centered in the viewport, so if dragging is disabled the window may need
123 * to be positioned programmatically after render (e.g., myWindow.setPosition(100, 100);).<p>
127 <span id='Ext-window-Window-cfg-constrain'> /**
128 </span> * @cfg {Boolean} constrain
129 * True to constrain the window within its containing element, false to allow it to fall outside of its
130 * containing element. By default the window will be rendered to document.body. To render and constrain the
131 * window within another element specify {@link #renderTo}.
132 * (defaults to false). Optionally the header only can be constrained using {@link #constrainHeader}.
136 <span id='Ext-window-Window-cfg-constrainHeader'> /**
137 </span> * @cfg {Boolean} constrainHeader
138 * True to constrain the window header within its containing element (allowing the window body to fall outside
139 * of its containing element) or false to allow the header to fall outside its containing element (defaults to
140 * false). Optionally the entire window can be constrained using {@link #constrain}.
142 constrainHeader: false,
144 <span id='Ext-window-Window-cfg-plain'> /**
145 </span> * @cfg {Boolean} plain
146 * True to render the window body with a transparent background so that it will blend into the framing
147 * elements, false to add a lighter background color to visually highlight the body element and separate it
148 * more distinctly from the surrounding frame (defaults to false).
152 <span id='Ext-window-Window-cfg-minimizable'> /**
153 </span> * @cfg {Boolean} minimizable
154 * True to display the 'minimize' tool button and allow the user to minimize the window, false to hide the button
155 * and disallow minimizing the window (defaults to false). Note that this button provides no implementation --
156 * the behavior of minimizing a window is implementation-specific, so the minimize event must be handled and a
157 * custom minimize behavior implemented for this option to be useful.
161 <span id='Ext-window-Window-cfg-maximizable'> /**
162 </span> * @cfg {Boolean} maximizable
163 * True to display the 'maximize' tool button and allow the user to maximize the window, false to hide the button
164 * and disallow maximizing the window (defaults to false). Note that when a window is maximized, the tool button
165 * will automatically change to a 'restore' button with the appropriate behavior already built-in that will
166 * restore the window to its previous size.
176 <span id='Ext-window-Window-cfg-expandOnShow'> /**
177 </span> * @cfg {Boolean} expandOnShow
178 * True to always expand the window when it is displayed, false to keep it in its current state (which may be
179 * {@link #collapsed}) when displayed (defaults to true).
183 // inherited docs, same default
186 <span id='Ext-window-Window-cfg-closable'> /**
187 </span> * @cfg {Boolean} closable
188 * <p>True to display the 'close' tool button and allow the user to close the window, false to
189 * hide the button and disallow closing the window (defaults to <code>true</code>).</p>
190 * <p>By default, when close is requested by either clicking the close button in the header
191 * or pressing ESC when the Window has focus, the {@link #close} method will be called. This
192 * will <i>{@link Ext.Component#destroy destroy}</i> the Window and its content meaning that
193 * it may not be reused.</p>
194 * <p>To make closing a Window <i>hide</i> the Window so that it may be reused, set
195 * {@link #closeAction} to 'hide'.</p>
199 <span id='Ext-window-Window-cfg-hidden'> /**
200 </span> * @cfg {Boolean} hidden
201 * Render this Window hidden (default is <code>true</code>). If <code>true</code>, the
202 * {@link #hide} method will be called internally.
206 // Inherit docs from Component. Windows render to the body on first show.
209 // Inherit docs from Component. Windows hide using visibility.
210 hideMode: 'visibility',
212 <span id='Ext-window-Window-cfg-floating'> /** @cfg {Boolean} floating @hide Windows are always floating*/
213 </span> floating: true,
215 ariaRole: 'alertdialog',
217 itemCls: 'x-window-item',
221 ignoreHeaderBorderManagement: true,
224 initComponent: function() {
228 <span id='Ext-window-Window-event-activate'> /**
229 </span> * @event activate
230 * Fires after the window has been visually activated via {@link #setActive}.
231 * @param {Ext.window.Window} this
233 <span id='Ext-window-Window-event-deactivate'> /**
234 </span> * @event deactivate
235 * Fires after the window has been visually deactivated via {@link #setActive}.
236 * @param {Ext.window.Window} this
238 <span id='Ext-window-Window-event-resize'> /**
239 </span> * @event resize
240 * Fires after the window has been resized.
241 * @param {Ext.window.Window} this
242 * @param {Number} width The window's new width
243 * @param {Number} height The window's new height
246 <span id='Ext-window-Window-event-maximize'> /**
247 </span> * @event maximize
248 * Fires after the window has been maximized.
249 * @param {Ext.window.Window} this
252 <span id='Ext-window-Window-event-minimize'> /**
253 </span> * @event minimize
254 * Fires after the window has been minimized.
255 * @param {Ext.window.Window} this
258 <span id='Ext-window-Window-event-restore'> /**
259 </span> * @event restore
260 * Fires after the window has been restored to its original size after being maximized.
261 * @param {Ext.window.Window} this
267 me.addClsWithUI('plain');
271 me.ariaRole = 'dialog';
278 initStateEvents: function(){
279 var events = this.stateEvents;
280 // push on stateEvents if they don't exist
281 Ext.each(['maximize', 'restore', 'resize', 'dragend'], function(event){
282 if (Ext.Array.indexOf(events, event)) {
289 getState: function() {
291 state = me.callParent() || {},
292 maximized = !!me.maximized;
294 state.maximized = maximized;
296 size: maximized ? me.restoreSize : me.getSize(),
297 pos: maximized ? me.restorePos : me.getPosition()
302 applyState: function(state){
306 me.maximized = state.maximized;
308 me.hasSavedRestore = true;
309 me.restoreSize = state.size;
310 me.restorePos = state.pos;
313 width: state.size.width,
314 height: state.size.height,
323 onMouseDown: function () {
330 onRender: function(ct, position) {
332 me.callParent(arguments);
335 // Double clicking a header will toggleMaximize
336 if (me.maximizable) {
339 fn: me.toggleMaximize,
348 afterRender: function() {
354 // Component's afterRender sizes and positions the Component
358 // Create the proxy after the size has been applied in Component.afterRender
359 me.proxy = me.getProxy();
362 me.mon(me.el, 'mousedown', me.onMouseDown, me);
366 me.maximized = false;
371 keyMap = me.getKeyMap();
372 keyMap.on(27, me.onEsc, me);
374 //if (hidden) { ? would be consistent w/before/afterShow...
380 me.syncMonitorWindowResize();
385 <span id='Ext-window-Window-method-initDraggable'> /**
388 * Override Component.initDraggable.
389 * Window uses the header element as the delegate.
391 initDraggable: function() {
396 me.updateHeader(true);
400 * Check the header here again. If for whatever reason it wasn't created in
401 * updateHeader (preventHeader) then we'll just ignore the rest since the
402 * header acts as the drag handle.
405 ddConfig = Ext.applyIf({
407 delegate: '#' + me.header.id
410 // Add extra configs if Window is specified to be constrained
411 if (me.constrain || me.constrainHeader) {
412 ddConfig.constrain = me.constrain;
413 ddConfig.constrainDelegate = me.constrainHeader;
414 ddConfig.constrainTo = me.constrainTo || me.container;
417 <span id='Ext-window-Window-property-dd'> /**
418 </span> * <p>If this Window is configured {@link #draggable}, this property will contain
419 * an instance of {@link Ext.util.ComponentDragger} (A subclass of {@link Ext.dd.DragTracker DragTracker})
420 * which handles dragging the Window's DOM Element, and constraining according to the {@link #constrain}
421 * and {@link #constrainHeader} .</p>
422 * <p>This has implementations of <code>onBeforeStart</code>, <code>onDrag</code> and <code>onEnd</code>
423 * which perform the dragging action. If extra logic is needed at these points, use
424 * {@link Ext.Function#createInterceptor createInterceptor} or {@link Ext.Function#createSequence createSequence} to
425 * augment the existing implementations.</p>
426 * @type Ext.util.ComponentDragger
429 me.dd = Ext.create('Ext.util.ComponentDragger', this, ddConfig);
430 me.relayEvents(me.dd, ['dragstart', 'drag', 'dragend']);
435 onEsc: function(k, e) {
437 this[this.closeAction]();
441 beforeDestroy: function() {
444 delete this.animateTarget;
453 <span id='Ext-window-Window-method-addTools'> /**
456 * Contribute class-specific tools to the header.
457 * Called by Panel's initTools.
459 addTools: function() {
462 // Call Panel's initTools
465 if (me.minimizable) {
468 handler: Ext.Function.bind(me.minimize, me, [])
471 if (me.maximizable) {
474 handler: Ext.Function.bind(me.maximize, me, [])
478 handler: Ext.Function.bind(me.restore, me, []),
484 <span id='Ext-window-Window-method-getFocusEl'> /**
485 </span> * Gets the configured default focus item. If a {@link #defaultFocus} is set, it will receive focus, otherwise the
486 * Container itself will receive focus.
488 getFocusEl: function() {
491 defaultComp = me.defaultButton || me.defaultFocus,
496 if (Ext.isDefined(defaultComp)) {
497 if (Ext.isNumber(defaultComp)) {
498 f = me.query('button')[defaultComp];
499 } else if (Ext.isString(defaultComp)) {
500 f = me.down('#' + defaultComp);
505 return f || me.focusEl;
509 beforeShow: function() {
512 if (this.expandOnShow) {
518 afterShow: function(animateTarget) {
520 animating = animateTarget || me.animateTarget;
525 * If we're animating, constrain the positioning before calling the
526 * superclass, otherwise we'll be animating to the unconstrained
531 // Perform superclass's afterShow tasks
532 // Which might include animating a proxy from an animTarget
533 me.callParent(arguments);
539 me.syncMonitorWindowResize();
550 doClose: function() {
555 me.fireEvent('close', me);
556 me[me.closeAction]();
558 // close after hiding
559 me.hide(me.animTarget, me.doClose, me);
564 afterHide: function() {
567 // No longer subscribe to resizing now that we're hidden
568 me.syncMonitorWindowResize();
570 // Turn off keyboard handling once window is hidden
575 // Perform superclass's afterHide tasks.
576 me.callParent(arguments);
580 onWindowResize: function() {
581 if (this.maximized) {
587 <span id='Ext-window-Window-method-minimize'> /**
588 </span> * Placeholder method for minimizing the window. By default, this method simply fires the {@link #minimize} event
589 * since the behavior of minimizing a window is application-specific. To implement custom minimize behavior,
590 * either the minimize event can be handled or this method can be overridden.
591 * @return {Ext.window.Window} this
593 minimize: function() {
594 this.fireEvent('minimize', this);
598 afterCollapse: function() {
601 if (me.maximizable) {
602 me.tools.maximize.hide();
603 me.tools.restore.hide();
606 me.resizer.disable();
608 me.callParent(arguments);
611 afterExpand: function() {
615 me.tools.restore.show();
616 } else if (me.maximizable) {
617 me.tools.maximize.show();
622 me.callParent(arguments);
625 <span id='Ext-window-Window-method-maximize'> /**
626 </span> * Fits the window within its current container and automatically replaces
627 * the {@link #maximizable 'maximize' tool button} with the 'restore' tool button.
628 * Also see {@link #toggleMaximize}.
629 * @return {Ext.window.Window} this
631 maximize: function() {
636 if (!me.hasSavedRestore) {
637 me.restoreSize = me.getSize();
638 me.restorePos = me.getPosition(true);
640 if (me.maximizable) {
641 me.tools.maximize.hide();
642 me.tools.restore.show();
645 me.el.disableShadow();
650 if (me.collapseTool) {
651 me.collapseTool.hide();
653 me.el.addCls(Ext.baseCSSPrefix + 'window-maximized');
654 me.container.addCls(Ext.baseCSSPrefix + 'window-maximized-ct');
656 me.syncMonitorWindowResize();
657 me.setPosition(0, 0);
659 me.fireEvent('maximize', me);
664 <span id='Ext-window-Window-method-restore'> /**
665 </span> * Restores a {@link #maximizable maximized} window back to its original
666 * size and position prior to being maximized and also replaces
667 * the 'restore' tool button with the 'maximize' tool button.
668 * Also see {@link #toggleMaximize}.
669 * @return {Ext.window.Window} this
671 restore: function() {
676 delete me.hasSavedRestore;
677 me.removeCls(Ext.baseCSSPrefix + 'window-maximized');
679 // Toggle tool visibility
681 tools.restore.hide();
683 if (tools.maximize) {
684 tools.maximize.show();
686 if (me.collapseTool) {
687 me.collapseTool.show();
690 // Restore the position/sizing
691 me.setPosition(me.restorePos);
692 me.setSize(me.restoreSize);
694 // Unset old position/sizing
695 delete me.restorePos;
696 delete me.restoreSize;
698 me.maximized = false;
700 me.el.enableShadow(true);
702 // Allow users to drag and drop again
707 me.container.removeCls(Ext.baseCSSPrefix + 'window-maximized-ct');
709 me.syncMonitorWindowResize();
711 me.fireEvent('restore', me);
716 <span id='Ext-window-Window-method-syncMonitorWindowResize'> /**
717 </span> * Synchronizes the presence of our listener for window resize events. This method
718 * should be called whenever this status might change.
721 syncMonitorWindowResize: function () {
723 currentlyMonitoring = me._monitoringResize,
724 // all the states where we should be listening to window resize:
725 yes = me.monitorResize || me.constrain || me.constrainHeader || me.maximized,
726 // all the states where we veto this:
727 veto = me.hidden || me.destroying || me.isDestroyed;
729 if (yes && !veto) {
730 // we should be listening...
731 if (!currentlyMonitoring) {
732 // but we aren't, so set it up
733 Ext.EventManager.onWindowResize(me.onWindowResize, me);
734 me._monitoringResize = true;
736 } else if (currentlyMonitoring) {
737 // we should not be listening, but we are, so tear it down
738 Ext.EventManager.removeResizeListener(me.onWindowResize, me);
739 me._monitoringResize = false;
743 <span id='Ext-window-Window-method-toggleMaximize'> /**
744 </span> * A shortcut method for toggling between {@link #maximize} and {@link #restore} based on the current maximized
745 * state of the window.
746 * @return {Ext.window.Window} this
748 toggleMaximize: function() {
749 return this[this.maximized ? 'restore': 'maximize']();
752 <span id='Ext-window-Window-cfg-autoWidth'> /**
753 </span> * @cfg {Boolean} autoWidth @hide
754 * Absolute positioned element and therefore cannot support autoWidth.
755 * A width is a required configuration.