Upgrade to ExtJS 3.1.0 - Released 12/16/2009
[extjs.git] / docs / source / DomQuery.html
1 <html>\r
2 <head>\r
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
7 </head>\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
12  */\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
16 <p>\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
18 \r
19 <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
21 </p>\r
22 <h4>Element Selectors:</h4>\r
23 <ul class="list">\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
30 </ul>\r
31 <h4>Attribute Selectors:</h4>\r
32 <p>The use of &#64; and quotes are optional. For example, div[&#64;foo='bar'] is also a valid attribute selector.</p>\r
33 <ul class="list">\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
41 </ul>\r
42 <h4>Pseudo Classes:</h4>\r
43 <ul class="list">\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 </ul>\r
63 <h4>CSS Value Selectors:</h4>\r
64 <ul class="list">\r
65     <li> <b>E{display=none}</b> css value "display" that equals "none"</li>\r
66     <li> <b>E{display^=none}</b> css value "display" that starts with "none"</li>\r
67     <li> <b>E{display$=none}</b> css value "display" that ends with "none"</li>\r
68     <li> <b>E{display*=none}</b> css value "display" that contains the substring "none"</li>\r
69     <li> <b>E{display%=2}</b> css value "display" that is evenly divisible by 2</li>\r
70     <li> <b>E{display!=none}</b> css value "display" that does not equal "none"</li>\r
71 </ul>\r
72  * @singleton\r
73  */\r
74 Ext.DomQuery = function(){\r
75     var cache = {}, \r
76         simpleCache = {}, \r
77         valueCache = {},\r
78         nonSpace = /\S/,\r
79         trimRe = /^\s+|\s+$/g,\r
80         tplRe = /\{(\d+)\}/g,\r
81         modeRe = /^(\s?[\/>+~]\s?|\s|$)/,\r
82         tagTokenRe = /^(#)?([\w-\*]+)/,\r
83         nthRe = /(\d*)n\+?(\d*)/, \r
84         nthRe2 = /\D/,\r
85         // This is for IE MSXML which does not support expandos.\r
86             // IE runs the same speed using setAttribute, however FF slows way down\r
87             // and Safari completely fails so they need to continue to use expandos.\r
88             isIE = window.ActiveXObject ? true : false,\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 = 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 && typeof c1[0].selectSingleNode != "undefined"){\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), v;\r
528             n = n[0] ? n[0] : n;\r
529             \r
530             if (typeof n.normalize == 'function') n.normalize();\r
531             \r
532             v = (n && n.firstChild ? n.firstChild.nodeValue : null);\r
533             return ((v === null||v === undefined||v==='') ? defaultValue : v);\r
534         },\r
535 \r
536         <div id="method-Ext.DomQuery-selectNumber"></div>/**\r
537          * Selects the value of a node, parsing integers and floats. Returns the defaultValue, or 0 if none is specified.\r
538          * @param {String} selector The selector/xpath query\r
539          * @param {Node} root (optional) The start of the query (defaults to document).\r
540          * @param {Number} defaultValue\r
541          * @return {Number}\r
542          */\r
543         selectNumber : function(path, root, defaultValue){\r
544             var v = Ext.DomQuery.selectValue(path, root, defaultValue || 0);\r
545             return parseFloat(v);\r
546         },\r
547 \r
548         <div id="method-Ext.DomQuery-is"></div>/**\r
549          * Returns true if the passed element(s) match the passed simple selector (e.g. div.some-class or span:first-child)\r
550          * @param {String/HTMLElement/Array} el An element id, element or array of elements\r
551          * @param {String} selector The simple selector to test\r
552          * @return {Boolean}\r
553          */\r
554         is : function(el, ss){\r
555             if(typeof el == "string"){\r
556                 el = document.getElementById(el);\r
557             }\r
558             var isArray = Ext.isArray(el),\r
559                 result = Ext.DomQuery.filter(isArray ? el : [el], ss);\r
560             return isArray ? (result.length == el.length) : (result.length > 0);\r
561         },\r
562 \r
563         <div id="method-Ext.DomQuery-filter"></div>/**\r
564          * Filters an array of elements to only include matches of a simple selector (e.g. div.some-class or span:first-child)\r
565          * @param {Array} el An array of elements to filter\r
566          * @param {String} selector The simple selector to test\r
567          * @param {Boolean} nonMatches If true, it returns the elements that DON'T match\r
568          * the selector instead of the ones that match\r
569          * @return {Array} An Array of DOM elements which match the selector. If there are\r
570          * no matches, and empty Array is returned.\r
571          */\r
572         filter : function(els, ss, nonMatches){\r
573             ss = ss.replace(trimRe, "");\r
574             if(!simpleCache[ss]){\r
575                 simpleCache[ss] = Ext.DomQuery.compile(ss, "simple");\r
576             }\r
577             var result = simpleCache[ss](els);\r
578             return nonMatches ? quickDiff(result, els) : result;\r
579         },\r
580 \r
581         <div id="prop-Ext.DomQuery-matchers"></div>/**\r
582          * Collection of matching regular expressions and code snippets.\r
583          */\r
584         matchers : [{\r
585                 re: /^\.([\w-]+)/,\r
586                 select: 'n = byClassName(n, null, " {1} ");'\r
587             }, {\r
588                 re: /^\:([\w-]+)(?:\(((?:[^\s>\/]*|.*?))\))?/,\r
589                 select: 'n = byPseudo(n, "{1}", "{2}");'\r
590             },{\r
591                 re: /^(?:([\[\{])(?:@)?([\w-]+)\s?(?:(=|.=)\s?['"]?(.*?)["']?)?[\]\}])/,\r
592                 select: 'n = byAttribute(n, "{2}", "{4}", "{3}", "{1}");'\r
593             }, {\r
594                 re: /^#([\w-]+)/,\r
595                 select: 'n = byId(n, null, "{1}");'\r
596             },{\r
597                 re: /^@([\w-]+)/,\r
598                 select: 'return {firstChild:{nodeValue:attrValue(n, "{1}")}};'\r
599             }\r
600         ],\r
601 \r
602         <div id="method-Ext.DomQuery-operators"></div>/**\r
603          * Collection of operator comparison functions. The default operators are =, !=, ^=, $=, *=, %=, |= and ~=.\r
604          * 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
605          */\r
606         operators : {\r
607             "=" : function(a, v){\r
608                 return a == v;\r
609             },\r
610             "!=" : function(a, v){\r
611                 return a != v;\r
612             },\r
613             "^=" : function(a, v){\r
614                 return a && a.substr(0, v.length) == v;\r
615             },\r
616             "$=" : function(a, v){\r
617                 return a && a.substr(a.length-v.length) == v;\r
618             },\r
619             "*=" : function(a, v){\r
620                 return a && a.indexOf(v) !== -1;\r
621             },\r
622             "%=" : function(a, v){\r
623                 return (a % v) == 0;\r
624             },\r
625             "|=" : function(a, v){\r
626                 return a && (a == v || a.substr(0, v.length+1) == v+'-');\r
627             },\r
628             "~=" : function(a, v){\r
629                 return a && (' '+a+' ').indexOf(' '+v+' ') != -1;\r
630             }\r
631         },\r
632 \r
633         <div id="prop-Ext.DomQuery-pseudos"></div>/**\r
634          * <p>Object hash of "pseudo class" filter functions which are used when filtering selections. Each function is passed\r
635          * two parameters:</p><div class="mdetail-params"><ul>\r
636          * <li><b>c</b> : Array<div class="sub-desc">An Array of DOM elements to filter.</div></li>\r
637          * <li><b>v</b> : String<div class="sub-desc">The argument (if any) supplied in the selector.</div></li>\r
638          * </ul></div>\r
639          * <p>A filter function returns an Array of DOM elements which conform to the pseudo class.</p>\r
640          * <p>In addition to the provided pseudo classes listed above such as <code>first-child</code> and <code>nth-child</code>,\r
641          * developers may add additional, custom psuedo class filters to select elements according to application-specific requirements.</p>\r
642          * <p>For example, to filter <code>&lt;a></code> elements to only return links to <i>external</i> resources:</p>\r
643          * <code><pre>\r
644 Ext.DomQuery.pseudos.external = function(c, v){\r
645     var r = [], ri = -1;\r
646     for(var i = 0, ci; ci = c[i]; i++){\r
647 //      Include in result set only if it's a link to an external resource\r
648         if(ci.hostname != location.hostname){\r
649             r[++ri] = ci;\r
650         }\r
651     }\r
652     return r;\r
653 };</pre></code>\r
654          * Then external links could be gathered with the following statement:<code><pre>\r
655 var externalLinks = Ext.select("a:external");\r
656 </code></pre>\r
657          */\r
658         pseudos : {\r
659             "first-child" : function(c){\r
660                 var r = [], ri = -1, n;\r
661                 for(var i = 0, ci; ci = n = c[i]; i++){\r
662                     while((n = n.previousSibling) && n.nodeType != 1);\r
663                     if(!n){\r
664                         r[++ri] = ci;\r
665                     }\r
666                 }\r
667                 return r;\r
668             },\r
669 \r
670             "last-child" : function(c){\r
671                 var r = [], ri = -1, n;\r
672                 for(var i = 0, ci; ci = n = c[i]; i++){\r
673                     while((n = n.nextSibling) && n.nodeType != 1);\r
674                     if(!n){\r
675                         r[++ri] = ci;\r
676                     }\r
677                 }\r
678                 return r;\r
679             },\r
680 \r
681             "nth-child" : function(c, a) {\r
682                 var r = [], ri = -1,\r
683                         m = nthRe.exec(a == "even" && "2n" || a == "odd" && "2n+1" || !nthRe2.test(a) && "n+" + a || a),\r
684                         f = (m[1] || 1) - 0, l = m[2] - 0;\r
685                 for(var i = 0, n; n = c[i]; i++){\r
686                     var pn = n.parentNode;\r
687                     if (batch != pn._batch) {\r
688                         var j = 0;\r
689                         for(var cn = pn.firstChild; cn; cn = cn.nextSibling){\r
690                             if(cn.nodeType == 1){\r
691                                cn.nodeIndex = ++j;\r
692                             }\r
693                         }\r
694                         pn._batch = batch;\r
695                     }\r
696                     if (f == 1) {\r
697                         if (l == 0 || n.nodeIndex == l){\r
698                             r[++ri] = n;\r
699                         }\r
700                     } else if ((n.nodeIndex + l) % f == 0){\r
701                         r[++ri] = n;\r
702                     }\r
703                 }\r
704 \r
705                 return r;\r
706             },\r
707 \r
708             "only-child" : function(c){\r
709                 var r = [], ri = -1;;\r
710                 for(var i = 0, ci; ci = c[i]; i++){\r
711                     if(!prev(ci) && !next(ci)){\r
712                         r[++ri] = ci;\r
713                     }\r
714                 }\r
715                 return r;\r
716             },\r
717 \r
718             "empty" : function(c){\r
719                 var r = [], ri = -1;\r
720                 for(var i = 0, ci; ci = c[i]; i++){\r
721                     var cns = ci.childNodes, j = 0, cn, empty = true;\r
722                     while(cn = cns[j]){\r
723                         ++j;\r
724                         if(cn.nodeType == 1 || cn.nodeType == 3){\r
725                             empty = false;\r
726                             break;\r
727                         }\r
728                     }\r
729                     if(empty){\r
730                         r[++ri] = ci;\r
731                     }\r
732                 }\r
733                 return r;\r
734             },\r
735 \r
736             "contains" : function(c, v){\r
737                 var r = [], ri = -1;\r
738                 for(var i = 0, ci; ci = c[i]; i++){\r
739                     if((ci.textContent||ci.innerText||'').indexOf(v) != -1){\r
740                         r[++ri] = ci;\r
741                     }\r
742                 }\r
743                 return r;\r
744             },\r
745 \r
746             "nodeValue" : function(c, v){\r
747                 var r = [], ri = -1;\r
748                 for(var i = 0, ci; ci = c[i]; i++){\r
749                     if(ci.firstChild && ci.firstChild.nodeValue == v){\r
750                         r[++ri] = ci;\r
751                     }\r
752                 }\r
753                 return r;\r
754             },\r
755 \r
756             "checked" : function(c){\r
757                 var r = [], ri = -1;\r
758                 for(var i = 0, ci; ci = c[i]; i++){\r
759                     if(ci.checked == true){\r
760                         r[++ri] = ci;\r
761                     }\r
762                 }\r
763                 return r;\r
764             },\r
765 \r
766             "not" : function(c, ss){\r
767                 return Ext.DomQuery.filter(c, ss, true);\r
768             },\r
769 \r
770             "any" : function(c, selectors){\r
771                 var ss = selectors.split('|'),\r
772                         r = [], ri = -1, s;\r
773                 for(var i = 0, ci; ci = c[i]; i++){\r
774                     for(var j = 0; s = ss[j]; j++){\r
775                         if(Ext.DomQuery.is(ci, s)){\r
776                             r[++ri] = ci;\r
777                             break;\r
778                         }\r
779                     }\r
780                 }\r
781                 return r;\r
782             },\r
783 \r
784             "odd" : function(c){\r
785                 return this["nth-child"](c, "odd");\r
786             },\r
787 \r
788             "even" : function(c){\r
789                 return this["nth-child"](c, "even");\r
790             },\r
791 \r
792             "nth" : function(c, a){\r
793                 return c[a-1] || [];\r
794             },\r
795 \r
796             "first" : function(c){\r
797                 return c[0] || [];\r
798             },\r
799 \r
800             "last" : function(c){\r
801                 return c[c.length-1] || [];\r
802             },\r
803 \r
804             "has" : function(c, ss){\r
805                 var s = Ext.DomQuery.select,\r
806                         r = [], ri = -1;\r
807                 for(var i = 0, ci; ci = c[i]; i++){\r
808                     if(s(ss, ci).length > 0){\r
809                         r[++ri] = ci;\r
810                     }\r
811                 }\r
812                 return r;\r
813             },\r
814 \r
815             "next" : function(c, ss){\r
816                 var is = Ext.DomQuery.is,\r
817                         r = [], ri = -1;\r
818                 for(var i = 0, ci; ci = c[i]; i++){\r
819                     var n = next(ci);\r
820                     if(n && is(n, ss)){\r
821                         r[++ri] = ci;\r
822                     }\r
823                 }\r
824                 return r;\r
825             },\r
826 \r
827             "prev" : function(c, ss){\r
828                 var is = Ext.DomQuery.is,\r
829                         r = [], ri = -1;\r
830                 for(var i = 0, ci; ci = c[i]; i++){\r
831                     var n = prev(ci);\r
832                     if(n && is(n, ss)){\r
833                         r[++ri] = ci;\r
834                     }\r
835                 }\r
836                 return r;\r
837             }\r
838         }\r
839     };\r
840 }();\r
841 \r
842 <div id="method-Ext-query"></div>/**\r
843  * Selects an array of DOM nodes by CSS/XPath selector. Shorthand of {@link Ext.DomQuery#select}\r
844  * @param {String} path The selector/xpath query\r
845  * @param {Node} root (optional) The start of the query (defaults to document).\r
846  * @return {Array}\r
847  * @member Ext\r
848  * @method query\r
849  */\r
850 Ext.query = Ext.DomQuery.select;\r
851 </pre>    \r
852 </body>\r
853 </html>