当可拖动插件的实例被销毁(或之前的步骤)时,是否有任何可能的方法来删除可拖动插件所做的所有更改?我尝试做类似的事情:
if (target) {
$(target).draggable("option","revert",true);
$(target).draggable("destroy");
}
不工作。
编辑:
我的猜测是,在我更改了 revert 选项之后,它基本上设置了元素现在所在的起点,而不是它最初所在的位置。
编辑2:
更多代码:
$(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 . .}
}