@@ -61,8 +61,8 @@ $.widget("ui.draggable", $.ui.mouse, {
6161 } ,
6262 _create : function ( ) {
6363
64- if ( this . options . helper === "original" && ! ( / ^ (?: r | a | f ) / ) . test ( this . element . css ( "position" ) ) ) {
65- this . element [ 0 ] . style . position = "relative" ;
64+ if ( this . options . helper === "original" ) {
65+ this . _setPositionRelative ( ) ;
6666 }
6767 if ( this . options . addClasses ) {
6868 this . element . addClass ( "ui-draggable" ) ;
@@ -345,12 +345,24 @@ $.widget("ui.draggable", $.ui.mouse, {
345345 _createHelper : function ( event ) {
346346
347347 var o = this . options ,
348- helper = $ . isFunction ( o . helper ) ? $ ( o . helper . apply ( this . element [ 0 ] , [ event ] ) ) : ( o . helper === "clone" ? this . element . clone ( ) . removeAttr ( "id" ) : this . element ) ;
348+ helperIsFunction = $ . isFunction ( o . helper ) ,
349+ helper = helperIsFunction ?
350+ $ ( o . helper . apply ( this . element [ 0 ] , [ event ] ) ) :
351+ ( o . helper === "clone" ?
352+ this . element . clone ( ) . removeAttr ( "id" ) :
353+ this . element ) ;
349354
350355 if ( ! helper . parents ( "body" ) . length ) {
351356 helper . appendTo ( ( o . appendTo === "parent" ? this . element [ 0 ] . parentNode : o . appendTo ) ) ;
352357 }
353358
359+ // http://bugs.jqueryui.com/ticket/9446
360+ // a helper function can return the original element
361+ // which wouldn't have been set to relative in _create
362+ if ( helperIsFunction && helper [ 0 ] === this . element [ 0 ] ) {
363+ this . _setPositionRelative ( ) ;
364+ }
365+
354366 if ( helper [ 0 ] !== this . element [ 0 ] && ! ( / ( f i x e d | a b s o l u t e ) / ) . test ( helper . css ( "position" ) ) ) {
355367 helper . css ( "position" , "absolute" ) ;
356368 }
@@ -359,6 +371,12 @@ $.widget("ui.draggable", $.ui.mouse, {
359371
360372 } ,
361373
374+ _setPositionRelative : function ( ) {
375+ if ( ! ( / ^ (?: r | a | f ) / ) . test ( this . element . css ( "position" ) ) ) {
376+ this . element [ 0 ] . style . position = "relative" ;
377+ }
378+ } ,
379+
362380 _adjustOffsetFromHelper : function ( obj ) {
363381 if ( typeof obj === "string" ) {
364382 obj = obj . split ( " " ) ;
0 commit comments