Commit 890bdcdc authored by techird's avatar techird

添加右键拖动的功能

parent 4d023087
...@@ -27,7 +27,11 @@ KM.registerUI( 'contextmenu', function () { ...@@ -27,7 +27,11 @@ KM.registerUI( 'contextmenu', function () {
} }
}); });
me.$container.append($menu); me.$container.append($menu);
me.on('contextmenu',function(e){ me.on('contextmenu', function (e) {
e.preventDefault();
if (me.getStatus() == 'hand') return;
var node = e.getTargetNode(); var node = e.getTargetNode();
if(node){ if(node){
this.removeAllSelectedNodes(); this.removeAllSelectedNodes();
...@@ -59,7 +63,6 @@ KM.registerUI( 'contextmenu', function () { ...@@ -59,7 +63,6 @@ KM.registerUI( 'contextmenu', function () {
data:data data:data
}).position(e.getPosition()).show(); }).position(e.getPosition()).show();
} }
e.preventDefault()
}); });
me.on('click',function(){ me.on('click',function(){
...@@ -67,7 +70,7 @@ KM.registerUI( 'contextmenu', function () { ...@@ -67,7 +70,7 @@ KM.registerUI( 'contextmenu', function () {
}); });
me.on('beforemousedown',function(e){ me.on('beforemousedown',function(e){
if(e.isRightMB()){ if(e.isRightMB()){
e.stopPropagationImmediately(); //e.stopPropagationImmediately();
} }
}) })
} ); } );
......
...@@ -24,20 +24,21 @@ var ViewDragger = kity.createClass("ViewDragger", { ...@@ -24,20 +24,21 @@ var ViewDragger = kity.createClass("ViewDragger", {
_bind: function() { _bind: function() {
var dragger = this, var dragger = this,
isRootDrag = false, isTempDrag = false,
lastPosition = null, lastPosition = null,
currentPosition = null; currentPosition = null;
this._minder.on('normal.mousedown readonly.mousedown readonly.touchstart', function(e) { this._minder.on('normal.beforemousedown readonly.mousedown readonly.touchstart', function (e) {
e.originEvent.preventDefault(); // 阻止中键拉动
// 点击未选中的根节点临时开启 // 点击未选中的根节点临时开启
if (e.getTargetNode() == this.getRoot()) { if (e.getTargetNode() == this.getRoot() || e.originEvent.button == 2) {
lastPosition = e.getPosition(); lastPosition = e.getPosition();
isRootDrag = true; isTempDrag = true;
} }
}) })
.on('normal.mousemove normal.touchmove', function(e) { .on('normal.mousemove normal.touchmove', function(e) {
if (!isRootDrag) return; if (!isTempDrag) return;
var offset = kity.Vector.fromPoints(lastPosition, e.getPosition()); var offset = kity.Vector.fromPoints(lastPosition, e.getPosition());
if (offset.length() > 3) this.setStatus('hand'); if (offset.length() > 3) this.setStatus('hand');
}) })
...@@ -68,10 +69,13 @@ var ViewDragger = kity.createClass("ViewDragger", { ...@@ -68,10 +69,13 @@ var ViewDragger = kity.createClass("ViewDragger", {
lastPosition = null; lastPosition = null;
// 临时拖动需要还原状态 // 临时拖动需要还原状态
if (isRootDrag) { if (isTempDrag) {
dragger.setEnabled(false); dragger.setEnabled(false);
isRootDrag = false; isTempDrag = false;
this.rollbackStatus(); var me = this;
setTimeout(function () {
me.rollbackStatus();
});
} }
}); });
} }
...@@ -155,11 +159,10 @@ KityMinder.registerModule('View', function() { ...@@ -155,11 +159,10 @@ KityMinder.registerModule('View', function() {
e.preventDefault(); e.preventDefault();
} }
}, },
mousewheel: function(e) { mousewheel: function (e) {
var dx, dy; var dx, dy;
e = e.originEvent; e = e.originEvent;
if (e.ctrlKey || e.shiftKey) return; if (e.ctrlKey || e.shiftKey) return;
if ('wheelDeltaX' in e) { if ('wheelDeltaX' in e) {
dx = e.wheelDeltaX || 0; dx = e.wheelDeltaX || 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment