/ext-4.0.7/docs/source/Element.traversal.html

https://bitbucket.org/srogerf/javascript · HTML · 190 lines · 175 code · 15 blank · 0 comment · 0 complexity · 4c7cb1254d396e98436691c6e1942292 MD5 · raw file

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  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; }
  10. </style>
  11. <script type="text/javascript">
  12. function highlight() {
  13. document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
  14. }
  15. </script>
  16. </head>
  17. <body onload="prettyPrint(); highlight();">
  18. <pre class="prettyprint lang-js"><span id='Ext-Element'>/**
  19. </span> * @class Ext.Element
  20. */
  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)
  29. */
  30. findParent : function(simpleSelector, maxDepth, returnEl) {
  31. var p = this.dom,
  32. b = document.body,
  33. depth = 0,
  34. stopEl;
  35. maxDepth = maxDepth || 50;
  36. if (isNaN(maxDepth)) {
  37. stopEl = Ext.getDom(maxDepth);
  38. maxDepth = Number.MAX_VALUE;
  39. }
  40. while (p &amp;&amp; p.nodeType == 1 &amp;&amp; depth &lt; maxDepth &amp;&amp; p != b &amp;&amp; p != stopEl) {
  41. if (Ext.DomQuery.is(p, simpleSelector)) {
  42. return returnEl ? Ext.get(p) : p;
  43. }
  44. depth++;
  45. p = p.parentNode;
  46. }
  47. return null;
  48. },
  49. <span id='Ext-Element-method-findParentNode'> /**
  50. </span> * Looks at parent nodes for a match of the passed simple selector (e.g. div.some-class or span:first-child)
  51. * @param {String} selector The simple selector to test
  52. * @param {Number/String/HTMLElement/Ext.Element} maxDepth (optional)
  53. * The max depth to search as a number or element (defaults to 10 || document.body)
  54. * @param {Boolean} returnEl (optional) True to return a Ext.Element object instead of DOM node
  55. * @return {HTMLElement} The matching DOM node (or null if no match was found)
  56. */
  57. findParentNode : function(simpleSelector, maxDepth, returnEl) {
  58. var p = Ext.fly(this.dom.parentNode, '_internal');
  59. return p ? p.findParent(simpleSelector, maxDepth, returnEl) : null;
  60. },
  61. <span id='Ext-Element-method-up'> /**
  62. </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).
  63. * This is a shortcut for findParentNode() that always returns an Ext.Element.
  64. * @param {String} selector The simple selector to test
  65. * @param {Number/String/HTMLElement/Ext.Element} maxDepth (optional)
  66. * The max depth to search as a number or element (defaults to 10 || document.body)
  67. * @return {Ext.Element} The matching DOM node (or null if no match was found)
  68. */
  69. up : function(simpleSelector, maxDepth) {
  70. return this.findParentNode(simpleSelector, maxDepth, true);
  71. },
  72. <span id='Ext-Element-method-select'> /**
  73. </span> * Creates a {@link Ext.CompositeElement} for child nodes based on the passed CSS selector (the selector should not contain an id).
  74. * @param {String} selector The CSS selector
  75. * @return {Ext.CompositeElement/Ext.CompositeElement} The composite element
  76. */
  77. select : function(selector) {
  78. return Ext.Element.select(selector, false, this.dom);
  79. },
  80. <span id='Ext-Element-method-query'> /**
  81. </span> * Selects child nodes based on the passed CSS selector (the selector should not contain an id).
  82. * @param {String} selector The CSS selector
  83. * @return {HTMLElement[]} An array of the matched nodes
  84. */
  85. query : function(selector) {
  86. return Ext.DomQuery.select(selector, this.dom);
  87. },
  88. <span id='Ext-Element-method-down'> /**
  89. </span> * Selects a single child at any depth below this element based on the passed CSS selector (the selector should not contain an id).
  90. * @param {String} selector The CSS selector
  91. * @param {Boolean} returnDom (optional) True to return the DOM node instead of Ext.Element (defaults to false)
  92. * @return {HTMLElement/Ext.Element} The child Ext.Element (or DOM node if returnDom = true)
  93. */
  94. down : function(selector, returnDom) {
  95. var n = Ext.DomQuery.selectNode(selector, this.dom);
  96. return returnDom ? n : Ext.get(n);
  97. },
  98. <span id='Ext-Element-method-child'> /**
  99. </span> * Selects a single *direct* child based on the passed CSS selector (the selector should not contain an id).
  100. * @param {String} selector The CSS selector
  101. * @param {Boolean} returnDom (optional) True to return the DOM node instead of Ext.Element (defaults to false)
  102. * @return {HTMLElement/Ext.Element} The child Ext.Element (or DOM node if returnDom = true)
  103. */
  104. child : function(selector, returnDom) {
  105. var node,
  106. me = this,
  107. id;
  108. id = Ext.get(me).id;
  109. // Escape . or :
  110. id = id.replace(/[\.:]/g, &quot;\\$0&quot;);
  111. node = Ext.DomQuery.selectNode('#' + id + &quot; &gt; &quot; + selector, me.dom);
  112. return returnDom ? node : Ext.get(node);
  113. },
  114. <span id='Ext-Element-method-parent'> /**
  115. </span> * Gets the parent node for this element, optionally chaining up trying to match a selector
  116. * @param {String} selector (optional) Find a parent node that matches the passed simple selector
  117. * @param {Boolean} returnDom (optional) True to return a raw dom node instead of an Ext.Element
  118. * @return {Ext.Element/HTMLElement} The parent node or null
  119. */
  120. parent : function(selector, returnDom) {
  121. return this.matchNode('parentNode', 'parentNode', selector, returnDom);
  122. },
  123. <span id='Ext-Element-method-next'> /**
  124. </span> * Gets the next sibling, skipping text nodes
  125. * @param {String} selector (optional) Find the next sibling that matches the passed simple selector
  126. * @param {Boolean} returnDom (optional) True to return a raw dom node instead of an Ext.Element
  127. * @return {Ext.Element/HTMLElement} The next sibling or null
  128. */
  129. next : function(selector, returnDom) {
  130. return this.matchNode('nextSibling', 'nextSibling', selector, returnDom);
  131. },
  132. <span id='Ext-Element-method-prev'> /**
  133. </span> * Gets the previous sibling, skipping text nodes
  134. * @param {String} selector (optional) Find the previous 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 previous sibling or null
  137. */
  138. prev : function(selector, returnDom) {
  139. return this.matchNode('previousSibling', 'previousSibling', selector, returnDom);
  140. },
  141. <span id='Ext-Element-method-first'> /**
  142. </span> * Gets the first child, skipping text nodes
  143. * @param {String} selector (optional) Find the next sibling that matches the passed simple selector
  144. * @param {Boolean} returnDom (optional) True to return a raw dom node instead of an Ext.Element
  145. * @return {Ext.Element/HTMLElement} The first child or null
  146. */
  147. first : function(selector, returnDom) {
  148. return this.matchNode('nextSibling', 'firstChild', selector, returnDom);
  149. },
  150. <span id='Ext-Element-method-last'> /**
  151. </span> * Gets the last child, skipping text nodes
  152. * @param {String} selector (optional) Find the previous sibling that matches the passed simple selector
  153. * @param {Boolean} returnDom (optional) True to return a raw dom node instead of an Ext.Element
  154. * @return {Ext.Element/HTMLElement} The last child or null
  155. */
  156. last : function(selector, returnDom) {
  157. return this.matchNode('previousSibling', 'lastChild', selector, returnDom);
  158. },
  159. matchNode : function(dir, start, selector, returnDom) {
  160. if (!this.dom) {
  161. return null;
  162. }
  163. var n = this.dom[start];
  164. while (n) {
  165. if (n.nodeType == 1 &amp;&amp; (!selector || Ext.DomQuery.is(n, selector))) {
  166. return !returnDom ? Ext.get(n) : n;
  167. }
  168. n = n[dir];
  169. }
  170. return null;
  171. }
  172. });
  173. </pre>
  174. </body>
  175. </html>