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(function(){
\r
12 var PARENTNODE = 'parentNode',
\r
13 NEXTSIBLING = 'nextSibling',
\r
14 PREVIOUSSIBLING = 'previousSibling',
\r
19 <div id="method-Ext.Element-findParent"></div>/**
\r
20 * 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
21 * @param {String} selector The simple selector to test
\r
22 * @param {Number/Mixed} maxDepth (optional) The max depth to search as a number or element (defaults to 50 || document.body)
\r
23 * @param {Boolean} returnEl (optional) True to return a Ext.Element object instead of DOM node
\r
24 * @return {HTMLElement} The matching DOM node (or null if no match was found)
\r
26 findParent : function(simpleSelector, maxDepth, returnEl){
\r
31 if(Ext.isGecko && Object.prototype.toString.call(p) == '[object XULElement]') {
\r
34 maxDepth = maxDepth || 50;
\r
35 if (isNaN(maxDepth)) {
\r
36 stopEl = Ext.getDom(maxDepth);
\r
37 maxDepth = Number.MAX_VALUE;
\r
39 while(p && p.nodeType == 1 && depth < maxDepth && p != b && p != stopEl){
\r
40 if(DQ.is(p, simpleSelector)){
\r
41 return returnEl ? GET(p) : p;
\r
49 <div id="method-Ext.Element-findParentNode"></div>/**
\r
50 * Looks at parent nodes for a match of the passed simple selector (e.g. div.some-class or span:first-child)
\r
51 * @param {String} selector The simple selector to test
\r
52 * @param {Number/Mixed} maxDepth (optional) The max depth to
\r
53 search as a number or element (defaults to 10 || document.body)
\r
54 * @param {Boolean} returnEl (optional) True to return a Ext.Element object instead of DOM node
\r
55 * @return {HTMLElement} The matching DOM node (or null if no match was found)
\r
57 findParentNode : function(simpleSelector, maxDepth, returnEl){
\r
58 var p = Ext.fly(this.dom.parentNode, '_internal');
\r
59 return p ? p.findParent(simpleSelector, maxDepth, returnEl) : null;
\r
62 <div id="method-Ext.Element-up"></div>/**
\r
63 * 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
64 * This is a shortcut for findParentNode() that always returns an Ext.Element.
\r
65 * @param {String} selector The simple selector to test
\r
66 * @param {Number/Mixed} maxDepth (optional) The max depth to
\r
67 search as a number or element (defaults to 10 || document.body)
\r
68 * @return {Ext.Element} The matching DOM node (or null if no match was found)
\r
70 up : function(simpleSelector, maxDepth){
\r
71 return this.findParentNode(simpleSelector, maxDepth, true);
\r
74 <div id="method-Ext.Element-select"></div>/**
\r
75 * Creates a {@link Ext.CompositeElement} for child nodes based on the passed CSS selector (the selector should not contain an id).
\r
76 * @param {String} selector The CSS selector
\r
77 * @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
78 * @return {CompositeElement/CompositeElementLite} The composite element
\r
80 select : function(selector, unique){
\r
81 return Ext.Element.select(selector, unique, 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, unique){
\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