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-core-Element'>/**
19 </span> * @class Ext.core.Element
21 Ext.core.Element.addMethods({
22 <span id='Ext-core-Element-method-findParent'> /**
23 </span> * Looks at this node and then at parent nodes for a match of the passed simple selector (e.g. div.some-class or span:first-child)
24 * @param {String} selector The simple selector to test
25 * @param {Number/Mixed} maxDepth (optional) The max depth to search as a number or element (defaults to 50 || document.body)
26 * @param {Boolean} returnEl (optional) True to return a Ext.core.Element object instead of DOM node
27 * @return {HTMLElement} The matching DOM node (or null if no match was found)
29 findParent : function(simpleSelector, maxDepth, returnEl) {
35 maxDepth = maxDepth || 50;
36 if (isNaN(maxDepth)) {
37 stopEl = Ext.getDom(maxDepth);
38 maxDepth = Number.MAX_VALUE;
40 while (p && p.nodeType == 1 && depth < maxDepth && p != b && p != stopEl) {
41 if (Ext.DomQuery.is(p, simpleSelector)) {
42 return returnEl ? Ext.get(p) : p;
50 <span id='Ext-core-Element-method-findParentNode'> /**
51 </span> * Looks at parent nodes for a match of the passed simple selector (e.g. div.some-class or span:first-child)
52 * @param {String} selector The simple selector to test
53 * @param {Number/Mixed} maxDepth (optional) The max depth to
54 search as a number or element (defaults to 10 || document.body)
55 * @param {Boolean} returnEl (optional) True to return a Ext.core.Element object instead of DOM node
56 * @return {HTMLElement} The matching DOM node (or null if no match was found)
58 findParentNode : function(simpleSelector, maxDepth, returnEl) {
59 var p = Ext.fly(this.dom.parentNode, '_internal');
60 return p ? p.findParent(simpleSelector, maxDepth, returnEl) : null;
63 <span id='Ext-core-Element-method-up'> /**
64 </span> * Walks up the dom looking for a parent node that matches the passed simple selector (e.g. div.some-class or span:first-child).
65 * This is a shortcut for findParentNode() that always returns an Ext.core.Element.
66 * @param {String} selector The simple selector to test
67 * @param {Number/Mixed} maxDepth (optional) The max depth to
68 search as a number or element (defaults to 10 || document.body)
69 * @return {Ext.core.Element} The matching DOM node (or null if no match was found)
71 up : function(simpleSelector, maxDepth) {
72 return this.findParentNode(simpleSelector, maxDepth, true);
75 <span id='Ext-core-Element-method-select'> /**
76 </span> * Creates a {@link Ext.CompositeElement} for child nodes based on the passed CSS selector (the selector should not contain an id).
77 * @param {String} selector The CSS selector
78 * @return {CompositeElement/CompositeElement} The composite element
80 select : function(selector) {
81 return Ext.core.Element.select(selector, false, this.dom);
84 <span id='Ext-core-Element-method-query'> /**
85 </span> * Selects child nodes based on the passed CSS selector (the selector should not contain an id).
86 * @param {String} selector The CSS selector
87 * @return {Array} An array of the matched nodes
89 query : function(selector) {
90 return Ext.DomQuery.select(selector, this.dom);
93 <span id='Ext-core-Element-method-down'> /**
94 </span> * Selects a single child at any depth below this element based on the passed CSS selector (the selector should not contain an id).
95 * @param {String} selector The CSS selector
96 * @param {Boolean} returnDom (optional) True to return the DOM node instead of Ext.core.Element (defaults to false)
97 * @return {HTMLElement/Ext.core.Element} The child Ext.core.Element (or DOM node if returnDom = true)
99 down : function(selector, returnDom) {
100 var n = Ext.DomQuery.selectNode(selector, this.dom);
101 return returnDom ? n : Ext.get(n);
104 <span id='Ext-core-Element-method-child'> /**
105 </span> * Selects a single *direct* child based on the passed CSS selector (the selector should not contain an id).
106 * @param {String} selector The CSS selector
107 * @param {Boolean} returnDom (optional) True to return the DOM node instead of Ext.core.Element (defaults to false)
108 * @return {HTMLElement/Ext.core.Element} The child Ext.core.Element (or DOM node if returnDom = true)
110 child : function(selector, returnDom) {
116 id = id.replace(/[\.:]/g, "\\$0");
117 node = Ext.DomQuery.selectNode('#' + id + " > " + selector, me.dom);
118 return returnDom ? node : Ext.get(node);
121 <span id='Ext-core-Element-method-parent'> /**
122 </span> * Gets the parent node for this element, optionally chaining up trying to match a selector
123 * @param {String} selector (optional) Find a parent node that matches the passed simple selector
124 * @param {Boolean} returnDom (optional) True to return a raw dom node instead of an Ext.core.Element
125 * @return {Ext.core.Element/HTMLElement} The parent node or null
127 parent : function(selector, returnDom) {
128 return this.matchNode('parentNode', 'parentNode', selector, returnDom);
131 <span id='Ext-core-Element-method-next'> /**
132 </span> * Gets the next sibling, skipping text nodes
133 * @param {String} selector (optional) Find the next sibling that matches the passed simple selector
134 * @param {Boolean} returnDom (optional) True to return a raw dom node instead of an Ext.core.Element
135 * @return {Ext.core.Element/HTMLElement} The next sibling or null
137 next : function(selector, returnDom) {
138 return this.matchNode('nextSibling', 'nextSibling', selector, returnDom);
141 <span id='Ext-core-Element-method-prev'> /**
142 </span> * Gets the previous sibling, skipping text nodes
143 * @param {String} selector (optional) Find the previous sibling that matches the passed simple selector
144 * @param {Boolean} returnDom (optional) True to return a raw dom node instead of an Ext.core.Element
145 * @return {Ext.core.Element/HTMLElement} The previous sibling or null
147 prev : function(selector, returnDom) {
148 return this.matchNode('previousSibling', 'previousSibling', selector, returnDom);
152 <span id='Ext-core-Element-method-first'> /**
153 </span> * Gets the first child, skipping text nodes
154 * @param {String} selector (optional) Find the next sibling that matches the passed simple selector
155 * @param {Boolean} returnDom (optional) True to return a raw dom node instead of an Ext.core.Element
156 * @return {Ext.core.Element/HTMLElement} The first child or null
158 first : function(selector, returnDom) {
159 return this.matchNode('nextSibling', 'firstChild', selector, returnDom);
162 <span id='Ext-core-Element-method-last'> /**
163 </span> * Gets the last child, skipping text nodes
164 * @param {String} selector (optional) Find the previous sibling that matches the passed simple selector
165 * @param {Boolean} returnDom (optional) True to return a raw dom node instead of an Ext.core.Element
166 * @return {Ext.core.Element/HTMLElement} The last child or null
168 last : function(selector, returnDom) {
169 return this.matchNode('previousSibling', 'lastChild', selector, returnDom);
172 matchNode : function(dir, start, selector, returnDom) {
177 var n = this.dom[start];
179 if (n.nodeType == 1 && (!selector || Ext.DomQuery.is(n, selector))) {
180 return !returnDom ? Ext.get(n) : n;