From f7e60dc83d81cbf892de9dab39642dd67c49bd23 Mon Sep 17 00:00:00 2001 From: Oleg Gaidarenko Date: Tue, 11 Nov 2014 16:27:44 +0300 Subject: Dimensions: allow modification of coordinates argument Fixes gh-1848 Closes gh-1853 --- src/offset.js | 4 +++- test/unit/dimensions.js | 12 ++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/offset.js b/src/offset.js index aee95efde..69e571f7f 100644 --- a/src/offset.js +++ b/src/offset.js @@ -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 ) { diff --git a/test/unit/dimensions.js b/test/unit/dimensions.js index 8d51c6cde..7d37e13bc 100644 --- a/test/unit/dimensions.js +++ b/test/unit/dimensions.js @@ -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( "
" ).appendTo( "#qunit-fixture" ); + + element.offset(function( index, coords ) { + coords.top = 100; + + return coords; + }); + + equal( element.offset().top, 100, "coordinates are modified" ); +}); + })(); -- cgit v1.2.3