实现这个功能很easy,仅仅须要重写moveCells方法就能够了。以下是源文件里的代码:
mxGraph.prototype.moveCells = function(cells, dx, dy, clone, target, evt) { if (cells != null && (dx != 0 || dy != 0 || clone || target != null)) { this.model.beginUpdate(); try { if (clone) { cells = this.cloneCells(cells, this.isCloneInvalidEdges()); if (target == null) { target = this.getDefaultParent(); } } this.cellsMoved(cells, dx, dy, !clone && this.isDisconnectOnMove() && this.isAllowDanglingEdges(), target == null); if (target != null) { var index = this.model.getChildCount(target); this.cellsAdded(cells, target, index, null, null, true); } this.fireEvent(new mxEventObject(mxEvent.MOVE_CELLS, 'cells', cells, 'dx', dx, 'dy', dy, 'clone', clone, 'target', target, 'event', evt)); } finally { this.model.endUpdate(); } } return cells; };接下来要对这种方法进行改造。加一句就能够了
mxGraph.prototype.moveCells = function(cells, dx, dy, clone, target, evt) { clone=evt.ctrlKey;//对。就是这啦!if (cells != null && (dx != 0 || dy != 0 || clone || target != null)) { this.model.beginUpdate(); try { if (clone) { cells = this.cloneCells(cells, this.isCloneInvalidEdges()); if (target == null) { target = this.getDefaultParent(); } } this.cellsMoved(cells, dx, dy, !clone && this.isDisconnectOnMove() && this.isAllowDanglingEdges(), target == null); if (target != null) { var index = this.model.getChildCount(target); this.cellsAdded(cells, target, index, null, null, true); } this.fireEvent(new mxEventObject(mxEvent.MOVE_CELLS, 'cells', cells, 'dx', dx, 'dy', dy, 'clone', clone, 'target', target, 'event', evt)); } finally { this.model.endUpdate(); } } return cells; };
原文:http://www.cnblogs.com/mengfanrong/p/5275394.html