X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=src%2Fselector.js;h=69ea36cd91c54642062c15307214e2ce6c16d7c4;hb=a720bb31ab32c5629607a471e4674fd11e05b97c;hp=ecec83b9fccc833a39135974e754ebf5ee2bec3b;hpb=21dde30348fe9bcbd8db8c1b30e470a9e2f39c16;p=jquery.git diff --git a/src/selector.js b/src/selector.js index ecec83b..69ea36c 100644 --- a/src/selector.js +++ b/src/selector.js @@ -6,7 +6,7 @@ */ (function(){ -var chunker = /((?:\((?:\([^()]+\)|[^()]+)+\)|\[(?:\[[^[\]]*\]|['"][^'"]*['"]|[^[\]'"]+)+\]|\\.|[^ >+~,(\[]+)+|[>+~])(\s*,\s*)?/g, +var chunker = /((?:\((?:\([^()]+\)|[^()]+)+\)|\[(?:\[[^[\]]*\]|['"][^'"]*['"]|[^[\]'"]+)+\]|\\.|[^ >+~,(\[\\]+)+|[>+~])(\s*,\s*)?/g, done = 0, toString = Object.prototype.toString; @@ -223,8 +223,6 @@ Sizzle.filter = function(expr, set, inplace, not){ } } - expr = expr.replace(/\s*,\s*/, ""); - // Improper expression if ( expr == old ) { if ( anyFound == null ) { @@ -263,23 +261,32 @@ var Expr = Sizzle.selectors = { }, relative: { "+": function(checkSet, part, isXML){ - var isPartStr = typeof part === "string", + var isPartStr = typeof part === "string", isTag = isPartStr && !/\W/.test(part), isPartStrNotTag = isPartStr && !isTag; - if ( isTag && !isXML ) part = part.toUpperCase(); + + if ( isTag && !isXML ) { + part = part.toUpperCase(); + } + for ( var i = 0, l = checkSet.length, elem; i < l; i++ ) { - if ( elem = checkSet[i] ) { - while ( (elem = elem.previousSibling) && elem.nodeType !== 1 ) {}; + if ( (elem = checkSet[i]) ) { + while ( (elem = elem.previousSibling) && elem.nodeType !== 1 ) {} + checkSet[i] = isPartStrNotTag || elem && elem.nodeName === part ? - elem : elem === part; + elem || false : + elem === part; } } - if (isPartStrNotTag) { + + if ( isPartStrNotTag ) { Sizzle.filter( part, checkSet, true ); } }, ">": function(checkSet, part, isXML){ - if ( typeof part === "string" && !/\W/.test(part) ) { + var isPartStr = typeof part === "string"; + + if ( isPartStr && !/\W/.test(part) ) { part = isXML ? part : part.toUpperCase(); for ( var i = 0, l = checkSet.length; i < l; i++ ) { @@ -293,13 +300,13 @@ var Expr = Sizzle.selectors = { for ( var i = 0, l = checkSet.length; i < l; i++ ) { var elem = checkSet[i]; if ( elem ) { - checkSet[i] = typeof part === "string" ? + checkSet[i] = isPartStr ? elem.parentNode : elem.parentNode === part; } } - if ( typeof part === "string" ) { + if ( isPartStr ) { Sizzle.filter( part, checkSet, true ); } } @@ -334,7 +341,14 @@ var Expr = Sizzle.selectors = { }, NAME: function(match, context, isXML){ if ( typeof context.getElementsByName !== "undefined" ) { - var ret = context.getElementsByName(match[1]); + var ret = [], results = context.getElementsByName(match[1]); + + for ( var i = 0, l = results.length; i < l; i++ ) { + if ( results[i].getAttribute("name") === match[1] ) { + ret.push( results[i] ); + } + } + return ret.length === 0 ? null : ret; } }, @@ -399,7 +413,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 ) { + if ( match[3].match(chunker).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); @@ -923,15 +937,11 @@ jQuery.expr = Sizzle.selectors; jQuery.expr[":"] = jQuery.expr.filters; Sizzle.selectors.filters.hidden = function(elem){ - return "hidden" === elem.type || - jQuery.css(elem, "display") === "none" || - jQuery.css(elem, "visibility") === "hidden"; + return elem.offsetWidth === 0 || elem.offsetHeight === 0; }; Sizzle.selectors.filters.visible = function(elem){ - return "hidden" !== elem.type && - jQuery.css(elem, "display") !== "none" && - jQuery.css(elem, "visibility") !== "hidden"; + return elem.offsetWidth > 0 || elem.offsetHeight > 0; }; Sizzle.selectors.filters.animated = function(elem){