X-Git-Url: http://git.asbjorn.it/?a=blobdiff_plain;ds=inline;f=src%2Fselector.js;h=fb332465df18eb235a85b7f4920171f2ac1c805b;hb=4ea4fad0902839c06c281b5de7b0aca29922b63d;hp=c189515089f4b74ac3184af8789fbe6353bcb8b8;hpb=1c8c3883a98d7d896efefe92eb0d22b1681e92f1;p=jquery.git
diff --git a/src/selector.js b/src/selector.js
index c189515..fb33246 100644
--- a/src/selector.js
+++ b/src/selector.js
@@ -9,9 +9,7 @@
var chunker = /((?:\((?:\([^()]+\)|[^()]+)+\)|\[(?:\[[^[\]]*\]|['"][^'"]*['"]|[^[\]'"]+)+\]|\\.|[^ >+~,(\[\\]+)+|[>+~])(\s*,\s*)?/g,
done = 0,
toString = Object.prototype.toString,
- arraySplice = Array.prototype.splice,
- arrayPush = Array.prototype.push,
- arraySort = Array.prototype.sort;
+ hasDuplicate = false;
var Sizzle = function(selector, context, results, seed) {
results = results || [];
@@ -107,17 +105,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 +134,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);
}
}
}
@@ -334,7 +332,7 @@ var Expr = Sizzle.selectors = {
"": function(checkSet, part, isXML){
var doneName = done++, checkFn = dirCheck;
- if ( !part.match(/\W/) ) {
+ if ( !/\W/.test(part) ) {
var nodeCheck = part = isXML ? part : part.toUpperCase();
checkFn = dirNodeCheck;
}
@@ -344,7 +342,7 @@ var Expr = Sizzle.selectors = {
"~": function(checkSet, part, isXML){
var doneName = done++, checkFn = dirCheck;
- if ( typeof part === "string" && !part.match(/\W/) ) {
+ if ( typeof part === "string" && !/\W/.test(part) ) {
var nodeCheck = part = isXML ? part : part.toUpperCase();
checkFn = dirNodeCheck;
}
@@ -437,7 +435,7 @@ var Expr = Sizzle.selectors = {
PSEUDO: function(match, curLoop, inplace, result, not){
if ( match[1] === "not" ) {
// If we're dealing with a complex expression, or a simple one
- if ( match[3].match(chunker).length > 1 || /^\w/.test(match[3]) ) {
+ if ( chunker.exec(match[3]).length > 1 || /^\w/.test(match[3]) ) {
match[3] = Sizzle(match[3], null, null, curLoop);
} else {
var ret = Sizzle.filter(match[3], curLoop, inplace, true ^ not);
@@ -553,7 +551,7 @@ var Expr = Sizzle.selectors = {
} else if ( name === "not" ) {
var not = match[3];
- for ( var i = 0, l = not.length; i < l; i++ ) {
+ for ( i = 0, l = not.length; i < l; i++ ) {
if ( not[i] === elem ) {
return false;
}
@@ -567,13 +565,13 @@ var Expr = Sizzle.selectors = {
switch (type) {
case 'only':
case 'first':
- while (node = node.previousSibling) {
+ while ( (node = node.previousSibling) ) {
if ( node.nodeType === 1 ) return false;
}
if ( type == 'first') return true;
node = elem;
case 'last':
- while (node = node.nextSibling) {
+ while ( (node = node.nextSibling) ) {
if ( node.nodeType === 1 ) return false;
}
return true;
@@ -663,10 +661,10 @@ for ( var type in Expr.match ) {
}
var makeArray = function(array, results) {
- array = Array.prototype.slice.call( array );
+ array = Array.prototype.slice.call( array, 0 );
if ( results ) {
- arrayPush.apply( results, array );
+ results.push.apply( results, array );
return results;
}
@@ -676,7 +674,7 @@ var makeArray = function(array, results) {
// Perform a simple check to determine if the browser is capable of
// converting a NodeList to an array using builtin methods.
try {
- Array.prototype.slice.call( document.documentElement.childNodes );
+ Array.prototype.slice.call( document.documentElement.childNodes, 0 );
// Provide a fallback method if it does not work
} catch(e){
@@ -738,9 +736,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;
@@ -763,6 +761,7 @@ if ( document.documentElement.compareDocumentPosition ) {
}
root.removeChild( form );
+ root = form = null; // release memory in IE
})();
(function(){
@@ -803,6 +802,8 @@ if ( document.documentElement.compareDocumentPosition ) {
return elem.getAttribute("href", 2);
};
}
+
+ div = null; // release memory in IE
})();
if ( document.querySelectorAll ) (function(){
@@ -832,6 +833,8 @@ if ( document.querySelectorAll ) (function(){
for ( var prop in oldSizzle ) {
Sizzle[ prop ] = oldSizzle[ prop ];
}
+
+ div = null; // release memory in IE
})();
if ( document.getElementsByClassName && document.documentElement.getElementsByClassName ) (function(){
@@ -854,6 +857,8 @@ if ( document.getElementsByClassName && document.documentElement.getElementsByCl
return context.getElementsByClassName(match[1]);
}
};
+
+ div = null; // release memory in IE
})();
function dirNodeCheck( dir, cur, doneName, checkSet, nodeCheck, isXML ) {
@@ -972,11 +977,17 @@ jQuery.expr = Sizzle.selectors;
jQuery.expr[":"] = jQuery.expr.filters;
Sizzle.selectors.filters.hidden = function(elem){
- return elem.offsetWidth === 0 || elem.offsetHeight === 0;
+ var width = elem.offsetWidth, height = elem.offsetHeight,
+ force = /^tr$/i.test( elem.nodeName ); // ticket #4512
+ return ( width === 0 && height === 0 && !force ) ?
+ true :
+ ( width !== 0 && height !== 0 && !force ) ?
+ false :
+ !!( jQuery.curCSS(elem, "display") === "none" );
};
Sizzle.selectors.filters.visible = function(elem){
- return elem.offsetWidth > 0 || elem.offsetHeight > 0;
+ return !Sizzle.selectors.filters.hidden(elem);
};
Sizzle.selectors.filters.animated = function(elem){