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
22 * Base Layout class - extended by ComponentLayout and ContainerLayout
25 Ext.define('Ext.layout.Layout', {
27 /* Begin Definitions */
35 create: function(layout, defaultType) {
37 if (layout instanceof Ext.layout.Layout) {
38 return Ext.createByAlias('layout.' + layout);
40 if (Ext.isObject(layout)) {
44 type = layout || defaultType;
47 return Ext.createByAlias('layout.' + type, layout || {});
52 constructor : function(config) {
53 this.id = Ext.id(null, this.type + '-');
54 Ext.apply(this, config);
57 <span id='Ext-layout-Layout-method-layout'> /**
65 if (me.beforeLayout.apply(me, arguments) !== false) {
66 me.layoutCancelled = false;
67 me.onLayout.apply(me, arguments);
68 me.childrenChanged = false;
69 me.owner.needsLayout = false;
70 me.layoutBusy = false;
71 me.afterLayout.apply(me, arguments);
74 me.layoutCancelled = true;
76 me.layoutBusy = false;
77 me.doOwnerCtLayouts();
80 beforeLayout : function() {
81 this.renderItems(this.getLayoutItems(), this.getRenderTarget());
85 <span id='Ext-layout-Layout-method-renderItems'> /**
87 * Iterates over all passed items, ensuring they are rendered. If the items are already rendered,
88 * also determines if the items are in the proper place dom.
90 renderItems : function(items, target) {
91 var ln = items.length,
95 for (; i < ln; i++) {
97 if (item && !item.rendered) {
98 this.renderItem(item, target, i);
100 else if (!this.isValidParent(item, target, i)) {
101 this.moveItem(item, target, i);
106 // @private - Validates item is in the proper place in the dom.
107 isValidParent : function(item, target, position) {
108 var dom = item.el ? item.el.dom : Ext.getDom(item);
109 if (dom && target && target.dom) {
110 if (Ext.isNumber(position) && dom !== target.dom.childNodes[position]) {
113 return (dom.parentNode == (target.dom || target));
118 <span id='Ext-layout-Layout-method-renderItem'> /**
120 * Renders the given Component into the target Element.
121 * @param {Ext.Component} item The Component to render
122 * @param {Ext.core.Element} target The target Element
123 * @param {Number} position The position within the target to render the item to
125 renderItem : function(item, target, position) {
126 if (!item.rendered) {
127 item.render(target, position);
128 this.configureItem(item);
129 this.childrenChanged = true;
133 <span id='Ext-layout-Layout-method-moveItem'> /**
135 * Moved Component to the provided target instead.
137 moveItem : function(item, target, position) {
138 // Make sure target is a dom element
139 target = target.dom || target;
140 if (typeof position == 'number') {
141 position = target.childNodes[position];
143 target.insertBefore(item.el.dom, position || null);
144 item.container = Ext.get(target);
145 this.configureItem(item);
146 this.childrenChanged = true;
149 <span id='Ext-layout-Layout-method-initLayout'> /**
151 * Adds the layout's targetCls if necessary and sets
152 * initialized flag when complete.
154 initLayout : function() {
155 if (!this.initialized && !Ext.isEmpty(this.targetCls)) {
156 this.getTarget().addCls(this.targetCls);
158 this.initialized = true;
161 // @private Sets the layout owner
162 setOwner : function(owner) {
166 // @private - Returns empty array
167 getLayoutItems : function() {
171 <span id='Ext-layout-Layout-method-configureItem'> /**
175 configureItem: function(item) {
181 el.addCls(me.itemCls);
184 el.addCls(owner.itemCls);
188 // Placeholder empty functions for subclasses to extend
189 onLayout : Ext.emptyFn,
190 afterLayout : Ext.emptyFn,
191 onRemove : Ext.emptyFn,
192 onDestroy : Ext.emptyFn,
193 doOwnerCtLayouts : Ext.emptyFn,
195 <span id='Ext-layout-Layout-method-afterRemove'> /**
199 afterRemove : function(item) {
206 el.removeCls(me.itemCls);
209 el.removeCls(owner.itemCls);
215 * Destroys this layout. This is a template method that is empty by default, but should be implemented
216 * by subclasses that require explicit destruction to purge event handlers or remove DOM nodes.
219 destroy : function() {
220 if (!Ext.isEmpty(this.targetCls)) {
221 var target = this.getTarget();
223 target.removeCls(this.targetCls);