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