views:

1469

answers:

1

I'm creating a custom drag helper (in jQuery):

$('.dragme', element).draggable({
    appendTo: 'body',
    helper  : custom_drag_helper,
    opacity : 0.5
});

I'm doing this because I want to sometimes clone and sometimes do the default functionality, i.e. drag the original element.

function custom_drag_helper() {
    if (/*criteria on when to move instead of clone */) {
        return $(this); /* this is what helper: 'original' seems to do */
    } else {
        clone = $(this).clone(); /* this is what helper: 'clone' does */
        return clone;
    }
}

But I can't get the original functionality to work at all. return clone() works fine but return $(this) gives no joy.

+2  A: 

Ok, when typing up this question I did a bit more source diving and discovered this little line:

if (this.options.helper == 'original' && !(/^(?:r|a|f)/).test(this.element.css("position")))
  this.element[0].style.position = 'relative';

which I didn't find in the day I spent trying to solve this problem. Adding this.style.position = 'relative'; to my code above fixed the problem!

MDCore