Skip to content

Commit

Permalink
Dimensions: allow modification of coordinates argument
Browse files Browse the repository at this point in the history
  • Loading branch information
markelog committed Nov 11, 2014
1 parent 9d6beac commit 108ef21
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/offset.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ jQuery.offset = {
}

if ( jQuery.isFunction( options ) ) {
options = options.call( elem, i, curOffset );

// Use jQuery.extend here to allow modification of coordinates argument (gh-1848)
options = options.call( elem, i, jQuery.extend( {}, curOffset ) );
}

if ( options.top != null ) {
Expand Down
12 changes: 12 additions & 0 deletions test/unit/dimensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -455,4 +455,16 @@ testIframe( "dimensions/documentLarge", "window vs. large document", function( j
ok( jQuery( document ).width() > jQuery( window ).width(), "document width is larger than window width" );
});

test( "allow modification of coordinates argument (gh-1848)", 1, function() {
var element = jQuery( "<div/>" ).appendTo( "#qunit-fixture" );

element.offset(function( index, coords ) {
coords.top = 100;

return coords;
});

equal( element.offset().top, 100, "coordinates are modified" );
});

})();

0 comments on commit 108ef21

Please sign in to comment.