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