Upgrade to ExtJS 4.0.0 - Released 04/26/2011
[extjs.git] / src / window / Window-legacy.js
1 /**
2  * @class Ext.Window
3  * @ignore
4  */
5 Ext.Window.override({
6     /**
7      * Anchors this window to another element and realigns it when the window is resized or scrolled.
8      * @param {Mixed} element The element to align to.
9      * @param {String} position The position to align to (see {@link Ext.core.Element#alignTo} for more details)
10      * @param {Array} offsets (optional) Offset the positioning by [x, y]
11      * @param {Boolean/Number} monitorScroll (optional) true to monitor body scroll and reposition. If this parameter
12      * is a number, it is used as the buffer delay (defaults to 50ms).
13      * @return {Ext.window.Window} this
14      */
15     anchorTo: function(el, alignment, offsets, monitorScroll) {
16         this.clearAnchor();
17         this.anchorTarget = {
18             el: el,
19             alignment: alignment,
20             offsets: offsets
21         };
22
23         Ext.EventManager.onWindowResize(this.doAnchor, this);
24         var tm = typeof monitorScroll;
25         if (tm != 'undefined') {
26             Ext.EventManager.on(window, 'scroll', this.doAnchor, this,
27             {
28                 buffer: tm == 'number' ? monitorScroll: 50
29             });
30         }
31         return this.doAnchor();
32     },
33
34     /**
35      * Performs the anchor, using the saved anchorTarget property.
36      * @return {Ext.window.Window} this
37      * @private
38      */
39     doAnchor: function() {
40         var o = this.anchorTarget;
41         this.alignTo(o.el, o.alignment, o.offsets);
42         return this;
43     },
44
45     /**
46      * Removes any existing anchor from this window. See {@link #anchorTo}.
47      * @return {Ext.window.Window} this
48      */
49     clearAnchor: function() {
50         if (this.anchorTarget) {
51             Ext.EventManager.removeResizeListener(this.doAnchor, this);
52             Ext.EventManager.un(window, 'scroll', this.doAnchor, this);
53             delete this.anchorTarget;
54         }
55         return this;
56     }
57 });