]>
Commit | Line | Data |
---|---|---|
6527f429 DM |
1 | /**\r |
2 | * This is a layout that inherits the anchoring of {@link Ext.layout.container.Anchor} and adds the\r | |
3 | * ability for x/y positioning using the standard x and y component config options.\r | |
4 | *\r | |
5 | * This class is intended to be extended or created via the {@link Ext.container.Container#layout layout}\r | |
6 | * configuration property. See {@link Ext.container.Container#layout} for additional details.\r | |
7 | *\r | |
8 | * @example\r | |
9 | * Ext.create('Ext.form.Panel', {\r | |
10 | * title: 'Absolute Layout',\r | |
11 | * width: 300,\r | |
12 | * height: 275,\r | |
13 | * layout: {\r | |
14 | * type: 'absolute'\r | |
15 | * // layout-specific configs go here\r | |
16 | * //itemCls: 'x-abs-layout-item',\r | |
17 | * },\r | |
18 | * url:'save-form.php',\r | |
19 | * defaultType: 'textfield',\r | |
20 | * items: [{\r | |
21 | * x: 10,\r | |
22 | * y: 10,\r | |
23 | * xtype:'label',\r | |
24 | * text: 'Send To:'\r | |
25 | * },{\r | |
26 | * x: 80,\r | |
27 | * y: 10,\r | |
28 | * name: 'to',\r | |
29 | * anchor:'90%' // anchor width by percentage\r | |
30 | * },{\r | |
31 | * x: 10,\r | |
32 | * y: 40,\r | |
33 | * xtype:'label',\r | |
34 | * text: 'Subject:'\r | |
35 | * },{\r | |
36 | * x: 80,\r | |
37 | * y: 40,\r | |
38 | * name: 'subject',\r | |
39 | * anchor: '90%' // anchor width by percentage\r | |
40 | * },{\r | |
41 | * x:0,\r | |
42 | * y: 80,\r | |
43 | * xtype: 'textareafield',\r | |
44 | * name: 'msg',\r | |
45 | * anchor: '100% 100%' // anchor width and height\r | |
46 | * }],\r | |
47 | * renderTo: Ext.getBody()\r | |
48 | * });\r | |
49 | */\r | |
50 | Ext.define('Ext.layout.container.Absolute', {\r | |
51 | \r | |
52 | /* Begin Definitions */\r | |
53 | \r | |
54 | alias: 'layout.absolute',\r | |
55 | extend: 'Ext.layout.container.Anchor',\r | |
56 | alternateClassName: 'Ext.layout.AbsoluteLayout',\r | |
57 | \r | |
58 | /* End Definitions */\r | |
59 | \r | |
60 | targetCls: Ext.baseCSSPrefix + 'abs-layout-ct',\r | |
61 | itemCls: Ext.baseCSSPrefix + 'abs-layout-item',\r | |
62 | \r | |
63 | /**\r | |
64 | * @cfg {Boolean} ignoreOnContentChange\r | |
65 | * True indicates that changes to one item in this layout do not effect the layout in\r | |
66 | * general. This may need to be set to false if the component is\r | |
67 | * {@link Ext.Component#scrollable scrollable}.\r | |
68 | */\r | |
69 | ignoreOnContentChange: true,\r | |
70 | \r | |
71 | type: 'absolute',\r | |
72 | \r | |
73 | /**\r | |
74 | * @private\r | |
75 | */\r | |
76 | adjustWidthAnchor: function(value, childContext) {\r | |
77 | var padding = this.targetPadding,\r | |
78 | x = childContext.getStyle('left');\r | |
79 | \r | |
80 | return value - x + padding.left;\r | |
81 | },\r | |
82 | \r | |
83 | /**\r | |
84 | * @private\r | |
85 | */\r | |
86 | adjustHeightAnchor: function(value, childContext) {\r | |
87 | var padding = this.targetPadding,\r | |
88 | y = childContext.getStyle('top');\r | |
89 | \r | |
90 | return value - y + padding.top;\r | |
91 | },\r | |
92 | \r | |
93 | isItemLayoutRoot: function (item) {\r | |
94 | return this.ignoreOnContentChange || this.callParent(arguments);\r | |
95 | },\r | |
96 | \r | |
97 | isItemShrinkWrap: function (item) {\r | |
98 | return true;\r | |
99 | },\r | |
100 | \r | |
101 | beginLayout: function (ownerContext) {\r | |
102 | var me = this,\r | |
103 | target = me.getTarget();\r | |
104 | \r | |
105 | me.callParent(arguments);\r | |
106 | \r | |
107 | // Do not set position: relative; when the absolute layout target is the body\r | |
108 | if (target.dom !== document.body) {\r | |
109 | target.position();\r | |
110 | }\r | |
111 | \r | |
112 | me.targetPadding = ownerContext.targetContext.getPaddingInfo();\r | |
113 | },\r | |
114 | \r | |
115 | isItemBoxParent: function (itemContext) {\r | |
116 | return true;\r | |
117 | },\r | |
118 | \r | |
119 | onContentChange: function () {\r | |
120 | if (this.ignoreOnContentChange) {\r | |
121 | return false;\r | |
122 | }\r | |
123 | return this.callParent(arguments);\r | |
124 | },\r | |
125 | \r | |
126 | calculateContentSize: function (ownerContext, dimensions) {\r | |
127 | var me = this,\r | |
128 | containerDimensions = (dimensions || 0) | // jshint ignore:line\r | |
129 | ((ownerContext.widthModel.shrinkWrap ? 1 : 0) | // jshint ignore:line\r | |
130 | (ownerContext.heightModel.shrinkWrap ? 2 : 0)),\r | |
131 | calcWidth = (containerDimensions & 1) || undefined,// jshint ignore:line\r | |
132 | calcHeight = (containerDimensions & 2) || undefined,// jshint ignore:line\r | |
133 | childItems = ownerContext.childItems,\r | |
134 | length = childItems.length,\r | |
135 | contentHeight = 0,\r | |
136 | contentWidth = 0,\r | |
137 | needed = 0,\r | |
138 | props = ownerContext.props,\r | |
139 | targetPadding, child, childContext, height, i, margins, width;\r | |
140 | \r | |
141 | if (calcWidth) {\r | |
142 | if (isNaN(props.contentWidth)) {\r | |
143 | ++needed;\r | |
144 | } else {\r | |
145 | calcWidth = undefined;\r | |
146 | }\r | |
147 | }\r | |
148 | if (calcHeight) {\r | |
149 | if (isNaN(props.contentHeight)) {\r | |
150 | ++needed;\r | |
151 | } else {\r | |
152 | calcHeight = undefined;\r | |
153 | }\r | |
154 | }\r | |
155 | \r | |
156 | if (needed) {\r | |
157 | for (i = 0; i < length; ++i) {\r | |
158 | childContext = childItems[i];\r | |
159 | child = childContext.target;\r | |
160 | height = calcHeight && childContext.getProp('height');\r | |
161 | width = calcWidth && childContext.getProp('width');\r | |
162 | margins = childContext.getMarginInfo();\r | |
163 | \r | |
164 | height += margins.bottom;\r | |
165 | width += margins.right;\r | |
166 | \r | |
167 | contentHeight = Math.max(contentHeight, (child.y || 0) + height);\r | |
168 | contentWidth = Math.max(contentWidth, (child.x || 0) + width);\r | |
169 | \r | |
170 | if (isNaN(contentHeight) && isNaN(contentWidth)) {\r | |
171 | me.done = false;\r | |
172 | return;\r | |
173 | }\r | |
174 | }\r | |
175 | \r | |
176 | if (calcWidth || calcHeight) {\r | |
177 | targetPadding = ownerContext.targetContext.getPaddingInfo();\r | |
178 | }\r | |
179 | if (calcWidth && !ownerContext.setContentWidth(contentWidth + targetPadding.width)) {\r | |
180 | me.done = false;\r | |
181 | }\r | |
182 | if (calcHeight && !ownerContext.setContentHeight(contentHeight + targetPadding.height)) {\r | |
183 | me.done = false;\r | |
184 | }\r | |
185 | \r | |
186 | /* add a '/' to turn on this log ('//* enables, '/*' disables)\r | |
187 | if (me.done) {\r | |
188 | var el = ownerContext.targetContext.el.dom;\r | |
189 | Ext.log(this.owner.id, '.contentSize: ', contentWidth, 'x', contentHeight,\r | |
190 | ' => scrollSize: ', el.scrollWidth, 'x', el.scrollHeight);\r | |
191 | }/**/\r | |
192 | }\r | |
193 | }\r | |
194 | });\r |