From bb4657e84c73f045dbe3f85620275987dc595fc8 Mon Sep 17 00:00:00 2001 From: Duncan Beevers Date: Wed, 9 Nov 2011 00:47:05 -0800 Subject: [PATCH] Draggable: Compare aspects of original element and helper and modify click registration point. Fixed #7853 - Draggable cloned helper of different dimensions than original not dragged by click point --- ui/jquery.ui.draggable.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/ui/jquery.ui.draggable.js b/ui/jquery.ui.draggable.js index 6475ebd6116..f7f9a0d5740 100644 --- a/ui/jquery.ui.draggable.js +++ b/ui/jquery.ui.draggable.js @@ -102,6 +102,9 @@ $.widget("ui.draggable", $.ui.mouse, { //Create and append the visible helper this.helper = this._createHelper(event); + //Cache the element's size + this._cacheElementProportions(); + //Cache the helper size this._cacheHelperProportions(); @@ -351,6 +354,13 @@ $.widget("ui.draggable", $.ui.mouse, { }; }, + _cacheElementProportions: function() { + this.elementProportions = { + width: this.element.outerWidth(), + height: this.element.outerHeight() + }; + }, + _cacheHelperProportions: function() { this.helperProportions = { width: this.helper.outerWidth(), @@ -418,6 +428,17 @@ $.widget("ui.draggable", $.ui.mouse, { var pageX = event.pageX; var pageY = event.pageY; + // Correct for cloned element dimension differences + if ( this.helper.options == 'clone' && !this.helperProportions.width && !this.helperProportions.height ) { + this._cacheHelperProportions(); + var xAspect = this.helperProportions.width / this.elementProportions.width, + yAspect = this.helperProportions.height / this.elementProportions.height; + if ( xAspect && yAspect ) { + this.offset.click.left *= xAspect; + this.offset.click.top *= yAspect; + } + } + /* * - Position constraining - * Constrain the position to a mix of grid, containment.