4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../prettify/prettify.js"></script>
8 <style type="text/css">
9 .highlight { display: block; background-color: #ddd; }
11 <script type="text/javascript">
12 function highlight() {
13 document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
17 <body onload="prettyPrint(); highlight();">
18 <pre class="prettyprint lang-js"><span id='Ext-layout-Layout'>/**
19 </span> * @class Ext.layout.Layout
21 * Base Layout class - extended by ComponentLayout and ContainerLayout
23 Ext.define('Ext.layout.Layout', {
25 /* Begin Definitions */
33 create: function(layout, defaultType) {
35 if (layout instanceof Ext.layout.Layout) {
36 return Ext.createByAlias('layout.' + layout);
38 if (!layout || typeof layout === 'string') {
39 type = layout || defaultType;
45 return Ext.createByAlias('layout.' + type, layout || {});
50 constructor : function(config) {
51 this.id = Ext.id(null, this.type + '-');
52 Ext.apply(this, config);
55 <span id='Ext-layout-Layout-method-layout'> /**
63 if (me.beforeLayout.apply(me, arguments) !== false) {
64 me.layoutCancelled = false;
65 me.onLayout.apply(me, arguments);
66 me.childrenChanged = false;
67 me.owner.needsLayout = false;
68 me.layoutBusy = false;
69 me.afterLayout.apply(me, arguments);
72 me.layoutCancelled = true;
74 me.layoutBusy = false;
75 me.doOwnerCtLayouts();
78 beforeLayout : function() {
79 this.renderItems(this.getLayoutItems(), this.getRenderTarget());
83 <span id='Ext-layout-Layout-method-renderItems'> /**
85 * Iterates over all passed items, ensuring they are rendered. If the items are already rendered,
86 * also determines if the items are in the proper place dom.
88 renderItems : function(items, target) {
89 var ln = items.length,
93 for (; i < ln; i++) {
95 if (item && !item.rendered) {
96 this.renderItem(item, target, i);
98 else if (!this.isValidParent(item, target, i)) {
99 this.moveItem(item, target, i);
104 // @private - Validates item is in the proper place in the dom.
105 isValidParent : function(item, target, position) {
106 var dom = item.el ? item.el.dom : Ext.getDom(item);
107 if (dom && target && target.dom) {
108 if (Ext.isNumber(position) && dom !== target.dom.childNodes[position]) {
111 return (dom.parentNode == (target.dom || target));
116 <span id='Ext-layout-Layout-method-renderItem'> /**
118 * Renders the given Component into the target Element.
119 * @param {Ext.Component} item The Component to render
120 * @param {Ext.core.Element} target The target Element
121 * @param {Number} position The position within the target to render the item to
123 renderItem : function(item, target, position) {
125 if (!item.rendered) {
127 item.addCls(me.itemCls);
129 if (me.owner.itemCls) {
130 item.addCls(me.owner.itemCls);
132 item.render(target, position);
133 me.configureItem(item);
134 me.childrenChanged = true;
138 <span id='Ext-layout-Layout-method-moveItem'> /**
140 * Moved Component to the provided target instead.
142 moveItem : function(item, target, position) {
143 // Make sure target is a dom element
144 target = target.dom || target;
145 if (typeof position == 'number') {
146 position = target.childNodes[position];
148 target.insertBefore(item.el.dom, position || null);
149 item.container = Ext.get(target);
150 this.configureItem(item);
151 this.childrenChanged = true;
154 <span id='Ext-layout-Layout-method-initLayout'> /**
156 * Adds the layout's targetCls if necessary and sets
157 * initialized flag when complete.
159 initLayout : function() {
160 if (!this.initialized && !Ext.isEmpty(this.targetCls)) {
161 this.getTarget().addCls(this.targetCls);
163 this.initialized = true;
166 // @private Sets the layout owner
167 setOwner : function(owner) {
171 // @private - Returns empty array
172 getLayoutItems : function() {
176 <span id='Ext-layout-Layout-property-configureItem'> /**
179 * Empty template method
181 configureItem: Ext.emptyFn,
183 // Placeholder empty functions for subclasses to extend
184 onLayout : Ext.emptyFn,
185 afterLayout : Ext.emptyFn,
186 onRemove : Ext.emptyFn,
187 onDestroy : Ext.emptyFn,
188 doOwnerCtLayouts : Ext.emptyFn,
190 <span id='Ext-layout-Layout-method-afterRemove'> /**
194 afterRemove : function(item) {
199 // Clear managed dimensions flag when removed from the layout.
202 el.removeCls(me.itemCls);
205 el.removeCls(owner.itemCls);
209 // These flags are set at the time a child item is added to a layout.
210 // The layout must decide if it is managing the item's width, or its height, or both.
211 // See AbstractComponent for docs on these properties.
212 delete item.layoutManagedWidth;
213 delete item.layoutManagedHeight;
217 * Destroys this layout. This is a template method that is empty by default, but should be implemented
218 * by subclasses that require explicit destruction to purge event handlers or remove DOM nodes.
221 destroy : function() {
222 if (!Ext.isEmpty(this.targetCls)) {
223 var target = this.getTarget();
225 target.removeCls(this.targetCls);