Upgrade to ExtJS 3.0.0 - Released 07/06/2009
[extjs.git] / docs / source / DomQuery.html
1 <html>\r
2 <head>\r
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
6 </head>\r
7 <body  onload="prettyPrint();">\r
8     <pre class="prettyprint lang-js">/*\r
9  * This is code is also distributed under MIT license for use\r
10  * with jQuery and prototype JavaScript libraries.\r
11  */\r
12 <div id="cls-Ext.DomQuery"></div>/**\r
13  * @class Ext.DomQuery\r
14 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
15 <p>\r
16 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
17 \r
18 <p>\r
19 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
20 </p>\r
21 <h4>Element Selectors:</h4>\r
22 <ul class="list">\r
23     <li> <b>*</b> any element</li>\r
24     <li> <b>E</b> an element with the tag E</li>\r
25     <li> <b>E F</b> All descendent elements of E that have the tag F</li>\r
26     <li> <b>E > F</b> or <b>E/F</b> all direct children elements of E that have the tag F</li>\r
27     <li> <b>E + F</b> all elements with the tag F that are immediately preceded by an element with the tag E</li>\r
28     <li> <b>E ~ F</b> all elements with the tag F that are preceded by a sibling element with the tag E</li>\r
29 </ul>\r
30 <h4>Attribute Selectors:</h4>\r
31 <p>The use of &#64; and quotes are optional. For example, div[&#64;foo='bar'] is also a valid attribute selector.</p>\r
32 <ul class="list">\r
33     <li> <b>E[foo]</b> has an attribute "foo"</li>\r
34     <li> <b>E[foo=bar]</b> has an attribute "foo" that equals "bar"</li>\r
35     <li> <b>E[foo^=bar]</b> has an attribute "foo" that starts with "bar"</li>\r
36     <li> <b>E[foo$=bar]</b> has an attribute "foo" that ends with "bar"</li>\r
37     <li> <b>E[foo*=bar]</b> has an attribute "foo" that contains the substring "bar"</li>\r
38     <li> <b>E[foo%=2]</b> has an attribute "foo" that is evenly divisible by 2</li>\r
39     <li> <b>E[foo!=bar]</b> has an attribute "foo" that does not equal "bar"</li>\r
40 </ul>\r
41 <h4>Pseudo Classes:</h4>\r
42 <ul class="list">\r
43     <li> <b>E:first-child</b> E is the first child of its parent</li>\r
44     <li> <b>E:last-child</b> E is the last child of its parent</li>\r
45     <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
46     <li> <b>E:nth-child(odd)</b> E is an odd child of its parent</li>\r
47     <li> <b>E:nth-child(even)</b> E is an even child of its parent</li>\r
48     <li> <b>E:only-child</b> E is the only child of its parent</li>\r
49     <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
50     <li> <b>E:first</b> the first E in the resultset</li>\r
51     <li> <b>E:last</b> the last E in the resultset</li>\r
52     <li> <b>E:nth(<i>n</i>)</b> the <i>n</i>th E in the resultset (1 based)</li>\r
53     <li> <b>E:odd</b> shortcut for :nth-child(odd)</li>\r
54     <li> <b>E:even</b> shortcut for :nth-child(even)</li>\r
55     <li> <b>E:contains(foo)</b> E's innerHTML contains the substring "foo"</li>\r
56     <li> <b>E:nodeValue(foo)</b> E contains a textNode with a nodeValue that equals "foo"</li>\r
57     <li> <b>E:not(S)</b> an E element that does not match simple selector S</li>\r
58     <li> <b>E:has(S)</b> an E element that has a descendent that matches simple selector S</li>\r
59     <li> <b>E:next(S)</b> an E element whose next sibling matches simple selector S</li>\r
60     <li> <b>E:prev(S)</b> an E element whose previous sibling matches simple selector S</li>\r
61 </ul>\r
62 <h4>CSS Value Selectors:</h4>\r
63 <ul class="list">\r
64     <li> <b>E{display=none}</b> css value "display" that equals "none"</li>\r
65     <li> <b>E{display^=none}</b> css value "display" that starts with "none"</li>\r
66     <li> <b>E{display$=none}</b> css value "display" that ends with "none"</li>\r
67     <li> <b>E{display*=none}</b> css value "display" that contains the substring "none"</li>\r
68     <li> <b>E{display%=2}</b> css value "display" that is evenly divisible by 2</li>\r
69     <li> <b>E{display!=none}</b> css value "display" that does not equal "none"</li>\r
70 </ul>\r
71  * @singleton\r
72  */\r
73 Ext.DomQuery = function(){\r
74     var cache = {}, \r
75         simpleCache = {}, \r
76         valueCache = {},\r
77         nonSpace = /\S/,\r
78         trimRe = /^\s+|\s+$/g,\r
79         tplRe = /\{(\d+)\}/g,\r
80         modeRe = /^(\s?[\/>+~]\s?|\s|$)/,\r
81         tagTokenRe = /^(#)?([\w-\*]+)/,\r
82         nthRe = /(\d*)n\+?(\d*)/, \r
83         nthRe2 = /\D/,\r
84         // This is for IE MSXML which does not support expandos.\r
85             // IE runs the same speed using setAttribute, however FF slows way down\r
86             // and Safari completely fails so they need to continue to use expandos.\r
87             isIE = window.ActiveXObject ? true : false,\r
88         isOpera = Ext.isOpera,\r
89             key = 30803;\r
90             \r
91     // this eval is stop the compressor from\r
92         // renaming the variable to something shorter\r
93         eval("var batch = 30803;");     \r
94 \r
95     function child(p, index){\r
96         var i = 0,\r
97                 n = p.firstChild;\r
98         while(n){\r
99             if(n.nodeType == 1){\r
100                if(++i == index){\r
101                    return n;\r
102                }\r
103             }\r
104             n = n.nextSibling;\r
105         }\r
106         return null;\r
107     };\r
108 \r
109     function next(n){\r
110         while((n = n.nextSibling) && n.nodeType != 1);\r
111         return n;\r
112     };\r
113 \r
114     function prev(n){\r
115         while((n = n.previousSibling) && n.nodeType != 1);\r
116         return n;\r
117     };\r
118 \r
119     function children(d){\r
120         var n = d.firstChild, ni = -1,\r
121                 nx;\r
122             while(n){\r
123                 nx = n.nextSibling;\r
124                 if(n.nodeType == 3 && !nonSpace.test(n.nodeValue)){\r
125                     d.removeChild(n);\r
126                 }else{\r
127                     n.nodeIndex = ++ni;\r
128                 }\r
129                 n = nx;\r
130             }\r
131             return this;\r
132         };\r
133 \r
134     function byClassName(c, a, v){\r
135         if(!v){\r
136             return c;\r
137         }\r
138         var r = [], ri = -1, cn;\r
139         for(var i = 0, ci; ci = c[i]; i++){\r
140             if((' '+ci.className+' ').indexOf(v) != -1){\r
141                 r[++ri] = ci;\r
142             }\r
143         }\r
144         return r;\r
145     };\r
146 \r
147     function attrValue(n, attr){\r
148         if(!n.tagName && typeof n.length != "undefined"){\r
149             n = n[0];\r
150         }\r
151         if(!n){\r
152             return null;\r
153         }\r
154         if(attr == "for"){\r
155             return n.htmlFor;\r
156         }\r
157         if(attr == "class" || attr == "className"){\r
158             return n.className;\r
159         }\r
160         return n.getAttribute(attr) || n[attr];\r
161 \r
162     };\r
163 \r
164     function getNodes(ns, mode, tagName){\r
165         var result = [], ri = -1, cs;\r
166         if(!ns){\r
167             return result;\r
168         }\r
169         tagName = tagName || "*";\r
170         if(typeof ns.getElementsByTagName != "undefined"){\r
171             ns = [ns];\r
172         }\r
173         if(!mode){\r
174             for(var i = 0, ni; ni = ns[i]; i++){\r
175                 cs = ni.getElementsByTagName(tagName);\r
176                 for(var j = 0, ci; ci = cs[j]; j++){\r
177                     result[++ri] = ci;\r
178                 }\r
179             }\r
180         }else if(mode == "/" || mode == ">"){\r
181             var utag = tagName.toUpperCase();\r
182             for(var i = 0, ni, cn; ni = ns[i]; i++){\r
183                 cn = isOpera ? ni.childNodes : (ni.children || ni.childNodes);\r
184                 for(var j = 0, cj; cj = cn[j]; j++){\r
185                     if(cj.nodeName == utag || cj.nodeName == tagName  || tagName == '*'){\r
186                         result[++ri] = cj;\r
187                     }\r
188                 }\r
189             }\r
190         }else if(mode == "+"){\r
191             var utag = tagName.toUpperCase();\r
192             for(var i = 0, n; n = ns[i]; i++){\r
193                 while((n = n.nextSibling) && n.nodeType != 1);\r
194                 if(n && (n.nodeName == utag || n.nodeName == tagName || tagName == '*')){\r
195                     result[++ri] = n;\r
196                 }\r
197             }\r
198         }else if(mode == "~"){\r
199             var utag = tagName.toUpperCase();\r
200             for(var i = 0, n; n = ns[i]; i++){\r
201                 while((n = n.nextSibling)){\r
202                     if (n.nodeName == utag || n.nodeName == tagName || tagName == '*'){\r
203                         result[++ri] = n;\r
204                     }\r
205                 }\r
206             }\r
207         }\r
208         return result;\r
209     };\r
210 \r
211     function concat(a, b){\r
212         if(b.slice){\r
213             return a.concat(b);\r
214         }\r
215         for(var i = 0, l = b.length; i < l; i++){\r
216             a[a.length] = b[i];\r
217         }\r
218         return a;\r
219     }\r
220 \r
221     function byTag(cs, tagName){\r
222         if(cs.tagName || cs == document){\r
223             cs = [cs];\r
224         }\r
225         if(!tagName){\r
226             return cs;\r
227         }\r
228         var r = [], ri = -1;\r
229         tagName = tagName.toLowerCase();\r
230         for(var i = 0, ci; ci = cs[i]; i++){\r
231             if(ci.nodeType == 1 && ci.tagName.toLowerCase()==tagName){\r
232                 r[++ri] = ci;\r
233             }\r
234         }\r
235         return r;\r
236     };\r
237 \r
238     function byId(cs, attr, id){\r
239         if(cs.tagName || cs == document){\r
240             cs = [cs];\r
241         }\r
242         if(!id){\r
243             return cs;\r
244         }\r
245         var r = [], ri = -1;\r
246         for(var i = 0,ci; ci = cs[i]; i++){\r
247             if(ci && ci.id == id){\r
248                 r[++ri] = ci;\r
249                 return r;\r
250             }\r
251         }\r
252         return r;\r
253     };\r
254 \r
255     function byAttribute(cs, attr, value, op, custom){\r
256         var r = [], \r
257                 ri = -1, \r
258                 st = custom=="{",\r
259                 f = Ext.DomQuery.operators[op];\r
260         for(var i = 0, ci; ci = cs[i]; i++){\r
261             if(ci.nodeType != 1){\r
262                 continue;\r
263             }\r
264             var a;\r
265             if(st){\r
266                 a = Ext.DomQuery.getStyle(ci, attr);\r
267             }\r
268             else if(attr == "class" || attr == "className"){\r
269                 a = ci.className;\r
270             }else if(attr == "for"){\r
271                 a = ci.htmlFor;\r
272             }else if(attr == "href"){\r
273                 a = ci.getAttribute("href", 2);\r
274             }else{\r
275                 a = ci.getAttribute(attr);\r
276             }\r
277             if((f && f(a, value)) || (!f && a)){\r
278                 r[++ri] = ci;\r
279             }\r
280         }\r
281         return r;\r
282     };\r
283 \r
284     function byPseudo(cs, name, value){\r
285         return Ext.DomQuery.pseudos[name](cs, value);\r
286     };\r
287 \r
288     function nodupIEXml(cs){\r
289         var d = ++key, \r
290                 r;\r
291         cs[0].setAttribute("_nodup", d);\r
292         r = [cs[0]];\r
293         for(var i = 1, len = cs.length; i < len; i++){\r
294             var c = cs[i];\r
295             if(!c.getAttribute("_nodup") != d){\r
296                 c.setAttribute("_nodup", d);\r
297                 r[r.length] = c;\r
298             }\r
299         }\r
300         for(var i = 0, len = cs.length; i < len; i++){\r
301             cs[i].removeAttribute("_nodup");\r
302         }\r
303         return r;\r
304     }\r
305 \r
306     function nodup(cs){\r
307         if(!cs){\r
308             return [];\r
309         }\r
310         var len = cs.length, c, i, r = cs, cj, ri = -1;\r
311         if(!len || typeof cs.nodeType != "undefined" || len == 1){\r
312             return cs;\r
313         }\r
314         if(isIE && typeof cs[0].selectSingleNode != "undefined"){\r
315             return nodupIEXml(cs);\r
316         }\r
317         var d = ++key;\r
318         cs[0]._nodup = d;\r
319         for(i = 1; c = cs[i]; i++){\r
320             if(c._nodup != d){\r
321                 c._nodup = d;\r
322             }else{\r
323                 r = [];\r
324                 for(var j = 0; j < i; j++){\r
325                     r[++ri] = cs[j];\r
326                 }\r
327                 for(j = i+1; cj = cs[j]; j++){\r
328                     if(cj._nodup != d){\r
329                         cj._nodup = d;\r
330                         r[++ri] = cj;\r
331                     }\r
332                 }\r
333                 return r;\r
334             }\r
335         }\r
336         return r;\r
337     }\r
338 \r
339     function quickDiffIEXml(c1, c2){\r
340         var d = ++key,\r
341                 r = [];\r
342         for(var i = 0, len = c1.length; i < len; i++){\r
343             c1[i].setAttribute("_qdiff", d);\r
344         }        \r
345         for(var i = 0, len = c2.length; i < len; i++){\r
346             if(c2[i].getAttribute("_qdiff") != d){\r
347                 r[r.length] = c2[i];\r
348             }\r
349         }\r
350         for(var i = 0, len = c1.length; i < len; i++){\r
351            c1[i].removeAttribute("_qdiff");\r
352         }\r
353         return r;\r
354     }\r
355 \r
356     function quickDiff(c1, c2){\r
357         var len1 = c1.length,\r
358                 d = ++key,\r
359                 r = [];\r
360         if(!len1){\r
361             return c2;\r
362         }\r
363         if(isIE && c1[0].selectSingleNode){\r
364             return quickDiffIEXml(c1, c2);\r
365         }        \r
366         for(var i = 0; i < len1; i++){\r
367             c1[i]._qdiff = d;\r
368         }        \r
369         for(var i = 0, len = c2.length; i < len; i++){\r
370             if(c2[i]._qdiff != d){\r
371                 r[r.length] = c2[i];\r
372             }\r
373         }\r
374         return r;\r
375     }\r
376 \r
377     function quickId(ns, mode, root, id){\r
378         if(ns == root){\r
379            var d = root.ownerDocument || root;\r
380            return d.getElementById(id);\r
381         }\r
382         ns = getNodes(ns, mode, "*");\r
383         return byId(ns, null, id);\r
384     }\r
385 \r
386     return {\r
387         getStyle : function(el, name){\r
388             return Ext.fly(el).getStyle(name);\r
389         },\r
390         <div id="method-Ext.DomQuery-compile"></div>/**\r
391          * Compiles a selector/xpath query into a reusable function. The returned function\r
392          * takes one parameter "root" (optional), which is the context node from where the query should start.\r
393          * @param {String} selector The selector/xpath query\r
394          * @param {String} type (optional) Either "select" (the default) or "simple" for a simple selector match\r
395          * @return {Function}\r
396          */\r
397         compile : function(path, type){\r
398             type = type || "select";\r
399 \r
400             var fn = ["var f = function(root){\n var mode; ++batch; var n = root || document;\n"],\r
401                 q = path, mode, lq,\r
402                 tk = Ext.DomQuery.matchers,\r
403                 tklen = tk.length,\r
404                 mm,\r
405                 // accept leading mode switch\r
406                 lmode = q.match(modeRe);\r
407             \r
408             if(lmode && lmode[1]){\r
409                 fn[fn.length] = 'mode="'+lmode[1].replace(trimRe, "")+'";';\r
410                 q = q.replace(lmode[1], "");\r
411             }\r
412             // strip leading slashes\r
413             while(path.substr(0, 1)=="/"){\r
414                 path = path.substr(1);\r
415             }\r
416 \r
417             while(q && lq != q){\r
418                 lq = q;\r
419                 var tm = q.match(tagTokenRe);\r
420                 if(type == "select"){\r
421                     if(tm){\r
422                         if(tm[1] == "#"){\r
423                             fn[fn.length] = 'n = quickId(n, mode, root, "'+tm[2]+'");';\r
424                         }else{\r
425                             fn[fn.length] = 'n = getNodes(n, mode, "'+tm[2]+'");';\r
426                         }\r
427                         q = q.replace(tm[0], "");\r
428                     }else if(q.substr(0, 1) != '@'){\r
429                         fn[fn.length] = 'n = getNodes(n, mode, "*");';\r
430                     }\r
431                 }else{\r
432                     if(tm){\r
433                         if(tm[1] == "#"){\r
434                             fn[fn.length] = 'n = byId(n, null, "'+tm[2]+'");';\r
435                         }else{\r
436                             fn[fn.length] = 'n = byTag(n, "'+tm[2]+'");';\r
437                         }\r
438                         q = q.replace(tm[0], "");\r
439                     }\r
440                 }\r
441                 while(!(mm = q.match(modeRe))){\r
442                     var matched = false;\r
443                     for(var j = 0; j < tklen; j++){\r
444                         var t = tk[j];\r
445                         var m = q.match(t.re);\r
446                         if(m){\r
447                             fn[fn.length] = t.select.replace(tplRe, function(x, i){\r
448                                                     return m[i];\r
449                                                 });\r
450                             q = q.replace(m[0], "");\r
451                             matched = true;\r
452                             break;\r
453                         }\r
454                     }\r
455                     // prevent infinite loop on bad selector\r
456                     if(!matched){\r
457                         throw 'Error parsing selector, parsing failed at "' + q + '"';\r
458                     }\r
459                 }\r
460                 if(mm[1]){\r
461                     fn[fn.length] = 'mode="'+mm[1].replace(trimRe, "")+'";';\r
462                     q = q.replace(mm[1], "");\r
463                 }\r
464             }\r
465             fn[fn.length] = "return nodup(n);\n}";\r
466             eval(fn.join(""));\r
467             return f;\r
468         },\r
469 \r
470         <div id="method-Ext.DomQuery-select"></div>/**\r
471          * Selects a group of elements.\r
472          * @param {String} selector The selector/xpath query (can be a comma separated list of selectors)\r
473          * @param {Node} root (optional) The start of the query (defaults to document).\r
474          * @return {Array} An Array of DOM elements which match the selector. If there are\r
475          * no matches, and empty Array is returned.\r
476          */\r
477         select : function(path, root, type){\r
478             if(!root || root == document){\r
479                 root = document;\r
480             }\r
481             if(typeof root == "string"){\r
482                 root = document.getElementById(root);\r
483             }\r
484             var paths = path.split(","),\r
485                 results = [];\r
486             for(var i = 0, len = paths.length; i < len; i++){\r
487                 var p = paths[i].replace(trimRe, "");\r
488                 if(!cache[p]){\r
489                     cache[p] = Ext.DomQuery.compile(p);\r
490                     if(!cache[p]){\r
491                         throw p + " is not a valid selector";\r
492                     }\r
493                 }\r
494                 var result = cache[p](root);\r
495                 if(result && result != document){\r
496                     results = results.concat(result);\r
497                 }\r
498             }\r
499             if(paths.length > 1){\r
500                 return nodup(results);\r
501             }\r
502             return results;\r
503         },\r
504 \r
505         <div id="method-Ext.DomQuery-selectNode"></div>/**\r
506          * Selects a single element.\r
507          * @param {String} selector The selector/xpath query\r
508          * @param {Node} root (optional) The start of the query (defaults to document).\r
509          * @return {Element} The DOM element which matched the selector.\r
510          */\r
511         selectNode : function(path, root){\r
512             return Ext.DomQuery.select(path, root)[0];\r
513         },\r
514 \r
515         <div id="method-Ext.DomQuery-selectValue"></div>/**\r
516          * Selects the value of a node, optionally replacing null with the defaultValue.\r
517          * @param {String} selector The selector/xpath query\r
518          * @param {Node} root (optional) The start of the query (defaults to document).\r
519          * @param {String} defaultValue\r
520          * @return {String}\r
521          */\r
522         selectValue : function(path, root, defaultValue){\r
523             path = path.replace(trimRe, "");\r
524             if(!valueCache[path]){\r
525                 valueCache[path] = Ext.DomQuery.compile(path, "select");\r
526             }\r
527             var n = valueCache[path](root),\r
528                 v;\r
529             n = n[0] ? n[0] : n;\r
530             v = (n && n.firstChild ? n.firstChild.nodeValue : null);\r
531             return ((v === null||v === undefined||v==='') ? defaultValue : v);\r
532         },\r
533 \r
534         <div id="method-Ext.DomQuery-selectNumber"></div>/**\r
535          * Selects the value of a node, parsing integers and floats. Returns the defaultValue, or 0 if none is specified.\r
536          * @param {String} selector The selector/xpath query\r
537          * @param {Node} root (optional) The start of the query (defaults to document).\r
538          * @param {Number} defaultValue\r
539          * @return {Number}\r
540          */\r
541         selectNumber : function(path, root, defaultValue){\r
542             var v = Ext.DomQuery.selectValue(path, root, defaultValue || 0);\r
543             return parseFloat(v);\r
544         },\r
545 \r
546         <div id="method-Ext.DomQuery-is"></div>/**\r
547          * Returns true if the passed element(s) match the passed simple selector (e.g. div.some-class or span:first-child)\r
548          * @param {String/HTMLElement/Array} el An element id, element or array of elements\r
549          * @param {String} selector The simple selector to test\r
550          * @return {Boolean}\r
551          */\r
552         is : function(el, ss){\r
553             if(typeof el == "string"){\r
554                 el = document.getElementById(el);\r
555             }\r
556             var isArray = Ext.isArray(el),\r
557                 result = Ext.DomQuery.filter(isArray ? el : [el], ss);\r
558             return isArray ? (result.length == el.length) : (result.length > 0);\r
559         },\r
560 \r
561         <div id="method-Ext.DomQuery-filter"></div>/**\r
562          * Filters an array of elements to only include matches of a simple selector (e.g. div.some-class or span:first-child)\r
563          * @param {Array} el An array of elements to filter\r
564          * @param {String} selector The simple selector to test\r
565          * @param {Boolean} nonMatches If true, it returns the elements that DON'T match\r
566          * the selector instead of the ones that match\r
567          * @return {Array} An Array of DOM elements which match the selector. If there are\r
568          * no matches, and empty Array is returned.\r
569          */\r
570         filter : function(els, ss, nonMatches){\r
571             ss = ss.replace(trimRe, "");\r
572             if(!simpleCache[ss]){\r
573                 simpleCache[ss] = Ext.DomQuery.compile(ss, "simple");\r
574             }\r
575             var result = simpleCache[ss](els);\r
576             return nonMatches ? quickDiff(result, els) : result;\r
577         },\r
578 \r
579         <div id="prop-Ext.DomQuery-matchers"></div>/**\r
580          * Collection of matching regular expressions and code snippets.\r
581          */\r
582         matchers : [{\r
583                 re: /^\.([\w-]+)/,\r
584                 select: 'n = byClassName(n, null, " {1} ");'\r
585             }, {\r
586                 re: /^\:([\w-]+)(?:\(((?:[^\s>\/]*|.*?))\))?/,\r
587                 select: 'n = byPseudo(n, "{1}", "{2}");'\r
588             },{\r
589                 re: /^(?:([\[\{])(?:@)?([\w-]+)\s?(?:(=|.=)\s?['"]?(.*?)["']?)?[\]\}])/,\r
590                 select: 'n = byAttribute(n, "{2}", "{4}", "{3}", "{1}");'\r
591             }, {\r
592                 re: /^#([\w-]+)/,\r
593                 select: 'n = byId(n, null, "{1}");'\r
594             },{\r
595                 re: /^@([\w-]+)/,\r
596                 select: 'return {firstChild:{nodeValue:attrValue(n, "{1}")}};'\r
597             }\r
598         ],\r
599 \r
600         <div id="method-Ext.DomQuery-operators"></div>/**\r
601          * Collection of operator comparison functions. The default operators are =, !=, ^=, $=, *=, %=, |= and ~=.\r
602          * 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, &gt; &lt;.\r
603          */\r
604         operators : {\r
605             "=" : function(a, v){\r
606                 return a == v;\r
607             },\r
608             "!=" : function(a, v){\r
609                 return a != v;\r
610             },\r
611             "^=" : function(a, v){\r
612                 return a && a.substr(0, v.length) == v;\r
613             },\r
614             "$=" : function(a, v){\r
615                 return a && a.substr(a.length-v.length) == v;\r
616             },\r
617             "*=" : function(a, v){\r
618                 return a && a.indexOf(v) !== -1;\r
619             },\r
620             "%=" : function(a, v){\r
621                 return (a % v) == 0;\r
622             },\r
623             "|=" : function(a, v){\r
624                 return a && (a == v || a.substr(0, v.length+1) == v+'-');\r
625             },\r
626             "~=" : function(a, v){\r
627                 return a && (' '+a+' ').indexOf(' '+v+' ') != -1;\r
628             }\r
629         },\r
630 \r
631         <div id="prop-Ext.DomQuery-pseudos"></div>/**\r
632          * Collection of "pseudo class" processors. Each processor is passed the current nodeset (array)\r
633          * and the argument (if any) supplied in the selector.\r
634          */\r
635         pseudos : {\r
636             "first-child" : function(c){\r
637                 var r = [], ri = -1, n;\r
638                 for(var i = 0, ci; ci = n = c[i]; i++){\r
639                     while((n = n.previousSibling) && n.nodeType != 1);\r
640                     if(!n){\r
641                         r[++ri] = ci;\r
642                     }\r
643                 }\r
644                 return r;\r
645             },\r
646 \r
647             "last-child" : function(c){\r
648                 var r = [], ri = -1, n;\r
649                 for(var i = 0, ci; ci = n = c[i]; i++){\r
650                     while((n = n.nextSibling) && n.nodeType != 1);\r
651                     if(!n){\r
652                         r[++ri] = ci;\r
653                     }\r
654                 }\r
655                 return r;\r
656             },\r
657 \r
658             "nth-child" : function(c, a) {\r
659                 var r = [], ri = -1,\r
660                         m = nthRe.exec(a == "even" && "2n" || a == "odd" && "2n+1" || !nthRe2.test(a) && "n+" + a || a),\r
661                         f = (m[1] || 1) - 0, l = m[2] - 0;\r
662                 for(var i = 0, n; n = c[i]; i++){\r
663                     var pn = n.parentNode;\r
664                     if (batch != pn._batch) {\r
665                         var j = 0;\r
666                         for(var cn = pn.firstChild; cn; cn = cn.nextSibling){\r
667                             if(cn.nodeType == 1){\r
668                                cn.nodeIndex = ++j;\r
669                             }\r
670                         }\r
671                         pn._batch = batch;\r
672                     }\r
673                     if (f == 1) {\r
674                         if (l == 0 || n.nodeIndex == l){\r
675                             r[++ri] = n;\r
676                         }\r
677                     } else if ((n.nodeIndex + l) % f == 0){\r
678                         r[++ri] = n;\r
679                     }\r
680                 }\r
681 \r
682                 return r;\r
683             },\r
684 \r
685             "only-child" : function(c){\r
686                 var r = [], ri = -1;;\r
687                 for(var i = 0, ci; ci = c[i]; i++){\r
688                     if(!prev(ci) && !next(ci)){\r
689                         r[++ri] = ci;\r
690                     }\r
691                 }\r
692                 return r;\r
693             },\r
694 \r
695             "empty" : function(c){\r
696                 var r = [], ri = -1;\r
697                 for(var i = 0, ci; ci = c[i]; i++){\r
698                     var cns = ci.childNodes, j = 0, cn, empty = true;\r
699                     while(cn = cns[j]){\r
700                         ++j;\r
701                         if(cn.nodeType == 1 || cn.nodeType == 3){\r
702                             empty = false;\r
703                             break;\r
704                         }\r
705                     }\r
706                     if(empty){\r
707                         r[++ri] = ci;\r
708                     }\r
709                 }\r
710                 return r;\r
711             },\r
712 \r
713             "contains" : function(c, v){\r
714                 var r = [], ri = -1;\r
715                 for(var i = 0, ci; ci = c[i]; i++){\r
716                     if((ci.textContent||ci.innerText||'').indexOf(v) != -1){\r
717                         r[++ri] = ci;\r
718                     }\r
719                 }\r
720                 return r;\r
721             },\r
722 \r
723             "nodeValue" : function(c, v){\r
724                 var r = [], ri = -1;\r
725                 for(var i = 0, ci; ci = c[i]; i++){\r
726                     if(ci.firstChild && ci.firstChild.nodeValue == v){\r
727                         r[++ri] = ci;\r
728                     }\r
729                 }\r
730                 return r;\r
731             },\r
732 \r
733             "checked" : function(c){\r
734                 var r = [], ri = -1;\r
735                 for(var i = 0, ci; ci = c[i]; i++){\r
736                     if(ci.checked == true){\r
737                         r[++ri] = ci;\r
738                     }\r
739                 }\r
740                 return r;\r
741             },\r
742 \r
743             "not" : function(c, ss){\r
744                 return Ext.DomQuery.filter(c, ss, true);\r
745             },\r
746 \r
747             "any" : function(c, selectors){\r
748                 var ss = selectors.split('|'),\r
749                         r = [], ri = -1, s;\r
750                 for(var i = 0, ci; ci = c[i]; i++){\r
751                     for(var j = 0; s = ss[j]; j++){\r
752                         if(Ext.DomQuery.is(ci, s)){\r
753                             r[++ri] = ci;\r
754                             break;\r
755                         }\r
756                     }\r
757                 }\r
758                 return r;\r
759             },\r
760 \r
761             "odd" : function(c){\r
762                 return this["nth-child"](c, "odd");\r
763             },\r
764 \r
765             "even" : function(c){\r
766                 return this["nth-child"](c, "even");\r
767             },\r
768 \r
769             "nth" : function(c, a){\r
770                 return c[a-1] || [];\r
771             },\r
772 \r
773             "first" : function(c){\r
774                 return c[0] || [];\r
775             },\r
776 \r
777             "last" : function(c){\r
778                 return c[c.length-1] || [];\r
779             },\r
780 \r
781             "has" : function(c, ss){\r
782                 var s = Ext.DomQuery.select,\r
783                         r = [], ri = -1;\r
784                 for(var i = 0, ci; ci = c[i]; i++){\r
785                     if(s(ss, ci).length > 0){\r
786                         r[++ri] = ci;\r
787                     }\r
788                 }\r
789                 return r;\r
790             },\r
791 \r
792             "next" : function(c, ss){\r
793                 var is = Ext.DomQuery.is,\r
794                         r = [], ri = -1;\r
795                 for(var i = 0, ci; ci = c[i]; i++){\r
796                     var n = next(ci);\r
797                     if(n && is(n, ss)){\r
798                         r[++ri] = ci;\r
799                     }\r
800                 }\r
801                 return r;\r
802             },\r
803 \r
804             "prev" : function(c, ss){\r
805                 var is = Ext.DomQuery.is,\r
806                         r = [], ri = -1;\r
807                 for(var i = 0, ci; ci = c[i]; i++){\r
808                     var n = prev(ci);\r
809                     if(n && is(n, ss)){\r
810                         r[++ri] = ci;\r
811                     }\r
812                 }\r
813                 return r;\r
814             }\r
815         }\r
816     };\r
817 }();\r
818 \r
819 <div id="method-Ext-query"></div>/**\r
820  * Selects an array of DOM nodes by CSS/XPath selector. Shorthand of {@link Ext.DomQuery#select}\r
821  * @param {String} path The selector/xpath query\r
822  * @param {Node} root (optional) The start of the query (defaults to document).\r
823  * @return {Array}\r
824  * @member Ext\r
825  * @method query\r
826  */\r
827 Ext.query = Ext.DomQuery.select;\r
828 </pre>    \r
829 </body>\r
830 </html>