Jquery UI Draggable:回滚破坏的所有更改?

时间:2013-10-22 05:59:55

标签: javascript jquery jquery-ui

是否有任何可能的方法来删除可拖动插件在其实例被销毁时(或之前的一步)所做的所有更改?我尝试过这样的事情:

if (target) {
      $(target).draggable("option","revert",true);
      $(target).draggable("destroy");
}

不起作用。

编辑:

我的猜测是,在我更改了还原选项后,它基本上设置了元素现在的起点,而不是最初的位置。

EDIT2:

更多代码:

  $(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 . .}
}

0 个答案:

没有答案