Added logic for not using getElementsByClassName in different failure states. Fixes jQuery bugs #4058 and #4042.

This commit is contained in:
John Resig 2009-02-07 16:54:11 +00:00
parent ce00f88ae2
commit 2b7642cff0
2 changed files with 28 additions and 4 deletions

View File

@ -741,12 +741,25 @@ if ( document.querySelectorAll ) (function(){
Sizzle.matches = oldSizzle.matches; Sizzle.matches = oldSizzle.matches;
})(); })();
if ( document.getElementsByClassName && document.documentElement.getElementsByClassName ) { if ( document.getElementsByClassName && document.documentElement.getElementsByClassName ) (function(){
var div = document.createElement("div");
div.innerHTML = "<div class='test e'></div><div class='test'></div>";
// Opera can't find a second classname (in 9.6)
if ( div.getElementsByClassName("e").length === 0 )
return;
// Safari caches class attributes, doesn't catch changes (in 3.2)
div.lastChild.className = "e";
if ( div.getElementsByClassName("e").length === 1 )
return;
Expr.order.splice(1, 0, "CLASS"); Expr.order.splice(1, 0, "CLASS");
Expr.find.CLASS = function(match, context) { Expr.find.CLASS = function(match, context) {
return context.getElementsByClassName(match[1]); return context.getElementsByClassName(match[1]);
}; };
} })();
function dirNodeCheck( dir, cur, doneName, checkSet, nodeCheck, isXML ) { function dirNodeCheck( dir, cur, doneName, checkSet, nodeCheck, isXML ) {
for ( var i = 0, l = checkSet.length; i < l; i++ ) { for ( var i = 0, l = checkSet.length; i < l; i++ ) {

View File

@ -56,7 +56,7 @@ test("broken", function() {
}); });
test("id", function() { test("id", function() {
expect(25); expect(27);
t( "ID Selector", "#body", ["body"] ); t( "ID Selector", "#body", ["body"] );
t( "ID Selector w/ Element", "body#body", ["body"] ); t( "ID Selector w/ Element", "body#body", ["body"] );
t( "ID Selector w/ Element", "ul#first", [] ); t( "ID Selector w/ Element", "ul#first", [] );
@ -89,10 +89,13 @@ test("id", function() {
t( "ID selector with non-existant ancestor", "#asdfasdf #foobar", [] ); // bug #986 t( "ID selector with non-existant ancestor", "#asdfasdf #foobar", [] ); // bug #986
isSet( jQuery("body").find("div#form"), [], "ID selector within the context of another element" ); isSet( jQuery("body").find("div#form"), [], "ID selector within the context of another element" );
t( "Underscore ID", "#types_all", ["types_all"] );
t( "Dash ID", "#fx-queue", ["fx-queue"] );
}); });
test("class", function() { test("class", function() {
expect(16); expect(18);
t( "Class Selector", ".blog", ["mark","simon"] ); t( "Class Selector", ".blog", ["mark","simon"] );
t( "Class Selector", ".GROUPS", ["groups"] ); t( "Class Selector", ".GROUPS", ["groups"] );
t( "Class Selector", ".blog.link", ["simon"] ); t( "Class Selector", ".blog.link", ["simon"] );
@ -112,6 +115,14 @@ test("class", function() {
t( "Descendant scaped Class", "div .test\\.foo\\[5\\]bar", ["test.foo[5]bar"] ); t( "Descendant scaped Class", "div .test\\.foo\\[5\\]bar", ["test.foo[5]bar"] );
t( "Child escaped Class", "form > .foo\\:bar", ["foo:bar"] ); t( "Child escaped Class", "form > .foo\\:bar", ["foo:bar"] );
t( "Child escaped Class", "form > .test\\.foo\\[5\\]bar", ["test.foo[5]bar"] ); t( "Child escaped Class", "form > .test\\.foo\\[5\\]bar", ["test.foo[5]bar"] );
var div = document.createElement("div");
div.innerHTML = "<div class='test e'></div><div class='test'></div>";
isSet( jQuery(".e", div), [ div.firstChild ], "Finding a second class." );
div.lastChild.className = "e";
isSet( jQuery(".e", div), [ div.firstChild, div.lastChild ], "Finding a modified class." );
}); });
test("name", function() { test("name", function() {