Upgrade to ExtJS 3.0.0 - Released 07/06/2009
[extjs.git] / source / widgets / BoxComponent.js
diff --git a/source/widgets/BoxComponent.js b/source/widgets/BoxComponent.js
deleted file mode 100644 (file)
index 037579c..0000000
+++ /dev/null
@@ -1,361 +0,0 @@
-/*\r
- * Ext JS Library 2.2.1\r
- * Copyright(c) 2006-2009, Ext JS, LLC.\r
- * licensing@extjs.com\r
- * \r
- * http://extjs.com/license\r
- */\r
-\r
-/**\r
- * @class Ext.BoxComponent\r
- * @extends Ext.Component\r
- * <p>Base class for any visual {@link Ext.Component} that uses a box container.  BoxComponent provides automatic box\r
- * model adjustments for sizing and positioning and will work correctly withnin the Component rendering model.  All\r
- * container classes should subclass BoxComponent so that they will work consistently when nested within other Ext\r
- * layout containers.</p>\r
- * <p>A BoxComponent may be created as a custom Component which encapsulates any HTML element, either a pre-existing\r
- * element, or one that is created to your specifications at render time. Usually, to participate in layouts,\r
- * a Component will need to be a <b>Box</b>Component in order to have its width and height managed.</p>\r
- * <p>To use a pre-existing element as a BoxComponent, configure it so that you preset the <b>el</b> property to the\r
- * element to reference:<pre><code>\r
-var pageHeader = new Ext.BoxComponent({\r
-    el: 'my-header-div'\r
-});</code></pre>\r
- * This may then be {@link Ext.Container#add added} to a {@link Ext.Container Container} as a child item.</p>\r
- * <p>To create a BoxComponent based around a HTML element to be created at render time, use the\r
- * {@link Ext.Component#autoEl autoEl} config option which takes the form of a\r
- * {@link Ext.DomHelper DomHelper} specification:<pre><code>\r
-var myImage = new Ext.BoxComponent({\r
-    autoEl: {\r
-        tag: 'img',\r
-        src: '/images/my-image.jpg'\r
-    }\r
-});</code></pre></p>\r
- * @constructor\r
- * @param {Ext.Element/String/Object} config The configuration options.\r
- */\r
-Ext.BoxComponent = Ext.extend(Ext.Component, {\r
-    /**\r
-     * @cfg {Number} x\r
-     * The local x (left) coordinate for this component if contained within a positioning container.\r
-     */\r
-    /**\r
-     * @cfg {Number} y\r
-     * The local y (top) coordinate for this component if contained within a positioning container.\r
-     */\r
-    /**\r
-     * @cfg {Number} pageX\r
-     * The page level x coordinate for this component if contained within a positioning container.\r
-     */\r
-    /**\r
-     * @cfg {Number} pageY\r
-     * The page level y coordinate for this component if contained within a positioning container.\r
-     */\r
-    /**\r
-     * @cfg {Number} height\r
-     * The height of this component in pixels (defaults to auto).\r
-     */\r
-    /**\r
-     * @cfg {Number} width\r
-     * The width of this component in pixels (defaults to auto).\r
-     */\r
-    /**\r
-     * @cfg {Boolean} autoHeight\r
-     * True to use height:'auto', false to use fixed height (defaults to false). <b>Note</b>: Although many components \r
-     * inherit this config option, not all will function as expected with a height of 'auto'. Setting autoHeight:true \r
-     * means that the browser will manage height based on the element's contents, and that Ext will not manage it at all.\r
-     */\r
-    /**\r
-     * @cfg {Boolean} autoWidth\r
-     * True to use width:'auto', false to use fixed width (defaults to false). <b>Note</b>: Although many components \r
-     * inherit this config option, not all will function as expected with a width of 'auto'. Setting autoWidth:true \r
-     * means that the browser will manage width based on the element's contents, and that Ext will not manage it at all.\r
-     */\r
-\r
-    /* // private internal config\r
-     * {Boolean} deferHeight\r
-     * True to defer height calculations to an external component, false to allow this component to set its own\r
-     * height (defaults to false).\r
-     */\r
-\r
-       // private\r
-    initComponent : function(){\r
-        Ext.BoxComponent.superclass.initComponent.call(this);\r
-        this.addEvents(\r
-            /**\r
-             * @event resize\r
-             * Fires after the component is resized.\r
-             * @param {Ext.Component} this\r
-             * @param {Number} adjWidth The box-adjusted width that was set\r
-             * @param {Number} adjHeight The box-adjusted height that was set\r
-             * @param {Number} rawWidth The width that was originally specified\r
-             * @param {Number} rawHeight The height that was originally specified\r
-             */\r
-            'resize',\r
-            /**\r
-             * @event move\r
-             * Fires after the component is moved.\r
-             * @param {Ext.Component} this\r
-             * @param {Number} x The new x position\r
-             * @param {Number} y The new y position\r
-             */\r
-            'move'\r
-        );\r
-    },\r
-\r
-    // private, set in afterRender to signify that the component has been rendered\r
-    boxReady : false,\r
-    // private, used to defer height settings to subclasses\r
-    deferHeight: false,\r
-\r
-    /**\r
-     * Sets the width and height of the component.  This method fires the {@link #resize} event.  This method can accept\r
-     * either width and height as separate numeric arguments, or you can pass a size object like {width:10, height:20}.\r
-     * @param {Number/Object} width The new width to set, or a size object in the format {width, height}\r
-     * @param {Number} height The new height to set (not required if a size object is passed as the first arg)\r
-     * @return {Ext.BoxComponent} this\r
-     */\r
-    setSize : function(w, h){\r
-        // support for standard size objects\r
-        if(typeof w == 'object'){\r
-            h = w.height;\r
-            w = w.width;\r
-        }\r
-        // not rendered\r
-        if(!this.boxReady){\r
-            this.width = w;\r
-            this.height = h;\r
-            return this;\r
-        }\r
-\r
-        // prevent recalcs when not needed\r
-        if(this.lastSize && this.lastSize.width == w && this.lastSize.height == h){\r
-            return this;\r
-        }\r
-        this.lastSize = {width: w, height: h};\r
-        var adj = this.adjustSize(w, h);\r
-        var aw = adj.width, ah = adj.height;\r
-        if(aw !== undefined || ah !== undefined){ // this code is nasty but performs better with floaters\r
-            var rz = this.getResizeEl();\r
-            if(!this.deferHeight && aw !== undefined && ah !== undefined){\r
-                rz.setSize(aw, ah);\r
-            }else if(!this.deferHeight && ah !== undefined){\r
-                rz.setHeight(ah);\r
-            }else if(aw !== undefined){\r
-                rz.setWidth(aw);\r
-            }\r
-            this.onResize(aw, ah, w, h);\r
-            this.fireEvent('resize', this, aw, ah, w, h);\r
-        }\r
-        return this;\r
-    },\r
-\r
-    /**\r
-     * Sets the width of the component.  This method fires the {@link #resize} event.\r
-     * @param {Number} width The new width to set\r
-     * @return {Ext.BoxComponent} this\r
-     */\r
-    setWidth : function(width){\r
-        return this.setSize(width);\r
-    },\r
-\r
-    /**\r
-     * Sets the height of the component.  This method fires the {@link #resize} event.\r
-     * @param {Number} height The new height to set\r
-     * @return {Ext.BoxComponent} this\r
-     */\r
-    setHeight : function(height){\r
-        return this.setSize(undefined, height);\r
-    },\r
-\r
-    /**\r
-     * Gets the current size of the component's underlying element.\r
-     * @return {Object} An object containing the element's size {width: (element width), height: (element height)}\r
-     */\r
-    getSize : function(){\r
-        return this.el.getSize();\r
-    },\r
-\r
-    /**\r
-     * Gets the current XY position of the component's underlying element.\r
-     * @param {Boolean} local (optional) If true the element's left and top are returned instead of page XY (defaults to false)\r
-     * @return {Array} The XY position of the element (e.g., [100, 200])\r
-     */\r
-    getPosition : function(local){\r
-        if(local === true){\r
-            return [this.el.getLeft(true), this.el.getTop(true)];\r
-        }\r
-        return this.xy || this.el.getXY();\r
-    },\r
-\r
-    /**\r
-     * Gets the current box measurements of the component's underlying element.\r
-     * @param {Boolean} local (optional) If true the element's left and top are returned instead of page XY (defaults to false)\r
-     * @return {Object} box An object in the format {x, y, width, height}\r
-     */\r
-    getBox : function(local){\r
-        var s = this.el.getSize();\r
-        if(local === true){\r
-            s.x = this.el.getLeft(true);\r
-            s.y = this.el.getTop(true);\r
-        }else{\r
-            var xy = this.xy || this.el.getXY();\r
-            s.x = xy[0];\r
-            s.y = xy[1];\r
-        }\r
-        return s;\r
-    },\r
-\r
-    /**\r
-     * Sets the current box measurements of the component's underlying element.\r
-     * @param {Object} box An object in the format {x, y, width, height}\r
-     * @return {Ext.BoxComponent} this\r
-     */\r
-    updateBox : function(box){\r
-        this.setSize(box.width, box.height);\r
-        this.setPagePosition(box.x, box.y);\r
-        return this;\r
-    },\r
-\r
-    // protected\r
-    getResizeEl : function(){\r
-        return this.resizeEl || this.el;\r
-    },\r
-\r
-    // protected\r
-    getPositionEl : function(){\r
-        return this.positionEl || this.el;\r
-    },\r
-\r
-    /**\r
-     * Sets the left and top of the component.  To set the page XY position instead, use {@link #setPagePosition}.\r
-     * This method fires the {@link #move} event.\r
-     * @param {Number} left The new left\r
-     * @param {Number} top The new top\r
-     * @return {Ext.BoxComponent} this\r
-     */\r
-    setPosition : function(x, y){\r
-        if(x && typeof x[1] == 'number'){\r
-            y = x[1];\r
-            x = x[0];\r
-        }\r
-        this.x = x;\r
-        this.y = y;\r
-        if(!this.boxReady){\r
-            return this;\r
-        }\r
-        var adj = this.adjustPosition(x, y);\r
-        var ax = adj.x, ay = adj.y;\r
-\r
-        var el = this.getPositionEl();\r
-        if(ax !== undefined || ay !== undefined){\r
-            if(ax !== undefined && ay !== undefined){\r
-                el.setLeftTop(ax, ay);\r
-            }else if(ax !== undefined){\r
-                el.setLeft(ax);\r
-            }else if(ay !== undefined){\r
-                el.setTop(ay);\r
-            }\r
-            this.onPosition(ax, ay);\r
-            this.fireEvent('move', this, ax, ay);\r
-        }\r
-        return this;\r
-    },\r
-\r
-    /**\r
-     * Sets the page XY position of the component.  To set the left and top instead, use {@link #setPosition}.\r
-     * This method fires the {@link #move} event.\r
-     * @param {Number} x The new x position\r
-     * @param {Number} y The new y position\r
-     * @return {Ext.BoxComponent} this\r
-     */\r
-    setPagePosition : function(x, y){\r
-        if(x && typeof x[1] == 'number'){\r
-            y = x[1];\r
-            x = x[0];\r
-        }\r
-        this.pageX = x;\r
-        this.pageY = y;\r
-        if(!this.boxReady){\r
-            return;\r
-        }\r
-        if(x === undefined || y === undefined){ // cannot translate undefined points\r
-            return;\r
-        }\r
-        var p = this.el.translatePoints(x, y);\r
-        this.setPosition(p.left, p.top);\r
-        return this;\r
-    },\r
-\r
-    // private\r
-    onRender : function(ct, position){\r
-        Ext.BoxComponent.superclass.onRender.call(this, ct, position);\r
-        if(this.resizeEl){\r
-            this.resizeEl = Ext.get(this.resizeEl);\r
-        }\r
-        if(this.positionEl){\r
-            this.positionEl = Ext.get(this.positionEl);\r
-        }\r
-    },\r
-\r
-    // private\r
-    afterRender : function(){\r
-        Ext.BoxComponent.superclass.afterRender.call(this);\r
-        this.boxReady = true;\r
-        this.setSize(this.width, this.height);\r
-        if(this.x || this.y){\r
-            this.setPosition(this.x, this.y);\r
-        }else if(this.pageX || this.pageY){\r
-            this.setPagePosition(this.pageX, this.pageY);\r
-        }\r
-    },\r
-\r
-    /**\r
-     * Force the component's size to recalculate based on the underlying element's current height and width.\r
-     * @return {Ext.BoxComponent} this\r
-     */\r
-    syncSize : function(){\r
-        delete this.lastSize;\r
-        this.setSize(this.autoWidth ? undefined : this.el.getWidth(), this.autoHeight ? undefined : this.el.getHeight());\r
-        return this;\r
-    },\r
-\r
-    /* // protected\r
-     * Called after the component is resized, this method is empty by default but can be implemented by any\r
-     * subclass that needs to perform custom logic after a resize occurs.\r
-     * @param {Number} adjWidth The box-adjusted width that was set\r
-     * @param {Number} adjHeight The box-adjusted height that was set\r
-     * @param {Number} rawWidth The width that was originally specified\r
-     * @param {Number} rawHeight The height that was originally specified\r
-     */\r
-    onResize : function(adjWidth, adjHeight, rawWidth, rawHeight){\r
-\r
-    },\r
-\r
-    /* // protected\r
-     * Called after the component is moved, this method is empty by default but can be implemented by any\r
-     * subclass that needs to perform custom logic after a move occurs.\r
-     * @param {Number} x The new x position\r
-     * @param {Number} y The new y position\r
-     */\r
-    onPosition : function(x, y){\r
-\r
-    },\r
-\r
-    // private\r
-    adjustSize : function(w, h){\r
-        if(this.autoWidth){\r
-            w = 'auto';\r
-        }\r
-        if(this.autoHeight){\r
-            h = 'auto';\r
-        }\r
-        return {width : w, height: h};\r
-    },\r
-\r
-    // private\r
-    adjustPosition : function(x, y){\r
-        return {x : x, y: y};\r
-    }\r
-});\r
-Ext.reg('box', Ext.BoxComponent);
\ No newline at end of file