4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../resources/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-Element'>/**
19 </span> * @class Ext.Element
21 Ext.Element.addMethods({
22 <span id='Ext-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/String/HTMLElement/Ext.Element} maxDepth (optional)
26 * The max depth to search as a number or element (defaults to 50 || document.body)
27 * @param {Boolean} returnEl (optional) True to return a Ext.Element object instead of DOM node
28 * @return {HTMLElement} The matching DOM node (or null if no match was found)
30 findParent : function(simpleSelector, maxDepth, returnEl) {
36 maxDepth = maxDepth || 50;
37 if (isNaN(maxDepth)) {
38 stopEl = Ext.getDom(maxDepth);
39 maxDepth = Number.MAX_VALUE;
41 while (p && p.nodeType == 1 && depth < maxDepth && p != b && p != stopEl) {
42 if (Ext.DomQuery.is(p, simpleSelector)) {
43 return returnEl ? Ext.get(p) : p;
51 <span id='Ext-Element-method-findParentNode'> /**
52 </span> * Looks at parent nodes for a match of the passed simple selector (e.g. div.some-class or span:first-child)
53 * @param {String} selector The simple selector to test
54 * @param {Number/String/HTMLElement/Ext.Element} maxDepth (optional)
55 * The max depth to search as a number or element (defaults to 10 || document.body)
56 * @param {Boolean} returnEl (optional) True to return a Ext.Element object instead of DOM node
57 * @return {HTMLElement} The matching DOM node (or null if no match was found)
59 findParentNode : function(simpleSelector, maxDepth, returnEl) {
60 var p = Ext.fly(this.dom.parentNode, '_internal');
61 return p ? p.findParent(simpleSelector, maxDepth, returnEl) : null;
64 <span id='Ext-Element-method-up'> /**
65 </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).
66 * This is a shortcut for findParentNode() that always returns an Ext.Element.
67 * @param {String} selector The simple selector to test
68 * @param {Number/String/HTMLElement/Ext.Element} maxDepth (optional)
69 * The max depth to search as a number or element (defaults to 10 || document.body)
70 * @return {Ext.Element} The matching DOM node (or null if no match was found)
72 up : function(simpleSelector, maxDepth) {
73 return this.findParentNode(simpleSelector, maxDepth, true);
76 <span id='Ext-Element-method-select'> /**
77 </span> * Creates a {@link Ext.CompositeElement} for child nodes based on the passed CSS selector (the selector should not contain an id).
78 * @param {String} selector The CSS selector
79 * @return {Ext.CompositeElement/Ext.CompositeElement} The composite element
81 select : function(selector) {
82 return Ext.Element.select(selector, false, this.dom);
85 <span id='Ext-Element-method-query'> /**
86 </span> * Selects child nodes based on the passed CSS selector (the selector should not contain an id).
87 * @param {String} selector The CSS selector
88 * @return {HTMLElement[]} An array of the matched nodes
90 query : function(selector) {
91 return Ext.DomQuery.select(selector, this.dom);
94 <span id='Ext-Element-method-down'> /**
95 </span> * Selects a single child at any depth below this element based on the passed CSS selector (the selector should not contain an id).
96 * @param {String} selector The CSS selector
97 * @param {Boolean} returnDom (optional) True to return the DOM node instead of Ext.Element (defaults to false)
98 * @return {HTMLElement/Ext.Element} The child Ext.Element (or DOM node if returnDom = true)
100 down : function(selector, returnDom) {
101 var n = Ext.DomQuery.selectNode(selector, this.dom);
102 return returnDom ? n : Ext.get(n);
105 <span id='Ext-Element-method-child'> /**
106 </span> * Selects a single *direct* child based on the passed CSS selector (the selector should not contain an id).
107 * @param {String} selector The CSS selector
108 * @param {Boolean} returnDom (optional) True to return the DOM node instead of Ext.Element (defaults to false)
109 * @return {HTMLElement/Ext.Element} The child Ext.Element (or DOM node if returnDom = true)
111 child : function(selector, returnDom) {
117 id = id.replace(/[\.:]/g, "\\$0");
118 node = Ext.DomQuery.selectNode('#' + id + " > " + selector, me.dom);
119 return returnDom ? node : Ext.get(node);
122 <span id='Ext-Element-method-parent'> /**
123 </span> * Gets the parent node for this element, optionally chaining up trying to match a selector
124 * @param {String} selector (optional) Find a parent node that matches the passed simple selector
125 * @param {Boolean} returnDom (optional) True to return a raw dom node instead of an Ext.Element
126 * @return {Ext.Element/HTMLElement} The parent node or null
128 parent : function(selector, returnDom) {
129 return this.matchNode('parentNode', 'parentNode', selector, returnDom);
132 <span id='Ext-Element-method-next'> /**
133 </span> * Gets the next sibling, skipping text nodes
134 * @param {String} selector (optional) Find the next sibling that matches the passed simple selector
135 * @param {Boolean} returnDom (optional) True to return a raw dom node instead of an Ext.Element
136 * @return {Ext.Element/HTMLElement} The next sibling or null
138 next : function(selector, returnDom) {
139 return this.matchNode('nextSibling', 'nextSibling', selector, returnDom);
142 <span id='Ext-Element-method-prev'> /**
143 </span> * Gets the previous sibling, skipping text nodes
144 * @param {String} selector (optional) Find the previous sibling that matches the passed simple selector
145 * @param {Boolean} returnDom (optional) True to return a raw dom node instead of an Ext.Element
146 * @return {Ext.Element/HTMLElement} The previous sibling or null
148 prev : function(selector, returnDom) {
149 return this.matchNode('previousSibling', 'previousSibling', selector, returnDom);
153 <span id='Ext-Element-method-first'> /**
154 </span> * Gets the first child, skipping text nodes
155 * @param {String} selector (optional) Find the next sibling that matches the passed simple selector
156 * @param {Boolean} returnDom (optional) True to return a raw dom node instead of an Ext.Element
157 * @return {Ext.Element/HTMLElement} The first child or null
159 first : function(selector, returnDom) {
160 return this.matchNode('nextSibling', 'firstChild', selector, returnDom);
163 <span id='Ext-Element-method-last'> /**
164 </span> * Gets the last child, skipping text nodes
165 * @param {String} selector (optional) Find the previous sibling that matches the passed simple selector
166 * @param {Boolean} returnDom (optional) True to return a raw dom node instead of an Ext.Element
167 * @return {Ext.Element/HTMLElement} The last child or null
169 last : function(selector, returnDom) {
170 return this.matchNode('previousSibling', 'lastChild', selector, returnDom);
173 matchNode : function(dir, start, selector, returnDom) {
178 var n = this.dom[start];
180 if (n.nodeType == 1 && (!selector || Ext.DomQuery.is(n, selector))) {
181 return !returnDom ? Ext.get(n) : n;