Commit e07b444d authored by Timmy Willison's avatar Timmy Willison

Fix a regression where has with multiple contexts was not filtering correctly. Test added.

parent 4039d366
...@@ -48,12 +48,12 @@ jQuery.fn.extend({ ...@@ -48,12 +48,12 @@ jQuery.fn.extend({
}, },
has: function( target ) { has: function( target ) {
var i = 0, var i,
targets = jQuery( target, this ), targets = jQuery( target, this ),
l = targets.length; len = targets.length;
return this.filter(function() { return this.filter(function() {
for ( ; i < l; i++ ) { for ( i = 0; i < len; i++ ) {
if ( jQuery.contains( this, targets[i] ) ) { if ( jQuery.contains( this, targets[i] ) ) {
return true; return true;
} }
......
...@@ -376,7 +376,7 @@ test("has(Element)", function() { ...@@ -376,7 +376,7 @@ test("has(Element)", function() {
}); });
test("has(Selector)", function() { test("has(Selector)", function() {
expect(4); expect( 5 );
var obj = jQuery("#qunit-fixture").has("#sndp"); var obj = jQuery("#qunit-fixture").has("#sndp");
deepEqual( obj.get(), q("qunit-fixture"), "Keeps elements that have any element matching the selector as a descendant" ); deepEqual( obj.get(), q("qunit-fixture"), "Keeps elements that have any element matching the selector as a descendant" );
...@@ -385,7 +385,10 @@ test("has(Selector)", function() { ...@@ -385,7 +385,10 @@ test("has(Selector)", function() {
deepEqual( detached.has("i").get(), detached.get(), "...Even when detached" ); deepEqual( detached.has("i").get(), detached.get(), "...Even when detached" );
var multipleParent = jQuery("#qunit-fixture, #header").has("#sndp"); var multipleParent = jQuery("#qunit-fixture, #header").has("#sndp");
deepEqual( obj.get(), q("qunit-fixture"), "Does not include elements that do not have the element as a descendant" ); deepEqual( multipleParent.get(), q("qunit-fixture"), "Does not include elements that do not have the element as a descendant" );
multipleParent = jQuery("#select1, #select2, #select3").has("#option1a, #option3a");
deepEqual( multipleParent.get(), q("select1", "select3"), "Multiple contexts are checks correctly" );
var multipleHas = jQuery("#qunit-fixture").has("#sndp, #first"); var multipleHas = jQuery("#qunit-fixture").has("#sndp, #first");
deepEqual( multipleHas.get(), q("qunit-fixture"), "Only adds elements once" ); deepEqual( multipleHas.get(), q("qunit-fixture"), "Only adds elements once" );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment