142
St
startsInvasion / files
startsInvasion / libs / node_modules / bean / support / qwery / vendor / sizzle.js
31.9 KB
1/*! 2 * Sizzle CSS Selector Engine 3 * Copyright 2011, The Dojo Foundation 4 * Released under the MIT, BSD, and GPL Licenses. 5 * More information: http://sizzlejs.com/ 6 */ 7(function(){ 8 9var chunker = /((?:\((?:\([^()]+\)|[^()]+)+\)|\[(?:\[[^\[\]]*\]|['"][^'"]*['"]|[^\[\]'"]+)+\]|\\.|[^ >+~,(\[\\]+)+|[>+~])(\s*,\s*)?((?:.|\r|\n)*)/g, 10 done = 0, 11 toString = Object.prototype.toString, 12 hasDuplicate = false, 13 baseHasDuplicate = true, 14 rBackslash = /\\/g, 15 rNonWord = /\W/; 16 17// Here we check if the JavaScript engine is using some sort of 18// optimization where it does not always call our comparision 19// function. If that is the case, discard the hasDuplicate value. 20// Thus far that includes Google Chrome. 21[0, 0].sort(function() { 22 baseHasDuplicate = false; 23 return 0; 24}); 25 26var Sizzle = function( selector, context, results, seed ) { 27 results = results || []; 28 context = context || document; 29 30 var origContext = context; 31 32 if ( context.nodeType !== 1 && context.nodeType !== 9 ) { 33 return []; 34 } 35 36 if ( !selector || typeof selector !== "string" ) { 37 return results; 38 } 39 40 var m, set, checkSet, extra, ret, cur, pop, i, 41 prune = true, 42 contextXML = Sizzle.isXML( context ), 43 parts = [], 44 soFar = selector; 45 46 // Reset the position of the chunker regexp (start from head) 47 do { 48 chunker.exec( "" ); 49 m = chunker.exec( soFar ); 50 51 if ( m ) { 52 soFar = m[3]; 53 54 parts.push( m[1] ); 55 56 if ( m[2] ) { 57 extra = m[3]; 58 break; 59 } 60 } 61 } while ( m ); 62 63 if ( parts.length > 1 && origPOS.exec( selector ) ) { 64 65 if ( parts.length === 2 && Expr.relative[ parts[0] ] ) { 66 set = posProcess( parts[0] + parts[1], context ); 67 68 } else { 69 set = Expr.relative[ parts[0] ] ? 70 [ context ] : 71 Sizzle( parts.shift(), context ); 72 73 while ( parts.length ) { 74 selector = parts.shift(); 75 76 if ( Expr.relative[ selector ] ) { 77 selector += parts.shift(); 78 } 79 80 set = posProcess( selector, set ); 81 } 82 } 83 84 } else { 85 // Take a shortcut and set the context if the root selector is an ID 86 // (but not if it'll be faster if the inner selector is an ID) 87 if ( !seed && parts.length > 1 && context.nodeType === 9 && !contextXML && 88 Expr.match.ID.test(parts[0]) && !Expr.match.ID.test(parts[parts.length - 1]) ) { 89 90 ret = Sizzle.find( parts.shift(), context, contextXML ); 91 context = ret.expr ? 92 Sizzle.filter( ret.expr, ret.set )[0] : 93 ret.set[0]; 94 } 95 96 if ( context ) { 97 ret = seed ? 98 { expr: parts.pop(), set: makeArray(seed) } : 99 Sizzle.find( parts.pop(), parts.length === 1 && (parts[0] === "~" || parts[0] === "+") && context.parentNode ? context.parentNode : context, contextXML ); 100 101 set = ret.expr ? 102 Sizzle.filter( ret.expr, ret.set ) : 103 ret.set; 104 105 if ( parts.length > 0 ) { 106 checkSet = makeArray( set ); 107 108 } else { 109 prune = false; 110 } 111 112 while ( parts.length ) { 113 cur = parts.pop(); 114 pop = cur; 115 116 if ( !Expr.relative[ cur ] ) { 117 cur = ""; 118 } else { 119 pop = parts.pop(); 120 } 121 122 if ( pop == null ) { 123 pop = context; 124 } 125 126 Expr.relative[ cur ]( checkSet, pop, contextXML ); 127 } 128 129 } else { 130 checkSet = parts = []; 131 } 132 } 133 134 if ( !checkSet ) { 135 checkSet = set; 136 } 137 138 if ( !checkSet ) { 139 Sizzle.error( cur || selector ); 140 } 141 142 if ( toString.call(checkSet) === "[object Array]" ) { 143 if ( !prune ) { 144 results.push.apply( results, checkSet ); 145 146 } else if ( context && context.nodeType === 1 ) { 147 for ( i = 0; checkSet[i] != null; i++ ) { 148 if ( checkSet[i] && (checkSet[i] === true || checkSet[i].nodeType === 1 && Sizzle.contains(context, checkSet[i])) ) { 149 results.push( set[i] ); 150 } 151 } 152 153 } else { 154 for ( i = 0; checkSet[i] != null; i++ ) { 155 if ( checkSet[i] && checkSet[i].nodeType === 1 ) { 156 results.push( set[i] ); 157 } 158 } 159 } 160 161 } else { 162 makeArray( checkSet, results ); 163 } 164 165 if ( extra ) { 166 Sizzle( extra, origContext, results, seed ); 167 Sizzle.uniqueSort( results ); 168 } 169 170 return results; 171}; 172 173Sizzle.uniqueSort = function( results ) { 174 if ( sortOrder ) { 175 hasDuplicate = baseHasDuplicate; 176 results.sort( sortOrder ); 177 178 if ( hasDuplicate ) { 179 for ( var i = 1; i < results.length; i++ ) { 180 if ( results[i] === results[ i - 1 ] ) { 181 results.splice( i--, 1 ); 182 } 183 } 184 } 185 } 186 187 return results; 188}; 189 190Sizzle.matches = function( expr, set ) { 191 return Sizzle( expr, null, null, set ); 192}; 193 194Sizzle.matchesSelector = function( node, expr ) { 195 return Sizzle( expr, null, null, [node] ).length > 0; 196}; 197 198Sizzle.find = function( expr, context, isXML ) { 199 var set; 200 201 if ( !expr ) { 202 return []; 203 } 204 205 for ( var i = 0, l = Expr.order.length; i < l; i++ ) { 206 var match, 207 type = Expr.order[i]; 208 209 if ( (match = Expr.leftMatch[ type ].exec( expr )) ) { 210 var left = match[1]; 211 match.splice( 1, 1 ); 212 213 if ( left.substr( left.length - 1 ) !== "\\" ) { 214 match[1] = (match[1] || "").replace( rBackslash, "" ); 215 set = Expr.find[ type ]( match, context, isXML ); 216 217 if ( set != null ) { 218 expr = expr.replace( Expr.match[ type ], "" ); 219 break; 220 } 221 } 222 } 223 } 224 225 if ( !set ) { 226 set = typeof context.getElementsByTagName !== "undefined" ? 227 context.getElementsByTagName( "*" ) : 228 []; 229 } 230 231 return { set: set, expr: expr }; 232}; 233 234Sizzle.filter = function( expr, set, inplace, not ) { 235 var match, anyFound, 236 old = expr, 237 result = [], 238 curLoop = set, 239 isXMLFilter = set && set[0] && Sizzle.isXML( set[0] ); 240 241 while ( expr && set.length ) { 242 for ( var type in Expr.filter ) { 243 if ( (match = Expr.leftMatch[ type ].exec( expr )) != null && match[2] ) { 244 var found, item, 245 filter = Expr.filter[ type ], 246 left = match[1]; 247 248 anyFound = false; 249 250 match.splice(1,1); 251 252 if ( left.substr( left.length - 1 ) === "\\" ) { 253 continue; 254 } 255 256 if ( curLoop === result ) { 257 result = []; 258 } 259 260 if ( Expr.preFilter[ type ] ) { 261 match = Expr.preFilter[ type ]( match, curLoop, inplace, result, not, isXMLFilter ); 262 263 if ( !match ) { 264 anyFound = found = true; 265 266 } else if ( match === true ) { 267 continue; 268 } 269 } 270 271 if ( match ) { 272 for ( var i = 0; (item = curLoop[i]) != null; i++ ) { 273 if ( item ) { 274 found = filter( item, match, i, curLoop ); 275 var pass = not ^ !!found; 276 277 if ( inplace && found != null ) { 278 if ( pass ) { 279 anyFound = true; 280 281 } else { 282 curLoop[i] = false; 283 } 284 285 } else if ( pass ) { 286 result.push( item ); 287 anyFound = true; 288 } 289 } 290 } 291 } 292 293 if ( found !== undefined ) { 294 if ( !inplace ) { 295 curLoop = result; 296 } 297 298 expr = expr.replace( Expr.match[ type ], "" ); 299 300 if ( !anyFound ) { 301 return []; 302 } 303 304 break; 305 } 306 } 307 } 308 309 // Improper expression 310 if ( expr === old ) { 311 if ( anyFound == null ) { 312 Sizzle.error( expr ); 313 314 } else { 315 break; 316 } 317 } 318 319 old = expr; 320 } 321 322 return curLoop; 323}; 324 325Sizzle.error = function( msg ) { 326 throw "Syntax error, unrecognized expression: " + msg; 327}; 328 329var Expr = Sizzle.selectors = { 330 order: [ "ID", "NAME", "TAG" ], 331 332 match: { 333 ID: /#((?:[\w\u00c0-\uFFFF\-]|\\.)+)/, 334 CLASS: /\.((?:[\w\u00c0-\uFFFF\-]|\\.)+)/, 335 NAME: /\[name=['"]*((?:[\w\u00c0-\uFFFF\-]|\\.)+)['"]*\]/, 336 ATTR: /\[\s*((?:[\w\u00c0-\uFFFF\-]|\\.)+)\s*(?:(\S?=)\s*(?:(['"])(.*?)\3|(#?(?:[\w\u00c0-\uFFFF\-]|\\.)*)|)|)\s*\]/, 337 TAG: /^((?:[\w\u00c0-\uFFFF\*\-]|\\.)+)/, 338 CHILD: /:(only|nth|last|first)-child(?:\(\s*(even|odd|(?:[+\-]?\d+|(?:[+\-]?\d*)?n\s*(?:[+\-]\s*\d+)?))\s*\))?/, 339 POS: /:(nth|eq|gt|lt|first|last|even|odd)(?:\((\d*)\))?(?=[^\-]|$)/, 340 PSEUDO: /:((?:[\w\u00c0-\uFFFF\-]|\\.)+)(?:\((['"]?)((?:\([^\)]+\)|[^\(\)]*)+)\2\))?/ 341 }, 342 343 leftMatch: {}, 344 345 attrMap: { 346 "class": "className", 347 "for": "htmlFor" 348 }, 349 350 attrHandle: { 351 href: function( elem ) { 352 return elem.getAttribute( "href" ); 353 }, 354 type: function( elem ) { 355 return elem.getAttribute( "type" ); 356 } 357 }, 358 359 relative: { 360 "+": function(checkSet, part){ 361 var isPartStr = typeof part === "string", 362 isTag = isPartStr && !rNonWord.test( part ), 363 isPartStrNotTag = isPartStr && !isTag; 364 365 if ( isTag ) { 366 part = part.toLowerCase(); 367 } 368 369 for ( var i = 0, l = checkSet.length, elem; i < l; i++ ) { 370 if ( (elem = checkSet[i]) ) { 371 while ( (elem = elem.previousSibling) && elem.nodeType !== 1 ) {} 372 373 checkSet[i] = isPartStrNotTag || elem && elem.nodeName.toLowerCase() === part ? 374 elem || false : 375 elem === part; 376 } 377 } 378 379 if ( isPartStrNotTag ) { 380 Sizzle.filter( part, checkSet, true ); 381 } 382 }, 383 384 ">": function( checkSet, part ) { 385 var elem, 386 isPartStr = typeof part === "string", 387 i = 0, 388 l = checkSet.length; 389 390 if ( isPartStr && !rNonWord.test( part ) ) { 391 part = part.toLowerCase(); 392 393 for ( ; i < l; i++ ) { 394 elem = checkSet[i]; 395 396 if ( elem ) { 397 var parent = elem.parentNode; 398 checkSet[i] = parent.nodeName.toLowerCase() === part ? parent : false; 399 } 400 } 401 402 } else { 403 for ( ; i < l; i++ ) { 404 elem = checkSet[i]; 405 406 if ( elem ) { 407 checkSet[i] = isPartStr ? 408 elem.parentNode : 409 elem.parentNode === part; 410 } 411 } 412 413 if ( isPartStr ) { 414 Sizzle.filter( part, checkSet, true ); 415 } 416 } 417 }, 418 419 "": function(checkSet, part, isXML){ 420 var nodeCheck, 421 doneName = done++, 422 checkFn = dirCheck; 423 424 if ( typeof part === "string" && !rNonWord.test( part ) ) { 425 part = part.toLowerCase(); 426 nodeCheck = part; 427 checkFn = dirNodeCheck; 428 } 429 430 checkFn( "parentNode", part, doneName, checkSet, nodeCheck, isXML ); 431 }, 432 433 "~": function( checkSet, part, isXML ) { 434 var nodeCheck, 435 doneName = done++, 436 checkFn = dirCheck; 437 438 if ( typeof part === "string" && !rNonWord.test( part ) ) { 439 part = part.toLowerCase(); 440 nodeCheck = part; 441 checkFn = dirNodeCheck; 442 } 443 444 checkFn( "previousSibling", part, doneName, checkSet, nodeCheck, isXML ); 445 } 446 }, 447 448 find: { 449 ID: function( match, context, isXML ) { 450 if ( typeof context.getElementById !== "undefined" && !isXML ) { 451 var m = context.getElementById(match[1]); 452 // Check parentNode to catch when Blackberry 4.6 returns 453 // nodes that are no longer in the document #6963 454 return m && m.parentNode ? [m] : []; 455 } 456 }, 457 458 NAME: function( match, context ) { 459 if ( typeof context.getElementsByName !== "undefined" ) { 460 var ret = [], 461 results = context.getElementsByName( match[1] ); 462 463 for ( var i = 0, l = results.length; i < l; i++ ) { 464 if ( results[i].getAttribute("name") === match[1] ) { 465 ret.push( results[i] ); 466 } 467 } 468 469 return ret.length === 0 ? null : ret; 470 } 471 }, 472 473 TAG: function( match, context ) { 474 if ( typeof context.getElementsByTagName !== "undefined" ) { 475 return context.getElementsByTagName( match[1] ); 476 } 477 } 478 }, 479 preFilter: { 480 CLASS: function( match, curLoop, inplace, result, not, isXML ) { 481 match = " " + match[1].replace( rBackslash, "" ) + " "; 482 483 if ( isXML ) { 484 return match; 485 } 486 487 for ( var i = 0, elem; (elem = curLoop[i]) != null; i++ ) { 488 if ( elem ) { 489 if ( not ^ (elem.className && (" " + elem.className + " ").replace(/[\t\n\r]/g, " ").indexOf(match) >= 0) ) { 490 if ( !inplace ) { 491 result.push( elem ); 492 } 493 494 } else if ( inplace ) { 495 curLoop[i] = false; 496 } 497 } 498 } 499 500 return false; 501 }, 502 503 ID: function( match ) { 504 return match[1].replace( rBackslash, "" ); 505 }, 506 507 TAG: function( match, curLoop ) { 508 return match[1].replace( rBackslash, "" ).toLowerCase(); 509 }, 510 511 CHILD: function( match ) { 512 if ( match[1] === "nth" ) { 513 if ( !match[2] ) { 514 Sizzle.error( match[0] ); 515 } 516 517 match[2] = match[2].replace(/^\+|\s*/g, ''); 518 519 // parse equations like 'even', 'odd', '5', '2n', '3n+2', '4n-1', '-n+6' 520 var test = /(-?)(\d*)(?:n([+\-]?\d*))?/.exec( 521 match[2] === "even" && "2n" || match[2] === "odd" && "2n+1" || 522 !/\D/.test( match[2] ) && "0n+" + match[2] || match[2]); 523 524 // calculate the numbers (first)n+(last) including if they are negative 525 match[2] = (test[1] + (test[2] || 1)) - 0; 526 match[3] = test[3] - 0; 527 } 528 else if ( match[2] ) { 529 Sizzle.error( match[0] ); 530 } 531 532 // TODO: Move to normal caching system 533 match[0] = done++; 534 535 return match; 536 }, 537 538 ATTR: function( match, curLoop, inplace, result, not, isXML ) { 539 var name = match[1] = match[1].replace( rBackslash, "" ); 540 541 if ( !isXML && Expr.attrMap[name] ) { 542 match[1] = Expr.attrMap[name]; 543 } 544 545 // Handle if an un-quoted value was used 546 match[4] = ( match[4] || match[5] || "" ).replace( rBackslash, "" ); 547 548 if ( match[2] === "~=" ) { 549 match[4] = " " + match[4] + " "; 550 } 551 552 return match; 553 }, 554 555 PSEUDO: function( match, curLoop, inplace, result, not ) { 556 if ( match[1] === "not" ) { 557 // If we're dealing with a complex expression, or a simple one 558 if ( ( chunker.exec(match[3]) || "" ).length > 1 || /^\w/.test(match[3]) ) { 559 match[3] = Sizzle(match[3], null, null, curLoop); 560 561 } else { 562 var ret = Sizzle.filter(match[3], curLoop, inplace, true ^ not); 563 564 if ( !inplace ) { 565 result.push.apply( result, ret ); 566 } 567 568 return false; 569 } 570 571 } else if ( Expr.match.POS.test( match[0] ) || Expr.match.CHILD.test( match[0] ) ) { 572 return true; 573 } 574 575 return match; 576 }, 577 578 POS: function( match ) { 579 match.unshift( true ); 580 581 return match; 582 } 583 }, 584 585 filters: { 586 enabled: function( elem ) { 587 return elem.disabled === false && elem.type !== "hidden"; 588 }, 589 590 disabled: function( elem ) { 591 return elem.disabled === true; 592 }, 593 594 checked: function( elem ) { 595 return elem.checked === true; 596 }, 597 598 selected: function( elem ) { 599 // Accessing this property makes selected-by-default 600 // options in Safari work properly 601 if ( elem.parentNode ) { 602 elem.parentNode.selectedIndex; 603 } 604 605 return elem.selected === true; 606 }, 607 608 parent: function( elem ) { 609 return !!elem.firstChild; 610 }, 611 612 empty: function( elem ) { 613 return !elem.firstChild; 614 }, 615 616 has: function( elem, i, match ) { 617 return !!Sizzle( match[3], elem ).length; 618 }, 619 620 header: function( elem ) { 621 return (/h\d/i).test( elem.nodeName ); 622 }, 623 624 text: function( elem ) { 625 var attr = elem.getAttribute( "type" ), type = elem.type; 626 // IE6 and 7 will map elem.type to 'text' for new HTML5 types (search, etc) 627 // use getAttribute instead to test this case 628 return "text" === type && ( attr === type || attr === null ); 629 }, 630 631 radio: function( elem ) { 632 return "radio" === elem.type; 633 }, 634 635 checkbox: function( elem ) { 636 return "checkbox" === elem.type; 637 }, 638 639 file: function( elem ) { 640 return "file" === elem.type; 641 }, 642 password: function( elem ) { 643 return "password" === elem.type; 644 }, 645 646 submit: function( elem ) { 647 return "submit" === elem.type; 648 }, 649 650 image: function( elem ) { 651 return "image" === elem.type; 652 }, 653 654 reset: function( elem ) { 655 return "reset" === elem.type; 656 }, 657 658 button: function( elem ) { 659 return "button" === elem.type || elem.nodeName.toLowerCase() === "button"; 660 }, 661 662 input: function( elem ) { 663 return (/input|select|textarea|button/i).test( elem.nodeName ); 664 } 665 }, 666 setFilters: { 667 first: function( elem, i ) { 668 return i === 0; 669 }, 670 671 last: function( elem, i, match, array ) { 672 return i === array.length - 1; 673 }, 674 675 even: function( elem, i ) { 676 return i % 2 === 0; 677 }, 678 679 odd: function( elem, i ) { 680 return i % 2 === 1; 681 }, 682 683 lt: function( elem, i, match ) { 684 return i < match[3] - 0; 685 }, 686 687 gt: function( elem, i, match ) { 688 return i > match[3] - 0; 689 }, 690 691 nth: function( elem, i, match ) { 692 return match[3] - 0 === i; 693 }, 694 695 eq: function( elem, i, match ) { 696 return match[3] - 0 === i; 697 } 698 }, 699 filter: { 700 PSEUDO: function( elem, match, i, array ) { 701 var name = match[1], 702 filter = Expr.filters[ name ]; 703 704 if ( filter ) { 705 return filter( elem, i, match, array ); 706 707 } else if ( name === "contains" ) { 708 return (elem.textContent || elem.innerText || Sizzle.getText([ elem ]) || "").indexOf(match[3]) >= 0; 709 710 } else if ( name === "not" ) { 711 var not = match[3]; 712 713 for ( var j = 0, l = not.length; j < l; j++ ) { 714 if ( not[j] === elem ) { 715 return false; 716 } 717 } 718 719 return true; 720 721 } else { 722 Sizzle.error( name ); 723 } 724 }, 725 726 CHILD: function( elem, match ) { 727 var type = match[1], 728 node = elem; 729 730 switch ( type ) { 731 case "only": 732 case "first": 733 while ( (node = node.previousSibling) ) { 734 if ( node.nodeType === 1 ) { 735 return false; 736 } 737 } 738 739 if ( type === "first" ) { 740 return true; 741 } 742 743 node = elem; 744 745 case "last": 746 while ( (node = node.nextSibling) ) { 747 if ( node.nodeType === 1 ) { 748 return false; 749 } 750 } 751 752 return true; 753 754 case "nth": 755 var first = match[2], 756 last = match[3]; 757 758 if ( first === 1 && last === 0 ) { 759 return true; 760 } 761 762 var doneName = match[0], 763 parent = elem.parentNode; 764 765 if ( parent && (parent.sizcache !== doneName || !elem.nodeIndex) ) { 766 var count = 0; 767 768 for ( node = parent.firstChild; node; node = node.nextSibling ) { 769 if ( node.nodeType === 1 ) { 770 node.nodeIndex = ++count; 771 } 772 } 773 774 parent.sizcache = doneName; 775 } 776 777 var diff = elem.nodeIndex - last; 778 779 if ( first === 0 ) { 780 return diff === 0; 781 782 } else { 783 return ( diff % first === 0 && diff / first >= 0 ); 784 } 785 } 786 }, 787 788 ID: function( elem, match ) { 789 return elem.nodeType === 1 && elem.getAttribute("id") === match; 790 }, 791 792 TAG: function( elem, match ) { 793 return (match === "*" && elem.nodeType === 1) || elem.nodeName.toLowerCase() === match; 794 }, 795 796 CLASS: function( elem, match ) { 797 return (" " + (elem.className || elem.getAttribute("class")) + " ") 798 .indexOf( match ) > -1; 799 }, 800 801 ATTR: function( elem, match ) { 802 var name = match[1], 803 result = Expr.attrHandle[ name ] ? 804 Expr.attrHandle[ name ]( elem ) : 805 elem[ name ] != null ? 806 elem[ name ] : 807 elem.getAttribute( name ), 808 value = result + "", 809 type = match[2], 810 check = match[4]; 811 812 return result == null ? 813 type === "!=" : 814 type === "=" ? 815 value === check : 816 type === "*=" ? 817 value.indexOf(check) >= 0 : 818 type === "~=" ? 819 (" " + value + " ").indexOf(check) >= 0 : 820 !check ? 821 value && result !== false : 822 type === "!=" ? 823 value !== check : 824 type === "^=" ? 825 value.indexOf(check) === 0 : 826 type === "$=" ? 827 value.substr(value.length - check.length) === check : 828 type === "|=" ? 829 value === check || value.substr(0, check.length + 1) === check + "-" : 830 false; 831 }, 832 833 POS: function( elem, match, i, array ) { 834 var name = match[2], 835 filter = Expr.setFilters[ name ]; 836 837 if ( filter ) { 838 return filter( elem, i, match, array ); 839 } 840 } 841 } 842}; 843 844var origPOS = Expr.match.POS, 845 fescape = function(all, num){ 846 return "\\" + (num - 0 + 1); 847 }; 848 849for ( var type in Expr.match ) { 850 Expr.match[ type ] = new RegExp( Expr.match[ type ].source + (/(?![^\[]*\])(?![^\(]*\))/.source) ); 851 Expr.leftMatch[ type ] = new RegExp( /(^(?:.|\r|\n)*?)/.source + Expr.match[ type ].source.replace(/\\(\d+)/g, fescape) ); 852} 853 854var makeArray = function( array, results ) { 855 array = Array.prototype.slice.call( array, 0 ); 856 857 if ( results ) { 858 results.push.apply( results, array ); 859 return results; 860 } 861 862 return array; 863}; 864 865// Perform a simple check to determine if the browser is capable of 866// converting a NodeList to an array using builtin methods. 867// Also verifies that the returned array holds DOM nodes 868// (which is not the case in the Blackberry browser) 869try { 870 Array.prototype.slice.call( document.documentElement.childNodes, 0 )[0].nodeType; 871 872// Provide a fallback method if it does not work 873} catch( e ) { 874 makeArray = function( array, results ) { 875 var i = 0, 876 ret = results || []; 877 878 if ( toString.call(array) === "[object Array]" ) { 879 Array.prototype.push.apply( ret, array ); 880 881 } else { 882 if ( typeof array.length === "number" ) { 883 for ( var l = array.length; i < l; i++ ) { 884 ret.push( array[i] ); 885 } 886 887 } else { 888 for ( ; array[i]; i++ ) { 889 ret.push( array[i] ); 890 } 891 } 892 } 893 894 return ret; 895 }; 896} 897 898var sortOrder, siblingCheck; 899 900if ( document.documentElement.compareDocumentPosition ) { 901 sortOrder = function( a, b ) { 902 if ( a === b ) { 903 hasDuplicate = true; 904 return 0; 905 } 906 907 if ( !a.compareDocumentPosition || !b.compareDocumentPosition ) { 908 return a.compareDocumentPosition ? -1 : 1; 909 } 910 911 return a.compareDocumentPosition(b) & 4 ? -1 : 1; 912 }; 913 914} else { 915 sortOrder = function( a, b ) { 916 var al, bl, 917 ap = [], 918 bp = [], 919 aup = a.parentNode, 920 bup = b.parentNode, 921 cur = aup; 922 923 // The nodes are identical, we can exit early 924 if ( a === b ) { 925 hasDuplicate = true; 926 return 0; 927 928 // If the nodes are siblings (or identical) we can do a quick check 929 } else if ( aup === bup ) { 930 return siblingCheck( a, b ); 931 932 // If no parents were found then the nodes are disconnected 933 } else if ( !aup ) { 934 return -1; 935 936 } else if ( !bup ) { 937 return 1; 938 } 939 940 // Otherwise they're somewhere else in the tree so we need 941 // to build up a full list of the parentNodes for comparison 942 while ( cur ) { 943 ap.unshift( cur ); 944 cur = cur.parentNode; 945 } 946 947 cur = bup; 948 949 while ( cur ) { 950 bp.unshift( cur ); 951 cur = cur.parentNode; 952 } 953 954 al = ap.length; 955 bl = bp.length; 956 957 // Start walking down the tree looking for a discrepancy 958 for ( var i = 0; i < al && i < bl; i++ ) { 959 if ( ap[i] !== bp[i] ) { 960 return siblingCheck( ap[i], bp[i] ); 961 } 962 } 963 964 // We ended someplace up the tree so do a sibling check 965 return i === al ? 966 siblingCheck( a, bp[i], -1 ) : 967 siblingCheck( ap[i], b, 1 ); 968 }; 969 970 siblingCheck = function( a, b, ret ) { 971 if ( a === b ) { 972 return ret; 973 } 974 975 var cur = a.nextSibling; 976 977 while ( cur ) { 978 if ( cur === b ) { 979 return -1; 980 } 981 982 cur = cur.nextSibling; 983 } 984 985 return 1; 986 }; 987} 988 989// Utility function for retreiving the text value of an array of DOM nodes 990Sizzle.getText = function( elems ) { 991 var ret = "", elem; 992 993 for ( var i = 0; elems[i]; i++ ) { 994 elem = elems[i]; 995 996 // Get the text from text nodes and CDATA nodes 997 if ( elem.nodeType === 3 || elem.nodeType === 4 ) { 998 ret += elem.nodeValue; 999 1000 // Traverse everything else, except comment nodes 1001 } else if ( elem.nodeType !== 8 ) { 1002 ret += Sizzle.getText( elem.childNodes ); 1003 } 1004 } 1005 1006 return ret; 1007}; 1008 1009// Check to see if the browser returns elements by name when 1010// querying by getElementById (and provide a workaround) 1011(function(){ 1012 // We're going to inject a fake input element with a specified name 1013 var form = document.createElement("div"), 1014 id = "script" + (new Date()).getTime(), 1015 root = document.documentElement; 1016 1017 form.innerHTML = "<a name='" + id + "'/>"; 1018 1019 // Inject it into the root element, check its status, and remove it quickly 1020 root.insertBefore( form, root.firstChild ); 1021 1022 // The workaround has to do additional checks after a getElementById 1023 // Which slows things down for other browsers (hence the branching) 1024 if ( document.getElementById( id ) ) { 1025 Expr.find.ID = function( match, context, isXML ) { 1026 if ( typeof context.getElementById !== "undefined" && !isXML ) { 1027 var m = context.getElementById(match[1]); 1028 1029 return m ? 1030 m.id === match[1] || typeof m.getAttributeNode !== "undefined" && m.getAttributeNode("id").nodeValue === match[1] ? 1031 [m] : 1032 undefined : 1033 []; 1034 } 1035 }; 1036 1037 Expr.filter.ID = function( elem, match ) { 1038 var node = typeof elem.getAttributeNode !== "undefined" && elem.getAttributeNode("id"); 1039 1040 return elem.nodeType === 1 && node && node.nodeValue === match; 1041 }; 1042 } 1043 1044 root.removeChild( form ); 1045 1046 // release memory in IE 1047 root = form = null; 1048})(); 1049 1050(function(){ 1051 // Check to see if the browser returns only elements 1052 // when doing getElementsByTagName("*") 1053 1054 // Create a fake element 1055 var div = document.createElement("div"); 1056 div.appendChild( document.createComment("") ); 1057 1058 // Make sure no comments are found 1059 if ( div.getElementsByTagName("*").length > 0 ) { 1060 Expr.find.TAG = function( match, context ) { 1061 var results = context.getElementsByTagName( match[1] ); 1062 1063 // Filter out possible comments 1064 if ( match[1] === "*" ) { 1065 var tmp = []; 1066 1067 for ( var i = 0; results[i]; i++ ) { 1068 if ( results[i].nodeType === 1 ) { 1069 tmp.push( results[i] ); 1070 } 1071 } 1072 1073 results = tmp; 1074 } 1075 1076 return results; 1077 }; 1078 } 1079 1080 // Check to see if an attribute returns normalized href attributes 1081 div.innerHTML = "<a href='#'></a>"; 1082 1083 if ( div.firstChild && typeof div.firstChild.getAttribute !== "undefined" && 1084 div.firstChild.getAttribute("href") !== "#" ) { 1085 1086 Expr.attrHandle.href = function( elem ) { 1087 return elem.getAttribute( "href", 2 ); 1088 }; 1089 } 1090 1091 // release memory in IE 1092 div = null; 1093})(); 1094 1095if ( document.querySelectorAll ) { 1096 (function(){ 1097 var oldSizzle = Sizzle, 1098 div = document.createElement("div"), 1099 id = "__sizzle__"; 1100 1101 div.innerHTML = "<p class='TEST'></p>"; 1102 1103 // Safari can't handle uppercase or unicode characters when 1104 // in quirks mode. 1105 if ( div.querySelectorAll && div.querySelectorAll(".TEST").length === 0 ) { 1106 return; 1107 } 1108 1109 Sizzle = function( query, context, extra, seed ) { 1110 context = context || document; 1111 1112 // Only use querySelectorAll on non-XML documents 1113 // (ID selectors don't work in non-HTML documents) 1114 if ( !seed && !Sizzle.isXML(context) ) { 1115 // See if we find a selector to speed up 1116 var match = /^(\w+$)|^\.([\w\-]+$)|^#([\w\-]+$)/.exec( query ); 1117 1118 if ( match && (context.nodeType === 1 || context.nodeType === 9) ) { 1119 // Speed-up: Sizzle("TAG") 1120 if ( match[1] ) { 1121 return makeArray( context.getElementsByTagName( query ), extra ); 1122 1123 // Speed-up: Sizzle(".CLASS") 1124 } else if ( match[2] && Expr.find.CLASS && context.getElementsByClassName ) { 1125 return makeArray( context.getElementsByClassName( match[2] ), extra ); 1126 } 1127 } 1128 1129 if ( context.nodeType === 9 ) { 1130 // Speed-up: Sizzle("body") 1131 // The body element only exists once, optimize finding it 1132 if ( query === "body" && context.body ) { 1133 return makeArray( [ context.body ], extra ); 1134 1135 // Speed-up: Sizzle("#ID") 1136 } else if ( match && match[3] ) { 1137 var elem = context.getElementById( match[3] ); 1138 1139 // Check parentNode to catch when Blackberry 4.6 returns 1140 // nodes that are no longer in the document #6963 1141 if ( elem && elem.parentNode ) { 1142 // Handle the case where IE and Opera return items 1143 // by name instead of ID 1144 if ( elem.id === match[3] ) { 1145 return makeArray( [ elem ], extra ); 1146 } 1147 1148 } else { 1149 return makeArray( [], extra ); 1150 } 1151 } 1152 1153 try { 1154 return makeArray( context.querySelectorAll(query), extra ); 1155 } catch(qsaError) {} 1156 1157 // qSA works strangely on Element-rooted queries 1158 // We can work around this by specifying an extra ID on the root 1159 // and working up from there (Thanks to Andrew Dupont for the technique) 1160 // IE 8 doesn't work on object elements 1161 } else if ( context.nodeType === 1 && context.nodeName.toLowerCase() !== "object" ) { 1162 var oldContext = context, 1163 old = context.getAttribute( "id" ), 1164 nid = old || id, 1165 hasParent = context.parentNode, 1166 relativeHierarchySelector = /^\s*[+~]/.test( query ); 1167 1168 if ( !old ) { 1169 context.setAttribute( "id", nid ); 1170 } else { 1171 nid = nid.replace( /'/g, "\\$&" ); 1172 } 1173 if ( relativeHierarchySelector && hasParent ) { 1174 context = context.parentNode; 1175 } 1176 1177 try { 1178 if ( !relativeHierarchySelector || hasParent ) { 1179 return makeArray( context.querySelectorAll( "[id='" + nid + "'] " + query ), extra ); 1180 } 1181 1182 } catch(pseudoError) { 1183 } finally { 1184 if ( !old ) { 1185 oldContext.removeAttribute( "id" ); 1186 } 1187 } 1188 } 1189 } 1190 1191 return oldSizzle(query, context, extra, seed); 1192 }; 1193 1194 for ( var prop in oldSizzle ) { 1195 Sizzle[ prop ] = oldSizzle[ prop ]; 1196 } 1197 1198 // release memory in IE 1199 div = null; 1200 })(); 1201} 1202 1203(function(){ 1204 var html = document.documentElement, 1205 matches = html.matchesSelector || html.mozMatchesSelector || html.webkitMatchesSelector || html.msMatchesSelector; 1206 1207 if ( matches ) { 1208 // Check to see if it's possible to do matchesSelector 1209 // on a disconnected node (IE 9 fails this) 1210 var disconnectedMatch = !matches.call( document.createElement( "div" ), "div" ), 1211 pseudoWorks = false; 1212 1213 try { 1214 // This should fail with an exception 1215 // Gecko does not error, returns false instead 1216 matches.call( document.documentElement, "[test!='']:sizzle" ); 1217 1218 } catch( pseudoError ) { 1219 pseudoWorks = true; 1220 } 1221 1222 Sizzle.matchesSelector = function( node, expr ) { 1223 // Make sure that attribute selectors are quoted 1224 expr = expr.replace(/\=\s*([^'"\]]*)\s*\]/g, "='$1']"); 1225 1226 if ( !Sizzle.isXML( node ) ) { 1227 try { 1228 if ( pseudoWorks || !Expr.match.PSEUDO.test( expr ) && !/!=/.test( expr ) ) { 1229 var ret = matches.call( node, expr ); 1230 1231 // IE 9's matchesSelector returns false on disconnected nodes 1232 if ( ret || !disconnectedMatch || 1233 // As well, disconnected nodes are said to be in a document 1234 // fragment in IE 9, so check for that 1235 node.document && node.document.nodeType !== 11 ) { 1236 return ret; 1237 } 1238 } 1239 } catch(e) {} 1240 } 1241 1242 return Sizzle(expr, null, null, [node]).length > 0; 1243 }; 1244 } 1245})(); 1246 1247(function(){ 1248 var div = document.createElement("div"); 1249 1250 div.innerHTML = "<div class='test e'></div><div class='test'></div>"; 1251 1252 // Opera can't find a second classname (in 9.6) 1253 // Also, make sure that getElementsByClassName actually exists 1254 if ( !div.getElementsByClassName || div.getElementsByClassName("e").length === 0 ) { 1255 return; 1256 } 1257 1258 // Safari caches class attributes, doesn't catch changes (in 3.2) 1259 div.lastChild.className = "e"; 1260 1261 if ( div.getElementsByClassName("e").length === 1 ) { 1262 return; 1263 } 1264 1265 Expr.order.splice(1, 0, "CLASS"); 1266 Expr.find.CLASS = function( match, context, isXML ) { 1267 if ( typeof context.getElementsByClassName !== "undefined" && !isXML ) { 1268 return context.getElementsByClassName(match[1]); 1269 } 1270 }; 1271 1272 // release memory in IE 1273 div = null; 1274})(); 1275 1276function dirNodeCheck( dir, cur, doneName, checkSet, nodeCheck, isXML ) { 1277 for ( var i = 0, l = checkSet.length; i < l; i++ ) { 1278 var elem = checkSet[i]; 1279 1280 if ( elem ) { 1281 var match = false; 1282 1283 elem = elem[dir]; 1284 1285 while ( elem ) { 1286 if ( elem.sizcache === doneName ) { 1287 match = checkSet[elem.sizset]; 1288 break; 1289 } 1290 1291 if ( elem.nodeType === 1 && !isXML ){ 1292 elem.sizcache = doneName; 1293 elem.sizset = i; 1294 } 1295 1296 if ( elem.nodeName.toLowerCase() === cur ) { 1297 match = elem; 1298 break; 1299 } 1300 1301 elem = elem[dir]; 1302 } 1303 1304 checkSet[i] = match; 1305 } 1306 } 1307} 1308 1309function dirCheck( dir, cur, doneName, checkSet, nodeCheck, isXML ) { 1310 for ( var i = 0, l = checkSet.length; i < l; i++ ) { 1311 var elem = checkSet[i]; 1312 1313 if ( elem ) { 1314 var match = false; 1315 1316 elem = elem[dir]; 1317 1318 while ( elem ) { 1319 if ( elem.sizcache === doneName ) { 1320 match = checkSet[elem.sizset]; 1321 break; 1322 } 1323 1324 if ( elem.nodeType === 1 ) { 1325 if ( !isXML ) { 1326 elem.sizcache = doneName; 1327 elem.sizset = i; 1328 } 1329 1330 if ( typeof cur !== "string" ) { 1331 if ( elem === cur ) { 1332 match = true; 1333 break; 1334 } 1335 1336 } else if ( Sizzle.filter( cur, [elem] ).length > 0 ) { 1337 match = elem; 1338 break; 1339 } 1340 } 1341 1342 elem = elem[dir]; 1343 } 1344 1345 checkSet[i] = match; 1346 } 1347 } 1348} 1349 1350if ( document.documentElement.contains ) { 1351 Sizzle.contains = function( a, b ) { 1352 return a !== b && (a.contains ? a.contains(b) : true); 1353 }; 1354 1355} else if ( document.documentElement.compareDocumentPosition ) { 1356 Sizzle.contains = function( a, b ) { 1357 return !!(a.compareDocumentPosition(b) & 16); 1358 }; 1359 1360} else { 1361 Sizzle.contains = function() { 1362 return false; 1363 }; 1364} 1365 1366Sizzle.isXML = function( elem ) { 1367 // documentElement is verified for cases where it doesn't yet exist 1368 // (such as loading iframes in IE - #4833) 1369 var documentElement = (elem ? elem.ownerDocument || elem : 0).documentElement; 1370 1371 return documentElement ? documentElement.nodeName !== "HTML" : false; 1372}; 1373 1374var posProcess = function( selector, context ) { 1375 var match, 1376 tmpSet = [], 1377 later = "", 1378 root = context.nodeType ? [context] : context; 1379 1380 // Position selectors must be done after the filter 1381 // And so must :not(positional) so we move all PSEUDOs to the end 1382 while ( (match = Expr.match.PSEUDO.exec( selector )) ) { 1383 later += match[0]; 1384 selector = selector.replace( Expr.match.PSEUDO, "" ); 1385 } 1386 1387 selector = Expr.relative[selector] ? selector + "*" : selector; 1388 1389 for ( var i = 0, l = root.length; i < l; i++ ) { 1390 Sizzle( selector, root[i], tmpSet ); 1391 } 1392 1393 return Sizzle.filter( later, tmpSet ); 1394}; 1395 1396// EXPOSE 1397 1398window.Sizzle = Sizzle; 1399 1400})();