Upgrade to ExtJS 4.0.7 - Released 10/19/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.Window
17  */
18 Ext.Window.override({
19     /*
20      * Anchors this window to another element and realigns it when the window is resized or scrolled.
21      * @param {String/HTMLElement/Ext.Element} element The element to align to.
22      * @param {String} position The position to align to (see {@link Ext.Element#alignTo} for more details)
23      * @param {Number[]} offsets (optional) Offset the positioning by [x, y]
24      * @param {Boolean/Number} monitorScroll (optional) true to monitor body scroll and reposition. If this parameter
25      * is a number, it is used as the buffer delay (defaults to 50ms).
26      * @return {Ext.window.Window} this
27      */
28     anchorTo: function(el, alignment, offsets, monitorScroll) {
29         this.clearAnchor();
30         this.anchorTarget = {
31             el: el,
32             alignment: alignment,
33             offsets: offsets
34         };
35
36         Ext.EventManager.onWindowResize(this.doAnchor, this);
37         var tm = typeof monitorScroll;
38         if (tm != 'undefined') {
39             Ext.EventManager.on(window, 'scroll', this.doAnchor, this,
40             {
41                 buffer: tm == 'number' ? monitorScroll: 50
42             });
43         }
44         return this.doAnchor();
45     },
46
47     /*
48      * Performs the anchor, using the saved anchorTarget property.
49      * @return {Ext.window.Window} this
50      * @private
51      */
52     doAnchor: function() {
53         var o = this.anchorTarget;
54         this.alignTo(o.el, o.alignment, o.offsets);
55         return this;
56     },
57
58     /*
59      * Removes any existing anchor from this window. See {@link #anchorTo}.
60      * @return {Ext.window.Window} this
61      */
62     clearAnchor: function() {
63         if (this.anchorTarget) {
64             Ext.EventManager.removeResizeListener(this.doAnchor, this);
65             Ext.EventManager.un(window, 'scroll', this.doAnchor, this);
66             delete this.anchorTarget;
67         }
68         return this;
69     }
70 });