*/
(function(){
-var chunker = /((?:\((?:\([^()]+\)|[^()]+)+\)|\[(?:\[[^[\]]+\]|[^[\]]+)+\]|\\.|[^ >+~,(\[]+)+|[>+~])(\s*,\s*)?/g;
+var chunker = /((?:\((?:\([^()]+\)|[^()]+)+\)|\[(?:\[[^[\]]*\]|[^[\]]+)+\]|\\.|[^ >+~,(\[]+)+|[>+~])(\s*,\s*)?/g;
var done = 0;
return results;
}
- var parts = [], m, set, checkSet, check, mode, extra;
+ var parts = [], m, set, checkSet, check, mode, extra, prune = true;
// Reset the position of the chunker regexp (start from head)
chunker.lastIndex = 0;
if ( parts.length > 0 ) {
checkSet = makeArray(set);
+ } else {
+ prune = false;
}
while ( parts.length ) {
}
if ( checkSet instanceof Array ) {
- if ( context.nodeType === 1 ) {
+ if ( !prune ) {
+ results.push.apply( results, checkSet );
+ } else if ( context.nodeType === 1 ) {
for ( var i = 0; checkSet[i] != null; i++ ) {
if ( checkSet[i] && (checkSet[i] === true || checkSet[i].nodeType === 1 && contains(context, checkSet[i])) ) {
results.push( set[i] );
}
if ( extra ) {
- Sizzle( extra, context, results );
+ Sizzle( extra, context, results, seed );
}
return results;
return [];
}
- var later = "", match;
-
- // Pseudo-selectors could contain other selectors (like :not)
- while ( (match = Expr.match.PSEUDO.exec( expr )) ) {
- var left = RegExp.leftContext;
-
- if ( left.substr( left.length - 1 ) !== "\\" ) {
- later += match[0];
- expr = expr.replace( Expr.match.PSEUDO, "" );
- } else {
- // TODO: Need a better solution, fails: .class\:foo:realfoo(#id)
- break;
- }
- }
-
for ( var i = 0, l = Expr.order.length; i < l; i++ ) {
- var type = Expr.order[i];
+ var type = Expr.order[i], match;
if ( (match = Expr.match[ type ].exec( expr )) ) {
var left = RegExp.leftContext;
if ( left.substr( left.length - 1 ) !== "\\" ) {
match[1] = (match[1] || "").replace(/\\/g, "");
set = Expr.find[ type ]( match, context );
-
if ( set != null ) {
expr = expr.replace( Expr.match[ type ], "" );
break;
set = context.getElementsByTagName("*");
}
- expr += later;
-
return {set: set, expr: expr};
};
-Sizzle.filter = function(expr, set, inplace){
- var old = expr, result = [], curLoop = set, match;
+Sizzle.filter = function(expr, set, inplace, not){
+ var old = expr, result = [], curLoop = set, match, anyFound;
while ( expr && set.length ) {
for ( var type in Expr.filter ) {
if ( (match = Expr.match[ type ].exec( expr )) != null ) {
- var anyFound = false, filter = Expr.filter[ type ], goodArray = null;
+ var filter = Expr.filter[ type ], goodArray = null, goodPos = 0, found, item;
+ anyFound = false;
if ( curLoop == result ) {
result = [];
}
if ( Expr.preFilter[ type ] ) {
- match = Expr.preFilter[ type ]( match, curLoop );
+ match = Expr.preFilter[ type ]( match, curLoop, inplace, result, not );
- if ( match[0] === true ) {
+ if ( !match ) {
+ anyFound = found = true;
+ } else if ( match[0] === true ) {
goodArray = [];
var last = null, elem;
for ( var i = 0; (elem = curLoop[i]) !== undefined; i++ ) {
}
}
}
-
}
- var goodPos = 0, found, item;
-
- for ( var i = 0; (item = curLoop[i]) !== undefined; i++ ) {
- if ( item ) {
- if ( goodArray && item != goodArray[goodPos] ) {
- goodPos++;
- }
-
- found = filter( item, match, goodPos, goodArray );
- if ( inplace && found != null ) {
- curLoop[i] = found ? curLoop[i] : false;
- if ( found ) {
+ if ( match ) {
+ for ( var i = 0; (item = curLoop[i]) !== undefined; i++ ) {
+ if ( item ) {
+ if ( goodArray && item != goodArray[goodPos] ) {
+ goodPos++;
+ }
+
+ found = filter( item, match, goodPos, goodArray );
+ var pass = not ^ !!found;
+
+ if ( inplace && found != null ) {
+ if ( pass ) {
+ anyFound = true;
+ } else {
+ curLoop[i] = false;
+ }
+ } else if ( pass ) {
+ result.push( item );
anyFound = true;
}
- } else if ( found ) {
- result.push( item );
- anyFound = true;
}
}
}
}
}
-
expr = expr.replace(/\s*,\s*/, "");
// Improper expression
if ( expr == old ) {
- throw "Syntax error, unrecognized expression: " + expr;
+ if ( anyFound == null ) {
+ throw "Syntax error, unrecognized expression: " + expr;
+ } else {
+ break;
+ }
}
old = expr;
match: {
ID: /#((?:[\w\u0128-\uFFFF_-]|\\.)+)/,
CLASS: /\.((?:[\w\u0128-\uFFFF_-]|\\.)+)/,
- NAME: /\[name=((?:[\w\u0128-\uFFFF_-]|\\.)+)\]/,
- ATTR: /\[((?:[\w\u0128-\uFFFF_-]|\\.)+)\s*(?:(\S{0,1}=)\s*(['"]*)(.*?)\3|)\]/,
+ NAME: /\[name=['"]*((?:[\w\u0128-\uFFFF_-]|\\.)+)['"]*\]/,
+ ATTR: /\[((?:[\w\u0128-\uFFFF_-]|\\.)+)\s*(?:(\S?=)\s*(['"]*)(.*?)\3|)\]/,
TAG: /^((?:[\w\u0128-\uFFFF\*_-]|\\.)+)/,
CHILD: /:(only|nth|last|first)-child\(?(even|odd|[\dn+-]*)\)?/,
POS: /:(nth|eq|gt|lt|first|last|even|odd)\(?(\d*)\)?(?:[^-]|$)/,
}
},
NAME: function(match, context){
- return context.getElementsByName(match[1]);
+ return context.getElementsByName ? context.getElementsByName(match[1]) : null;
},
TAG: function(match, context){
return context.getElementsByTagName(match[1]);
}
},
preFilter: {
- CLASS: function(match){
- return new RegExp( "(?:^|\\s)" + match[1] + "(?:\\s|$)" );
+ CLASS: function(match, curLoop, inplace, result, not){
+ match = " " + match[1].replace(/\\/g, "") + " ";
+
+ for ( var i = 0; curLoop[i]; i++ ) {
+ if ( not ^ (" " + curLoop[i].className + " ").indexOf(match) >= 0 ) {
+ if ( !inplace )
+ result.push( curLoop[i] );
+ } else if ( inplace ) {
+ curLoop[i] = false;
+ }
+ }
+
+ return false;
},
ID: function(match){
return match[1];
return match;
},
- PSEUDO: function(match){
+ PSEUDO: function(match, curLoop, inplace, result, not){
if ( match[1] === "not" ) {
- match[3] = match[3].split(/\s*,\s*/);
+ // If we're dealing with a complex expression, or a simple one
+ if ( match[3].match(chunker).length > 1 ) {
+ match[3] = Sizzle(match[3], null, null, curLoop);
+ } else {
+ var ret = Sizzle.filter(match[3], curLoop, inplace, true ^ not);
+ if ( !inplace ) {
+ result.push.apply( result, ret );
+ }
+ return false;
+ }
}
return match;
var name = match[1], filter = Expr.filters[ name ];
if ( filter ) {
- return filter( elem, i, match, array )
+ return filter( elem, i, match, array );
} else if ( name === "contains" ) {
return (elem.textContent || elem.innerText || "").indexOf(match[3]) >= 0;
} else if ( name === "not" ) {
var not = match[3];
for ( var i = 0, l = not.length; i < l; i++ ) {
- if ( Sizzle.filter(not[i], [elem]).length > 0 ) {
+ if ( not[i] === elem ) {
return false;
}
}
}
};
+for ( var type in Expr.match ) {
+ Expr.match[ type ] = RegExp( Expr.match[ type ].source + /(?![^\[]*\])(?![^\(]*\))/.source );
+}
+
var makeArray = function(array, results) {
array = Array.prototype.slice.call( array );
if ( document.querySelectorAll ) (function(){
var oldSizzle = Sizzle;
- Sizzle = function(query, context, extra){
+ Sizzle = function(query, context, extra, seed){
context = context || document;
- if ( context.nodeType === 9 ) {
+ if ( !seed && context.nodeType === 9 ) {
try {
- return makeArray( context.querySelectorAll(query) );
+ return makeArray( context.querySelectorAll(query), extra );
} catch(e){}
}
- return oldSizzle(query, context, extra);
+ return oldSizzle(query, context, extra, seed);
};
Sizzle.find = oldSizzle.find;
Sizzle.filter = oldSizzle.filter;
Sizzle.selectors = oldSizzle.selectors;
+ Sizzle.matches = oldSizzle.matches;
})();
if ( document.documentElement.getElementsByClassName ) {
for ( var i = 0, l = checkSet.length; i < l; i++ ) {
var elem = checkSet[i];
if ( elem ) {
- elem = elem[dir]
+ elem = elem[dir];
var match = false;
while ( elem && elem.nodeType ) {
for ( var i = 0, l = checkSet.length; i < l; i++ ) {
var elem = checkSet[i];
if ( elem ) {
- elem = elem[dir]
+ elem = elem[dir];
var match = false;
while ( elem && elem.nodeType ) {
var contains = document.compareDocumentPosition ? function(a, b){
return a.compareDocumentPosition(b) & 16;
} : function(a, b){
- return a !== b && a.contains(b);
+ return a !== b && (a.contains ? a.contains(b) : true);
};
// EXPOSE
jQuery.css(elem, "visibility") !== "hidden";
};
+Sizzle.selectors.filters.animated = function(elem){
+ return jQuery.grep(jQuery.timers, function(fn){
+ return elem === fn.elem;
+ }).length;
+};
+
jQuery.multiFilter = function( expr, elems, not ) {
if ( not ) {
- return jQuery.multiFilter( ":not(" + expr + ")", elems );
+ expr = ":not(" + expr + ")";
}
- var exprs = expr.split(/\s*,\s*/), cur = [];
-
- for ( var i = 0; i < exprs.length; i++ ) {
- cur = jQuery.merge( cur, jQuery.filter( exprs[i], elems ) );
- }
-
- return cur;
+ return Sizzle.matches(expr, elems);
};
jQuery.dir = function( elem, dir ){