3 <title>The source code</title>
\r
4 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
\r
5 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
\r
7 <body onload="prettyPrint();">
\r
8 <pre class="prettyprint lang-js">/**
\r
11 Ext.Element.addMethods(
\r
13 var GETDOM = Ext.getDom,
\r
16 isEl = function(el){
\r
17 return (el.nodeType || el.dom || typeof el == 'string');
\r
21 <div id="method-Ext.Element-appendChild"></div>/**
\r
22 * Appends the passed element(s) to this element
\r
23 * @param {String/HTMLElement/Array/Element/CompositeElement} el
\r
24 * @return {Ext.Element} this
\r
26 appendChild: function(el){
\r
27 return GET(el).appendTo(this);
\r
30 <div id="method-Ext.Element-appendTo"></div>/**
\r
31 * Appends this element to the passed element
\r
32 * @param {Mixed} el The new parent element
\r
33 * @return {Ext.Element} this
\r
35 appendTo: function(el){
\r
36 GETDOM(el).appendChild(this.dom);
\r
40 <div id="method-Ext.Element-insertBefore"></div>/**
\r
41 * Inserts this element before the passed element in the DOM
\r
42 * @param {Mixed} el The element before which this element will be inserted
\r
43 * @return {Ext.Element} this
\r
45 insertBefore: function(el){
\r
46 (el = GETDOM(el)).parentNode.insertBefore(this.dom, el);
\r
50 <div id="method-Ext.Element-insertAfter"></div>/**
\r
51 * Inserts this element after the passed element in the DOM
\r
52 * @param {Mixed} el The element to insert after
\r
53 * @return {Ext.Element} this
\r
55 insertAfter: function(el){
\r
56 (el = GETDOM(el)).parentNode.insertBefore(this.dom, el.nextSibling);
\r
60 <div id="method-Ext.Element-insertFirst"></div>/**
\r
61 * Inserts (or creates) an element (or DomHelper config) as the first child of this element
\r
62 * @param {Mixed/Object} el The id or element to insert or a DomHelper config to create and insert
\r
63 * @return {Ext.Element} The new child
\r
65 insertFirst: function(el, returnDom){
\r
67 if(isEl(el)){ // element
\r
69 this.dom.insertBefore(el, this.dom.firstChild);
\r
70 return !returnDom ? GET(el) : el;
\r
72 return this.createChild(el, this.dom.firstChild, returnDom);
\r
76 <div id="method-Ext.Element-replace"></div>/**
\r
77 * Replaces the passed element with this element
\r
78 * @param {Mixed} el The element to replace
\r
79 * @return {Ext.Element} this
\r
81 replace: function(el){
\r
83 this.insertBefore(el);
\r
88 <div id="method-Ext.Element-replaceWith"></div>/**
\r
89 * Replaces this element with the passed element
\r
90 * @param {Mixed/Object} el The new element or a DomHelper config of an element to create
\r
91 * @return {Ext.Element} this
\r
93 replaceWith: function(el){
\r
95 Element = Ext.Element;
\r
98 me.dom.parentNode.insertBefore(el, me.dom);
\r
100 el = DH.insertBefore(me.dom, el);
\r
103 delete Element.cache[me.id];
\r
104 Ext.removeNode(me.dom);
\r
105 me.id = Ext.id(me.dom = el);
\r
106 return Element.cache[me.id] = me;
\r
109 <div id="method-Ext.Element-createChild"></div>/**
\r
110 * Creates the passed DomHelper config and appends it to this element or optionally inserts it before the passed child element.
\r
111 * @param {Object} config DomHelper element config object. If no tag is specified (e.g., {tag:'input'}) then a div will be
\r
112 * automatically generated with the specified attributes.
\r
113 * @param {HTMLElement} insertBefore (optional) a child element of this element
\r
114 * @param {Boolean} returnDom (optional) true to return the dom node instead of creating an Element
\r
115 * @return {Ext.Element} The new child element
\r
117 createChild: function(config, insertBefore, returnDom){
\r
118 config = config || {tag:'div'};
\r
119 return insertBefore ?
\r
120 DH.insertBefore(insertBefore, config, returnDom !== true) :
\r
121 DH[!this.dom.firstChild ? 'overwrite' : 'append'](this.dom, config, returnDom !== true);
\r
124 <div id="method-Ext.Element-wrap"></div>/**
\r
125 * Creates and wraps this element with another element
\r
126 * @param {Object} config (optional) DomHelper element config object for the wrapper element or null for an empty div
\r
127 * @param {Boolean} returnDom (optional) True to return the raw DOM element instead of Ext.Element
\r
128 * @return {HTMLElement/Element} The newly created wrapper element
\r
130 wrap: function(config, returnDom){
\r
131 var newEl = DH.insertBefore(this.dom, config || {tag: "div"}, !returnDom);
\r
132 newEl.dom ? newEl.dom.appendChild(this.dom) : newEl.appendChild(this.dom);
\r
136 <div id="method-Ext.Element-insertHtml"></div>/**
\r
137 * Inserts an html fragment into this element
\r
138 * @param {String} where Where to insert the html in relation to this element - beforeBegin, afterBegin, beforeEnd, afterEnd.
\r
139 * @param {String} html The HTML fragment
\r
140 * @param {Boolean} returnEl (optional) True to return an Ext.Element (defaults to false)
\r
141 * @return {HTMLElement/Ext.Element} The inserted node (or nearest related if more than 1 inserted)
\r
143 insertHtml : function(where, html, returnEl){
\r
144 var el = DH.insertHtml(where, this.dom, html);
\r
145 return returnEl ? Ext.get(el) : el;
\r