Is there any possible way to remove all the changes made by the draggable plugin when its instance is destroyed (or a step before that)? I tried doing something like:
if (target) {
$(target).draggable("option","revert",true);
$(target).draggable("destroy");
}
Doesn't work.
EDIT:
My guess is that after I change the revert option, it basically sets the starting point where the element is now, not where it was initially.
EDIT2:
More code:
$(editbtn).toggle(
function() {
var target;
$(this).attr('data', 'on');
//appedning editor to body
editor.draggable().appendTo($('body'));
//make hints selectable
$('.ui-hint').live('click.hintAdmin', function(e) {
//get rid of prev binds/drags if present
if (target) {
$(target).draggable();
$(target).draggable("destroy");
}
$(save).unbind('click.hintAdmin');
$(del).unbind('click');
$('.ui-hintAdmin-edit-hl').removeClass('ui-hintAdmin-edit-hl');
$('.ui-hintAdmin-hider').remove();
target = e.target;
var $this = $(this);
//get hint instances and targets
var hint_t = $(this).prev();
var hint = $(this).prev().data('hint');
var offset_start, offset_stop, offset_final, axis;
$(target).append(del);
self._hintHider(hint, $this);
//making delete work and clean after itself
$(del).on('click.hintAdmin', function() {
$('.ui-hintAdmin-edit-hl').removeClass('ui-hintAdmin-edit-hl');
$(save).unbind('click.hintAdmin');
$(label).html('');
$(edit).val('');
$(del).unbind('click');
$(target).draggable("destroy");
hint_t.hint("destroy");
$('.ui-hintAdmin-hider').remove();
})
$(target).addClass('ui-hintAdmin-edit-hl');
$(label).html('Editing hint # ' + hint.options.id);
$(edit).val(hint.options.text);
//choosing the axis
switch (hint.options.position) {
case 'top':
axis = 'x';
break;
case 'bottom':
axis = 'x';
break;
case 'left':
axis = 'y';
break;
case 'right':
axis = 'y';
break;
}
offset_start = $(target).offset();
$(target).draggable({
axis: axis,
grid: [5, 5],
stop: function(e, ui) {
offset_stop = ui.offset;
switch (hint.options.position) {
case 'top':
offset_final = '' + offset_stop.left - offset_start.left + '';
console.log('top' + offset_final);
break;
case 'bottom':
offset_final = '' + offset_start.left - offset_stop.left + '';
console.log('bottom' + offset_final);
break;
case 'left':
offset_final = '' + offset_stop.top - offset_start.top + '';
console.log('left' + offset_final);
break;
case 'right':
offset_final = '' + offset_stop.top - offset_start.top + '';
console.log('right' + offset_final);
break;
}
;
}
});
{rest of the code . .}
}