Upgrade to ExtJS 4.0.2 - Released 06/09/2011
[extjs.git] / src / window / Window-legacy.js
1 /*
2
3 This file is part of Ext JS 4
4
5 Copyright (c) 2011 Sencha Inc
6
7 Contact:  http://www.sencha.com/contact
8
9 GNU General Public License Usage
10 This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file.  Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
11
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
13
14 */
15 /**
16  * @class Ext.Window
17  * @ignore
18  */
19 Ext.Window.override({
20     /**
21      * Anchors this window to another element and realigns it when the window is resized or scrolled.
22      * @param {Mixed} element The element to align to.
23      * @param {String} position The position to align to (see {@link Ext.core.Element#alignTo} for more details)
24      * @param {Array} offsets (optional) Offset the positioning by [x, y]
25      * @param {Boolean/Number} monitorScroll (optional) true to monitor body scroll and reposition. If this parameter
26      * is a number, it is used as the buffer delay (defaults to 50ms).
27      * @return {Ext.window.Window} this
28      */
29     anchorTo: function(el, alignment, offsets, monitorScroll) {
30         this.clearAnchor();
31         this.anchorTarget = {
32             el: el,
33             alignment: alignment,
34             offsets: offsets
35         };
36
37         Ext.EventManager.onWindowResize(this.doAnchor, this);
38         var tm = typeof monitorScroll;
39         if (tm != 'undefined') {
40             Ext.EventManager.on(window, 'scroll', this.doAnchor, this,
41             {
42                 buffer: tm == 'number' ? monitorScroll: 50
43             });
44         }
45         return this.doAnchor();
46     },
47
48     /**
49      * Performs the anchor, using the saved anchorTarget property.
50      * @return {Ext.window.Window} this
51      * @private
52      */
53     doAnchor: function() {
54         var o = this.anchorTarget;
55         this.alignTo(o.el, o.alignment, o.offsets);
56         return this;
57     },
58
59     /**
60      * Removes any existing anchor from this window. See {@link #anchorTo}.
61      * @return {Ext.window.Window} this
62      */
63     clearAnchor: function() {
64         if (this.anchorTarget) {
65             Ext.EventManager.removeResizeListener(this.doAnchor, this);
66             Ext.EventManager.un(window, 'scroll', this.doAnchor, this);
67             delete this.anchorTarget;
68         }
69         return this;
70     }
71 });