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/
9 var chunker = /((?:\((?:\([^()]+\)|[^()]+)+\)|\[(?:\[[^\[\]]*\]|['"][^'"]*['"]|[^\[\]'"]+)+\]|\\.|[^ >+~,(\[\\]+)+|[>+~])(\s*,\s*)?((?:.|\r|\n)*)/g,
11 toString = Object.prototype.toString,
13 baseHasDuplicate = true,
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;
26 var Sizzle = function( selector, context, results, seed ) {
27 results = results || [];
28 context = context || document;
30 var origContext = context;
32 if ( context.nodeType !== 1 && context.nodeType !== 9 ) {
36 if ( !selector || typeof selector !== "string" ) {
40 var m, set, checkSet, extra, ret, cur, pop, i,
42 contextXML = Sizzle.isXML( context ),
46 // Reset the position of the chunker regexp (start from head)
49 m = chunker.exec( soFar );
63 if ( parts.length > 1 && origPOS.exec( selector ) ) {
65 if ( parts.length === 2 && Expr.relative[ parts[0] ] ) {
66 set = posProcess( parts[0] + parts[1], context );
69 set = Expr.relative[ parts[0] ] ?
71 Sizzle( parts.shift(), context );
73 while ( parts.length ) {
74 selector = parts.shift();
76 if ( Expr.relative[ selector ] ) {
77 selector += parts.shift();
80 set = posProcess( selector, set );
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]) ) {
90 ret = Sizzle.find( parts.shift(), context, contextXML );
92 Sizzle.filter( ret.expr, ret.set )[0] :
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 );
102 Sizzle.filter( ret.expr, ret.set ) :
105 if ( parts.length > 0 ) {
106 checkSet = makeArray( set );
112 while ( parts.length ) {
116 if ( !Expr.relative[ cur ] ) {
126 Expr.relative[ cur ]( checkSet, pop, contextXML );
130 checkSet = parts = [];
139 Sizzle.error( cur || selector );
142 if ( toString.call(checkSet) === "[object Array]" ) {
144 results.push.apply( results, checkSet );
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] );
154 for ( i = 0; checkSet[i] != null; i++ ) {
155 if ( checkSet[i] && checkSet[i].nodeType === 1 ) {
156 results.push( set[i] );
162 makeArray( checkSet, results );
166 Sizzle( extra, origContext, results, seed );
167 Sizzle.uniqueSort( results );
173 Sizzle.uniqueSort = function( results ) {
175 hasDuplicate = baseHasDuplicate;
176 results.sort( sortOrder );
178 if ( hasDuplicate ) {
179 for ( var i = 1; i < results.length; i++ ) {
180 if ( results[i] === results[ i - 1 ] ) {
181 results.splice( i--, 1 );
190 Sizzle.matches = function( expr, set ) {
191 return Sizzle( expr, null, null, set );
194 Sizzle.matchesSelector = function( node, expr ) {
195 return Sizzle( expr, null, null, [node] ).length > 0;
198 Sizzle.find = function( expr, context, isXML ) {
205 for ( var i = 0, l = Expr.order.length; i < l; i++ ) {
207 type = Expr.order[i];
209 if ( (match = Expr.leftMatch[ type ].exec( expr )) ) {
211 match.splice( 1, 1 );
213 if ( left.substr( left.length - 1 ) !== "\\" ) {
214 match[1] = (match[1] || "").replace( rBackslash, "" );
215 set = Expr.find[ type ]( match, context, isXML );
218 expr = expr.replace( Expr.match[ type ], "" );
226 set = typeof context.getElementsByTagName !== "undefined" ?
227 context.getElementsByTagName( "*" ) :
231 return { set: set, expr: expr };
234 Sizzle.filter = function( expr, set, inplace, not ) {
239 isXMLFilter = set && set[0] && Sizzle.isXML( set[0] );
241 while ( expr && set.length ) {
242 for ( var type in Expr.filter ) {
243 if ( (match = Expr.leftMatch[ type ].exec( expr )) != null && match[2] ) {
245 filter = Expr.filter[ type ],
252 if ( left.substr( left.length - 1 ) === "\\" ) {
256 if ( curLoop === result ) {
260 if ( Expr.preFilter[ type ] ) {
261 match = Expr.preFilter[ type ]( match, curLoop, inplace, result, not, isXMLFilter );
264 anyFound = found = true;
266 } else if ( match === true ) {
272 for ( var i = 0; (item = curLoop[i]) != null; i++ ) {
274 found = filter( item, match, i, curLoop );
275 var pass = not ^ !!found;
277 if ( inplace && found != null ) {
293 if ( found !== undefined ) {
298 expr = expr.replace( Expr.match[ type ], "" );
309 // Improper expression
310 if ( expr === old ) {
311 if ( anyFound == null ) {
312 Sizzle.error( expr );
325 Sizzle.error = function( msg ) {
326 throw "Syntax error, unrecognized expression: " + msg;
329 var Expr = Sizzle.selectors = {
330 order: [ "ID", "NAME", "TAG" ],
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\))?/
346 "class": "className",
351 href: function( elem ) {
352 return elem.getAttribute( "href" );
354 type: function( elem ) {
355 return elem.getAttribute( "type" );
360 "+": function(checkSet, part){
361 var isPartStr = typeof part === "string",
362 isTag = isPartStr && !rNonWord.test( part ),
363 isPartStrNotTag = isPartStr && !isTag;
366 part = part.toLowerCase();
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 ) {}
373 checkSet[i] = isPartStrNotTag || elem && elem.nodeName.toLowerCase() === part ?
379 if ( isPartStrNotTag ) {
380 Sizzle.filter( part, checkSet, true );
384 ">": function( checkSet, part ) {
386 isPartStr = typeof part === "string",
390 if ( isPartStr && !rNonWord.test( part ) ) {
391 part = part.toLowerCase();
393 for ( ; i < l; i++ ) {
397 var parent = elem.parentNode;
398 checkSet[i] = parent.nodeName.toLowerCase() === part ? parent : false;
403 for ( ; i < l; i++ ) {
407 checkSet[i] = isPartStr ?
409 elem.parentNode === part;
414 Sizzle.filter( part, checkSet, true );
419 "": function(checkSet, part, isXML){
424 if ( typeof part === "string" && !rNonWord.test( part ) ) {
425 part = part.toLowerCase();
427 checkFn = dirNodeCheck;
430 checkFn( "parentNode", part, doneName, checkSet, nodeCheck, isXML );
433 "~": function( checkSet, part, isXML ) {
438 if ( typeof part === "string" && !rNonWord.test( part ) ) {
439 part = part.toLowerCase();
441 checkFn = dirNodeCheck;
444 checkFn( "previousSibling", part, doneName, checkSet, nodeCheck, isXML );
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] : [];
458 NAME: function( match, context ) {
459 if ( typeof context.getElementsByName !== "undefined" ) {
461 results = context.getElementsByName( match[1] );
463 for ( var i = 0, l = results.length; i < l; i++ ) {
464 if ( results[i].getAttribute("name") === match[1] ) {
465 ret.push( results[i] );
469 return ret.length === 0 ? null : ret;
473 TAG: function( match, context ) {
474 if ( typeof context.getElementsByTagName !== "undefined" ) {
475 return context.getElementsByTagName( match[1] );
480 CLASS: function( match, curLoop, inplace, result, not, isXML ) {
481 match = " " + match[1].replace( rBackslash, "" ) + " ";
487 for ( var i = 0, elem; (elem = curLoop[i]) != null; i++ ) {
489 if ( not ^ (elem.className && (" " + elem.className + " ").replace(/[\t\n\r]/g, " ").indexOf(match) >= 0) ) {
494 } else if ( inplace ) {
503 ID: function( match ) {
504 return match[1].replace( rBackslash, "" );
507 TAG: function( match, curLoop ) {
508 return match[1].replace( rBackslash, "" ).toLowerCase();
511 CHILD: function( match ) {
512 if ( match[1] === "nth" ) {
514 Sizzle.error( match[0] );
517 match[2] = match[2].replace(/^\+|\s*/g, '');
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]);
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;
528 else if ( match[2] ) {
529 Sizzle.error( match[0] );
532 // TODO: Move to normal caching system
538 ATTR: function( match, curLoop, inplace, result, not, isXML ) {
539 var name = match[1] = match[1].replace( rBackslash, "" );
541 if ( !isXML && Expr.attrMap[name] ) {
542 match[1] = Expr.attrMap[name];
545 // Handle if an un-quoted value was used
546 match[4] = ( match[4] || match[5] || "" ).replace( rBackslash, "" );
548 if ( match[2] === "~=" ) {
549 match[4] = " " + match[4] + " ";
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);
562 var ret = Sizzle.filter(match[3], curLoop, inplace, true ^ not);
565 result.push.apply( result, ret );
571 } else if ( Expr.match.POS.test( match[0] ) || Expr.match.CHILD.test( match[0] ) ) {
578 POS: function( match ) {
579 match.unshift( true );
586 enabled: function( elem ) {
587 return elem.disabled === false && elem.type !== "hidden";
590 disabled: function( elem ) {
591 return elem.disabled === true;
594 checked: function( elem ) {
595 return elem.checked === true;
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;
605 return elem.selected === true;
608 parent: function( elem ) {
609 return !!elem.firstChild;
612 empty: function( elem ) {
613 return !elem.firstChild;
616 has: function( elem, i, match ) {
617 return !!Sizzle( match[3], elem ).length;
620 header: function( elem ) {
621 return (/h\d/i).test( elem.nodeName );
624 text: function( elem ) {
625 // IE6 and 7 will map elem.type to 'text' for new HTML5 types (search, etc)
626 // use getAttribute instead to test this case
627 return "text" === elem.getAttribute( 'type' );
629 radio: function( elem ) {
630 return "radio" === elem.type;
633 checkbox: function( elem ) {
634 return "checkbox" === elem.type;
637 file: function( elem ) {
638 return "file" === elem.type;
640 password: function( elem ) {
641 return "password" === elem.type;
644 submit: function( elem ) {
645 return "submit" === elem.type;
648 image: function( elem ) {
649 return "image" === elem.type;
652 reset: function( elem ) {
653 return "reset" === elem.type;
656 button: function( elem ) {
657 return "button" === elem.type || elem.nodeName.toLowerCase() === "button";
660 input: function( elem ) {
661 return (/input|select|textarea|button/i).test( elem.nodeName );
665 first: function( elem, i ) {
669 last: function( elem, i, match, array ) {
670 return i === array.length - 1;
673 even: function( elem, i ) {
677 odd: function( elem, i ) {
681 lt: function( elem, i, match ) {
682 return i < match[3] - 0;
685 gt: function( elem, i, match ) {
686 return i > match[3] - 0;
689 nth: function( elem, i, match ) {
690 return match[3] - 0 === i;
693 eq: function( elem, i, match ) {
694 return match[3] - 0 === i;
698 PSEUDO: function( elem, match, i, array ) {
700 filter = Expr.filters[ name ];
703 return filter( elem, i, match, array );
705 } else if ( name === "contains" ) {
706 return (elem.textContent || elem.innerText || Sizzle.getText([ elem ]) || "").indexOf(match[3]) >= 0;
708 } else if ( name === "not" ) {
711 for ( var j = 0, l = not.length; j < l; j++ ) {
712 if ( not[j] === elem ) {
720 Sizzle.error( name );
724 CHILD: function( elem, match ) {
731 while ( (node = node.previousSibling) ) {
732 if ( node.nodeType === 1 ) {
737 if ( type === "first" ) {
744 while ( (node = node.nextSibling) ) {
745 if ( node.nodeType === 1 ) {
753 var first = match[2],
756 if ( first === 1 && last === 0 ) {
760 var doneName = match[0],
761 parent = elem.parentNode;
763 if ( parent && (parent.sizcache !== doneName || !elem.nodeIndex) ) {
766 for ( node = parent.firstChild; node; node = node.nextSibling ) {
767 if ( node.nodeType === 1 ) {
768 node.nodeIndex = ++count;
772 parent.sizcache = doneName;
775 var diff = elem.nodeIndex - last;
781 return ( diff % first === 0 && diff / first >= 0 );
786 ID: function( elem, match ) {
787 return elem.nodeType === 1 && elem.getAttribute("id") === match;
790 TAG: function( elem, match ) {
791 return (match === "*" && elem.nodeType === 1) || elem.nodeName.toLowerCase() === match;
794 CLASS: function( elem, match ) {
795 return (" " + (elem.className || elem.getAttribute("class")) + " ")
796 .indexOf( match ) > -1;
799 ATTR: function( elem, match ) {
801 result = Expr.attrHandle[ name ] ?
802 Expr.attrHandle[ name ]( elem ) :
803 elem[ name ] != null ?
805 elem.getAttribute( name ),
810 return result == null ?
815 value.indexOf(check) >= 0 :
817 (" " + value + " ").indexOf(check) >= 0 :
819 value && result !== false :
823 value.indexOf(check) === 0 :
825 value.substr(value.length - check.length) === check :
827 value === check || value.substr(0, check.length + 1) === check + "-" :
831 POS: function( elem, match, i, array ) {
833 filter = Expr.setFilters[ name ];
836 return filter( elem, i, match, array );
842 var origPOS = Expr.match.POS,
843 fescape = function(all, num){
844 return "\\" + (num - 0 + 1);
847 for ( var type in Expr.match ) {
848 Expr.match[ type ] = new RegExp( Expr.match[ type ].source + (/(?![^\[]*\])(?![^\(]*\))/.source) );
849 Expr.leftMatch[ type ] = new RegExp( /(^(?:.|\r|\n)*?)/.source + Expr.match[ type ].source.replace(/\\(\d+)/g, fescape) );
852 var makeArray = function( array, results ) {
853 array = Array.prototype.slice.call( array, 0 );
856 results.push.apply( results, array );
863 // Perform a simple check to determine if the browser is capable of
864 // converting a NodeList to an array using builtin methods.
865 // Also verifies that the returned array holds DOM nodes
866 // (which is not the case in the Blackberry browser)
868 Array.prototype.slice.call( document.documentElement.childNodes, 0 )[0].nodeType;
870 // Provide a fallback method if it does not work
872 makeArray = function( array, results ) {
876 if ( toString.call(array) === "[object Array]" ) {
877 Array.prototype.push.apply( ret, array );
880 if ( typeof array.length === "number" ) {
881 for ( var l = array.length; i < l; i++ ) {
882 ret.push( array[i] );
886 for ( ; array[i]; i++ ) {
887 ret.push( array[i] );
896 var sortOrder, siblingCheck;
898 if ( document.documentElement.compareDocumentPosition ) {
899 sortOrder = function( a, b ) {
905 if ( !a.compareDocumentPosition || !b.compareDocumentPosition ) {
906 return a.compareDocumentPosition ? -1 : 1;
909 return a.compareDocumentPosition(b) & 4 ? -1 : 1;
913 sortOrder = function( a, b ) {
921 // The nodes are identical, we can exit early
926 // If the nodes are siblings (or identical) we can do a quick check
927 } else if ( aup === bup ) {
928 return siblingCheck( a, b );
930 // If no parents were found then the nodes are disconnected
938 // Otherwise they're somewhere else in the tree so we need
939 // to build up a full list of the parentNodes for comparison
942 cur = cur.parentNode;
949 cur = cur.parentNode;
955 // Start walking down the tree looking for a discrepancy
956 for ( var i = 0; i < al && i < bl; i++ ) {
957 if ( ap[i] !== bp[i] ) {
958 return siblingCheck( ap[i], bp[i] );
962 // We ended someplace up the tree so do a sibling check
964 siblingCheck( a, bp[i], -1 ) :
965 siblingCheck( ap[i], b, 1 );
968 siblingCheck = function( a, b, ret ) {
973 var cur = a.nextSibling;
980 cur = cur.nextSibling;
987 // Utility function for retreiving the text value of an array of DOM nodes
988 Sizzle.getText = function( elems ) {
991 for ( var i = 0; elems[i]; i++ ) {
994 // Get the text from text nodes and CDATA nodes
995 if ( elem.nodeType === 3 || elem.nodeType === 4 ) {
996 ret += elem.nodeValue;
998 // Traverse everything else, except comment nodes
999 } else if ( elem.nodeType !== 8 ) {
1000 ret += Sizzle.getText( elem.childNodes );
1007 // Check to see if the browser returns elements by name when
1008 // querying by getElementById (and provide a workaround)
1010 // We're going to inject a fake input element with a specified name
1011 var form = document.createElement("div"),
1012 id = "script" + (new Date()).getTime(),
1013 root = document.documentElement;
1015 form.innerHTML = "<a name='" + id + "'/>";
1017 // Inject it into the root element, check its status, and remove it quickly
1018 root.insertBefore( form, root.firstChild );
1020 // The workaround has to do additional checks after a getElementById
1021 // Which slows things down for other browsers (hence the branching)
1022 if ( document.getElementById( id ) ) {
1023 Expr.find.ID = function( match, context, isXML ) {
1024 if ( typeof context.getElementById !== "undefined" && !isXML ) {
1025 var m = context.getElementById(match[1]);
1028 m.id === match[1] || typeof m.getAttributeNode !== "undefined" && m.getAttributeNode("id").nodeValue === match[1] ?
1035 Expr.filter.ID = function( elem, match ) {
1036 var node = typeof elem.getAttributeNode !== "undefined" && elem.getAttributeNode("id");
1038 return elem.nodeType === 1 && node && node.nodeValue === match;
1042 root.removeChild( form );
1044 // release memory in IE
1049 // Check to see if the browser returns only elements
1050 // when doing getElementsByTagName("*")
1052 // Create a fake element
1053 var div = document.createElement("div");
1054 div.appendChild( document.createComment("") );
1056 // Make sure no comments are found
1057 if ( div.getElementsByTagName("*").length > 0 ) {
1058 Expr.find.TAG = function( match, context ) {
1059 var results = context.getElementsByTagName( match[1] );
1061 // Filter out possible comments
1062 if ( match[1] === "*" ) {
1065 for ( var i = 0; results[i]; i++ ) {
1066 if ( results[i].nodeType === 1 ) {
1067 tmp.push( results[i] );
1078 // Check to see if an attribute returns normalized href attributes
1079 div.innerHTML = "<a href='#'></a>";
1081 if ( div.firstChild && typeof div.firstChild.getAttribute !== "undefined" &&
1082 div.firstChild.getAttribute("href") !== "#" ) {
1084 Expr.attrHandle.href = function( elem ) {
1085 return elem.getAttribute( "href", 2 );
1089 // release memory in IE
1093 if ( document.querySelectorAll ) {
1095 var oldSizzle = Sizzle,
1096 div = document.createElement("div"),
1099 div.innerHTML = "<p class='TEST'></p>";
1101 // Safari can't handle uppercase or unicode characters when
1103 if ( div.querySelectorAll && div.querySelectorAll(".TEST").length === 0 ) {
1107 Sizzle = function( query, context, extra, seed ) {
1108 context = context || document;
1110 // Only use querySelectorAll on non-XML documents
1111 // (ID selectors don't work in non-HTML documents)
1112 if ( !seed && !Sizzle.isXML(context) ) {
1113 // See if we find a selector to speed up
1114 var match = /^(\w+$)|^\.([\w\-]+$)|^#([\w\-]+$)/.exec( query );
1116 if ( match && (context.nodeType === 1 || context.nodeType === 9) ) {
1117 // Speed-up: Sizzle("TAG")
1119 return makeArray( context.getElementsByTagName( query ), extra );
1121 // Speed-up: Sizzle(".CLASS")
1122 } else if ( match[2] && Expr.find.CLASS && context.getElementsByClassName ) {
1123 return makeArray( context.getElementsByClassName( match[2] ), extra );
1127 if ( context.nodeType === 9 ) {
1128 // Speed-up: Sizzle("body")
1129 // The body element only exists once, optimize finding it
1130 if ( query === "body" && context.body ) {
1131 return makeArray( [ context.body ], extra );
1133 // Speed-up: Sizzle("#ID")
1134 } else if ( match && match[3] ) {
1135 var elem = context.getElementById( match[3] );
1137 // Check parentNode to catch when Blackberry 4.6 returns
1138 // nodes that are no longer in the document #6963
1139 if ( elem && elem.parentNode ) {
1140 // Handle the case where IE and Opera return items
1141 // by name instead of ID
1142 if ( elem.id === match[3] ) {
1143 return makeArray( [ elem ], extra );
1147 return makeArray( [], extra );
1152 return makeArray( context.querySelectorAll(query), extra );
1153 } catch(qsaError) {}
1155 // qSA works strangely on Element-rooted queries
1156 // We can work around this by specifying an extra ID on the root
1157 // and working up from there (Thanks to Andrew Dupont for the technique)
1158 // IE 8 doesn't work on object elements
1159 } else if ( context.nodeType === 1 && context.nodeName.toLowerCase() !== "object" ) {
1160 var oldContext = context,
1161 old = context.getAttribute( "id" ),
1163 hasParent = context.parentNode,
1164 relativeHierarchySelector = /^\s*[+~]/.test( query );
1167 context.setAttribute( "id", nid );
1169 nid = nid.replace( /'/g, "\\$&" );
1171 if ( relativeHierarchySelector && hasParent ) {
1172 context = context.parentNode;
1176 if ( !relativeHierarchySelector || hasParent ) {
1177 return makeArray( context.querySelectorAll( "[id='" + nid + "'] " + query ), extra );
1180 } catch(pseudoError) {
1183 oldContext.removeAttribute( "id" );
1189 return oldSizzle(query, context, extra, seed);
1192 for ( var prop in oldSizzle ) {
1193 Sizzle[ prop ] = oldSizzle[ prop ];
1196 // release memory in IE
1202 var html = document.documentElement,
1203 matches = html.matchesSelector || html.mozMatchesSelector || html.webkitMatchesSelector || html.msMatchesSelector,
1204 pseudoWorks = false;
1207 // This should fail with an exception
1208 // Gecko does not error, returns false instead
1209 matches.call( document.documentElement, "[test!='']:sizzle" );
1211 } catch( pseudoError ) {
1216 Sizzle.matchesSelector = function( node, expr ) {
1217 // Make sure that attribute selectors are quoted
1218 expr = expr.replace(/\=\s*([^'"\]]*)\s*\]/g, "='$1']");
1220 if ( !Sizzle.isXML( node ) ) {
1222 if ( pseudoWorks || !Expr.match.PSEUDO.test( expr ) && !/!=/.test( expr ) ) {
1223 return matches.call( node, expr );
1228 return Sizzle(expr, null, null, [node]).length > 0;
1234 var div = document.createElement("div");
1236 div.innerHTML = "<div class='test e'></div><div class='test'></div>";
1238 // Opera can't find a second classname (in 9.6)
1239 // Also, make sure that getElementsByClassName actually exists
1240 if ( !div.getElementsByClassName || div.getElementsByClassName("e").length === 0 ) {
1244 // Safari caches class attributes, doesn't catch changes (in 3.2)
1245 div.lastChild.className = "e";
1247 if ( div.getElementsByClassName("e").length === 1 ) {
1251 Expr.order.splice(1, 0, "CLASS");
1252 Expr.find.CLASS = function( match, context, isXML ) {
1253 if ( typeof context.getElementsByClassName !== "undefined" && !isXML ) {
1254 return context.getElementsByClassName(match[1]);
1258 // release memory in IE
1262 function dirNodeCheck( dir, cur, doneName, checkSet, nodeCheck, isXML ) {
1263 for ( var i = 0, l = checkSet.length; i < l; i++ ) {
1264 var elem = checkSet[i];
1272 if ( elem.sizcache === doneName ) {
1273 match = checkSet[elem.sizset];
1277 if ( elem.nodeType === 1 && !isXML ){
1278 elem.sizcache = doneName;
1282 if ( elem.nodeName.toLowerCase() === cur ) {
1290 checkSet[i] = match;
1295 function dirCheck( dir, cur, doneName, checkSet, nodeCheck, isXML ) {
1296 for ( var i = 0, l = checkSet.length; i < l; i++ ) {
1297 var elem = checkSet[i];
1305 if ( elem.sizcache === doneName ) {
1306 match = checkSet[elem.sizset];
1310 if ( elem.nodeType === 1 ) {
1312 elem.sizcache = doneName;
1316 if ( typeof cur !== "string" ) {
1317 if ( elem === cur ) {
1322 } else if ( Sizzle.filter( cur, [elem] ).length > 0 ) {
1331 checkSet[i] = match;
1336 if ( document.documentElement.contains ) {
1337 Sizzle.contains = function( a, b ) {
1338 return a !== b && (a.contains ? a.contains(b) : true);
1341 } else if ( document.documentElement.compareDocumentPosition ) {
1342 Sizzle.contains = function( a, b ) {
1343 return !!(a.compareDocumentPosition(b) & 16);
1347 Sizzle.contains = function() {
1352 Sizzle.isXML = function( elem ) {
1353 // documentElement is verified for cases where it doesn't yet exist
1354 // (such as loading iframes in IE - #4833)
1355 var documentElement = (elem ? elem.ownerDocument || elem : 0).documentElement;
1357 return documentElement ? documentElement.nodeName !== "HTML" : false;
1360 var posProcess = function( selector, context ) {
1364 root = context.nodeType ? [context] : context;
1366 // Position selectors must be done after the filter
1367 // And so must :not(positional) so we move all PSEUDOs to the end
1368 while ( (match = Expr.match.PSEUDO.exec( selector )) ) {
1370 selector = selector.replace( Expr.match.PSEUDO, "" );
1373 selector = Expr.relative[selector] ? selector + "*" : selector;
1375 for ( var i = 0, l = root.length; i < l; i++ ) {
1376 Sizzle( selector, root[i], tmpSet );
1379 return Sizzle.filter( later, tmpSet );
1383 jQuery.find = Sizzle;
1384 jQuery.expr = Sizzle.selectors;
1385 jQuery.expr[":"] = jQuery.expr.filters;
1386 jQuery.unique = Sizzle.uniqueSort;
1387 jQuery.text = Sizzle.getText;
1388 jQuery.isXMLDoc = Sizzle.isXML;
1389 jQuery.contains = Sizzle.contains;