3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
4 <title>The source code</title>
5 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
6 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
8 <body onload="prettyPrint();">
9 <pre class="prettyprint lang-js">/*!
10 * Ext JS Library 3.2.0
11 * Copyright(c) 2006-2010 Ext JS, Inc.
13 * http://www.extjs.com/license
18 Ext.Element.addMethods(
20 var GETDOM = Ext.getDom,
25 <div id="method-Ext.Element-appendChild"></div>/**
26 * Appends the passed element(s) to this element
27 * @param {String/HTMLElement/Array/Element/CompositeElement} el
28 * @return {Ext.Element} this
30 appendChild: function(el){
31 return GET(el).appendTo(this);
34 <div id="method-Ext.Element-appendTo"></div>/**
35 * Appends this element to the passed element
36 * @param {Mixed} el The new parent element
37 * @return {Ext.Element} this
39 appendTo: function(el){
40 GETDOM(el).appendChild(this.dom);
44 <div id="method-Ext.Element-insertBefore"></div>/**
45 * Inserts this element before the passed element in the DOM
46 * @param {Mixed} el The element before which this element will be inserted
47 * @return {Ext.Element} this
49 insertBefore: function(el){
50 (el = GETDOM(el)).parentNode.insertBefore(this.dom, el);
54 <div id="method-Ext.Element-insertAfter"></div>/**
55 * Inserts this element after the passed element in the DOM
56 * @param {Mixed} el The element to insert after
57 * @return {Ext.Element} this
59 insertAfter: function(el){
60 (el = GETDOM(el)).parentNode.insertBefore(this.dom, el.nextSibling);
64 <div id="method-Ext.Element-insertFirst"></div>/**
65 * Inserts (or creates) an element (or DomHelper config) as the first child of this element
66 * @param {Mixed/Object} el The id or element to insert or a DomHelper config to create and insert
67 * @return {Ext.Element} The new child
69 insertFirst: function(el, returnDom){
71 if(el.nodeType || el.dom || typeof el == 'string'){ // element
73 this.dom.insertBefore(el, this.dom.firstChild);
74 return !returnDom ? GET(el) : el;
76 return this.createChild(el, this.dom.firstChild, returnDom);
80 <div id="method-Ext.Element-replace"></div>/**
81 * Replaces the passed element with this element
82 * @param {Mixed} el The element to replace
83 * @return {Ext.Element} this
85 replace: function(el){
87 this.insertBefore(el);
92 <div id="method-Ext.Element-replaceWith"></div>/**
93 * Replaces this element with the passed element
94 * @param {Mixed/Object} el The new element or a DomHelper config of an element to create
95 * @return {Ext.Element} this
97 replaceWith: function(el){
100 if(el.nodeType || el.dom || typeof el == 'string'){
102 me.dom.parentNode.insertBefore(el, me.dom);
104 el = DH.insertBefore(me.dom, el);
107 delete Ext.elCache[me.id];
108 Ext.removeNode(me.dom);
109 me.id = Ext.id(me.dom = el);
110 Ext.Element.addToCache(me.isFlyweight ? new Ext.Element(me.dom) : me);
114 <div id="method-Ext.Element-createChild"></div>/**
115 * Creates the passed DomHelper config and appends it to this element or optionally inserts it before the passed child element.
116 * @param {Object} config DomHelper element config object. If no tag is specified (e.g., {tag:'input'}) then a div will be
117 * automatically generated with the specified attributes.
118 * @param {HTMLElement} insertBefore (optional) a child element of this element
119 * @param {Boolean} returnDom (optional) true to return the dom node instead of creating an Element
120 * @return {Ext.Element} The new child element
122 createChild: function(config, insertBefore, returnDom){
123 config = config || {tag:'div'};
124 return insertBefore ?
125 DH.insertBefore(insertBefore, config, returnDom !== true) :
126 DH[!this.dom.firstChild ? 'overwrite' : 'append'](this.dom, config, returnDom !== true);
129 <div id="method-Ext.Element-wrap"></div>/**
130 * Creates and wraps this element with another element
131 * @param {Object} config (optional) DomHelper element config object for the wrapper element or null for an empty div
132 * @param {Boolean} returnDom (optional) True to return the raw DOM element instead of Ext.Element
133 * @return {HTMLElement/Element} The newly created wrapper element
135 wrap: function(config, returnDom){
136 var newEl = DH.insertBefore(this.dom, config || {tag: "div"}, !returnDom);
137 newEl.dom ? newEl.dom.appendChild(this.dom) : newEl.appendChild(this.dom);
141 <div id="method-Ext.Element-insertHtml"></div>/**
142 * Inserts an html fragment into this element
143 * @param {String} where Where to insert the html in relation to this element - beforeBegin, afterBegin, beforeEnd, afterEnd.
144 * @param {String} html The HTML fragment
145 * @param {Boolean} returnEl (optional) True to return an Ext.Element (defaults to false)
146 * @return {HTMLElement/Ext.Element} The inserted node (or nearest related if more than 1 inserted)
148 insertHtml : function(where, html, returnEl){
149 var el = DH.insertHtml(where, this.dom, html);
150 return returnEl ? Ext.get(el) : el;