]> git.wh0rd.org Git - tt-rss.git/blob - lib/dojo/_base/query-sizzle.js
remove call-by-reference to comply with php 5.4
[tt-rss.git] / lib / dojo / _base / query-sizzle.js
1 /*
2         Copyright (c) 2004-2011, The Dojo Foundation All Rights Reserved.
3         Available via Academic Free License >= 2.1 OR the modified BSD license.
4         see: http://dojotoolkit.org/license for details
5 */
6
7
8 if(!dojo._hasResource["dojo._base.query"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
9 dojo._hasResource["dojo._base.query"] = true;
10 /*!
11  * Sizzle CSS Selector Engine - v0.9
12  *  Copyright 2009, John Resig
13  *  Redistributed with the Dojo Toolkit under the terms of the New BSD license.
14  *  More information: http://sizzlejs.com/
15  *
16  *  This version from github, dated 1/23/2009, commit: e374a73bbffc12ec3b5f252e7f76e593c508dfa5
17  *  Modified for dojo loader, and to fit into dojo namespace. This was done by passing
18  *  dojo object to anonymous function, then assigning Sizzle to dojo.Sizzle instead of window.Sizzle.
19  *  Then an alias for dojo.query and dojo._filterQueryResult(). dojo.psuedos is not mapped.
20  *  Finally, dojo.provide/require added.
21  */
22
23 var startDojoMappings= function(dojo) {
24         //Start Dojo mappings.
25         dojo.query = function(/*String*/ query, /*String|DOMNode?*/ root, /*Function?*/listCtor){
26                 listCtor = listCtor || dojo.NodeList;
27
28                 if(!query){
29                         return new listCtor();
30                 }
31
32                 if(query.constructor == listCtor){
33                         return query;
34                 }
35                 if(!dojo.isString(query)){
36                         return new listCtor(query); // dojo.NodeList
37                 }
38                 if(dojo.isString(root)){
39                         root = dojo.byId(root);
40                         if(!root){ return new listCtor(); }
41                 }
42
43                 return dojo.Sizzle(query, root, new listCtor());
44         };
45
46         dojo._filterQueryResult = function(nodeList, simpleFilter){
47                 return dojo.Sizzle.filter(simpleFilter, nodeList);
48         };
49 };
50
51 //Main Sizzle code follows...
52 //ns argument, added for dojo, used at the end of the file.
53 var defineSizzle= function(ns){
54
55 var chunker = /((?:\((?:\([^()]+\)|[^()]+)+\)|\[(?:\[[^[\]]*\]|[^[\]]+)+\]|\\.|[^ >+~,(\[]+)+|[>+~])(\s*,\s*)?/g,
56         done = 0,
57         toString = Object.prototype.toString;
58
59 var Sizzle = function(selector, context, results, seed) {
60         results = results || [];
61         context = context || document;
62
63         if ( context.nodeType !== 1 && context.nodeType !== 9 )
64                 return [];
65         
66         if ( !selector || typeof selector !== "string" ) {
67                 return results;
68         }
69
70         var parts = [], m, set, checkSet, check, mode, extra, prune = true;
71         
72         // Reset the position of the chunker regexp (start from head)
73         chunker.lastIndex = 0;
74         
75         while ( (m = chunker.exec(selector)) !== null ) {
76                 parts.push( m[1] );
77                 
78                 if ( m[2] ) {
79                         extra = RegExp.rightContext;
80                         break;
81                 }
82         }
83
84         if ( parts.length > 1 && Expr.match.POS.exec( selector ) ) {
85                 if ( parts.length === 2 && Expr.relative[ parts[0] ] ) {
86                         var later = "", match;
87
88                         // Position selectors must be done after the filter
89                         while ( (match = Expr.match.POS.exec( selector )) ) {
90                                 later += match[0];
91                                 selector = selector.replace( Expr.match.POS, "" );
92                         }
93
94                         set = Sizzle.filter( later, Sizzle( selector, context ) );
95                 } else {
96                         set = Expr.relative[ parts[0] ] ?
97                                 [ context ] :
98                                 Sizzle( parts.shift(), context );
99
100                         while ( parts.length ) {
101                                 var tmpSet = [];
102
103                                 selector = parts.shift();
104                                 if ( Expr.relative[ selector ] )
105                                         selector += parts.shift();
106
107                                 for ( var i = 0, l = set.length; i < l; i++ ) {
108                                         Sizzle( selector, set[i], tmpSet );
109                                 }
110
111                                 set = tmpSet;
112                         }
113                 }
114         } else {
115                 var ret = seed ?
116                         { expr: parts.pop(), set: makeArray(seed) } :
117                         Sizzle.find( parts.pop(), parts.length === 1 && context.parentNode ? context.parentNode : context );
118                 set = Sizzle.filter( ret.expr, ret.set );
119
120                 if ( parts.length > 0 ) {
121                         checkSet = makeArray(set);
122                 } else {
123                         prune = false;
124                 }
125
126                 while ( parts.length ) {
127                         var cur = parts.pop(), pop = cur;
128
129                         if ( !Expr.relative[ cur ] ) {
130                                 cur = "";
131                         } else {
132                                 pop = parts.pop();
133                         }
134
135                         if ( pop == null ) {
136                                 pop = context;
137                         }
138
139                         Expr.relative[ cur ]( checkSet, pop );
140                 }
141         }
142
143         if ( !checkSet ) {
144                 checkSet = set;
145         }
146
147         if ( !checkSet ) {
148                 throw "Syntax error, unrecognized expression: " + (cur || selector);
149         }
150
151         if ( toString.call(checkSet) === "[object Array]" ) {
152                 if ( !prune ) {
153                         results.push.apply( results, checkSet );
154                 } else if ( context.nodeType === 1 ) {
155                         for ( var i = 0; checkSet[i] != null; i++ ) {
156                                 if ( checkSet[i] && (checkSet[i] === true || checkSet[i].nodeType === 1 && contains(context, checkSet[i])) ) {
157                                         results.push( set[i] );
158                                 }
159                         }
160                 } else {
161                         for ( var i = 0; checkSet[i] != null; i++ ) {
162                                 if ( checkSet[i] && checkSet[i].nodeType === 1 ) {
163                                         results.push( set[i] );
164                                 }
165                         }
166                 }
167         } else {
168                 makeArray( checkSet, results );
169         }
170
171         if ( extra ) {
172                 Sizzle( extra, context, results, seed );
173         }
174
175         return results;
176 };
177
178 Sizzle.matches = function(expr, set){
179         return Sizzle(expr, null, null, set);
180 };
181
182 Sizzle.find = function(expr, context){
183         var set, match;
184
185         if ( !expr ) {
186                 return [];
187         }
188
189         for ( var i = 0, l = Expr.order.length; i < l; i++ ) {
190                 var type = Expr.order[i], match;
191                 
192                 if ( (match = Expr.match[ type ].exec( expr )) ) {
193                         var left = RegExp.leftContext;
194
195                         if ( left.substr( left.length - 1 ) !== "\\" ) {
196                                 match[1] = (match[1] || "").replace(/\\/g, "");
197                                 set = Expr.find[ type ]( match, context );
198                                 if ( set != null ) {
199                                         expr = expr.replace( Expr.match[ type ], "" );
200                                         break;
201                                 }
202                         }
203                 }
204         }
205
206         if ( !set ) {
207                 set = context.getElementsByTagName("*");
208         }
209
210         return {set: set, expr: expr};
211 };
212
213 Sizzle.filter = function(expr, set, inplace, not){
214         var old = expr, result = [], curLoop = set, match, anyFound;
215
216         while ( expr && set.length ) {
217                 for ( var type in Expr.filter ) {
218                         if ( (match = Expr.match[ type ].exec( expr )) != null ) {
219                                 var filter = Expr.filter[ type ], goodArray = null, goodPos = 0, found, item;
220                                 anyFound = false;
221
222                                 if ( curLoop == result ) {
223                                         result = [];
224                                 }
225
226                                 if ( Expr.preFilter[ type ] ) {
227                                         match = Expr.preFilter[ type ]( match, curLoop, inplace, result, not );
228
229                                         if ( !match ) {
230                                                 anyFound = found = true;
231                                         } else if ( match[0] === true ) {
232                                                 goodArray = [];
233                                                 var last = null, elem;
234                                                 for ( var i = 0; (elem = curLoop[i]) !== undefined; i++ ) {
235                                                         if ( elem && last !== elem ) {
236                                                                 goodArray.push( elem );
237                                                                 last = elem;
238                                                         }
239                                                 }
240                                         }
241                                 }
242
243                                 if ( match ) {
244                                         for ( var i = 0; (item = curLoop[i]) !== undefined; i++ ) {
245                                                 if ( item ) {
246                                                         if ( goodArray && item != goodArray[goodPos] ) {
247                                                                 goodPos++;
248                                                         }
249         
250                                                         found = filter( item, match, goodPos, goodArray );
251                                                         var pass = not ^ !!found;
252
253                                                         if ( inplace && found != null ) {
254                                                                 if ( pass ) {
255                                                                         anyFound = true;
256                                                                 } else {
257                                                                         curLoop[i] = false;
258                                                                 }
259                                                         } else if ( pass ) {
260                                                                 result.push( item );
261                                                                 anyFound = true;
262                                                         }
263                                                 }
264                                         }
265                                 }
266
267                                 if ( found !== undefined ) {
268                                         if ( !inplace ) {
269                                                 curLoop = result;
270                                         }
271
272                                         expr = expr.replace( Expr.match[ type ], "" );
273
274                                         if ( !anyFound ) {
275                                                 return [];
276                                         }
277
278                                         break;
279                                 }
280                         }
281                 }
282
283                 expr = expr.replace(/\s*,\s*/, "");
284
285                 // Improper expression
286                 if ( expr == old ) {
287                         if ( anyFound == null ) {
288                                 throw "Syntax error, unrecognized expression: " + expr;
289                         } else {
290                                 break;
291                         }
292                 }
293
294                 old = expr;
295         }
296
297         return curLoop;
298 };
299
300 var Expr = Sizzle.selectors = {
301         order: [ "ID", "NAME", "TAG" ],
302         match: {
303                 ID: /#((?:[\w\u0128-\uFFFF_-]|\\.)+)/,
304                 CLASS: /\.((?:[\w\u0128-\uFFFF_-]|\\.)+)/,
305                 NAME: /\[name=['"]*((?:[\w\u0128-\uFFFF_-]|\\.)+)['"]*\]/,
306                 ATTR: /\[((?:[\w\u0128-\uFFFF_-]|\\.)+)\s*(?:(\S?=)\s*(['"]*)(.*?)\3|)\]/,
307                 TAG: /^((?:[\w\u0128-\uFFFF\*_-]|\\.)+)/,
308                 CHILD: /:(only|nth|last|first)-child\(?(even|odd|[\dn+-]*)\)?/,
309                 POS: /:(nth|eq|gt|lt|first|last|even|odd)\(?(\d*)\)?(?:[^-]|$)/,
310                 PSEUDO: /:((?:[\w\u0128-\uFFFF_-]|\\.)+)(?:\((['"]*)((?:\([^\)]+\)|[^\2\(\)]*)+)\2\))?/
311         },
312         attrMap: {
313                 "class": "className",
314                 "for": "htmlFor"
315         },
316         relative: {
317                 "+": function(checkSet, part){
318                         for ( var i = 0, l = checkSet.length; i < l; i++ ) {
319                                 var elem = checkSet[i];
320                                 if ( elem ) {
321                                         var cur = elem.previousSibling;
322                                         while ( cur && cur.nodeType !== 1 ) {
323                                                 cur = cur.previousSibling;
324                                         }
325                                         checkSet[i] = typeof part === "string" ?
326                                                 cur || false :
327                                                 cur === part;
328                                 }
329                         }
330
331                         if ( typeof part === "string" ) {
332                                 Sizzle.filter( part, checkSet, true );
333                         }
334                 },
335                 ">": function(checkSet, part){
336                         if ( typeof part === "string" && !/\W/.test(part) ) {
337                                 part = part.toUpperCase();
338
339                                 for ( var i = 0, l = checkSet.length; i < l; i++ ) {
340                                         var elem = checkSet[i];
341                                         if ( elem ) {
342                                                 var parent = elem.parentNode;
343                                                 checkSet[i] = parent.nodeName === part ? parent : false;
344                                         }
345                                 }
346                         } else {
347                                 for ( var i = 0, l = checkSet.length; i < l; i++ ) {
348                                         var elem = checkSet[i];
349                                         if ( elem ) {
350                                                 checkSet[i] = typeof part === "string" ?
351                                                         elem.parentNode :
352                                                         elem.parentNode === part;
353                                         }
354                                 }
355
356                                 if ( typeof part === "string" ) {
357                                         Sizzle.filter( part, checkSet, true );
358                                 }
359                         }
360                 },
361                 "": function(checkSet, part){
362                         var doneName = "done" + (done++), checkFn = dirCheck;
363
364                         if ( !part.match(/\W/) ) {
365                                 var nodeCheck = part = part.toUpperCase();
366                                 checkFn = dirNodeCheck;
367                         }
368
369                         checkFn("parentNode", part, doneName, checkSet, nodeCheck);
370                 },
371                 "~": function(checkSet, part){
372                         var doneName = "done" + (done++), checkFn = dirCheck;
373
374                         if ( typeof part === "string" && !part.match(/\W/) ) {
375                                 var nodeCheck = part = part.toUpperCase();
376                                 checkFn = dirNodeCheck;
377                         }
378
379                         checkFn("previousSibling", part, doneName, checkSet, nodeCheck);
380                 }
381         },
382         find: {
383                 ID: function(match, context){
384                         if ( context.getElementById ) {
385                                 var m = context.getElementById(match[1]);
386                                 return m ? [m] : [];
387                         }
388                 },
389                 NAME: function(match, context){
390                         return context.getElementsByName ? context.getElementsByName(match[1]) : null;
391                 },
392                 TAG: function(match, context){
393                         return context.getElementsByTagName(match[1]);
394                 }
395         },
396         preFilter: {
397                 CLASS: function(match, curLoop, inplace, result, not){
398                         match = " " + match[1].replace(/\\/g, "") + " ";
399
400                         for ( var i = 0; curLoop[i]; i++ ) {
401                                 if ( not ^ (" " + curLoop[i].className + " ").indexOf(match) >= 0 ) {
402                                         if ( !inplace )
403                                                 result.push( curLoop[i] );
404                                 } else if ( inplace ) {
405                                         curLoop[i] = false;
406                                 }
407                         }
408
409                         return false;
410                 },
411                 ID: function(match){
412                         return match[1];
413                 },
414                 TAG: function(match){
415                         return match[1].toUpperCase();
416                 },
417                 CHILD: function(match){
418                         if ( match[1] == "nth" ) {
419                                 // parse equations like 'even', 'odd', '5', '2n', '3n+2', '4n-1', '-n+6'
420                                 var test = /(-?)(\d*)n((?:\+|-)?\d*)/.exec(
421                                         match[2] == "even" && "2n" || match[2] == "odd" && "2n+1" ||
422                                         !/\D/.test( match[2] ) && "0n+" + match[2] || match[2]);
423
424                                 // calculate the numbers (first)n+(last) including if they are negative
425                                 match[2] = (test[1] + (test[2] || 1)) - 0;
426                                 match[3] = test[3] - 0;
427                         }
428
429                         // TODO: Move to normal caching system
430                         match[0] = "done" + (done++);
431
432                         return match;
433                 },
434                 ATTR: function(match){
435                         var name = match[1];
436                         
437                         if ( Expr.attrMap[name] ) {
438                                 match[1] = Expr.attrMap[name];
439                         }
440
441                         if ( match[2] === "~=" ) {
442                                 match[4] = " " + match[4] + " ";
443                         }
444
445                         return match;
446                 },
447                 PSEUDO: function(match, curLoop, inplace, result, not){
448                         if ( match[1] === "not" ) {
449                                 // If we're dealing with a complex expression, or a simple one
450                                 if ( match[3].match(chunker).length > 1 ) {
451                                         match[3] = Sizzle(match[3], null, null, curLoop);
452                                 } else {
453                                         var ret = Sizzle.filter(match[3], curLoop, inplace, true ^ not);
454                                         if ( !inplace ) {
455                                                 result.push.apply( result, ret );
456                                         }
457                                         return false;
458                                 }
459                         }
460                         
461                         return match;
462                 },
463                 POS: function(match){
464                         match.unshift( true );
465                         return match;
466                 }
467         },
468         filters: {
469                 enabled: function(elem){
470                         return elem.disabled === false && elem.type !== "hidden";
471                 },
472                 disabled: function(elem){
473                         return elem.disabled === true;
474                 },
475                 checked: function(elem){
476                         return elem.checked === true;
477                 },
478                 selected: function(elem){
479                         // Accessing this property makes selected-by-default
480                         // options in Safari work properly
481                         elem.parentNode.selectedIndex;
482                         return elem.selected === true;
483                 },
484                 parent: function(elem){
485                         return !!elem.firstChild;
486                 },
487                 empty: function(elem){
488                         return !elem.firstChild;
489                 },
490                 has: function(elem, i, match){
491                         return !!Sizzle( match[3], elem ).length;
492                 },
493                 header: function(elem){
494                         return /h\d/i.test( elem.nodeName );
495                 },
496                 text: function(elem){
497                         return "text" === elem.type;
498                 },
499                 radio: function(elem){
500                         return "radio" === elem.type;
501                 },
502                 checkbox: function(elem){
503                         return "checkbox" === elem.type;
504                 },
505                 file: function(elem){
506                         return "file" === elem.type;
507                 },
508                 password: function(elem){
509                         return "password" === elem.type;
510                 },
511                 submit: function(elem){
512                         return "submit" === elem.type;
513                 },
514                 image: function(elem){
515                         return "image" === elem.type;
516                 },
517                 reset: function(elem){
518                         return "reset" === elem.type;
519                 },
520                 button: function(elem){
521                         return "button" === elem.type || elem.nodeName.toUpperCase() === "BUTTON";
522                 },
523                 input: function(elem){
524                         return /input|select|textarea|button/i.test(elem.nodeName);
525                 }
526         },
527         setFilters: {
528                 first: function(elem, i){
529                         return i === 0;
530                 },
531                 last: function(elem, i, match, array){
532                         return i === array.length - 1;
533                 },
534                 even: function(elem, i){
535                         return i % 2 === 0;
536                 },
537                 odd: function(elem, i){
538                         return i % 2 === 1;
539                 },
540                 lt: function(elem, i, match){
541                         return i < match[3] - 0;
542                 },
543                 gt: function(elem, i, match){
544                         return i > match[3] - 0;
545                 },
546                 nth: function(elem, i, match){
547                         return match[3] - 0 == i;
548                 },
549                 eq: function(elem, i, match){
550                         return match[3] - 0 == i;
551                 }
552         },
553         filter: {
554                 CHILD: function(elem, match){
555                         var type = match[1], parent = elem.parentNode;
556
557                         var doneName = match[0];
558                         
559                         if ( parent && !parent[ doneName ] ) {
560                                 var count = 1;
561
562                                 for ( var node = parent.firstChild; node; node = node.nextSibling ) {
563                                         if ( node.nodeType == 1 ) {
564                                                 node.nodeIndex = count++;
565                                         }
566                                 }
567
568                                 parent[ doneName ] = count - 1;
569                         }
570
571                         if ( type == "first" ) {
572                                 return elem.nodeIndex == 1;
573                         } else if ( type == "last" ) {
574                                 return elem.nodeIndex == parent[ doneName ];
575                         } else if ( type == "only" ) {
576                                 return parent[ doneName ] == 1;
577                         } else if ( type == "nth" ) {
578                                 var add = false, first = match[2], last = match[3];
579
580                                 if ( first == 1 && last == 0 ) {
581                                         return true;
582                                 }
583
584                                 if ( first == 0 ) {
585                                         if ( elem.nodeIndex == last ) {
586                                                 add = true;
587                                         }
588                                 } else if ( (elem.nodeIndex - last) % first == 0 && (elem.nodeIndex - last) / first >= 0 ) {
589                                         add = true;
590                                 }
591
592                                 return add;
593                         }
594                 },
595                 PSEUDO: function(elem, match, i, array){
596                         var name = match[1], filter = Expr.filters[ name ];
597
598                         if ( filter ) {
599                                 return filter( elem, i, match, array );
600                         } else if ( name === "contains" ) {
601                                 return (elem.textContent || elem.innerText || "").indexOf(match[3]) >= 0;
602                         } else if ( name === "not" ) {
603                                 var not = match[3];
604
605                                 for ( var i = 0, l = not.length; i < l; i++ ) {
606                                         if ( not[i] === elem ) {
607                                                 return false;
608                                         }
609                                 }
610
611                                 return true;
612                         }
613                 },
614                 ID: function(elem, match){
615                         return elem.nodeType === 1 && elem.getAttribute("id") === match;
616                 },
617                 TAG: function(elem, match){
618                         return (match === "*" && elem.nodeType === 1) || elem.nodeName === match;
619                 },
620                 CLASS: function(elem, match){
621                         return match.test( elem.className );
622                 },
623                 ATTR: function(elem, match){
624                         var result = elem[ match[1] ] || elem.getAttribute( match[1] ), value = result + "", type = match[2], check = match[4];
625                         return result == null ?
626                                 false :
627                                 type === "=" ?
628                                 value === check :
629                                 type === "*=" ?
630                                 value.indexOf(check) >= 0 :
631                                 type === "~=" ?
632                                 (" " + value + " ").indexOf(check) >= 0 :
633                                 !match[4] ?
634                                 result :
635                                 type === "!=" ?
636                                 value != check :
637                                 type === "^=" ?
638                                 value.indexOf(check) === 0 :
639                                 type === "$=" ?
640                                 value.substr(value.length - check.length) === check :
641                                 type === "|=" ?
642                                 value === check || value.substr(0, check.length + 1) === check + "-" :
643                                 false;
644                 },
645                 POS: function(elem, match, i, array){
646                         var name = match[2], filter = Expr.setFilters[ name ];
647
648                         if ( filter ) {
649                                 return filter( elem, i, match, array );
650                         }
651                 }
652         }
653 };
654
655 for ( var type in Expr.match ) {
656         Expr.match[ type ] = RegExp( Expr.match[ type ].source + /(?![^\[]*\])(?![^\(]*\))/.source );
657 }
658
659 var makeArray = function(array, results) {
660         array = Array.prototype.slice.call( array );
661
662         if ( results ) {
663                 results.push.apply( results, array );
664                 return results;
665         }
666         
667         return array;
668 };
669
670 // Perform a simple check to determine if the browser is capable of
671 // converting a NodeList to an array using builtin methods.
672 try {
673         Array.prototype.slice.call( document.documentElement.childNodes );
674
675 // Provide a fallback method if it does not work
676 } catch(e){
677         makeArray = function(array, results) {
678                 var ret = results || [];
679
680                 if ( toString.call(array) === "[object Array]" ) {
681                         Array.prototype.push.apply( ret, array );
682                 } else {
683                         if ( typeof array.length === "number" ) {
684                                 for ( var i = 0, l = array.length; i < l; i++ ) {
685                                         ret.push( array[i] );
686                                 }
687                         } else {
688                                 for ( var i = 0; array[i]; i++ ) {
689                                         ret.push( array[i] );
690                                 }
691                         }
692                 }
693
694                 return ret;
695         };
696 }
697
698 // Check to see if the browser returns elements by name when
699 // querying by getElementById (and provide a workaround)
700 (function(){
701         // We're going to inject a fake input element with a specified name
702         var form = document.createElement("form"),
703                 id = "script" + (new Date).getTime();
704         form.innerHTML = "<input name='" + id + "'/>";
705
706         // Inject it into the root element, check its status, and remove it quickly
707         var root = document.documentElement;
708         root.insertBefore( form, root.firstChild );
709
710         // The workaround has to do additional checks after a getElementById
711         // Which slows things down for other browsers (hence the branching)
712         if ( !!document.getElementById( id ) ) {
713                 Expr.find.ID = function(match, context){
714                         if ( context.getElementById ) {
715                                 var m = context.getElementById(match[1]);
716                                 return m ? m.id === match[1] || m.getAttributeNode && m.getAttributeNode("id").nodeValue === match[1] ? [m] : undefined : [];
717                         }
718                 };
719
720                 Expr.filter.ID = function(elem, match){
721                         var node = elem.getAttributeNode && elem.getAttributeNode("id");
722                         return elem.nodeType === 1 && node && node.nodeValue === match;
723                 };
724         }
725
726         root.removeChild( form );
727 })();
728
729 // Check to see if the browser returns only elements
730 // when doing getElementsByTagName("*")
731 (function(){
732         // Create a fake element
733         var div = document.createElement("div");
734         div.appendChild( document.createComment("") );
735
736         // Make sure no comments are found
737         if ( div.getElementsByTagName("*").length > 0 ) {
738                 Expr.find.TAG = function(match, context){
739                         var results = context.getElementsByTagName(match[1]);
740
741                         // Filter out possible comments
742                         if ( match[1] === "*" ) {
743                                 var tmp = [];
744
745                                 for ( var i = 0; results[i]; i++ ) {
746                                         if ( results[i].nodeType === 1 ) {
747                                                 tmp.push( results[i] );
748                                         }
749                                 }
750
751                                 results = tmp;
752                         }
753
754                         return results;
755                 };
756         }
757 })();
758
759 if ( document.querySelectorAll ) (function(){
760         var oldSizzle = Sizzle;
761         
762         Sizzle = function(query, context, extra, seed){
763                 context = context || document;
764
765                 if ( !seed && context.nodeType === 9 ) {
766                         try {
767                                 return makeArray( context.querySelectorAll(query), extra );
768                         } catch(e){}
769                 }
770                 
771                 return oldSizzle(query, context, extra, seed);
772         };
773
774         Sizzle.find = oldSizzle.find;
775         Sizzle.filter = oldSizzle.filter;
776         Sizzle.selectors = oldSizzle.selectors;
777         Sizzle.matches = oldSizzle.matches;
778 })();
779
780 if ( document.documentElement.getElementsByClassName ) {
781         Expr.order.splice(1, 0, "CLASS");
782         Expr.find.CLASS = function(match, context) {
783                 return context.getElementsByClassName(match[1]);
784         };
785 }
786
787 function dirNodeCheck( dir, cur, doneName, checkSet, nodeCheck ) {
788         for ( var i = 0, l = checkSet.length; i < l; i++ ) {
789                 var elem = checkSet[i];
790                 if ( elem ) {
791                         elem = elem[dir];
792                         var match = false;
793
794                         while ( elem && elem.nodeType ) {
795                                 var done = elem[doneName];
796                                 if ( done ) {
797                                         match = checkSet[ done ];
798                                         break;
799                                 }
800
801                                 if ( elem.nodeType === 1 )
802                                         elem[doneName] = i;
803
804                                 if ( elem.nodeName === cur ) {
805                                         match = elem;
806                                         break;
807                                 }
808
809                                 elem = elem[dir];
810                         }
811
812                         checkSet[i] = match;
813                 }
814         }
815 }
816
817 function dirCheck( dir, cur, doneName, checkSet, nodeCheck ) {
818         for ( var i = 0, l = checkSet.length; i < l; i++ ) {
819                 var elem = checkSet[i];
820                 if ( elem ) {
821                         elem = elem[dir];
822                         var match = false;
823
824                         while ( elem && elem.nodeType ) {
825                                 if ( elem[doneName] ) {
826                                         match = checkSet[ elem[doneName] ];
827                                         break;
828                                 }
829
830                                 if ( elem.nodeType === 1 ) {
831                                         elem[doneName] = i;
832
833                                         if ( typeof cur !== "string" ) {
834                                                 if ( elem === cur ) {
835                                                         match = true;
836                                                         break;
837                                                 }
838
839                                         } else if ( Sizzle.filter( cur, [elem] ).length > 0 ) {
840                                                 match = elem;
841                                                 break;
842                                         }
843                                 }
844
845                                 elem = elem[dir];
846                         }
847
848                         checkSet[i] = match;
849                 }
850         }
851 }
852
853 var contains = document.compareDocumentPosition ?  function(a, b){
854         return a.compareDocumentPosition(b) & 16;
855 } : function(a, b){
856         return a !== b && (a.contains ? a.contains(b) : true);
857 };
858
859 // EXPOSE
860
861 ns.Sizzle = Sizzle;
862
863 };
864
865 if (this["dojo"]) {
866   var defined= 0;
867   if (!defined) {
868     // must be in a built version that stripped out the define above
869         dojo.provide("dojo._base.query");
870     dojo.require("dojo._base.NodeList");
871     defineSizzle(dojo);
872   } // else must be in a source version (or a build that likes define)
873 } else {
874   defineSizzle(window);
875 }
876
877 }