3 <title>The source code</title>
4 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
5 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
7 <body onload="prettyPrint();">
8 <pre class="prettyprint lang-js">/*!
10 * Copyright(c) 2006-2009 Ext JS, LLC
12 * http://www.extjs.com/license
15 * @class Ext.Element
\r
17 Ext.Element.addMethods(function(){
\r
18 var PARENTNODE = 'parentNode',
\r
19 NEXTSIBLING = 'nextSibling',
\r
20 PREVIOUSSIBLING = 'previousSibling',
\r
25 <div id="method-Ext.Element-findParent"></div>/**
\r
26 * 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
27 * @param {String} selector The simple selector to test
\r
28 * @param {Number/Mixed} maxDepth (optional) The max depth to search as a number or element (defaults to 50 || document.body)
\r
29 * @param {Boolean} returnEl (optional) True to return a Ext.Element object instead of DOM node
\r
30 * @return {HTMLElement} The matching DOM node (or null if no match was found)
\r
32 findParent : function(simpleSelector, maxDepth, returnEl){
\r
37 if(Ext.isGecko && Object.prototype.toString.call(p) == '[object XULElement]') {
\r
40 maxDepth = maxDepth || 50;
\r
41 if (isNaN(maxDepth)) {
\r
42 stopEl = Ext.getDom(maxDepth);
\r
43 maxDepth = Number.MAX_VALUE;
\r
45 while(p && p.nodeType == 1 && depth < maxDepth && p != b && p != stopEl){
\r
46 if(DQ.is(p, simpleSelector)){
\r
47 return returnEl ? GET(p) : p;
\r
55 <div id="method-Ext.Element-findParentNode"></div>/**
\r
56 * Looks at parent nodes for a match of the passed simple selector (e.g. div.some-class or span:first-child)
\r
57 * @param {String} selector The simple selector to test
\r
58 * @param {Number/Mixed} maxDepth (optional) The max depth to
\r
59 search as a number or element (defaults to 10 || document.body)
\r
60 * @param {Boolean} returnEl (optional) True to return a Ext.Element object instead of DOM node
\r
61 * @return {HTMLElement} The matching DOM node (or null if no match was found)
\r
63 findParentNode : function(simpleSelector, maxDepth, returnEl){
\r
64 var p = Ext.fly(this.dom.parentNode, '_internal');
\r
65 return p ? p.findParent(simpleSelector, maxDepth, returnEl) : null;
\r
68 <div id="method-Ext.Element-up"></div>/**
\r
69 * 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
70 * This is a shortcut for findParentNode() that always returns an Ext.Element.
\r
71 * @param {String} selector The simple selector to test
\r
72 * @param {Number/Mixed} maxDepth (optional) The max depth to
\r
73 search as a number or element (defaults to 10 || document.body)
\r
74 * @return {Ext.Element} The matching DOM node (or null if no match was found)
\r
76 up : function(simpleSelector, maxDepth){
\r
77 return this.findParentNode(simpleSelector, maxDepth, true);
\r
80 <div id="method-Ext.Element-select"></div>/**
\r
81 * Creates a {@link Ext.CompositeElement} for child nodes based on the passed CSS selector (the selector should not contain an id).
\r
82 * @param {String} selector The CSS selector
\r
83 * @param {Boolean} unique (optional) True to create a unique Ext.Element for each child (defaults to false, which creates a single shared flyweight object)
\r
84 * @return {CompositeElement/CompositeElementLite} The composite element
\r
86 select : function(selector, unique){
\r
87 return Ext.Element.select(selector, unique, this.dom);
\r
90 <div id="method-Ext.Element-query"></div>/**
\r
91 * Selects child nodes based on the passed CSS selector (the selector should not contain an id).
\r
92 * @param {String} selector The CSS selector
\r
93 * @return {Array} An array of the matched nodes
\r
95 query : function(selector, unique){
\r
96 return DQ.select(selector, this.dom);
\r
99 <div id="method-Ext.Element-child"></div>/**
\r
100 * Selects a single child at any depth below this element based on the passed CSS selector (the selector should not contain an id).
\r
101 * @param {String} selector The CSS selector
\r
102 * @param {Boolean} returnDom (optional) True to return the DOM node instead of Ext.Element (defaults to false)
\r
103 * @return {HTMLElement/Ext.Element} The child Ext.Element (or DOM node if returnDom = true)
\r
105 child : function(selector, returnDom){
\r
106 var n = DQ.selectNode(selector, this.dom);
\r
107 return returnDom ? n : GET(n);
\r
110 <div id="method-Ext.Element-down"></div>/**
\r
111 * Selects a single *direct* child based on the passed CSS selector (the selector should not contain an id).
\r
112 * @param {String} selector The CSS selector
\r
113 * @param {Boolean} returnDom (optional) True to return the DOM node instead of Ext.Element (defaults to false)
\r
114 * @return {HTMLElement/Ext.Element} The child Ext.Element (or DOM node if returnDom = true)
\r
116 down : function(selector, returnDom){
\r
117 var n = DQ.selectNode(" > " + selector, this.dom);
\r
118 return returnDom ? n : GET(n);
\r
121 <div id="method-Ext.Element-parent"></div>/**
\r
122 * Gets the parent node for this element, optionally chaining up trying to match a selector
\r
123 * @param {String} selector (optional) Find a parent node that matches the passed simple selector
\r
124 * @param {Boolean} returnDom (optional) True to return a raw dom node instead of an Ext.Element
\r
125 * @return {Ext.Element/HTMLElement} The parent node or null
\r
127 parent : function(selector, returnDom){
\r
128 return this.matchNode(PARENTNODE, PARENTNODE, selector, returnDom);
\r
131 <div id="method-Ext.Element-next"></div>/**
\r
132 * Gets the next sibling, skipping text nodes
\r
133 * @param {String} selector (optional) Find the next sibling that matches the passed simple selector
\r
134 * @param {Boolean} returnDom (optional) True to return a raw dom node instead of an Ext.Element
\r
135 * @return {Ext.Element/HTMLElement} The next sibling or null
\r
137 next : function(selector, returnDom){
\r
138 return this.matchNode(NEXTSIBLING, NEXTSIBLING, selector, returnDom);
\r
141 <div id="method-Ext.Element-prev"></div>/**
\r
142 * Gets the previous sibling, skipping text nodes
\r
143 * @param {String} selector (optional) Find the previous sibling that matches the passed simple selector
\r
144 * @param {Boolean} returnDom (optional) True to return a raw dom node instead of an Ext.Element
\r
145 * @return {Ext.Element/HTMLElement} The previous sibling or null
\r
147 prev : function(selector, returnDom){
\r
148 return this.matchNode(PREVIOUSSIBLING, PREVIOUSSIBLING, selector, returnDom);
\r
152 <div id="method-Ext.Element-first"></div>/**
\r
153 * Gets the first child, skipping text nodes
\r
154 * @param {String} selector (optional) Find the next sibling that matches the passed simple selector
\r
155 * @param {Boolean} returnDom (optional) True to return a raw dom node instead of an Ext.Element
\r
156 * @return {Ext.Element/HTMLElement} The first child or null
\r
158 first : function(selector, returnDom){
\r
159 return this.matchNode(NEXTSIBLING, 'firstChild', selector, returnDom);
\r
162 <div id="method-Ext.Element-last"></div>/**
\r
163 * Gets the last child, skipping text nodes
\r
164 * @param {String} selector (optional) Find the previous sibling that matches the passed simple selector
\r
165 * @param {Boolean} returnDom (optional) True to return a raw dom node instead of an Ext.Element
\r
166 * @return {Ext.Element/HTMLElement} The last child or null
\r
168 last : function(selector, returnDom){
\r
169 return this.matchNode(PREVIOUSSIBLING, 'lastChild', selector, returnDom);
\r
172 matchNode : function(dir, start, selector, returnDom){
\r
173 var n = this.dom[start];
\r
175 if(n.nodeType == 1 && (!selector || DQ.is(n, selector))){
\r
176 return !returnDom ? GET(n) : n;
\r