From d20e5cf6d5368bdb56a8bcaa033ee86937187859 Mon Sep 17 00:00:00 2001 From: Paulo Veiga Date: Sun, 28 Aug 2011 11:38:15 -0300 Subject: [PATCH] Replace owr mouse function for a mootool one. --- core-js/src/main/javascript/Utils.js | 70 ------------------- .../src/main/javascript/MindmapDesigner.js | 2 + mindplot/src/main/javascript/ScreenManager.js | 35 +++++++--- mindplot/src/main/javascript/Workspace.js | 1 - 4 files changed, 27 insertions(+), 81 deletions(-) diff --git a/core-js/src/main/javascript/Utils.js b/core-js/src/main/javascript/Utils.js index 8dfc4ed3..a4b03f2f 100644 --- a/core-js/src/main/javascript/Utils.js +++ b/core-js/src/main/javascript/Utils.js @@ -50,76 +50,6 @@ Math.sign = function(value) { return (value >= 0) ? 1 : -1; }; - -/** - * Retrieve the mouse position. - */ -core.Utils.getMousePosition = function(event) { - var xcoord = -1; - var ycoord = -1; - - if (!$defined(event)) { - if ($defined(window.event)) { - //Internet Explorer - event = window.event; - } else { - //total failure, we have no way of referencing the event - throw "Could not obtain mouse position"; - } - } - if ($defined(event.$extended)) { - event = event.event; - } - if (typeof( event.pageX ) == 'number') { - //most browsers - xcoord = event.pageX; - ycoord = event.pageY; - } else if (typeof( event.clientX ) == 'number') { - //Internet Explorer and older browsers - //other browsers provide this, but follow the pageX/Y branch - xcoord = event.clientX; - ycoord = event.clientY; - var badOldBrowser = ( window.navigator.userAgent.indexOf('Opera') + 1 ) || - ( window.ScriptEngine && ScriptEngine().indexOf('InScript') + 1 ) || - ( navigator.vendor == 'KDE' ); - if (!badOldBrowser) { - if (document.body && ( document.body.scrollLeft || document.body.scrollTop )) { - //IE 4, 5 & 6 (in non-standards compliant mode) - xcoord += document.body.scrollLeft; - ycoord += document.body.scrollTop; - } else if (document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop )) { - //IE 6 (in standards compliant mode) - xcoord += document.documentElement.scrollLeft; - ycoord += document.documentElement.scrollTop; - } - } - } else { - throw "Could not obtain mouse position"; - } - - - return {x:xcoord,y:ycoord}; -}; - - -/** - * Calculate the position of the passed element. - */ -core.Utils.workOutDivElementPosition = function(divElement) { - var curleft = 0; - var curtop = 0; - if ($defined(divElement.offsetParent)) { - curleft = divElement.offsetLeft; - curtop = divElement.offsetTop; - while (divElement = divElement.offsetParent) { - curleft += divElement.offsetLeft; - curtop += divElement.offsetTop; - } - } - return {x:curleft,y:curtop}; -}; - - core.Utils.innerXML = function(/*Node*/node) { // summary: // Implementation of MS's innerXML function. diff --git a/mindplot/src/main/javascript/MindmapDesigner.js b/mindplot/src/main/javascript/MindmapDesigner.js index 1550a056..42db9db6 100644 --- a/mindplot/src/main/javascript/MindmapDesigner.js +++ b/mindplot/src/main/javascript/MindmapDesigner.js @@ -132,6 +132,8 @@ mindplot.MindmapDesigner = new Class({ setViewPort : function(size) { this._workspace.setViewPort(size); + var model = this.getModel(); + this._workspace.setZoom(model.getZoom(), true); }, _buildNodeGraph : function(model) { diff --git a/mindplot/src/main/javascript/ScreenManager.js b/mindplot/src/main/javascript/ScreenManager.js index 5272e8fb..969a6721 100644 --- a/mindplot/src/main/javascript/ScreenManager.js +++ b/mindplot/src/main/javascript/ScreenManager.js @@ -34,7 +34,7 @@ mindplot.ScreenManager = new Class({ setScale : function(scale) { $assert(scale, 'Screen scale can not be null'); - this._workspaceScale = scale; + this._scale = scale; }, addEvent : function(event, listener) { @@ -73,8 +73,8 @@ mindplot.ScreenManager = new Class({ y = y - this._offset.y; // Scale coordinate in order to be relative to the workspace. That's coord/size; - x = x / this._workspaceScale; - y = y / this._workspaceScale; + x = x / this._scale; + y = y / this._scale; // Remove decimal part.. return {x:x,y:y}; @@ -113,21 +113,21 @@ mindplot.ScreenManager = new Class({ return {x:x + topicPosition.x,y:y + topicPosition.y}; }, - getWorkspaceMousePosition : function(e) { + getWorkspaceMousePosition : function(event) { // Retrieve current mouse position. - var mousePosition = this._getMousePosition(e); + var mousePosition = this._getMousePosition(event); var x = mousePosition.x; var y = mousePosition.y; // Subtract div position. var containerElem = this.getContainer(); - var containerPosition = core.Utils.workOutDivElementPosition(containerElem); + var containerPosition = this._getDivPosition(containerElem); x = x - containerPosition.x; y = y - containerPosition.y; // Scale coordinate in order to be relative to the workspace. That's coordSize/size; - x = x * this._workspaceScale; - y = y * this._workspaceScale; + x = x * this._scale; + y = y * this._scale; // Add workspace offset. x = x + this._offset.x; @@ -138,10 +138,25 @@ mindplot.ScreenManager = new Class({ }, /** - * http://www.howtocreate.co.uk/tutorials/javascript/eventinfo + * Calculate the position of the passed element. */ + _getDivPosition : function(divElement) { + var curleft = 0; + var curtop = 0; + if ($defined(divElement.offsetParent)) { + curleft = divElement.offsetLeft; + curtop = divElement.offsetTop; + while (divElement = divElement.offsetParent) { + curleft += divElement.offsetLeft; + curtop += divElement.offsetTop; + } + } + return {x:curleft,y:curtop}; + }, + _getMousePosition : function(event) { - return core.Utils.getMousePosition(event); + $assert(event, 'event can not be null'); + return {x:event.client.x,y:event.client.y}; }, getContainer : function() { diff --git a/mindplot/src/main/javascript/Workspace.js b/mindplot/src/main/javascript/Workspace.js index f5b5d252..48b482f1 100644 --- a/mindplot/src/main/javascript/Workspace.js +++ b/mindplot/src/main/javascript/Workspace.js @@ -219,7 +219,6 @@ mindplot.Workspace = new Class({ setViewPort : function(size) { this._viewPort = size; - this.setZoom(this._zoom, true); } });