2 * @class Ext.core.Element
4 Ext.core.Element.addMethods({
6 * Appends the passed element(s) to this element
7 * @param {String/HTMLElement/Array/Element/CompositeElement} el
8 * @return {Ext.core.Element} this
10 appendChild : function(el) {
11 return Ext.get(el).appendTo(this);
15 * Appends this element to the passed element
16 * @param {Mixed} el The new parent element
17 * @return {Ext.core.Element} this
19 appendTo : function(el) {
20 Ext.getDom(el).appendChild(this.dom);
25 * Inserts this element before the passed element in the DOM
26 * @param {Mixed} el The element before which this element will be inserted
27 * @return {Ext.core.Element} this
29 insertBefore : function(el) {
31 el.parentNode.insertBefore(this.dom, el);
36 * Inserts this element after the passed element in the DOM
37 * @param {Mixed} el The element to insert after
38 * @return {Ext.core.Element} this
40 insertAfter : function(el) {
42 el.parentNode.insertBefore(this.dom, el.nextSibling);
47 * Inserts (or creates) an element (or DomHelper config) as the first child of this element
48 * @param {Mixed/Object} el The id or element to insert or a DomHelper config to create and insert
49 * @return {Ext.core.Element} The new child
51 insertFirst : function(el, returnDom) {
53 if (el.nodeType || el.dom || typeof el == 'string') { // element
55 this.dom.insertBefore(el, this.dom.firstChild);
56 return !returnDom ? Ext.get(el) : el;
59 return this.createChild(el, this.dom.firstChild, returnDom);
64 * Inserts (or creates) the passed element (or DomHelper config) as a sibling of this element
65 * @param {Mixed/Object/Array} el The id, element to insert or a DomHelper config to create and insert *or* an array of any of those.
66 * @param {String} where (optional) 'before' or 'after' defaults to before
67 * @param {Boolean} returnDom (optional) True to return the .;ll;l,raw DOM element instead of Ext.core.Element
68 * @return {Ext.core.Element} The inserted Element. If an array is passed, the last inserted element is returned.
70 insertSibling: function(el, where, returnDom){
72 isAfter = (where || 'before').toLowerCase() == 'after',
77 Ext.each(el, function(e) {
78 rt = Ext.fly(insertEl, '_internal').insertSibling(e, where, returnDom);
88 if(el.nodeType || el.dom){
89 rt = me.dom.parentNode.insertBefore(Ext.getDom(el), isAfter ? me.dom.nextSibling : me.dom);
94 if (isAfter && !me.dom.nextSibling) {
95 rt = Ext.core.DomHelper.append(me.dom.parentNode, el, !returnDom);
97 rt = Ext.core.DomHelper[isAfter ? 'insertAfter' : 'insertBefore'](me.dom, el, !returnDom);
104 * Replaces the passed element with this element
105 * @param {Mixed} el The element to replace
106 * @return {Ext.core.Element} this
108 replace : function(el) {
110 this.insertBefore(el);
116 * Replaces this element with the passed element
117 * @param {Mixed/Object} el The new element or a DomHelper config of an element to create
118 * @return {Ext.core.Element} this
120 replaceWith: function(el){
123 if(el.nodeType || el.dom || typeof el == 'string'){
125 me.dom.parentNode.insertBefore(el, me.dom);
127 el = Ext.core.DomHelper.insertBefore(me.dom, el);
130 delete Ext.cache[me.id];
131 Ext.removeNode(me.dom);
132 me.id = Ext.id(me.dom = el);
133 Ext.core.Element.addToCache(me.isFlyweight ? new Ext.core.Element(me.dom) : me);
138 * Creates the passed DomHelper config and appends it to this element or optionally inserts it before the passed child element.
139 * @param {Object} config DomHelper element config object. If no tag is specified (e.g., {tag:'input'}) then a div will be
140 * automatically generated with the specified attributes.
141 * @param {HTMLElement} insertBefore (optional) a child element of this element
142 * @param {Boolean} returnDom (optional) true to return the dom node instead of creating an Element
143 * @return {Ext.core.Element} The new child element
145 createChild : function(config, insertBefore, returnDom) {
146 config = config || {tag:'div'};
148 return Ext.core.DomHelper.insertBefore(insertBefore, config, returnDom !== true);
151 return Ext.core.DomHelper[!this.dom.firstChild ? 'insertFirst' : 'append'](this.dom, config, returnDom !== true);
156 * Creates and wraps this element with another element
157 * @param {Object} config (optional) DomHelper element config object for the wrapper element or null for an empty div
158 * @param {Boolean} returnDom (optional) True to return the raw DOM element instead of Ext.core.Element
159 * @return {HTMLElement/Element} The newly created wrapper element
161 wrap : function(config, returnDom) {
162 var newEl = Ext.core.DomHelper.insertBefore(this.dom, config || {tag: "div"}, !returnDom),
163 d = newEl.dom || newEl;
165 d.appendChild(this.dom);
170 * Inserts an html fragment into this element
171 * @param {String} where Where to insert the html in relation to this element - beforeBegin, afterBegin, beforeEnd, afterEnd.
172 * @param {String} html The HTML fragment
173 * @param {Boolean} returnEl (optional) True to return an Ext.core.Element (defaults to false)
174 * @return {HTMLElement/Ext.core.Element} The inserted node (or nearest related if more than 1 inserted)
176 insertHtml : function(where, html, returnEl) {
177 var el = Ext.core.DomHelper.insertHtml(where, this.dom, html);
178 return returnEl ? Ext.get(el) : el;