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 * This is code is also distributed under MIT license for use
\r
11 * with jQuery and prototype JavaScript libraries.
\r
13 <div id="cls-Ext.DomQuery"></div>/**
\r
14 * @class Ext.DomQuery
\r
15 Provides high performance selector/xpath processing by compiling queries into reusable functions. New pseudo classes and matchers can be plugged. It works on HTML and XML documents (if a content node is passed in).
\r
17 DomQuery supports most of the <a href="http://www.w3.org/TR/2005/WD-css3-selectors-20051215/#selectors">CSS3 selectors spec</a>, along with some custom selectors and basic XPath.</p>
\r
20 All selectors, attribute filters and pseudos below can be combined infinitely in any order. For example "div.foo:nth-child(odd)[@foo=bar].bar:first" would be a perfectly valid selector. Node filters are processed in the order in which they appear, which allows you to optimize your queries for your document structure.
\r
22 <h4>Element Selectors:</h4>
\r
24 <li> <b>*</b> any element</li>
\r
25 <li> <b>E</b> an element with the tag E</li>
\r
26 <li> <b>E F</b> All descendent elements of E that have the tag F</li>
\r
27 <li> <b>E > F</b> or <b>E/F</b> all direct children elements of E that have the tag F</li>
\r
28 <li> <b>E + F</b> all elements with the tag F that are immediately preceded by an element with the tag E</li>
\r
29 <li> <b>E ~ F</b> all elements with the tag F that are preceded by a sibling element with the tag E</li>
\r
31 <h4>Attribute Selectors:</h4>
\r
32 <p>The use of @ and quotes are optional. For example, div[@foo='bar'] is also a valid attribute selector.</p>
\r
34 <li> <b>E[foo]</b> has an attribute "foo"</li>
\r
35 <li> <b>E[foo=bar]</b> has an attribute "foo" that equals "bar"</li>
\r
36 <li> <b>E[foo^=bar]</b> has an attribute "foo" that starts with "bar"</li>
\r
37 <li> <b>E[foo$=bar]</b> has an attribute "foo" that ends with "bar"</li>
\r
38 <li> <b>E[foo*=bar]</b> has an attribute "foo" that contains the substring "bar"</li>
\r
39 <li> <b>E[foo%=2]</b> has an attribute "foo" that is evenly divisible by 2</li>
\r
40 <li> <b>E[foo!=bar]</b> has an attribute "foo" that does not equal "bar"</li>
\r
42 <h4>Pseudo Classes:</h4>
\r
44 <li> <b>E:first-child</b> E is the first child of its parent</li>
\r
45 <li> <b>E:last-child</b> E is the last child of its parent</li>
\r
46 <li> <b>E:nth-child(<i>n</i>)</b> E is the <i>n</i>th child of its parent (1 based as per the spec)</li>
\r
47 <li> <b>E:nth-child(odd)</b> E is an odd child of its parent</li>
\r
48 <li> <b>E:nth-child(even)</b> E is an even child of its parent</li>
\r
49 <li> <b>E:only-child</b> E is the only child of its parent</li>
\r
50 <li> <b>E:checked</b> E is an element that is has a checked attribute that is true (e.g. a radio or checkbox) </li>
\r
51 <li> <b>E:first</b> the first E in the resultset</li>
\r
52 <li> <b>E:last</b> the last E in the resultset</li>
\r
53 <li> <b>E:nth(<i>n</i>)</b> the <i>n</i>th E in the resultset (1 based)</li>
\r
54 <li> <b>E:odd</b> shortcut for :nth-child(odd)</li>
\r
55 <li> <b>E:even</b> shortcut for :nth-child(even)</li>
\r
56 <li> <b>E:contains(foo)</b> E's innerHTML contains the substring "foo"</li>
\r
57 <li> <b>E:nodeValue(foo)</b> E contains a textNode with a nodeValue that equals "foo"</li>
\r
58 <li> <b>E:not(S)</b> an E element that does not match simple selector S</li>
\r
59 <li> <b>E:has(S)</b> an E element that has a descendent that matches simple selector S</li>
\r
60 <li> <b>E:next(S)</b> an E element whose next sibling matches simple selector S</li>
\r
61 <li> <b>E:prev(S)</b> an E element whose previous sibling matches simple selector S</li>
\r
62 <li> <b>E:any(S1|S2|S2)</b> an E element which matches any of the simple selectors S1, S2 or S3//\\</li>
\r
64 <h4>CSS Value Selectors:</h4>
\r
66 <li> <b>E{display=none}</b> css value "display" that equals "none"</li>
\r
67 <li> <b>E{display^=none}</b> css value "display" that starts with "none"</li>
\r
68 <li> <b>E{display$=none}</b> css value "display" that ends with "none"</li>
\r
69 <li> <b>E{display*=none}</b> css value "display" that contains the substring "none"</li>
\r
70 <li> <b>E{display%=2}</b> css value "display" that is evenly divisible by 2</li>
\r
71 <li> <b>E{display!=none}</b> css value "display" that does not equal "none"</li>
\r
75 Ext.DomQuery = function(){
\r
80 trimRe = /^\s+|\s+$/g,
\r
81 tplRe = /\{(\d+)\}/g,
\r
82 modeRe = /^(\s?[\/>+~]\s?|\s|$)/,
\r
83 tagTokenRe = /^(#)?([\w-\*]+)/,
\r
84 nthRe = /(\d*)n\+?(\d*)/,
\r
86 // This is for IE MSXML which does not support expandos.
\r
87 // IE runs the same speed using setAttribute, however FF slows way down
\r
88 // and Safari completely fails so they need to continue to use expandos.
\r
89 isIE = window.ActiveXObject ? true : false,
\r
92 // this eval is stop the compressor from
\r
93 // renaming the variable to something shorter
\r
94 eval("var batch = 30803;");
\r
96 // Retrieve the child node from a particular
\r
97 // parent at the specified index.
\r
98 function child(parent, index){
\r
100 n = parent.firstChild;
\r
102 if(n.nodeType == 1){
\r
112 // retrieve the next element node
\r
114 while((n = n.nextSibling) && n.nodeType != 1);
\r
118 // retrieve the previous element node
\r
120 while((n = n.previousSibling) && n.nodeType != 1);
\r
124 // Mark each child node with a nodeIndex skipping and
\r
125 // removing empty text nodes.
\r
126 function children(parent){
\r
127 var n = parent.firstChild,
\r
131 nextNode = n.nextSibling;
\r
132 // clean worthless empty nodes.
\r
133 if(n.nodeType == 3 && !nonSpace.test(n.nodeValue)){
\r
134 parent.removeChild(n);
\r
136 // add an expando nodeIndex
\r
137 n.nodeIndex = ++nodeIndex;
\r
145 // nodeSet - array of nodes
\r
147 function byClassName(nodeSet, cls){
\r
151 var result = [], ri = -1;
\r
152 for(var i = 0, ci; ci = nodeSet[i]; i++){
\r
153 if((' '+ci.className+' ').indexOf(cls) != -1){
\r
160 function attrValue(n, attr){
\r
161 // if its an array, use the first node.
\r
162 if(!n.tagName && typeof n.length != "undefined"){
\r
172 if(attr == "class" || attr == "className"){
\r
173 return n.className;
\r
175 return n.getAttribute(attr) || n[attr];
\r
181 // mode - false, /, >, +, ~
\r
182 // tagName - defaults to "*"
\r
183 function getNodes(ns, mode, tagName){
\r
184 var result = [], ri = -1, cs;
\r
188 tagName = tagName || "*";
\r
189 // convert to array
\r
190 if(typeof ns.getElementsByTagName != "undefined"){
\r
194 // no mode specified, grab all elements by tagName
\r
197 for(var i = 0, ni; ni = ns[i]; i++){
\r
198 cs = ni.getElementsByTagName(tagName);
\r
199 for(var j = 0, ci; ci = cs[j]; j++){
\r
203 // Direct Child mode (/ or >)
\r
204 // E > F or E/F all direct children elements of E that have the tag
\r
205 } else if(mode == "/" || mode == ">"){
\r
206 var utag = tagName.toUpperCase();
\r
207 for(var i = 0, ni, cn; ni = ns[i]; i++){
\r
208 cn = ni.childNodes;
\r
209 for(var j = 0, cj; cj = cn[j]; j++){
\r
210 if(cj.nodeName == utag || cj.nodeName == tagName || tagName == '*'){
\r
215 // Immediately Preceding mode (+)
\r
216 // E + F all elements with the tag F that are immediately preceded by an element with the tag E
\r
217 }else if(mode == "+"){
\r
218 var utag = tagName.toUpperCase();
\r
219 for(var i = 0, n; n = ns[i]; i++){
\r
220 while((n = n.nextSibling) && n.nodeType != 1);
\r
221 if(n && (n.nodeName == utag || n.nodeName == tagName || tagName == '*')){
\r
225 // Sibling mode (~)
\r
226 // E ~ F all elements with the tag F that are preceded by a sibling element with the tag E
\r
227 }else if(mode == "~"){
\r
228 var utag = tagName.toUpperCase();
\r
229 for(var i = 0, n; n = ns[i]; i++){
\r
230 while((n = n.nextSibling)){
\r
231 if (n.nodeName == utag || n.nodeName == tagName || tagName == '*'){
\r
240 function concat(a, b){
\r
242 return a.concat(b);
\r
244 for(var i = 0, l = b.length; i < l; i++){
\r
245 a[a.length] = b[i];
\r
250 function byTag(cs, tagName){
\r
251 if(cs.tagName || cs == document){
\r
257 var result = [], ri = -1;
\r
258 tagName = tagName.toLowerCase();
\r
259 for(var i = 0, ci; ci = cs[i]; i++){
\r
260 if(ci.nodeType == 1 && ci.tagName.toLowerCase() == tagName){
\r
267 function byId(cs, id){
\r
268 if(cs.tagName || cs == document){
\r
274 var result = [], ri = -1;
\r
275 for(var i = 0, ci; ci = cs[i]; i++){
\r
276 if(ci && ci.id == id){
\r
284 // operators are =, !=, ^=, $=, *=, %=, |= and ~=
\r
285 // custom can be "{"
\r
286 function byAttribute(cs, attr, value, op, custom){
\r
289 useGetStyle = custom == "{",
\r
290 fn = Ext.DomQuery.operators[op],
\r
293 for(var i = 0, ci; ci = cs[i]; i++){
\r
294 // skip non-element nodes.
\r
295 if(ci.nodeType != 1){
\r
299 innerHTML = ci.innerHTML;
\r
300 // we only need to change the property names if we're dealing with html nodes, not XML
\r
301 if(innerHTML !== null && innerHTML !== undefined){
\r
303 a = Ext.DomQuery.getStyle(ci, attr);
\r
304 } else if (attr == "class" || attr == "className"){
\r
306 } else if (attr == "for"){
\r
308 } else if (attr == "href"){
\r
309 // getAttribute href bug
\r
310 // http://www.glennjones.net/Post/809/getAttributehrefbug.htm
\r
311 a = ci.getAttribute("href", 2);
\r
313 a = ci.getAttribute(attr);
\r
316 a = ci.getAttribute(attr);
\r
318 if((fn && fn(a, value)) || (!fn && a)){
\r
325 function byPseudo(cs, name, value){
\r
326 return Ext.DomQuery.pseudos[name](cs, value);
\r
329 function nodupIEXml(cs){
\r
332 cs[0].setAttribute("_nodup", d);
\r
334 for(var i = 1, len = cs.length; i < len; i++){
\r
336 if(!c.getAttribute("_nodup") != d){
\r
337 c.setAttribute("_nodup", d);
\r
341 for(var i = 0, len = cs.length; i < len; i++){
\r
342 cs[i].removeAttribute("_nodup");
\r
347 function nodup(cs){
\r
351 var len = cs.length, c, i, r = cs, cj, ri = -1;
\r
352 if(!len || typeof cs.nodeType != "undefined" || len == 1){
\r
355 if(isIE && typeof cs[0].selectSingleNode != "undefined"){
\r
356 return nodupIEXml(cs);
\r
360 for(i = 1; c = cs[i]; i++){
\r
365 for(var j = 0; j < i; j++){
\r
368 for(j = i+1; cj = cs[j]; j++){
\r
369 if(cj._nodup != d){
\r
380 function quickDiffIEXml(c1, c2){
\r
383 for(var i = 0, len = c1.length; i < len; i++){
\r
384 c1[i].setAttribute("_qdiff", d);
\r
386 for(var i = 0, len = c2.length; i < len; i++){
\r
387 if(c2[i].getAttribute("_qdiff") != d){
\r
388 r[r.length] = c2[i];
\r
391 for(var i = 0, len = c1.length; i < len; i++){
\r
392 c1[i].removeAttribute("_qdiff");
\r
397 function quickDiff(c1, c2){
\r
398 var len1 = c1.length,
\r
404 if(isIE && typeof c1[0].selectSingleNode != "undefined"){
\r
405 return quickDiffIEXml(c1, c2);
\r
407 for(var i = 0; i < len1; i++){
\r
410 for(var i = 0, len = c2.length; i < len; i++){
\r
411 if(c2[i]._qdiff != d){
\r
412 r[r.length] = c2[i];
\r
418 function quickId(ns, mode, root, id){
\r
420 var d = root.ownerDocument || root;
\r
421 return d.getElementById(id);
\r
423 ns = getNodes(ns, mode, "*");
\r
424 return byId(ns, id);
\r
428 getStyle : function(el, name){
\r
429 return Ext.fly(el).getStyle(name);
\r
431 <div id="method-Ext.DomQuery-compile"></div>/**
\r
432 * Compiles a selector/xpath query into a reusable function. The returned function
\r
433 * takes one parameter "root" (optional), which is the context node from where the query should start.
\r
434 * @param {String} selector The selector/xpath query
\r
435 * @param {String} type (optional) Either "select" (the default) or "simple" for a simple selector match
\r
436 * @return {Function}
\r
438 compile : function(path, type){
\r
439 type = type || "select";
\r
441 // setup fn preamble
\r
442 var fn = ["var f = function(root){\n var mode; ++batch; var n = root || document;\n"],
\r
445 matchers = Ext.DomQuery.matchers,
\r
446 matchersLn = matchers.length,
\r
448 // accept leading mode switch
\r
449 lmode = path.match(modeRe);
\r
451 if(lmode && lmode[1]){
\r
452 fn[fn.length] = 'mode="'+lmode[1].replace(trimRe, "")+'";';
\r
453 path = path.replace(lmode[1], "");
\r
456 // strip leading slashes
\r
457 while(path.substr(0, 1)=="/"){
\r
458 path = path.substr(1);
\r
461 while(path && lastPath != path){
\r
463 var tokenMatch = path.match(tagTokenRe);
\r
464 if(type == "select"){
\r
467 if(tokenMatch[1] == "#"){
\r
468 fn[fn.length] = 'n = quickId(n, mode, root, "'+tokenMatch[2]+'");';
\r
470 fn[fn.length] = 'n = getNodes(n, mode, "'+tokenMatch[2]+'");';
\r
472 path = path.replace(tokenMatch[0], "");
\r
473 }else if(path.substr(0, 1) != '@'){
\r
474 fn[fn.length] = 'n = getNodes(n, mode, "*");';
\r
476 // type of "simple"
\r
479 if(tokenMatch[1] == "#"){
\r
480 fn[fn.length] = 'n = byId(n, "'+tokenMatch[2]+'");';
\r
482 fn[fn.length] = 'n = byTag(n, "'+tokenMatch[2]+'");';
\r
484 path = path.replace(tokenMatch[0], "");
\r
487 while(!(modeMatch = path.match(modeRe))){
\r
488 var matched = false;
\r
489 for(var j = 0; j < matchersLn; j++){
\r
490 var t = matchers[j];
\r
491 var m = path.match(t.re);
\r
493 fn[fn.length] = t.select.replace(tplRe, function(x, i){
\r
496 path = path.replace(m[0], "");
\r
501 // prevent infinite loop on bad selector
\r
503 throw 'Error parsing selector, parsing failed at "' + path + '"';
\r
507 fn[fn.length] = 'mode="'+modeMatch[1].replace(trimRe, "")+'";';
\r
508 path = path.replace(modeMatch[1], "");
\r
512 fn[fn.length] = "return nodup(n);\n}";
\r
514 // eval fn and return it
\r
519 <div id="method-Ext.DomQuery-jsSelect"></div>/**
\r
520 * Selects a group of elements.
\r
521 * @param {String} selector The selector/xpath query (can be a comma separated list of selectors)
\r
522 * @param {Node/String} root (optional) The start of the query (defaults to document).
\r
523 * @return {Array} An Array of DOM elements which match the selector. If there are
\r
524 * no matches, and empty Array is returned.
\r
526 jsSelect: function(path, root, type){
\r
527 // set root to doc if not specified.
\r
528 root = root || document;
\r
530 if(typeof root == "string"){
\r
531 root = document.getElementById(root);
\r
533 var paths = path.split(","),
\r
536 // loop over each selector
\r
537 for(var i = 0, len = paths.length; i < len; i++){
\r
538 var subPath = paths[i].replace(trimRe, "");
\r
539 // compile and place in cache
\r
540 if(!cache[subPath]){
\r
541 cache[subPath] = Ext.DomQuery.compile(subPath);
\r
542 if(!cache[subPath]){
\r
543 throw subPath + " is not a valid selector";
\r
546 var result = cache[subPath](root);
\r
547 if(result && result != document){
\r
548 results = results.concat(result);
\r
552 // if there were multiple selectors, make sure dups
\r
554 if(paths.length > 1){
\r
555 return nodup(results);
\r
559 isXml: function(el) {
\r
560 var docEl = (el ? el.ownerDocument || el : 0).documentElement;
\r
561 return docEl ? docEl.nodeName !== "HTML" : false;
\r
563 select : document.querySelectorAll ? function(path, root, type) {
\r
564 root = root || document;
\r
565 if (!Ext.DomQuery.isXml(root)) {
\r
567 var cs = root.querySelectorAll(path);
\r
568 return Ext.toArray(cs);
\r
572 return Ext.DomQuery.jsSelect.call(this, path, root, type);
\r
573 } : function(path, root, type) {
\r
574 return Ext.DomQuery.jsSelect.call(this, path, root, type);
\r
577 <div id="method-Ext.DomQuery-selectNode"></div>/**
\r
578 * Selects a single element.
\r
579 * @param {String} selector The selector/xpath query
\r
580 * @param {Node} root (optional) The start of the query (defaults to document).
\r
581 * @return {Element} The DOM element which matched the selector.
\r
583 selectNode : function(path, root){
\r
584 return Ext.DomQuery.select(path, root)[0];
\r
587 <div id="method-Ext.DomQuery-selectValue"></div>/**
\r
588 * Selects the value of a node, optionally replacing null with the defaultValue.
\r
589 * @param {String} selector The selector/xpath query
\r
590 * @param {Node} root (optional) The start of the query (defaults to document).
\r
591 * @param {String} defaultValue
\r
594 selectValue : function(path, root, defaultValue){
\r
595 path = path.replace(trimRe, "");
\r
596 if(!valueCache[path]){
\r
597 valueCache[path] = Ext.DomQuery.compile(path, "select");
\r
599 var n = valueCache[path](root), v;
\r
600 n = n[0] ? n[0] : n;
\r
602 // overcome a limitation of maximum textnode size
\r
603 // Rumored to potentially crash IE6 but has not been confirmed.
\r
604 // http://reference.sitepoint.com/javascript/Node/normalize
\r
605 // https://developer.mozilla.org/En/DOM/Node.normalize
\r
606 if (typeof n.normalize == 'function') n.normalize();
\r
608 v = (n && n.firstChild ? n.firstChild.nodeValue : null);
\r
609 return ((v === null||v === undefined||v==='') ? defaultValue : v);
\r
612 <div id="method-Ext.DomQuery-selectNumber"></div>/**
\r
613 * Selects the value of a node, parsing integers and floats. Returns the defaultValue, or 0 if none is specified.
\r
614 * @param {String} selector The selector/xpath query
\r
615 * @param {Node} root (optional) The start of the query (defaults to document).
\r
616 * @param {Number} defaultValue
\r
619 selectNumber : function(path, root, defaultValue){
\r
620 var v = Ext.DomQuery.selectValue(path, root, defaultValue || 0);
\r
621 return parseFloat(v);
\r
624 <div id="method-Ext.DomQuery-is"></div>/**
\r
625 * Returns true if the passed element(s) match the passed simple selector (e.g. div.some-class or span:first-child)
\r
626 * @param {String/HTMLElement/Array} el An element id, element or array of elements
\r
627 * @param {String} selector The simple selector to test
\r
628 * @return {Boolean}
\r
630 is : function(el, ss){
\r
631 if(typeof el == "string"){
\r
632 el = document.getElementById(el);
\r
634 var isArray = Ext.isArray(el),
\r
635 result = Ext.DomQuery.filter(isArray ? el : [el], ss);
\r
636 return isArray ? (result.length == el.length) : (result.length > 0);
\r
639 <div id="method-Ext.DomQuery-filter"></div>/**
\r
640 * Filters an array of elements to only include matches of a simple selector (e.g. div.some-class or span:first-child)
\r
641 * @param {Array} el An array of elements to filter
\r
642 * @param {String} selector The simple selector to test
\r
643 * @param {Boolean} nonMatches If true, it returns the elements that DON'T match
\r
644 * the selector instead of the ones that match
\r
645 * @return {Array} An Array of DOM elements which match the selector. If there are
\r
646 * no matches, and empty Array is returned.
\r
648 filter : function(els, ss, nonMatches){
\r
649 ss = ss.replace(trimRe, "");
\r
650 if(!simpleCache[ss]){
\r
651 simpleCache[ss] = Ext.DomQuery.compile(ss, "simple");
\r
653 var result = simpleCache[ss](els);
\r
654 return nonMatches ? quickDiff(result, els) : result;
\r
657 <div id="prop-Ext.DomQuery-matchers"></div>/**
\r
658 * Collection of matching regular expressions and code snippets.
\r
659 * Each capture group within () will be replace the {} in the select
\r
660 * statement as specified by their index.
\r
664 select: 'n = byClassName(n, " {1} ");'
\r
666 re: /^\:([\w-]+)(?:\(((?:[^\s>\/]*|.*?))\))?/,
\r
667 select: 'n = byPseudo(n, "{1}", "{2}");'
\r
669 re: /^(?:([\[\{])(?:@)?([\w-]+)\s?(?:(=|.=)\s?['"]?(.*?)["']?)?[\]\}])/,
\r
670 select: 'n = byAttribute(n, "{2}", "{4}", "{3}", "{1}");'
\r
673 select: 'n = byId(n, "{1}");'
\r
676 select: 'return {firstChild:{nodeValue:attrValue(n, "{1}")}};'
\r
680 <div id="method-Ext.DomQuery-operators"></div>/**
\r
681 * Collection of operator comparison functions. The default operators are =, !=, ^=, $=, *=, %=, |= and ~=.
\r
682 * New operators can be added as long as the match the format <i>c</i>= where <i>c</i> is any character other than space, > <.
\r
685 "=" : function(a, v){
\r
688 "!=" : function(a, v){
\r
691 "^=" : function(a, v){
\r
692 return a && a.substr(0, v.length) == v;
\r
694 "$=" : function(a, v){
\r
695 return a && a.substr(a.length-v.length) == v;
\r
697 "*=" : function(a, v){
\r
698 return a && a.indexOf(v) !== -1;
\r
700 "%=" : function(a, v){
\r
701 return (a % v) == 0;
\r
703 "|=" : function(a, v){
\r
704 return a && (a == v || a.substr(0, v.length+1) == v+'-');
\r
706 "~=" : function(a, v){
\r
707 return a && (' '+a+' ').indexOf(' '+v+' ') != -1;
\r
711 <div id="prop-Ext.DomQuery-pseudos"></div>/**
\r
712 * <p>Object hash of "pseudo class" filter functions which are used when filtering selections. Each function is passed
\r
713 * two parameters:</p><div class="mdetail-params"><ul>
\r
714 * <li><b>c</b> : Array<div class="sub-desc">An Array of DOM elements to filter.</div></li>
\r
715 * <li><b>v</b> : String<div class="sub-desc">The argument (if any) supplied in the selector.</div></li>
\r
717 * <p>A filter function returns an Array of DOM elements which conform to the pseudo class.</p>
\r
718 * <p>In addition to the provided pseudo classes listed above such as <code>first-child</code> and <code>nth-child</code>,
\r
719 * developers may add additional, custom psuedo class filters to select elements according to application-specific requirements.</p>
\r
720 * <p>For example, to filter <code><a></code> elements to only return links to <i>external</i> resources:</p>
\r
722 Ext.DomQuery.pseudos.external = function(c, v){
\r
723 var r = [], ri = -1;
\r
724 for(var i = 0, ci; ci = c[i]; i++){
\r
725 // Include in result set only if it's a link to an external resource
\r
726 if(ci.hostname != location.hostname){
\r
732 * Then external links could be gathered with the following statement:<code><pre>
\r
733 var externalLinks = Ext.select("a:external");
\r
737 "first-child" : function(c){
\r
738 var r = [], ri = -1, n;
\r
739 for(var i = 0, ci; ci = n = c[i]; i++){
\r
740 while((n = n.previousSibling) && n.nodeType != 1);
\r
748 "last-child" : function(c){
\r
749 var r = [], ri = -1, n;
\r
750 for(var i = 0, ci; ci = n = c[i]; i++){
\r
751 while((n = n.nextSibling) && n.nodeType != 1);
\r
759 "nth-child" : function(c, a) {
\r
760 var r = [], ri = -1,
\r
761 m = nthRe.exec(a == "even" && "2n" || a == "odd" && "2n+1" || !nthRe2.test(a) && "n+" + a || a),
\r
762 f = (m[1] || 1) - 0, l = m[2] - 0;
\r
763 for(var i = 0, n; n = c[i]; i++){
\r
764 var pn = n.parentNode;
\r
765 if (batch != pn._batch) {
\r
767 for(var cn = pn.firstChild; cn; cn = cn.nextSibling){
\r
768 if(cn.nodeType == 1){
\r
769 cn.nodeIndex = ++j;
\r
775 if (l == 0 || n.nodeIndex == l){
\r
778 } else if ((n.nodeIndex + l) % f == 0){
\r
786 "only-child" : function(c){
\r
787 var r = [], ri = -1;;
\r
788 for(var i = 0, ci; ci = c[i]; i++){
\r
789 if(!prev(ci) && !next(ci)){
\r
796 "empty" : function(c){
\r
797 var r = [], ri = -1;
\r
798 for(var i = 0, ci; ci = c[i]; i++){
\r
799 var cns = ci.childNodes, j = 0, cn, empty = true;
\r
800 while(cn = cns[j]){
\r
802 if(cn.nodeType == 1 || cn.nodeType == 3){
\r
814 "contains" : function(c, v){
\r
815 var r = [], ri = -1;
\r
816 for(var i = 0, ci; ci = c[i]; i++){
\r
817 if((ci.textContent||ci.innerText||'').indexOf(v) != -1){
\r
824 "nodeValue" : function(c, v){
\r
825 var r = [], ri = -1;
\r
826 for(var i = 0, ci; ci = c[i]; i++){
\r
827 if(ci.firstChild && ci.firstChild.nodeValue == v){
\r
834 "checked" : function(c){
\r
835 var r = [], ri = -1;
\r
836 for(var i = 0, ci; ci = c[i]; i++){
\r
837 if(ci.checked == true){
\r
844 "not" : function(c, ss){
\r
845 return Ext.DomQuery.filter(c, ss, true);
\r
848 "any" : function(c, selectors){
\r
849 var ss = selectors.split('|'),
\r
850 r = [], ri = -1, s;
\r
851 for(var i = 0, ci; ci = c[i]; i++){
\r
852 for(var j = 0; s = ss[j]; j++){
\r
853 if(Ext.DomQuery.is(ci, s)){
\r
862 "odd" : function(c){
\r
863 return this["nth-child"](c, "odd");
\r
866 "even" : function(c){
\r
867 return this["nth-child"](c, "even");
\r
870 "nth" : function(c, a){
\r
871 return c[a-1] || [];
\r
874 "first" : function(c){
\r
878 "last" : function(c){
\r
879 return c[c.length-1] || [];
\r
882 "has" : function(c, ss){
\r
883 var s = Ext.DomQuery.select,
\r
885 for(var i = 0, ci; ci = c[i]; i++){
\r
886 if(s(ss, ci).length > 0){
\r
893 "next" : function(c, ss){
\r
894 var is = Ext.DomQuery.is,
\r
896 for(var i = 0, ci; ci = c[i]; i++){
\r
898 if(n && is(n, ss)){
\r
905 "prev" : function(c, ss){
\r
906 var is = Ext.DomQuery.is,
\r
908 for(var i = 0, ci; ci = c[i]; i++){
\r
910 if(n && is(n, ss)){
\r
920 <div id="method-Ext-query"></div>/**
\r
921 * Selects an array of DOM nodes by CSS/XPath selector. Shorthand of {@link Ext.DomQuery#select}
\r
922 * @param {String} path The selector/xpath query
\r
923 * @param {Node} root (optional) The start of the query (defaults to document).
\r
928 Ext.query = Ext.DomQuery.select;
\r