From 55a69aeb3c66b533d5a2d27d7548471c2c8b5dfc Mon Sep 17 00:00:00 2001 From: Valerio Virgillito Date: Tue, 24 Jul 2012 00:24:20 -0700 Subject: jshint cleanup on the tools directory Signed-off-by: Valerio Virgillito --- js/tools/ZoomTool.js | 330 +++++++++++++++++++++------------------------------ 1 file changed, 132 insertions(+), 198 deletions(-) (limited to 'js/tools/ZoomTool.js') diff --git a/js/tools/ZoomTool.js b/js/tools/ZoomTool.js index a285db0f..0bcba2a3 100755 --- a/js/tools/ZoomTool.js +++ b/js/tools/ZoomTool.js @@ -34,7 +34,6 @@ var Montage = require("montage/core/core").Montage, snapManager = require("js/helper-classes/3D/snap-manager").SnapManager, viewUtils = require("js/helper-classes/3D/view-utils").ViewUtils, vecUtils = require("js/helper-classes/3D/vec-utils").VecUtils, - drawUtils = require("js/helper-classes/3D/draw-utils").DrawUtils, DrawingTool = require("js/tools/drawing-tool").DrawingTool; exports.ZoomTool = Montage.create(DrawingTool, { @@ -53,13 +52,11 @@ exports.ZoomTool = Montage.create(DrawingTool, { HandleLeftButtonDown: { - value : function (event) { - + value: function(event) { NJevent("enableStageMove"); - this._isDrawing=true; + this._isDrawing = true; - var point = webkitConvertPointFromPageToNode(this.application.ninja.stage.canvas, - new WebKitPoint(event.pageX, event.pageY)); + var point = webkitConvertPointFromPageToNode(this.application.ninja.stage.canvas, new WebKitPoint(event.pageX, event.pageY)); this.downPoint.x = point.x; this.downPoint.y = point.y; } @@ -67,40 +64,36 @@ exports.ZoomTool = Montage.create(DrawingTool, { HandleAltKeyDown: { value: function(event) { - this.setCursor(); - this._altKeyDown=true; - + this._altKeyDown = true; } }, HandleAltKeyUp: { value: function(event) { - this.setCursor(); - this._altKeyDown=false; + this._altKeyDown = false; } }, HandleEscape: { value: function(event) { this.application.ninja.stage.clearDrawingCanvas(); - this._escPressed=false; + this._escPressed = false; } }, Configure: { value: function(wasSelected) { - - if(this.options.selectedElement==="zoomOutTool"){ + if(this.options.selectedElement === "zoomOutTool") { var cursor = "url('images/cursors/zoom_minus.png'), default"; this.application.ninja.stage.drawingCanvas.style.cursor = cursor; } - if(wasSelected) { + + if(wasSelected) { this.AddCustomFeedback(); - this.eventManager.addEventListener( "toolDoubleClick", this, false); + this.eventManager.addEventListener("toolDoubleClick", this, false); this.application.ninja.stage.drawingCanvas.addEventListener("mousewheel", this, false); - } else { this.RemoveCustomFeedback(); this.eventManager.removeEventListener( "toolDoubleClick", this, false); @@ -110,87 +103,76 @@ exports.ZoomTool = Montage.create(DrawingTool, { }, AddCustomFeedback: { - value: function (event) { - + value: function(event) { this.application.ninja.stage.canvas.addEventListener("mousewheel", this, false); - } }, - handleScrollValue:{ - value:function(){ - + handleScrollValue: { + value: function() { this._mode = "mouseWheelZoom"; - this._zoomFactor= this.application.ninja.documentBar.zoomFactor/100; + this._zoomFactor = this.application.ninja.documentBar.zoomFactor/100; if(this._delta > 0){ this._zoomFactor *= 1.2; - } - else{ + } else{ this._zoomFactor /= 1.2; } + this._zoomFactor = this.checkZoomLimit(this._zoomFactor); this._setZoom(this._mode,this._zoomFactor); - this._mode="modeReset"; - + this._mode = "modeReset"; } }, - handleMousewheel :{ - value:function(event){ - - var point = webkitConvertPointFromPageToNode(this.application.ninja.stage.canvas, - new WebKitPoint(event.pageX, event.pageY)); + handleMousewheel: { + value: function(event) { + var point = webkitConvertPointFromPageToNode(this.application.ninja.stage.canvas, new WebKitPoint(event.pageX, event.pageY)); this._layerX = point.x; this._layerY = point.y; - this._delta = 0; + this._delta = 0; - if (event.wheelDelta) { - this._delta = event.wheelDelta/120; - } + if(event.wheelDelta) { + this._delta = event.wheelDelta/120; + } - if (this._delta){ - this.handleScrollValue(this._delta); - } + if(this._delta) { + this.handleScrollValue(this._delta); + } - if (event.preventDefault) - event.preventDefault(); - event.returnValue = false; + if(event.preventDefault) { + event.preventDefault(); + } + event.returnValue = false; } }, - HandleMouseMove: - { - value : function (event) - { - var point = webkitConvertPointFromPageToNode(this.application.ninja.stage.canvas, - new WebKitPoint(event.pageX, event.pageY)); + HandleMouseMove: { + value: function(event) { + var point = webkitConvertPointFromPageToNode(this.application.ninja.stage.canvas, new WebKitPoint(event.pageX, event.pageY)); // check for some reasonable amount of mouse movement var dx = Math.abs(point.x - this.downPoint.x), dy = Math.abs(point.y - this.downPoint.y); - if ((dx >= 10) || (dy >= 10)) - { + if ((dx >= 10) || (dy >= 10)) { // Drawing the Marquee - if(this.options.selectedElement==="zoomInTool") - { - if(this._altKeyDown) + if(this.options.selectedElement === "zoomInTool") { + if(this._altKeyDown) { this._hasDraw=false; - else + } else { this._hasDraw = true; - } - else - { - if(this._altKeyDown) + } + } else { + if(this._altKeyDown) { this._hasDraw=true; - else + } else { this._hasDraw=false; + } } - if(this._hasDraw) - { + if(this._hasDraw) { this.doDraw(event); this._x = this.downPoint.x; this._y = this.downPoint.y; @@ -199,50 +181,36 @@ exports.ZoomTool = Montage.create(DrawingTool, { } }, - handleZoomChange: - { - value: function(event) - { - } - }, - - _setZoom:{ - value:function(mode,zoomFactor) - { + _setZoom: { + value: function(mode,zoomFactor) { var userContent = this.application.ninja.currentDocument.model.documentRoot; this._oldValue = this.application.ninja.documentBar.zoomFactor; - var globalPt; - if(this._mode==="mouseClickZoom") - { - if(this.options.selectedElement==="zoomInTool") - { - if(this._altKeyDown) + var globalPt, localPt, w, h; + if(this._mode === "mouseClickZoom") { + if(this.options.selectedElement === "zoomInTool") { + if(this._altKeyDown) { this._factor = this._oldValue/(zoomFactor*100); - else + } else { this._factor = (zoomFactor*100)/this._oldValue; - } - else - { - if(this._altKeyDown) + } + } else { + if(this._altKeyDown) { this._factor = (zoomFactor*100)/this._oldValue; - else + } else { this._factor = this._oldValue/(zoomFactor*100); + } } var hitRec = snapManager.snap( this._layerX, this._layerY, true ); - if (hitRec) - { + if(hitRec) { var elt = hitRec.getElement(); - if (elt) - { -// console.log( "hit: " + hitRec.getElement().id ); + if(elt) { + // console.log( "hit: " + hitRec.getElement().id ); var localToGlobalMat = viewUtils.getLocalToGlobalMatrix( elt ); - var localPt; - if (elt != userContent) + if (elt != userContent) { localPt = hitRec.calculateElementPreTransformScreenPoint(); - else - { + } else { localPt = hitRec.calculateElementWorldPoint(); viewUtils.pushViewportObj( userContent ); var cop = viewUtils.getCenterOfProjection(); @@ -252,68 +220,57 @@ exports.ZoomTool = Montage.create(DrawingTool, { } globalPt = MathUtils.transformAndDivideHomogeneousPoint( localPt, localToGlobalMat ); - } - else + } else { globalPt = [this._layerX, this._layerY, 0]; - } - else + } + } else { globalPt = [this._layerX, this._layerY, 0]; - } - else if (this._mode==="marqueeZoom") - { + } + } else if(this._mode === "marqueeZoom") { this._factor = (zoomFactor*100)/this._oldValue; var p0 = [this._x, this._y, 0]; var p1 = [this._layerX, this._layerY, 0]; globalPt = vecUtils.vecAdd(3, p0, p1); vecUtils.vecScale(3, globalPt, 0.5); - } - else if (this._mode === "doubleClickReset") - { - if (userContent) - { - var w = userContent.offsetWidth, - h = userContent.offsetHeight; + } else if (this._mode === "doubleClickReset") { + if (userContent) { + w = userContent.offsetWidth; + h = userContent.offsetHeight; if(userContent.width) w = userContent.width; if(userContent.height) h = userContent.height; globalPt = [ w/2, h/2, 0]; - } - else + } else { globalPt = [0,0,0]; + } zoomFactor = 1; - } - else if (this._mode === "mouseWheelZoom") - { - var w = this.application.ninja.stage._canvas.width, - h = this.application.ninja.stage._canvas.height; + } else if (this._mode === "mouseWheelZoom") { + w = this.application.ninja.stage._canvas.width; + h = this.application.ninja.stage._canvas.height; globalPt = [w/2, h/2, 0]; - } - else - { + } else { console.log( "unhandled zoom mode: " + this._mode ); return; } // apply the scale to the matrices - var localPt = viewUtils.globalToLocal( globalPt, userContent ); + localPt = viewUtils.globalToLocal( globalPt, userContent ); viewUtils.setStageZoom( globalPt, zoomFactor ); // let the document and stage manager know about the zoom change this.application.ninja.stage._firstDraw = true; this.application.ninja.documentBar.zoomFactor = zoomFactor*100; //this.application.ninja.stage.zoomFactor = zoomFactor; - if (zoomFactor >= 1) - { + if (zoomFactor >= 1) { this.application.ninja.currentDocument.model.views.design.iframe.style.zoom = zoomFactor; } this.application.ninja.stage._firstDraw = false; //tmp3 = viewUtils.localToGlobal( localPt, userContent ); // DEBUG - remove this line // if we are resetting the zoom, clear out the translation from the matrices - if (this._mode === "doubleClickReset") - { + if (this._mode === "doubleClickReset") { viewUtils.clearStageTranslation(); this.application.ninja.stage.centerStage(); } @@ -324,127 +281,104 @@ exports.ZoomTool = Montage.create(DrawingTool, { }, handleToolDoubleClick: { - value: function () { - + value: function() { this._zoomFactor = 1; this._mode="doubleClickReset"; this._setZoom(this._mode ,this._zoomFactor); - } }, RemoveCustomFeedback: { value: function (event) { - this.application.ninja.stage.canvas.removeEventListener("mousewheel", this, false); - } }, - HandleLeftButtonUp : { - value : function(event) { - var point = webkitConvertPointFromPageToNode(this.application.ninja.stage.canvas, - new WebKitPoint(event.pageX, event.pageY)); + HandleLeftButtonUp: { + value: function(event) { + var point = webkitConvertPointFromPageToNode(this.application.ninja.stage.canvas, new WebKitPoint(event.pageX, event.pageY)); this._layerX = point.x; this._layerY = point.y; - if(event.which===1){ - if(this._isDrawing){ - this.endDraw(event); - if(this._hasDraw){ - if(this._escPressed){ - this._mode="marqueeZoom"; - this._zoomFactor =this.application.ninja.documentBar.zoomFactor/100; - this._zoomFactor *=4; - this._zoomFactor = this.checkZoomLimit(this._zoomFactor); - this._setZoom(this._mode,this._zoomFactor); - this._mode="modeReset"; - - } - this._escPressed=true; + if(event.which === 1) { + if(this._isDrawing) { + this.endDraw(event); + if(this._hasDraw) { + if(this._escPressed) { + this._mode = "marqueeZoom"; + this._zoomFactor = this.application.ninja.documentBar.zoomFactor/100; + this._zoomFactor *= 4; + this._zoomFactor = this.checkZoomLimit(this._zoomFactor); + this._setZoom(this._mode,this._zoomFactor); + this._mode="modeReset"; - } else{ - this._mode="mouseClickZoom"; - this._zoomFactor=this.application.ninja.documentBar.zoomFactor/100; - - if((this.options.selectedElement==="zoomInTool")){ + } + this._escPressed=true; + } else { + this._mode = "mouseClickZoom"; + this._zoomFactor = this.application.ninja.documentBar.zoomFactor/100; - if(this._altKeyDown) + if((this.options.selectedElement === "zoomInTool")) { + if(this._altKeyDown) { this._zoomFactor /= 1.2 ; - else + } else { this._zoomFactor *= 1.2 ; - - } - else{ - if(this._altKeyDown){ + } + } else { + if(this._altKeyDown) { this._zoomFactor *= 1.2 ; - } - else{ + } else { this._zoomFactor /= 1.2 ; } - } this._zoomFactor = this.checkZoomLimit(this._zoomFactor); this._setZoom(this._mode,this._zoomFactor); this._mode="modeReset"; - + } } - } - this._hasDraw=false; - NJevent("disableStageMove"); - this._isDrawing = false ; - } - else - { - return; + this._hasDraw = false; + NJevent("disableStageMove"); + this._isDrawing = false ; } - } + } }, - checkZoomLimit:{ - value:function( zoomFactor ){ - if(zoomFactor > 20) + checkZoomLimit: { + value: function(zoomFactor) { + if(zoomFactor > 20) { zoomFactor = 20; + } - if(zoomFactor < .25) - zoomFactor = .25; + if(zoomFactor < 0.25) { + zoomFactor = 0.25; + } return zoomFactor; } }, - setCursor:{ - value:function(){ - + setCursor: { + value: function() { + var cursor; if(this._altKeyDown){ - if(this.options.selectedElement==="zoomOutTool"){ - var cursor = "url('images/cursors/zoom_minus.png'), default"; + if(this.options.selectedElement === "zoomOutTool") { + cursor = "url('images/cursors/zoom_minus.png'), default"; this.application.ninja.stage.drawingCanvas.style.cursor = cursor; - } - else{ - var cursor = "url('images/cursors/zoom.png'), default"; + } else { + cursor = "url('images/cursors/zoom.png'), default"; this.application.ninja.stage.drawingCanvas.style.cursor = cursor; - - } - - } - else{ - - if(this.options.selectedElement==="zoomOutTool"){ - var cursor = "url('images/cursors/zoom.png'), default"; + } + } else { + if(this.options.selectedElement==="zoomOutTool") { + cursor = "url('images/cursors/zoom.png'), default"; this.application.ninja.stage.drawingCanvas.style.cursor = cursor; - } - else{ - var cursor = "url('images/cursors/zoom_minus.png'), default"; + } else { + cursor = "url('images/cursors/zoom_minus.png'), default"; this.application.ninja.stage.drawingCanvas.style.cursor = cursor; - + } } - } - } } - - }); -- cgit v1.2.3