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