Skip to content

Commit f7e60dc

Browse files
committed
Dimensions: allow modification of coordinates argument
Fixes gh-1848 Closes gh-1853
1 parent 9d6beac commit f7e60dc

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/offset.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ jQuery.offset = {
5151
}
5252

5353
if ( jQuery.isFunction( options ) ) {
54-
options = options.call( elem, i, curOffset );
54+
55+
// Use jQuery.extend here to allow modification of coordinates argument (gh-1848)
56+
options = options.call( elem, i, jQuery.extend( {}, curOffset ) );
5557
}
5658

5759
if ( options.top != null ) {

test/unit/dimensions.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,4 +455,16 @@ testIframe( "dimensions/documentLarge", "window vs. large document", function( j
455455
ok( jQuery( document ).width() > jQuery( window ).width(), "document width is larger than window width" );
456456
});
457457

458+
test( "allow modification of coordinates argument (gh-1848)", 1, function() {
459+
var element = jQuery( "<div/>" ).appendTo( "#qunit-fixture" );
460+
461+
element.offset(function( index, coords ) {
462+
coords.top = 100;
463+
464+
return coords;
465+
});
466+
467+
equal( element.offset().top, 100, "coordinates are modified" );
468+
});
469+
458470
})();

0 commit comments

Comments
 (0)