使用拖动和调整大小的jsPlumb问题

时间:2015-07-31 21:36:28

标签: jquery drag-and-drop resize jsplumb

我在我的项目中使用jsPlumb,基本上是构建一个流程图,用户可以将一个形状从一个div拖放到另一个div(#frame)。

所以我想要一些形状是可调整大小的,但我遇到了一些问题,因为当我尝试调整形状大小时,它会像我拖动一样移动。

我在resize事件中使用了jsPlumb.repaint,但仍然搞砸了。

/**
 * Enable element to be resizable at the div '#frame'.
 * Set a new ID to the element
 *
 * @param {Object} elem
 */
function make_resizable(elem) {
    count_id++;

    var id_name = "production_" + count_id; // build a new id 
    elem.attr("id", id_name);

    $("#frame").append(elem);

    elem.resizable({
        resize: function(event, ui) {
          jsPlumb.repaint(ui.helper);
        },
        handles: "all"
    });

    jsPlumb.draggable(elem, {
        containment: "parent"
    });
}

function make_draggable(elem) {
    elem.removeClass("drag").addClass("draggable onFrame");

    elem.attr("visible", "true");
    elem.draggable({
        containment: 'parent',
    });
}

$(document).ready(function(){
    $(".drag").draggable({
        revert: "invalid",
        helper: 'clone',
        cursor: "move",
        containment: 'frame'
    });

    $("#frame").droppable({
        accept: ".drag",
        drop: function(event, ui) {
            var cloned = $(ui.helper).clone();

            if ( $(ui.helper).parent("#frame").length == 0 ) {
                var pos = $(ui.helper).offset();
                var draggableOffset = ui.helper.offset(),
                    droppableOffset = $(this).offset(),
                    left = draggableOffset.left - droppableOffset.left,
                    thisTop = draggableOffset.top - droppableOffset.top;

                cloned.css({
                    "left": left,
                    "top": thisTop
                });

                if ( cloned.hasClass("production-unit")) {
                    make_resizable(cloned);
                    //cloned.css("z-index", zIndex_unit++);
                } else {
                    make_connectable(cloned);
                    //cloned.css("z-index", zIndex_elem++);
                }

                make_draggable(cloned);
            }
        }
    });
});

2 个答案:

答案 0 :(得分:0)

仅供参考,我有类似的问题。事实证明(并且由问题中的一条评论指出),你应该将全局jsPlumb与实例混合。相反,你应该使用jsPlumb的一个实例(在上面的例子中,它被命名为elem)。

这是基于开发人员(sporritt)的评论:https://github.com/sporritt/jsPlumb/issues/387#issuecomment-185099198

他们正在考虑删除2.1.0中的全局jsPlumb以消除这种情况下的混淆,在这种情况下你混合两个不同的实例并且它无法正常工作。

答案 1 :(得分:0)

对于较新版本的JsPlumb,该错误仍然存​​在。在这种情况下,只需在拖动选项中使用过滤器选项即可。

instance.draggable((element), {
   filter: ".ui-resizable-handle"
});

https://github.com/jsplumb/katavorio/wiki#filtering