From: Oleg Gaidarenko Date: Tue, 11 Nov 2014 13:27:44 +0000 (+0300) Subject: Dimensions: allow modification of coordinates argument X-Git-Tag: 3.0.0-alpha1+compat~201 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=1eedf0e9ea4dc2d12edf28e77b33ae23de01af3b;p=jquery.git Dimensions: allow modification of coordinates argument Ref f7e60dc83d81cbf892de9dab39642dd67c49bd23 --- diff --git a/src/offset.js b/src/offset.js index 0200dd64e..eb3c1f119 100644 --- a/src/offset.js +++ b/src/offset.js @@ -57,7 +57,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 ) { diff --git a/test/unit/dimensions.js b/test/unit/dimensions.js index 97e23d7e2..a5c650afa 100644 --- a/test/unit/dimensions.js +++ b/test/unit/dimensions.js @@ -470,4 +470,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( "
" ).appendTo( "#qunit-fixture" ); + + element.offset(function( index, coords ) { + coords.top = 100; + + return coords; + }); + + equal( element.offset().top, 100, "coordinates are modified" ); +}); + })();