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