11/*!
2- * Sizzle CSS Selector Engine v2.0.0
2+ * Sizzle CSS Selector Engine v2.1.1
33 * http://sizzlejs.com/
44 *
55 * Copyright 2008, 2014 jQuery Foundation, Inc. and other contributors
66 * Released under the MIT license
77 * http://jquery.org/license
88 *
9- * Date: 2014-07-01
9+ * Date: 2014-12-15
1010 */
1111( function ( window ) {
1212
3333 contains ,
3434
3535 // Instance-specific data
36- expando = "sizzle" + - ( new Date ( ) ) ,
36+ expando = "sizzle" + 1 * new Date ( ) ,
3737 preferredDoc = window . document ,
3838 dirruns = 0 ,
3939 done = 0 ,
4848 } ,
4949
5050 // General-purpose constants
51- strundefined = typeof undefined ,
5251 MAX_NEGATIVE = 1 << 31 ,
5352
5453 // Instance methods
@@ -58,12 +57,13 @@ var i,
5857 push_native = arr . push ,
5958 push = arr . push ,
6059 slice = arr . slice ,
61- // Use a stripped-down indexOf if we can't use a native one
62- indexOf = arr . indexOf || function ( elem ) {
60+ // Use a stripped-down indexOf as it's faster than native
61+ // http://jsperf.com/thor-indexof-vs-for/5
62+ indexOf = function ( list , elem ) {
6363 var i = 0 ,
64- len = this . length ;
64+ len = list . length ;
6565 for ( ; i < len ; i ++ ) {
66- if ( this [ i ] === elem ) {
66+ if ( list [ i ] === elem ) {
6767 return i ;
6868 }
6969 }
9999 ")\\)|)" ,
100100
101101 // Leading and non-escaped trailing whitespace, capturing some non-whitespace characters preceding the latter
102+ rwhitespace = new RegExp ( whitespace + "+" , "g" ) ,
102103 rtrim = new RegExp ( "^" + whitespace + "+|((?:^|[^\\\\])(?:\\\\.)*)" + whitespace + "+$" , "g" ) ,
103104
104105 rcomma = new RegExp ( "^" + whitespace + "*," + whitespace + "*" ) ,
@@ -150,6 +151,14 @@ var i,
150151 String . fromCharCode ( high + 0x10000 ) :
151152 // Supplemental Plane codepoint (surrogate pair)
152153 String . fromCharCode ( high >> 10 | 0xD800 , high & 0x3FF | 0xDC00 ) ;
154+ } ,
155+
156+ // Used for iframes
157+ // See setDocument()
158+ // Removing the function wrapper causes a "Permission Denied"
159+ // error in IE
160+ unloadHandler = function ( ) {
161+ setDocument ( ) ;
153162 } ;
154163
155164// Optimize for push.apply( _, NodeList )
@@ -197,14 +206,14 @@ function Sizzle( selector, context, results, seed ) {
197206 return results ;
198207 }
199208
200- if ( ( nodeType = context . nodeType ) !== 1 && nodeType !== 9 ) {
209+ if ( ( nodeType = context . nodeType ) !== 1 && nodeType !== 9 && nodeType !== 11 ) {
201210 return [ ] ;
202211 }
203212
204213 if ( documentIsHTML && ! seed ) {
205214
206- // Shortcuts
207- if ( ( match = rquickExpr . exec ( selector ) ) ) {
215+ // Try to shortcut find operations when possible (e.g., not under DocumentFragment)
216+ if ( nodeType !== 11 && ( match = rquickExpr . exec ( selector ) ) ) {
208217 // Speed-up: Sizzle("#ID")
209218 if ( ( m = match [ 1 ] ) ) {
210219 if ( nodeType === 9 ) {
@@ -246,7 +255,7 @@ function Sizzle( selector, context, results, seed ) {
246255 if ( support . qsa && ( ! rbuggyQSA || ! rbuggyQSA . test ( selector ) ) ) {
247256 nid = old = expando ;
248257 newContext = context ;
249- newSelector = nodeType === 9 && selector ;
258+ newSelector = nodeType !== 1 && selector ;
250259
251260 // qSA works strangely on Element-rooted queries
252261 // We can work around this by specifying an extra ID on the root
@@ -433,7 +442,7 @@ function createPositionalPseudo( fn ) {
433442 * @returns {Element|Object|Boolean } The input node if acceptable, otherwise a falsy value
434443 */
435444function testContext ( context ) {
436- return context && typeof context . getElementsByTagName !== strundefined && context ;
445+ return context && typeof context . getElementsByTagName !== "undefined" && context ;
437446}
438447
439448// Expose support vars for convenience
@@ -457,9 +466,8 @@ isXML = Sizzle.isXML = function( elem ) {
457466 * @returns {Object } Returns the current document
458467 */
459468setDocument = Sizzle . setDocument = function ( node ) {
460- var hasCompare ,
461- doc = node ? node . ownerDocument || node : preferredDoc ,
462- parent = doc . defaultView ;
469+ var hasCompare , parent ,
470+ doc = node ? node . ownerDocument || node : preferredDoc ;
463471
464472 // If no document and documentElement is available, return
465473 if ( doc === document || doc . nodeType !== 9 || ! doc . documentElement ) {
@@ -469,9 +477,7 @@ setDocument = Sizzle.setDocument = function( node ) {
469477 // Set our document
470478 document = doc ;
471479 docElem = doc . documentElement ;
472-
473- // Support tests
474- documentIsHTML = ! isXML ( doc ) ;
480+ parent = doc . defaultView ;
475481
476482 // Support: IE>8
477483 // If iframe document is assigned to "document" variable and if iframe has been reloaded,
@@ -480,21 +486,22 @@ setDocument = Sizzle.setDocument = function( node ) {
480486 if ( parent && parent !== parent . top ) {
481487 // IE11 does not have attachEvent, so all must suffer
482488 if ( parent . addEventListener ) {
483- parent . addEventListener ( "unload" , function ( ) {
484- setDocument ( ) ;
485- } , false ) ;
489+ parent . addEventListener ( "unload" , unloadHandler , false ) ;
486490 } else if ( parent . attachEvent ) {
487- parent . attachEvent ( "onunload" , function ( ) {
488- setDocument ( ) ;
489- } ) ;
491+ parent . attachEvent ( "onunload" , unloadHandler ) ;
490492 }
491493 }
492494
495+ /* Support tests
496+ ---------------------------------------------------------------------- */
497+ documentIsHTML = ! isXML ( doc ) ;
498+
493499 /* Attributes
494500 ---------------------------------------------------------------------- */
495501
496502 // Support: IE<8
497- // Verify that getAttribute really returns attributes and not properties (excepting IE8 booleans)
503+ // Verify that getAttribute really returns attributes and not properties
504+ // (excepting IE8 booleans)
498505 support . attributes = assert ( function ( div ) {
499506 div . className = "i" ;
500507 return ! div . getAttribute ( "className" ) ;
@@ -524,7 +531,7 @@ setDocument = Sizzle.setDocument = function( node ) {
524531 // ID find and filter
525532 if ( support . getById ) {
526533 Expr . find [ "ID" ] = function ( id , context ) {
527- if ( typeof context . getElementById !== strundefined && documentIsHTML ) {
534+ if ( typeof context . getElementById !== "undefined" && documentIsHTML ) {
528535 var m = context . getElementById ( id ) ;
529536 // Check parentNode to catch when Blackberry 4.6 returns
530537 // nodes that are no longer in the document #6963
@@ -545,7 +552,7 @@ setDocument = Sizzle.setDocument = function( node ) {
545552 Expr . filter [ "ID" ] = function ( id ) {
546553 var attrId = id . replace ( runescape , funescape ) ;
547554 return function ( elem ) {
548- var node = typeof elem . getAttributeNode !== strundefined && elem . getAttributeNode ( "id" ) ;
555+ var node = typeof elem . getAttributeNode !== "undefined" && elem . getAttributeNode ( "id" ) ;
549556 return node && node . value === attrId ;
550557 } ;
551558 } ;
@@ -554,14 +561,20 @@ setDocument = Sizzle.setDocument = function( node ) {
554561 // Tag
555562 Expr . find [ "TAG" ] = support . getElementsByTagName ?
556563 function ( tag , context ) {
557- if ( typeof context . getElementsByTagName !== strundefined ) {
564+ if ( typeof context . getElementsByTagName !== "undefined" ) {
558565 return context . getElementsByTagName ( tag ) ;
566+
567+ // DocumentFragment nodes don't have gEBTN
568+ } else if ( support . qsa ) {
569+ return context . querySelectorAll ( tag ) ;
559570 }
560571 } :
572+
561573 function ( tag , context ) {
562574 var elem ,
563575 tmp = [ ] ,
564576 i = 0 ,
577+ // By happy coincidence, a (broken) gEBTN appears on DocumentFragment nodes too
565578 results = context . getElementsByTagName ( tag ) ;
566579
567580 // Filter out possible comments
@@ -608,7 +621,9 @@ setDocument = Sizzle.setDocument = function( node ) {
608621 // setting a boolean content attribute,
609622 // since its presence should be enough
610623 // http://bugs.jquery.com/ticket/12359
611- div . innerHTML = "<select msallowcapture=''><option selected=''></option></select>" ;
624+ docElem . appendChild ( div ) . innerHTML = "<a id='" + expando + "'></a>" +
625+ "<select id='" + expando + "-\f]' msallowcapture=''>" +
626+ "<option selected=''></option></select>" ;
612627
613628 // Support: IE8, Opera 11-12.16
614629 // Nothing should be selected when empty strings follow ^= or $= or *=
@@ -624,12 +639,24 @@ setDocument = Sizzle.setDocument = function( node ) {
624639 rbuggyQSA . push ( "\\[" + whitespace + "*(?:value|" + booleans + ")" ) ;
625640 }
626641
642+ // Support: Chrome<29, Android<4.2+, Safari<7.0+, iOS<7.0+, PhantomJS<1.9.7+
643+ if ( ! div . querySelectorAll ( "[id~=" + expando + "-]" ) . length ) {
644+ rbuggyQSA . push ( "~=" ) ;
645+ }
646+
627647 // Webkit/Opera - :checked should return selected option elements
628648 // http://www.w3.org/TR/2011/REC-css3-selectors-20110929/#checked
629649 // IE8 throws error here and will not see later tests
630650 if ( ! div . querySelectorAll ( ":checked" ) . length ) {
631651 rbuggyQSA . push ( ":checked" ) ;
632652 }
653+
654+ // Support: Safari 8+, iOS 8+
655+ // https://bugs.webkit.org/show_bug.cgi?id=136851
656+ // In-page `selector#id sibing-combinator selector` fails
657+ if ( ! div . querySelectorAll ( "a#" + expando + "+*" ) . length ) {
658+ rbuggyQSA . push ( ".#.+[+~]" ) ;
659+ }
633660 } ) ;
634661
635662 assert ( function ( div ) {
@@ -746,7 +773,7 @@ setDocument = Sizzle.setDocument = function( node ) {
746773
747774 // Maintain original order
748775 return sortInput ?
749- ( indexOf . call ( sortInput , a ) - indexOf . call ( sortInput , b ) ) :
776+ ( indexOf ( sortInput , a ) - indexOf ( sortInput , b ) ) :
750777 0 ;
751778 }
752779
@@ -773,7 +800,7 @@ setDocument = Sizzle.setDocument = function( node ) {
773800 aup ? - 1 :
774801 bup ? 1 :
775802 sortInput ?
776- ( indexOf . call ( sortInput , a ) - indexOf . call ( sortInput , b ) ) :
803+ ( indexOf ( sortInput , a ) - indexOf ( sortInput , b ) ) :
777804 0 ;
778805
779806 // If the nodes are siblings, we can do a quick check
@@ -836,7 +863,7 @@ Sizzle.matchesSelector = function( elem, expr ) {
836863 elem . document && elem . document . nodeType !== 11 ) {
837864 return ret ;
838865 }
839- } catch ( e ) { }
866+ } catch ( e ) { }
840867 }
841868
842869 return Sizzle ( expr , document , null , [ elem ] ) . length > 0 ;
@@ -1055,7 +1082,7 @@ Expr = Sizzle.selectors = {
10551082 return pattern ||
10561083 ( pattern = new RegExp ( "(^|" + whitespace + ")" + className + "(" + whitespace + "|$)" ) ) &&
10571084 classCache ( className , function ( elem ) {
1058- return pattern . test ( typeof elem . className === "string" && elem . className || typeof elem . getAttribute !== strundefined && elem . getAttribute ( "class" ) || "" ) ;
1085+ return pattern . test ( typeof elem . className === "string" && elem . className || typeof elem . getAttribute !== "undefined" && elem . getAttribute ( "class" ) || "" ) ;
10591086 } ) ;
10601087 } ,
10611088
@@ -1077,7 +1104,7 @@ Expr = Sizzle.selectors = {
10771104 operator === "^=" ? check && result . indexOf ( check ) === 0 :
10781105 operator === "*=" ? check && result . indexOf ( check ) > - 1 :
10791106 operator === "$=" ? check && result . slice ( - check . length ) === check :
1080- operator === "~=" ? ( " " + result + " " ) . indexOf ( check ) > - 1 :
1107+ operator === "~=" ? ( " " + result . replace ( rwhitespace , " " ) + " " ) . indexOf ( check ) > - 1 :
10811108 operator === "|=" ? result === check || result . slice ( 0 , check . length + 1 ) === check + "-" :
10821109 false ;
10831110 } ;
@@ -1197,7 +1224,7 @@ Expr = Sizzle.selectors = {
11971224 matched = fn ( seed , argument ) ,
11981225 i = matched . length ;
11991226 while ( i -- ) {
1200- idx = indexOf . call ( seed , matched [ i ] ) ;
1227+ idx = indexOf ( seed , matched [ i ] ) ;
12011228 seed [ idx ] = ! ( matches [ idx ] = matched [ i ] ) ;
12021229 }
12031230 } ) :
@@ -1236,6 +1263,8 @@ Expr = Sizzle.selectors = {
12361263 function ( elem , context , xml ) {
12371264 input [ 0 ] = elem ;
12381265 matcher ( input , null , xml , results ) ;
1266+ // Don't keep the element (issue #299)
1267+ input [ 0 ] = null ;
12391268 return ! results . pop ( ) ;
12401269 } ;
12411270 } ) ,
@@ -1669,7 +1698,7 @@ function setMatcher( preFilter, selector, matcher, postFilter, postFinder, postS
16691698 i = matcherOut . length ;
16701699 while ( i -- ) {
16711700 if ( ( elem = matcherOut [ i ] ) &&
1672- ( temp = postFinder ? indexOf . call ( seed , elem ) : preMap [ i ] ) > - 1 ) {
1701+ ( temp = postFinder ? indexOf ( seed , elem ) : preMap [ i ] ) > - 1 ) {
16731702
16741703 seed [ temp ] = ! ( results [ temp ] = elem ) ;
16751704 }
@@ -1704,13 +1733,16 @@ function matcherFromTokens( tokens ) {
17041733 return elem === checkContext ;
17051734 } , implicitRelative , true ) ,
17061735 matchAnyContext = addCombinator ( function ( elem ) {
1707- return indexOf . call ( checkContext , elem ) > - 1 ;
1736+ return indexOf ( checkContext , elem ) > - 1 ;
17081737 } , implicitRelative , true ) ,
17091738 matchers = [ function ( elem , context , xml ) {
1710- return ( ! leadingRelative && ( xml || context !== outermostContext ) ) || (
1739+ var ret = ( ! leadingRelative && ( xml || context !== outermostContext ) ) || (
17111740 ( checkContext = context ) . nodeType ?
17121741 matchContext ( elem , context , xml ) :
17131742 matchAnyContext ( elem , context , xml ) ) ;
1743+ // Avoid hanging onto element (issue #299)
1744+ checkContext = null ;
1745+ return ret ;
17141746 } ] ;
17151747
17161748 for ( ; i < len ; i ++ ) {
0 commit comments