Commit f28f199d authored by John Resig's avatar John Resig

Added support for the new .andSelf() method. This method combines the previous...

Added support for the new .andSelf() method. This method combines the previous two matched sets on the stack into a single stack.

For example:
  $("#foo").parent();
  // => [ #bar ]

  $("#foo").parent().andSelf();
  // => [ #bar, #foo ]
parent d259ec1a
...@@ -849,6 +849,14 @@ test("not()", function() { ...@@ -849,6 +849,14 @@ test("not()", function() {
isSet( $("p").not($("#ap, #sndp, .result")).get(), q("firstp", "en", "sap", "first"), "not(jQuery)" ); isSet( $("p").not($("#ap, #sndp, .result")).get(), q("firstp", "en", "sap", "first"), "not(jQuery)" );
}); });
test("andSelf()", function() {
expect(4);
isSet( $("#en").siblings().andSelf().get(), q("sndp", "sap","en"), "Check for siblings and self" );
isSet( $("#foo").children().andSelf().get(), q("sndp", "en", "sap", "foo"), "Check for children and self" );
isSet( $("#en, #sndp").parent().andSelf().get(), q("foo","en","sndp"), "Check for parent and self" );
isSet( $("#groups").parents("p, div").andSelf().get(), q("ap", "main", "groups"), "Check for parents and self" );
});
test("siblings([String])", function() { test("siblings([String])", function() {
expect(5); expect(5);
isSet( $("#en").siblings().get(), q("sndp", "sap"), "Check for siblings" ); isSet( $("#en").siblings().get(), q("sndp", "sap"), "Check for siblings" );
......
...@@ -325,13 +325,17 @@ jQuery.fn = jQuery.prototype = { ...@@ -325,13 +325,17 @@ jQuery.fn = jQuery.prototype = {
return this.pushStack( Array.prototype.slice.apply( this, arguments ) ); return this.pushStack( Array.prototype.slice.apply( this, arguments ) );
}, },
map: function(fn){ map: function(fn) {
return this.pushStack(jQuery.map( this, function(elem,i){ return this.pushStack(jQuery.map( this, function(elem,i){
return fn.call( elem, i, elem ); return fn.call( elem, i, elem );
})); }));
}, },
domManip: function(args, table, dir, fn){ andSelf: function() {
return this.add( this.prevObject );
},
domManip: function(args, table, dir, fn) {
var clone = this.length > 1, a; var clone = this.length > 1, a;
return this.each(function(){ return this.each(function(){
......
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