X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=src%2Fselector.js;h=fcab67fbecdd19456e537348b88783f505bc4d58;hb=f8ef75eb9124ce924be5fb521c783efd5c996e33;hp=e58b2571cbc598f028e7fb97f931402760ad1661;hpb=410e13b40097fa6b26ce9a27f865ff258efa23b4;p=jquery.git
diff --git a/src/selector.js b/src/selector.js
index e58b257..fcab67f 100644
--- a/src/selector.js
+++ b/src/selector.js
@@ -8,10 +8,7 @@
var chunker = /((?:\((?:\([^()]+\)|[^()]+)+\)|\[(?:\[[^[\]]*\]|['"][^'"]*['"]|[^[\]'"]+)+\]|\\.|[^ >+~,(\[\\]+)+|[>+~])(\s*,\s*)?/g,
done = 0,
- toString = Object.prototype.toString,
- arraySplice = Array.prototype.splice,
- arrayPush = Array.prototype.push,
- arraySort = Array.prototype.sort;
+ toString = Object.prototype.toString;
var Sizzle = function(selector, context, results, seed) {
results = results || [];
@@ -20,19 +17,19 @@ var Sizzle = function(selector, context, results, seed) {
if ( context.nodeType !== 1 && context.nodeType !== 9 ) {
return [];
}
-
+
if ( !selector || typeof selector !== "string" ) {
return results;
}
var parts = [], m, set, checkSet, check, mode, extra, prune = true, contextXML = isXML(context);
-
+
// Reset the position of the chunker regexp (start from head)
chunker.lastIndex = 0;
-
+
while ( (m = chunker.exec(selector)) !== null ) {
parts.push( m[1] );
-
+
if ( m[2] ) {
extra = RegExp.rightContext;
break;
@@ -107,17 +104,17 @@ var Sizzle = function(selector, context, results, seed) {
if ( toString.call(checkSet) === "[object Array]" ) {
if ( !prune ) {
- arrayPush.apply( results, checkSet );
+ results.push.apply( results, checkSet );
} else if ( context && 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])) ) {
- arrayPush.call( results, set[i] );
+ results.push( set[i] );
}
}
} else {
for ( var i = 0; checkSet[i] != null; i++ ) {
if ( checkSet[i] && checkSet[i].nodeType === 1 ) {
- arrayPush.call( results, set[i] );
+ results.push( set[i] );
}
}
}
@@ -136,12 +133,12 @@ var Sizzle = function(selector, context, results, seed) {
Sizzle.uniqueSort = function(results){
if ( sortOrder ) {
hasDuplicate = false;
- arraySort.call(results, sortOrder);
+ results.sort(sortOrder);
if ( hasDuplicate ) {
for ( var i = 1; i < results.length; i++ ) {
if ( results[i] === results[i-1] ) {
- arraySplice.call(results, i--, 1);
+ results.splice(i--, 1);
}
}
}
@@ -161,7 +158,7 @@ Sizzle.find = function(expr, context, isXML){
for ( var i = 0, l = Expr.order.length; i < l; i++ ) {
var type = Expr.order[i], match;
-
+
if ( (match = Expr.match[ type ].exec( expr )) ) {
var left = RegExp.leftContext;
@@ -423,7 +420,7 @@ var Expr = Sizzle.selectors = {
},
ATTR: function(match, curLoop, inplace, result, not, isXML){
var name = match[1].replace(/\\/g, "");
-
+
if ( !isXML && Expr.attrMap[name] ) {
match[1] = Expr.attrMap[name];
}
@@ -449,7 +446,7 @@ var Expr = Sizzle.selectors = {
} else if ( Expr.match.POS.test( match[0] ) || Expr.match.CHILD.test( match[0] ) ) {
return true;
}
-
+
return match;
},
POS: function(match){
@@ -583,20 +580,20 @@ var Expr = Sizzle.selectors = {
if ( first == 1 && last == 0 ) {
return true;
}
-
+
var doneName = match[0],
parent = elem.parentNode;
-
+
if ( parent && (parent.sizcache !== doneName || !elem.nodeIndex) ) {
var count = 0;
for ( node = parent.firstChild; node; node = node.nextSibling ) {
if ( node.nodeType === 1 ) {
node.nodeIndex = ++count;
}
- }
+ }
parent.sizcache = doneName;
}
-
+
var diff = elem.nodeIndex - last;
if ( first == 0 ) {
return diff == 0;
@@ -659,17 +656,17 @@ var Expr = Sizzle.selectors = {
var origPOS = Expr.match.POS;
for ( var type in Expr.match ) {
- Expr.match[ type ] = RegExp( Expr.match[ type ].source + /(?![^\[]*\])(?![^\(]*\))/.source );
+ Expr.match[ type ] = new RegExp( Expr.match[ type ].source + /(?![^\[]*\])(?![^\(]*\))/.source );
}
var makeArray = function(array, results) {
array = Array.prototype.slice.call( array );
if ( results ) {
- arrayPush.apply( results, array );
+ results.push.apply( results, array );
return results;
}
-
+
return array;
};
@@ -738,9 +735,9 @@ if ( document.documentElement.compareDocumentPosition ) {
// querying by getElementById (and provide a workaround)
(function(){
// We're going to inject a fake input element with a specified name
- var form = document.createElement("form"),
+ var form = document.createElement("div"),
id = "script" + (new Date).getTime();
- form.innerHTML = "";
+ form.innerHTML = "";
// Inject it into the root element, check its status, and remove it quickly
var root = document.documentElement;
@@ -814,7 +811,7 @@ if ( document.querySelectorAll ) (function(){
if ( div.querySelectorAll && div.querySelectorAll(".TEST").length === 0 ) {
return;
}
-
+
Sizzle = function(query, context, extra, seed){
context = context || document;
@@ -825,14 +822,13 @@ if ( document.querySelectorAll ) (function(){
return makeArray( context.querySelectorAll(query), extra );
} catch(e){}
}
-
+
return oldSizzle(query, context, extra, seed);
};
- Sizzle.find = oldSizzle.find;
- Sizzle.filter = oldSizzle.filter;
- Sizzle.selectors = oldSizzle.selectors;
- Sizzle.matches = oldSizzle.matches;
+ for ( var prop in oldSizzle ) {
+ Sizzle[ prop ] = oldSizzle[ prop ];
+ }
})();
if ( document.getElementsByClassName && document.documentElement.getElementsByClassName ) (function(){
@@ -973,7 +969,7 @@ jQuery.expr = Sizzle.selectors;
jQuery.expr[":"] = jQuery.expr.filters;
Sizzle.selectors.filters.hidden = function(elem){
- return elem.offsetWidth === 0 || elem.offsetHeight === 0;
+ return elem.offsetWidth === 0 && elem.offsetHeight === 0;
};
Sizzle.selectors.filters.visible = function(elem){