3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
\r
4 <title>The source code</title>
\r
5 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
\r
6 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
\r
8 <body onload="prettyPrint();">
\r
9 <pre class="prettyprint lang-js">/**
\r
10 * @class Ext.Element
\r
12 Ext.Element.addMethods(function(){
\r
13 var PARENTNODE = 'parentNode',
\r
14 NEXTSIBLING = 'nextSibling',
\r
15 PREVIOUSSIBLING = 'previousSibling',
\r
20 <div id="method-Ext.Element-findParent"></div>/**
\r
21 * 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)
\r
22 * @param {String} selector The simple selector to test
\r
23 * @param {Number/Mixed} maxDepth (optional) The max depth to search as a number or element (defaults to 50 || document.body)
\r
24 * @param {Boolean} returnEl (optional) True to return a Ext.Element object instead of DOM node
\r
25 * @return {HTMLElement} The matching DOM node (or null if no match was found)
\r
27 findParent : function(simpleSelector, maxDepth, returnEl){
\r
32 if(Ext.isGecko && Object.prototype.toString.call(p) == '[object XULElement]') {
\r
35 maxDepth = maxDepth || 50;
\r
36 if (isNaN(maxDepth)) {
\r
37 stopEl = Ext.getDom(maxDepth);
\r
38 maxDepth = Number.MAX_VALUE;
\r
40 while(p && p.nodeType == 1 && depth < maxDepth && p != b && p != stopEl){
\r
41 if(DQ.is(p, simpleSelector)){
\r
42 return returnEl ? GET(p) : p;
\r
50 <div id="method-Ext.Element-findParentNode"></div>/**
\r
51 * Looks at parent nodes for a match of the passed simple selector (e.g. div.some-class or span:first-child)
\r
52 * @param {String} selector The simple selector to test
\r
53 * @param {Number/Mixed} maxDepth (optional) The max depth to
\r
54 search as a number or element (defaults to 10 || document.body)
\r
55 * @param {Boolean} returnEl (optional) True to return a Ext.Element object instead of DOM node
\r
56 * @return {HTMLElement} The matching DOM node (or null if no match was found)
\r
58 findParentNode : function(simpleSelector, maxDepth, returnEl){
\r
59 var p = Ext.fly(this.dom.parentNode, '_internal');
\r
60 return p ? p.findParent(simpleSelector, maxDepth, returnEl) : null;
\r
63 <div id="method-Ext.Element-up"></div>/**
\r
64 * Walks up the dom looking for a parent node that matches the passed simple selector (e.g. div.some-class or span:first-child).
\r
65 * This is a shortcut for findParentNode() that always returns an Ext.Element.
\r
66 * @param {String} selector The simple selector to test
\r
67 * @param {Number/Mixed} maxDepth (optional) The max depth to
\r
68 search as a number or element (defaults to 10 || document.body)
\r
69 * @return {Ext.Element} The matching DOM node (or null if no match was found)
\r
71 up : function(simpleSelector, maxDepth){
\r
72 return this.findParentNode(simpleSelector, maxDepth, true);
\r
75 <div id="method-Ext.Element-select"></div>/**
\r
76 * Creates a {@link Ext.CompositeElement} for child nodes based on the passed CSS selector (the selector should not contain an id).
\r
77 * @param {String} selector The CSS selector
\r
78 * @return {CompositeElement/CompositeElementLite} The composite element
\r
80 select : function(selector){
\r
81 return Ext.Element.select(selector, this.dom);
\r
84 <div id="method-Ext.Element-query"></div>/**
\r
85 * Selects child nodes based on the passed CSS selector (the selector should not contain an id).
\r
86 * @param {String} selector The CSS selector
\r
87 * @return {Array} An array of the matched nodes
\r
89 query : function(selector){
\r
90 return DQ.select(selector, this.dom);
\r
93 <div id="method-Ext.Element-child"></div>/**
\r
94 * Selects a single child at any depth below this element based on the passed CSS selector (the selector should not contain an id).
\r
95 * @param {String} selector The CSS selector
\r
96 * @param {Boolean} returnDom (optional) True to return the DOM node instead of Ext.Element (defaults to false)
\r
97 * @return {HTMLElement/Ext.Element} The child Ext.Element (or DOM node if returnDom = true)
\r
99 child : function(selector, returnDom){
\r
100 var n = DQ.selectNode(selector, this.dom);
\r
101 return returnDom ? n : GET(n);
\r
104 <div id="method-Ext.Element-down"></div>/**
\r
105 * Selects a single *direct* child based on the passed CSS selector (the selector should not contain an id).
\r
106 * @param {String} selector The CSS selector
\r
107 * @param {Boolean} returnDom (optional) True to return the DOM node instead of Ext.Element (defaults to false)
\r
108 * @return {HTMLElement/Ext.Element} The child Ext.Element (or DOM node if returnDom = true)
\r
110 down : function(selector, returnDom){
\r
111 var n = DQ.selectNode(" > " + selector, this.dom);
\r
112 return returnDom ? n : GET(n);
\r
115 <div id="method-Ext.Element-parent"></div>/**
\r
116 * Gets the parent node for this element, optionally chaining up trying to match a selector
\r
117 * @param {String} selector (optional) Find a parent node that matches the passed simple selector
\r
118 * @param {Boolean} returnDom (optional) True to return a raw dom node instead of an Ext.Element
\r
119 * @return {Ext.Element/HTMLElement} The parent node or null
\r
121 parent : function(selector, returnDom){
\r
122 return this.matchNode(PARENTNODE, PARENTNODE, selector, returnDom);
\r
125 <div id="method-Ext.Element-next"></div>/**
\r
126 * Gets the next sibling, skipping text nodes
\r
127 * @param {String} selector (optional) Find the next sibling that matches the passed simple selector
\r
128 * @param {Boolean} returnDom (optional) True to return a raw dom node instead of an Ext.Element
\r
129 * @return {Ext.Element/HTMLElement} The next sibling or null
\r
131 next : function(selector, returnDom){
\r
132 return this.matchNode(NEXTSIBLING, NEXTSIBLING, selector, returnDom);
\r
135 <div id="method-Ext.Element-prev"></div>/**
\r
136 * Gets the previous sibling, skipping text nodes
\r
137 * @param {String} selector (optional) Find the previous sibling that matches the passed simple selector
\r
138 * @param {Boolean} returnDom (optional) True to return a raw dom node instead of an Ext.Element
\r
139 * @return {Ext.Element/HTMLElement} The previous sibling or null
\r
141 prev : function(selector, returnDom){
\r
142 return this.matchNode(PREVIOUSSIBLING, PREVIOUSSIBLING, selector, returnDom);
\r
146 <div id="method-Ext.Element-first"></div>/**
\r
147 * Gets the first child, skipping text nodes
\r
148 * @param {String} selector (optional) Find the next sibling that matches the passed simple selector
\r
149 * @param {Boolean} returnDom (optional) True to return a raw dom node instead of an Ext.Element
\r
150 * @return {Ext.Element/HTMLElement} The first child or null
\r
152 first : function(selector, returnDom){
\r
153 return this.matchNode(NEXTSIBLING, 'firstChild', selector, returnDom);
\r
156 <div id="method-Ext.Element-last"></div>/**
\r
157 * Gets the last child, skipping text nodes
\r
158 * @param {String} selector (optional) Find the previous sibling that matches the passed simple selector
\r
159 * @param {Boolean} returnDom (optional) True to return a raw dom node instead of an Ext.Element
\r
160 * @return {Ext.Element/HTMLElement} The last child or null
\r
162 last : function(selector, returnDom){
\r
163 return this.matchNode(PREVIOUSSIBLING, 'lastChild', selector, returnDom);
\r
166 matchNode : function(dir, start, selector, returnDom){
\r
167 var n = this.dom[start];
\r
169 if(n.nodeType == 1 && (!selector || DQ.is(n, selector))){
\r
170 return !returnDom ? GET(n) : n;
\r