Skip to content

Commit 1eedf0e

Browse files
committed
Dimensions: allow modification of coordinates argument
Ref f7e60dc
1 parent 38ac3c4 commit 1eedf0e

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
@@ -57,7 +57,9 @@ jQuery.offset = {
5757
}
5858

5959
if ( jQuery.isFunction( options ) ) {
60-
options = options.call( elem, i, curOffset );
60+
61+
// Use jQuery.extend here to allow modification of coordinates argument (gh-1848)
62+
options = options.call( elem, i, jQuery.extend( {}, curOffset ) );
6163
}
6264

6365
if ( options.top != null ) {

test/unit/dimensions.js

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

473+
test( "allow modification of coordinates argument (gh-1848)", 1, function() {
474+
var element = jQuery( "<div/>" ).appendTo( "#qunit-fixture" );
475+
476+
element.offset(function( index, coords ) {
477+
coords.top = 100;
478+
479+
return coords;
480+
});
481+
482+
equal( element.offset().top, 100, "coordinates are modified" );
483+
});
484+
473485
})();

0 commit comments

Comments
 (0)