diff options
author | Mike Sherov <mike.sherov@gmail.com> | 2014-08-14 21:17:28 -0400 |
---|---|---|
committer | Mike Sherov <mike.sherov@gmail.com> | 2014-08-19 15:15:21 -0400 |
commit | 451dded230c3832a1baacc89333727b25c44cfc7 (patch) | |
tree | cb6ba4c421808a7f7d4595cd3dfb84150f6f8365 /ui | |
parent | 8eca7b8f45885d20c13f1bf64cad8bee5fc1d5c5 (diff) | |
download | jquery-ui-451dded230c3832a1baacc89333727b25c44cfc7.tar.gz jquery-ui-451dded230c3832a1baacc89333727b25c44cfc7.zip |
Draggable: Ensure helper is positioned even if its the element itself
Fixes #9446
Diffstat (limited to 'ui')
-rw-r--r-- | ui/draggable.js | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/ui/draggable.js b/ui/draggable.js index 826098feb..1529e94aa 100644 --- a/ui/draggable.js +++ b/ui/draggable.js @@ -61,8 +61,8 @@ $.widget("ui.draggable", $.ui.mouse, { }, _create: function() { - if (this.options.helper === "original" && !(/^(?:r|a|f)/).test(this.element.css("position"))) { - this.element[0].style.position = "relative"; + if ( this.options.helper === "original" ) { + this._setPositionRelative(); } if (this.options.addClasses){ this.element.addClass("ui-draggable"); @@ -345,12 +345,24 @@ $.widget("ui.draggable", $.ui.mouse, { _createHelper: function(event) { var o = this.options, - helper = $.isFunction(o.helper) ? $(o.helper.apply(this.element[ 0 ], [ event ])) : (o.helper === "clone" ? this.element.clone().removeAttr("id") : this.element); + helperIsFunction = $.isFunction( o.helper ), + helper = helperIsFunction ? + $( o.helper.apply( this.element[ 0 ], [ event ] ) ) : + ( o.helper === "clone" ? + this.element.clone().removeAttr( "id" ) : + this.element ); if (!helper.parents("body").length) { helper.appendTo((o.appendTo === "parent" ? this.element[0].parentNode : o.appendTo)); } + // http://bugs.jqueryui.com/ticket/9446 + // a helper function can return the original element + // which wouldn't have been set to relative in _create + if ( helperIsFunction && helper[ 0 ] === this.element[ 0 ] ) { + this._setPositionRelative(); + } + if (helper[0] !== this.element[0] && !(/(fixed|absolute)/).test(helper.css("position"))) { helper.css("position", "absolute"); } @@ -359,6 +371,12 @@ $.widget("ui.draggable", $.ui.mouse, { }, + _setPositionRelative: function() { + if ( !( /^(?:r|a|f)/ ).test( this.element.css( "position" ) ) ) { + this.element[ 0 ].style.position = "relative"; + } + }, + _adjustOffsetFromHelper: function(obj) { if (typeof obj === "string") { obj = obj.split(" "); |