@@ -61,8 +61,8 @@ $.widget("ui.draggable", $.ui.mouse, {
61
61
} ,
62
62
_create : function ( ) {
63
63
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 ( ) ;
66
66
}
67
67
if ( this . options . addClasses ) {
68
68
this . element . addClass ( "ui-draggable" ) ;
@@ -345,12 +345,24 @@ $.widget("ui.draggable", $.ui.mouse, {
345
345
_createHelper : function ( event ) {
346
346
347
347
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 ) ;
349
354
350
355
if ( ! helper . parents ( "body" ) . length ) {
351
356
helper . appendTo ( ( o . appendTo === "parent" ? this . element [ 0 ] . parentNode : o . appendTo ) ) ;
352
357
}
353
358
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
+
354
366
if ( helper [ 0 ] !== this . element [ 0 ] && ! ( / ( f i x e d | a b s o l u t e ) / ) . test ( helper . css ( "position" ) ) ) {
355
367
helper . css ( "position" , "absolute" ) ;
356
368
}
@@ -359,6 +371,12 @@ $.widget("ui.draggable", $.ui.mouse, {
359
371
360
372
} ,
361
373
374
+ _setPositionRelative : function ( ) {
375
+ if ( ! ( / ^ (?: r | a | f ) / ) . test ( this . element . css ( "position" ) ) ) {
376
+ this . element [ 0 ] . style . position = "relative" ;
377
+ }
378
+ } ,
379
+
362
380
_adjustOffsetFromHelper : function ( obj ) {
363
381
if ( typeof obj === "string" ) {
364
382
obj = obj . split ( " " ) ;
0 commit comments