AbstractQuery.html 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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-dom-AbstractQuery'>/**
  19. </span> * @class Ext.dom.AbstractQuery
  20. * @private
  21. */
  22. Ext.define('Ext.dom.AbstractQuery', {
  23. <span id='Ext-dom-AbstractQuery-method-select'> /**
  24. </span> * Selects a group of elements.
  25. * @param {String} selector The selector/xpath query (can be a comma separated list of selectors)
  26. * @param {HTMLElement/String} [root] The start of the query (defaults to document).
  27. * @return {HTMLElement[]} An Array of DOM elements which match the selector. If there are
  28. * no matches, and empty Array is returned.
  29. */
  30. select: function(q, root) {
  31. var results = [],
  32. nodes,
  33. i,
  34. j,
  35. qlen,
  36. nlen;
  37. root = root || document;
  38. if (typeof root == 'string') {
  39. root = document.getElementById(root);
  40. }
  41. q = q.split(&quot;,&quot;);
  42. for (i = 0,qlen = q.length; i &lt; qlen; i++) {
  43. if (typeof q[i] == 'string') {
  44. //support for node attribute selection
  45. if (typeof q[i][0] == '@') {
  46. nodes = root.getAttributeNode(q[i].substring(1));
  47. results.push(nodes);
  48. } else {
  49. nodes = root.querySelectorAll(q[i]);
  50. for (j = 0,nlen = nodes.length; j &lt; nlen; j++) {
  51. results.push(nodes[j]);
  52. }
  53. }
  54. }
  55. }
  56. return results;
  57. },
  58. <span id='Ext-dom-AbstractQuery-method-selectNode'> /**
  59. </span> * Selects a single element.
  60. * @param {String} selector The selector/xpath query
  61. * @param {HTMLElement/String} [root] The start of the query (defaults to document).
  62. * @return {HTMLElement} The DOM element which matched the selector.
  63. */
  64. selectNode: function(q, root) {
  65. return this.select(q, root)[0];
  66. },
  67. <span id='Ext-dom-AbstractQuery-method-is'> /**
  68. </span> * Returns true if the passed element(s) match the passed simple selector (e.g. div.some-class or span:first-child)
  69. * @param {String/HTMLElement/Array} el An element id, element or array of elements
  70. * @param {String} selector The simple selector to test
  71. * @return {Boolean}
  72. */
  73. is: function(el, q) {
  74. if (typeof el == &quot;string&quot;) {
  75. el = document.getElementById(el);
  76. }
  77. return this.select(q).indexOf(el) !== -1;
  78. }
  79. });
  80. </pre>
  81. </body>
  82. </html>