aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/offset.js4
-rw-r--r--test/unit/dimensions.js12
2 files changed, 15 insertions, 1 deletions
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( "<div/>" ).appendTo( "#qunit-fixture" );
+
+ element.offset(function( index, coords ) {
+ coords.top = 100;
+
+ return coords;
+ });
+
+ equal( element.offset().top, 100, "coordinates are modified" );
+});
+
})();