mirror of
https://bitbucket.org/wisemapping/wisemapping-open-source.git
synced 2024-11-25 23:44:54 +01:00
Improve drag. This should solve the drag bug ...
This commit is contained in:
parent
9748711011
commit
d8e05d7ce0
@ -20,7 +20,7 @@ mindplot.DragManager = new Class({
|
|||||||
initialize:function(workspace) {
|
initialize:function(workspace) {
|
||||||
this._workspace = workspace;
|
this._workspace = workspace;
|
||||||
this._listeners = {};
|
this._listeners = {};
|
||||||
|
this._isDragInProcess = false;
|
||||||
},
|
},
|
||||||
|
|
||||||
add : function(node) {
|
add : function(node) {
|
||||||
@ -36,8 +36,6 @@ mindplot.DragManager = new Class({
|
|||||||
|
|
||||||
// Set initial position.
|
// Set initial position.
|
||||||
var dragNode = node.createDragNode();
|
var dragNode = node.createDragNode();
|
||||||
var mousePos = screen.getWorkspaceMousePosition(event);
|
|
||||||
// dragNode.setPosition(mousePos.x, mousePos.y);
|
|
||||||
|
|
||||||
// Register mouse move listener ...
|
// Register mouse move listener ...
|
||||||
var mouseMoveListener = dragManager._buildMouseMoveListener(workspace, dragNode, dragManager);
|
var mouseMoveListener = dragManager._buildMouseMoveListener(workspace, dragNode, dragManager);
|
||||||
@ -47,14 +45,10 @@ mindplot.DragManager = new Class({
|
|||||||
var mouseUpListener = dragManager._buildMouseUpListener(workspace, node, dragNode, dragManager);
|
var mouseUpListener = dragManager._buildMouseUpListener(workspace, node, dragNode, dragManager);
|
||||||
screen.addEvent('mouseup', mouseUpListener);
|
screen.addEvent('mouseup', mouseUpListener);
|
||||||
|
|
||||||
// Execute Listeners ..
|
|
||||||
var startDragListener = dragManager._listeners['startdragging'];
|
|
||||||
startDragListener(event, node);
|
|
||||||
|
|
||||||
// Change cursor.
|
// Change cursor.
|
||||||
window.document.body.style.cursor = 'move';
|
window.document.body.style.cursor = 'move';
|
||||||
}
|
}
|
||||||
};
|
}.bind(this);
|
||||||
node.addEvent('mousedown', mouseDownListener);
|
node.addEvent('mousedown', mouseDownListener);
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -72,12 +66,18 @@ mindplot.DragManager = new Class({
|
|||||||
|
|
||||||
_buildMouseMoveListener : function(workspace, dragNode, dragManager) {
|
_buildMouseMoveListener : function(workspace, dragNode, dragManager) {
|
||||||
var screen = workspace.getScreenManager();
|
var screen = workspace.getScreenManager();
|
||||||
|
|
||||||
var result = function(event) {
|
var result = function(event) {
|
||||||
|
|
||||||
if (!dragNode._isInTheWorkspace) {
|
if (!this._isDragInProcess) {
|
||||||
|
// Execute Listeners ..
|
||||||
|
var startDragListener = dragManager._listeners['startdragging'];
|
||||||
|
startDragListener(event, dragNode);
|
||||||
|
|
||||||
// Add shadow node to the workspace.
|
// Add shadow node to the workspace.
|
||||||
workspace.appendChild(dragNode);
|
workspace.appendChild(dragNode);
|
||||||
dragNode._isInTheWorkspace = true;
|
|
||||||
|
this._isDragInProcess = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
var pos = screen.getWorkspaceMousePosition(event);
|
var pos = screen.getWorkspaceMousePosition(event);
|
||||||
@ -99,15 +99,8 @@ mindplot.DragManager = new Class({
|
|||||||
_buildMouseUpListener : function(workspace, node, dragNode, dragManager) {
|
_buildMouseUpListener : function(workspace, node, dragNode, dragManager) {
|
||||||
var screen = workspace.getScreenManager();
|
var screen = workspace.getScreenManager();
|
||||||
var result = function(event) {
|
var result = function(event) {
|
||||||
|
|
||||||
$assert(dragNode.isDragTopic, 'dragNode must be an DragTopic');
|
$assert(dragNode.isDragTopic, 'dragNode must be an DragTopic');
|
||||||
|
|
||||||
// Remove drag node from the workspace.
|
|
||||||
var hasBeenDragged = dragNode._isInTheWorkspace;
|
|
||||||
if (dragNode._isInTheWorkspace) {
|
|
||||||
dragNode.removeFromWorkspace(workspace);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remove all the events.
|
// Remove all the events.
|
||||||
screen.removeEvent('mousemove', dragManager._mouseMoveListener);
|
screen.removeEvent('mousemove', dragManager._mouseMoveListener);
|
||||||
screen.removeEvent('mouseup', dragManager._mouseUpListener);
|
screen.removeEvent('mouseup', dragManager._mouseUpListener);
|
||||||
@ -116,20 +109,24 @@ mindplot.DragManager = new Class({
|
|||||||
dragManager._mouseMoveListener = null;
|
dragManager._mouseMoveListener = null;
|
||||||
dragManager._mouseUpListener = null;
|
dragManager._mouseUpListener = null;
|
||||||
|
|
||||||
// Execute Listeners only if the node has been moved.
|
workspace.enableWorkspaceEvents(true);
|
||||||
var endDragListener = dragManager._listeners['enddragging'];
|
|
||||||
endDragListener(event, dragNode);
|
|
||||||
|
|
||||||
if (hasBeenDragged) {
|
|
||||||
dragNode._isInTheWorkspace = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Change the cursor to the default.
|
// Change the cursor to the default.
|
||||||
window.document.body.style.cursor = 'default';
|
window.document.body.style.cursor = 'default';
|
||||||
|
|
||||||
workspace.enableWorkspaceEvents(true);
|
if (this._isDragInProcess) {
|
||||||
|
|
||||||
};
|
// Execute Listeners only if the node has been moved.
|
||||||
|
var endDragListener = dragManager._listeners['enddragging'];
|
||||||
|
endDragListener(event, dragNode);
|
||||||
|
|
||||||
|
// Remove drag node from the workspace.
|
||||||
|
dragNode.removeFromWorkspace(workspace);
|
||||||
|
|
||||||
|
this._isDragInProcess = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}.bind(this);
|
||||||
dragManager._mouseUpListener = result;
|
dragManager._mouseUpListener = result;
|
||||||
return result;
|
return result;
|
||||||
},
|
},
|
||||||
|
@ -25,6 +25,7 @@ mindplot.DragTopic = new Class({
|
|||||||
this._order = null;
|
this._order = null;
|
||||||
this._draggedNode = draggedNode;
|
this._draggedNode = draggedNode;
|
||||||
this._position = new core.Point();
|
this._position = new core.Point();
|
||||||
|
this._isInWorkspace = false;
|
||||||
this._isFreeLayoutEnabled = false;
|
this._isFreeLayoutEnabled = false;
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -132,17 +133,23 @@ mindplot.DragTopic = new Class({
|
|||||||
removeFromWorkspace : function(workspace) {
|
removeFromWorkspace : function(workspace) {
|
||||||
// Remove drag shadow.
|
// Remove drag shadow.
|
||||||
workspace.removeChild(this._elem2d);
|
workspace.removeChild(this._elem2d);
|
||||||
|
this._isInWorkspace = false;
|
||||||
|
|
||||||
// Remove pivot shape. To improve performace it will not be removed. Only the visibility will be changed.
|
// Remove pivot shape. To improve performace it will not be removed. Only the visibility will be changed.
|
||||||
var dragPivot = this._getDragPivot();
|
var dragPivot = this._getDragPivot();
|
||||||
dragPivot.setVisibility(false);
|
dragPivot.setVisibility(false);
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
isInWorkspace: function(){
|
||||||
|
return this._isInWorkspace;
|
||||||
},
|
},
|
||||||
|
|
||||||
addToWorkspace : function(workspace) {
|
addToWorkspace : function(workspace) {
|
||||||
workspace.appendChild(this._elem2d);
|
workspace.appendChild(this._elem2d);
|
||||||
var dragPivot = this._getDragPivot();
|
var dragPivot = this._getDragPivot();
|
||||||
|
|
||||||
dragPivot.addToWorkspace(workspace);
|
dragPivot.addToWorkspace(workspace);
|
||||||
|
this._isInWorkspace = true;
|
||||||
},
|
},
|
||||||
|
|
||||||
_getDragPivot : function() {
|
_getDragPivot : function() {
|
||||||
|
@ -23,7 +23,6 @@ web2d.Element = new Class({
|
|||||||
throw "Element peer can not be null";
|
throw "Element peer can not be null";
|
||||||
}
|
}
|
||||||
|
|
||||||
this._dispatcherByEventType = new Hash({});
|
|
||||||
if ($defined(attributes)) {
|
if ($defined(attributes)) {
|
||||||
this._initialize(attributes);
|
this._initialize(attributes);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user