Upgrade to ExtJS 4.0.7 - Released 10/19/2011
[extjs.git] / src / layout / container / Absolute.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.layout.container.Absolute
17  * @extends Ext.layout.container.Anchor
18  *
19  * This is a layout that inherits the anchoring of {@link Ext.layout.container.Anchor} and adds the
20  * ability for x/y positioning using the standard x and y component config options.
21  *
22  * This class is intended to be extended or created via the {@link Ext.container.Container#layout layout}
23  * configuration property.  See {@link Ext.container.Container#layout} for additional details.
24  *
25  *     @example
26  *     Ext.create('Ext.form.Panel', {
27  *         title: 'Absolute Layout',
28  *         width: 300,
29  *         height: 275,
30  *         layout:'absolute',
31  *         layoutConfig: {
32  *             // layout-specific configs go here
33  *             //itemCls: 'x-abs-layout-item',
34  *         },
35  *         url:'save-form.php',
36  *         defaultType: 'textfield',
37  *         items: [{
38  *             x: 10,
39  *             y: 10,
40  *             xtype:'label',
41  *             text: 'Send To:'
42  *         },{
43  *             x: 80,
44  *             y: 10,
45  *             name: 'to',
46  *             anchor:'90%'  // anchor width by percentage
47  *         },{
48  *             x: 10,
49  *             y: 40,
50  *             xtype:'label',
51  *             text: 'Subject:'
52  *         },{
53  *             x: 80,
54  *             y: 40,
55  *             name: 'subject',
56  *             anchor: '90%'  // anchor width by percentage
57  *         },{
58  *             x:0,
59  *             y: 80,
60  *             xtype: 'textareafield',
61  *             name: 'msg',
62  *             anchor: '100% 100%'  // anchor width and height
63  *         }],
64  *         renderTo: Ext.getBody()
65  *     });
66  */
67 Ext.define('Ext.layout.container.Absolute', {
68
69     /* Begin Definitions */
70
71     alias: 'layout.absolute',
72     extend: 'Ext.layout.container.Anchor',
73     alternateClassName: 'Ext.layout.AbsoluteLayout',
74
75     /* End Definitions */
76
77     itemCls: Ext.baseCSSPrefix + 'abs-layout-item',
78
79     type: 'absolute',
80
81     onLayout: function() {
82         var me = this,
83             target = me.getTarget(),
84             targetIsBody = target.dom === document.body;
85
86         // Do not set position: relative; when the absolute layout target is the body
87         if (!targetIsBody) {
88             target.position();
89         }
90         me.paddingLeft = target.getPadding('l');
91         me.paddingTop = target.getPadding('t');
92         me.callParent(arguments);
93     },
94
95     // private
96     adjustWidthAnchor: function(value, comp) {
97         //return value ? value - comp.getPosition(true)[0] + this.paddingLeft: value;
98         return value ? value - comp.getPosition(true)[0] : value;
99     },
100
101     // private
102     adjustHeightAnchor: function(value, comp) {
103         //return value ? value - comp.getPosition(true)[1] + this.paddingTop: value;
104         return value ? value - comp.getPosition(true)[1] : value;
105     }
106 });