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/EyedropperTool.js | 26 ++- js/tools/FillTool.js | 7 +- js/tools/InkBottleTool.js | 7 +- js/tools/PanTool.js | 22 ++- js/tools/PenTool.js | 28 ++-- js/tools/Rotate3DToolBase.js | 7 +- js/tools/SelectionTool.js | 103 ++++++------ js/tools/ShapeTool.js | 12 +- js/tools/TextTool.js | 6 +- js/tools/TranslateObject3DTool.js | 11 +- js/tools/ZoomTool.js | 330 +++++++++++++++----------------------- js/tools/drawing-tool-base.js | 7 +- js/tools/modifier-tool-base.js | 8 +- 13 files changed, 251 insertions(+), 323 deletions(-) (limited to 'js/tools') diff --git a/js/tools/EyedropperTool.js b/js/tools/EyedropperTool.js index 3d0799e0..1d97d11b 100755 --- a/js/tools/EyedropperTool.js +++ b/js/tools/EyedropperTool.js @@ -95,22 +95,19 @@ exports.EyedropperTool = Montage.create(toolBase, { }, HandleLeftButtonUp: { - value : function (event) { - { - this._isMouseDown = false; + value: function(event) { + this._isMouseDown = false; - if(this._escape) - { - this._escape = false; - } + if(this._escape) { + this._escape = false; + } - this._updateColor(this._color, true); + this._updateColor(this._color, true); - this._color = null; + this._color = null; - this._elementUnderMouse = null; - this._deleteImageDataCanvas(); - } + this._elementUnderMouse = null; + this._deleteImageDataCanvas(); } }, @@ -237,8 +234,7 @@ exports.EyedropperTool = Montage.create(toolBase, { if(color.mode === "gradient") { - this.application.ninja.colorController.colorModel["gradient"] = - {value: color.color, wasSetByCode: true, type: eventType}; + this.application.ninja.colorController.colorModel.gradient = {value: color.color, wasSetByCode: true, type: eventType}; } else { @@ -253,7 +249,7 @@ exports.EyedropperTool = Montage.create(toolBase, { } else { - this.application.ninja.colorController.colorModel["rgb"] = color.color; + this.application.ninja.colorController.colorModel.rgb = color.color; } } diff --git a/js/tools/FillTool.js b/js/tools/FillTool.js index 16a6f464..2c783cb6 100755 --- a/js/tools/FillTool.js +++ b/js/tools/FillTool.js @@ -77,13 +77,12 @@ exports.FillTool = Montage.create(ModifierToolBase, { }, HandleLeftButtonUp: { - value : function () { - //if(this._isDrawing) - { + value: function() { + //if(this._isDrawing) { this.application.ninja.stage.clearDrawingCanvas(); this._hasDraw = false; this._isDrawing = false; - } + //} } }, diff --git a/js/tools/InkBottleTool.js b/js/tools/InkBottleTool.js index c4197e77..68e7d107 100755 --- a/js/tools/InkBottleTool.js +++ b/js/tools/InkBottleTool.js @@ -77,13 +77,12 @@ exports.InkBottleTool = Montage.create(ModifierToolBase, { }, HandleLeftButtonUp: { - value : function () { - //if(this._isDrawing) - { + value: function() { + //if(this._isDrawing) { this.application.ninja.stage.clearDrawingCanvas(); this._hasDraw = false; this._isDrawing = false; - } + //} } }, diff --git a/js/tools/PanTool.js b/js/tools/PanTool.js index 374886e8..cab25726 100755 --- a/js/tools/PanTool.js +++ b/js/tools/PanTool.js @@ -95,12 +95,9 @@ exports.PanTool = Montage.create(toolBase, } }, - HandleLeftButtonUp: - { - value : function ( event ) - { - //if(this._isDrawing) - { + HandleLeftButtonUp: { + value: function(event) { + //if(this._isDrawing) { // do one final mouse move to update the scrollbars this.mouseUp( event ); @@ -108,7 +105,7 @@ exports.PanTool = Montage.create(toolBase, this._hasDraw = false; this._isDrawing = false; this.isDrawing = false; - } + //} } }, @@ -234,11 +231,10 @@ exports.PanTool = Montage.create(toolBase, }, - doMouseDown: - { - value: function( point ) - { + doMouseDown: { + value: function(point) { //var tmpPt, tmpPt2, tmpPt3, tmpPt4, tmpMat, tmpMat2; // DEBUG. (see use of these points below) + var cop; var hitRec = snapManager.snap( point.x, point.y, true ); if (hitRec) { @@ -260,7 +256,7 @@ exports.PanTool = Montage.create(toolBase, { var localPt = hitRec.calculateElementWorldPoint(); viewUtils.pushViewportObj( userContent ); - var cop = viewUtils.getCenterOfProjection(); + cop = viewUtils.getCenterOfProjection(); this._localPt = [cop[0] + localPt[0], cop[1] + localPt[1], localPt[2]]; viewUtils.popViewportObj(); } @@ -284,7 +280,7 @@ exports.PanTool = Montage.create(toolBase, // get a matrix from user content world space to the screen viewUtils.pushViewportObj( userContent ); - var cop = viewUtils.getCenterOfProjection(); + cop = viewUtils.getCenterOfProjection(); var pDist = viewUtils.getPerspectiveDistFromElement(userContent); var projMat = glmat4.scale(Matrix.I(4), [pDist,pDist,pDist], []); projMat[11] = -1; diff --git a/js/tools/PenTool.js b/js/tools/PenTool.js index 4b4fd227..a44438ac 100755 --- a/js/tools/PenTool.js +++ b/js/tools/PenTool.js @@ -302,6 +302,7 @@ exports.PenTool = Montage.create(ShapeTool, { HandleLeftButtonDown: { value: function (event) { + var newAnchor; //ignore any right or middle clicks if (event.button !== 0) { //todo NOTE: this will work on Webkit only...IE has different codes (left: 1, middle: 4, right: 2) @@ -427,7 +428,7 @@ exports.PenTool = Montage.create(ShapeTool, { } else { this._selectedSubpath.addAnchor(new AnchorPoint()); - var newAnchor = this._selectedSubpath.getAnchor(this._selectedSubpath.getSelectedAnchorIndex()); + newAnchor = this._selectedSubpath.getAnchor(this._selectedSubpath.getSelectedAnchorIndex()); newAnchor.setPos(stageWorldMousePos[0], stageWorldMousePos[1], stageWorldMousePos[2]); newAnchor.setPrevPos(stageWorldMousePos[0], stageWorldMousePos[1], stageWorldMousePos[2]); newAnchor.setNextPos(stageWorldMousePos[0], stageWorldMousePos[1], stageWorldMousePos[2]); @@ -489,7 +490,7 @@ exports.PenTool = Montage.create(ShapeTool, { if (numAnchors>1 && !this._selectedSubpath.getIsClosed() && this._selectedSubpath.getSelectedAnchorIndex()===0 && prevSelectedAnchorIndex === numAnchors-1){ //insert an anchor temporarily that will get removed in the mouse up handler this._selectedSubpath.addAnchor(new AnchorPoint()); - var newAnchor = this._selectedSubpath.getAnchor(this._selectedSubpath.getSelectedAnchorIndex()); + newAnchor = this._selectedSubpath.getAnchor(this._selectedSubpath.getSelectedAnchorIndex()); newAnchor.setPos(localMousePos[0], localMousePos[1], localMousePos[2]); newAnchor.setPrevPos(localMousePos[0], localMousePos[1], localMousePos[2]); newAnchor.setNextPos(localMousePos[0], localMousePos[1], localMousePos[2]); @@ -534,7 +535,7 @@ exports.PenTool = Montage.create(ShapeTool, { ) { if (!this._selectedSubpath.getIsClosed()) { //todo this test is probably unnecessary, but doing it to be safe this._selectedSubpath.addAnchor(new AnchorPoint()); - var newAnchor = this._selectedSubpath.getAnchor(this._selectedSubpath.getSelectedAnchorIndex()); + newAnchor = this._selectedSubpath.getAnchor(this._selectedSubpath.getSelectedAnchorIndex()); newAnchor.setPos(localMousePos[0], localMousePos[1], localMousePos[2]); newAnchor.setPrevPos(localMousePos[0], localMousePos[1], localMousePos[2]); @@ -564,6 +565,7 @@ exports.PenTool = Montage.create(ShapeTool, { HandleMouseMove: { value: function (event) { + var cursor; //ignore any right or middle clicks if (event.button !== 0) { //NOTE: this will work on Webkit only...IE has different codes (left: 1, middle: 4, right: 2) @@ -678,7 +680,7 @@ exports.PenTool = Montage.create(ShapeTool, { { //the anchor was hit this._hoveredAnchorIndex = selAnchorAndParamAndCode[0]; var lastAnchorIndex = this._selectedSubpath.getNumAnchors()-1; - var cursor; + if (this._subtool===this.SUBTOOL_NONE){ cursor = "url('images/cursors/penCursors/Pen_anchorSelect.png') 5 1, default"; if (this._selectedSubpath.getIsClosed()===false){ @@ -697,7 +699,7 @@ exports.PenTool = Montage.create(ShapeTool, { } else if (selAnchorAndParamAndCode[2] & this._selectedSubpath.SEL_PATH) { //change the cursor only if we're not in pen-minus subtool if (this._subtool!==this.SUBTOOL_PENMINUS){ - var cursor = "url('images/cursors/penCursors/Pen_plus.png') 5 1, default"; + cursor = "url('images/cursors/penCursors/Pen_plus.png') 5 1, default"; this.application.ninja.stage.drawingCanvas.style.cursor = cursor; } } @@ -735,6 +737,8 @@ exports.PenTool = Montage.create(ShapeTool, { return; } + var world, subpath; + w = Math.round(w); h = Math.round(h); var left = Math.round(midPt[0] - 0.5 * w); @@ -743,16 +747,16 @@ exports.PenTool = Montage.create(ShapeTool, { if (!canvas) { this._doesSelectionChangeNeedHandling = false; //this will ignore the selection change event triggered by the new canvas var newCanvas = document.application.njUtils.make("canvas", {"data-RDGE-id": NJUtils.generateRandom()}, this.application.ninja.currentDocument); - var styles = document.application.njUtils.stylesFromDraw(newCanvas, parseInt(w), parseInt(h), {midPt: midPt, planeMat: planeMat}); + var styles = document.application.njUtils.stylesFromDraw(newCanvas, parseInt(w, 10), parseInt(h, 10), {midPt: midPt, planeMat: planeMat}); this.application.ninja.elementMediator.addElements(newCanvas, styles, false); // create all the GL stuff - var world = this.getGLWorld(newCanvas, this._useWebGL);//this.options.use3D);//this.CreateGLWorld(planeMat, midPt, newCanvas, this._useWebGL);//fillMaterial, strokeMaterial); + world = this.getGLWorld(newCanvas, this._useWebGL);//this.options.use3D);//this.CreateGLWorld(planeMat, midPt, newCanvas, this._useWebGL);//fillMaterial, strokeMaterial); //store a reference to this newly created canvas this._selectedSubpathCanvas = newCanvas; this._selectedSubpathPlaneMat = ElementMediator.getMatrix(newCanvas); - var subpath = this._selectedSubpath; //new GLSubpath(); + subpath = this._selectedSubpath; //new GLSubpath(); subpath.setWorld(world); subpath.setCanvas(newCanvas); @@ -791,7 +795,7 @@ exports.PenTool = Montage.create(ShapeTool, { } //if (!canvas) { else { - var world = null; + world = null; if (canvas.elementModel.shapeModel && canvas.elementModel.shapeModel.GLWorld) { world = canvas.elementModel.shapeModel.GLWorld; } else { @@ -815,7 +819,7 @@ exports.PenTool = Montage.create(ShapeTool, { } } - var subpath = this._selectedSubpath; + subpath = this._selectedSubpath; subpath.setDrawingTool(this); subpath.setWorld(world); @@ -1358,7 +1362,7 @@ exports.PenTool = Montage.create(ShapeTool, { ctx.lineWidth = 1; var defFill = "#FFFFFF"; var defStroke = "green"; - var selHandleFill = "#000000" + var selHandleFill = "#000000"; ctx.strokeStyle = defStroke; ctx.fillStyle = defFill; @@ -1608,7 +1612,7 @@ exports.PenTool = Montage.create(ShapeTool, { var world = ElementMediator.getShapeProperty(this._selectedSubpathCanvas, "GLWorld"); if (world === null){ throw("Pen tool handleSelectionChange did not work correctly"); - break; //something bad happened //TODO handle this better + //something bad happened //TODO handle this better } //TODO assuming that we want the first subpath in this world...fix this! diff --git a/js/tools/Rotate3DToolBase.js b/js/tools/Rotate3DToolBase.js index 545aedad..bd735eea 100755 --- a/js/tools/Rotate3DToolBase.js +++ b/js/tools/Rotate3DToolBase.js @@ -245,6 +245,7 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { value: function(data, event) { var mat, angle, + f, pt0 = data.pt0, pt1 = data.pt1; @@ -291,7 +292,7 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { angle = this._getAngleToRotate(pt1.x, pt1.y); if(event.shiftKey) { - var f = Math.floor(angle/(Math.PI/4)); + f = Math.floor(angle/(Math.PI/4)); angle = f*Math.PI/4; } this._delta = angle; @@ -324,7 +325,7 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { } if(event.shiftKey) { - var f = Math.floor(zAngle/(Math.PI/4)); + f = Math.floor(zAngle/(Math.PI/4)); zAngle = f*Math.PI/4; } mat = Matrix.RotationZ(zAngle); @@ -335,7 +336,7 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, { var xAngle = -this._mouseSpeed * (pt1.y - this.downPoint.y) * Math.PI / 180.0; if(event.shiftKey) { - var f = Math.floor(yAngle/(Math.PI/4)); + f = Math.floor(yAngle/(Math.PI/4)); yAngle = f*Math.PI/4; f = Math.floor(xAngle/(Math.PI/4)); xAngle = f*Math.PI/4; diff --git a/js/tools/SelectionTool.js b/js/tools/SelectionTool.js index a136113b..07ae8cf5 100755 --- a/js/tools/SelectionTool.js +++ b/js/tools/SelectionTool.js @@ -272,7 +272,7 @@ var SelectionTool = exports.SelectionTool = Montage.create(ModifierToolBase, { HandleKeyPress: { value: function(event){ - var inc; + var inc, newLeft, leftArr, newTop, topArr; if (!(event.target instanceof HTMLInputElement)) { if(this.application.ninja.selectedElements.length !== 0) { @@ -280,36 +280,36 @@ var SelectionTool = exports.SelectionTool = Montage.create(ModifierToolBase, { switch(event.keyCode) { case Keyboard.LEFT: - var newLeft = []; - var leftArr = this.application.ninja.selectedElements.map(function(item) { - newLeft.push( (parseInt(ElementsMediator.getProperty(item, "left")) - inc) + "px" ); + newLeft = []; + leftArr = this.application.ninja.selectedElements.map(function(item) { + newLeft.push( (parseInt(ElementsMediator.getProperty(item, "left"), 10) - inc) + "px" ); return ElementsMediator.getProperty(item, "left"); }); ElementsMediator.setProperty(this.application.ninja.selectedElements, "left", newLeft , "Change", "selectionTool", leftArr); break; case Keyboard.UP: - var newTop = []; - var topArr = this.application.ninja.selectedElements.map(function(item) { - newTop.push( (parseInt(ElementsMediator.getProperty(item, "top")) - inc) + "px" ); + newTop = []; + topArr = this.application.ninja.selectedElements.map(function(item) { + newTop.push( (parseInt(ElementsMediator.getProperty(item, "top"), 10) - inc) + "px" ); return ElementsMediator.getProperty(item, "top"); }); ElementsMediator.setProperty(this.application.ninja.selectedElements, "top", newTop , "Change", "selectionTool", topArr); break; case Keyboard.RIGHT: - var newLeft = []; - var leftArr = this.application.ninja.selectedElements.map(function(item) { - newLeft.push( (parseInt(ElementsMediator.getProperty(item, "left")) + inc) + "px" ); + newLeft = []; + leftArr = this.application.ninja.selectedElements.map(function(item) { + newLeft.push( (parseInt(ElementsMediator.getProperty(item, "left"), 10) + inc) + "px" ); return ElementsMediator.getProperty(item, "left"); }); ElementsMediator.setProperty(this.application.ninja.selectedElements, "left", newLeft , "Change", "selectionTool", leftArr); break; case Keyboard.DOWN: - var newTop = []; - var topArr = this.application.ninja.selectedElements.map(function(item) { - newTop.push( (parseInt(ElementsMediator.getProperty(item, "top")) + inc) + "px" ); + newTop = []; + topArr = this.application.ninja.selectedElements.map(function(item) { + newTop.push( (parseInt(ElementsMediator.getProperty(item, "top"), 10) + inc) + "px" ); return ElementsMediator.getProperty(item, "top"); }); @@ -317,7 +317,6 @@ var SelectionTool = exports.SelectionTool = Montage.create(ModifierToolBase, { break; default: return false; - break; } @@ -339,17 +338,17 @@ var SelectionTool = exports.SelectionTool = Montage.create(ModifierToolBase, { var modObject = [], mod3dObject = [], self = this; this.application.ninja.selectedElements.forEach(function(element) { - + var prevW, prevH, w, h; if(addToUndo) { if(!self._use3DMode) { var prevX = element.elementModel.getProperty("x"); var prevY = element.elementModel.getProperty("y"); - var prevW = element.elementModel.getProperty("w"); - var prevH = element.elementModel.getProperty("h"); + prevW = element.elementModel.getProperty("w"); + prevH = element.elementModel.getProperty("h"); var x = ElementsMediator.getProperty(element, "left"); var y = ElementsMediator.getProperty(element, "top"); - var w = ElementsMediator.getProperty(element, "width"); - var h = ElementsMediator.getProperty(element, "height"); + w = ElementsMediator.getProperty(element, "width"); + h = ElementsMediator.getProperty(element, "height"); // if we have a delta, that means the transform handles were used and // we should update the width and height too. Otherwise, just update left and top. @@ -362,10 +361,10 @@ var SelectionTool = exports.SelectionTool = Montage.create(ModifierToolBase, { } else { // Not using the 3d mode var previousMat = element.elementModel.getProperty("mat").slice(0); - var prevW = element.elementModel.getProperty("w"); - var prevH = element.elementModel.getProperty("h"); - var w = ElementsMediator.getProperty(element, "width"); - var h = ElementsMediator.getProperty(element, "height"); + prevW = element.elementModel.getProperty("w"); + prevH = element.elementModel.getProperty("h"); + w = ElementsMediator.getProperty(element, "width"); + h = ElementsMediator.getProperty(element, "height"); var previousStyleStr = {dist:element.elementModel.getProperty("dist"), mat:MathUtils.scientificToDecimal(previousMat, 5)}; var newStyleStr = {dist:viewUtils.getPerspectiveDistFromElement(element), mat:MathUtils.scientificToDecimal(viewUtils.getMatrixFromElement(element), 5)}; @@ -421,8 +420,8 @@ var SelectionTool = exports.SelectionTool = Montage.create(ModifierToolBase, { viewUtils.setMatrixForElement( element, curMat, true); element.elementModel.setProperty("mat", curMat); } else { - var x = (parseInt(ElementsMediator.getProperty(element, "left")) + transMat[12]) + "px"; - var y = (parseInt(ElementsMediator.getProperty(element, "top")) + transMat[13]) + "px"; + var x = (parseInt(ElementsMediator.getProperty(element, "left"), 10) + transMat[12]) + "px"; + var y = (parseInt(ElementsMediator.getProperty(element, "top"), 10) + transMat[13]) + "px"; targets.push({element:element, properties:{left:x , top:y}}); } @@ -452,21 +451,21 @@ var SelectionTool = exports.SelectionTool = Montage.create(ModifierToolBase, { // Resize North-West this.application.ninja.selectedElements.forEach(function(element) { delta = ~~(data.pt1[0] - data.pt0[0]); - width = parseInt(element.elementModel.getProperty("w")) - delta; + width = parseInt(element.elementModel.getProperty("w"), 10) - delta; if(width <= 0) { width = 1; - left = parseInt(element.elementModel.getProperty("x")) + parseInt(element.elementModel.getProperty("w")) - 1; + left = parseInt(element.elementModel.getProperty("x"), 10) + parseInt(element.elementModel.getProperty("w"), 10) - 1; } else { - left = parseInt(element.elementModel.getProperty("x")) + delta; + left = parseInt(element.elementModel.getProperty("x"), 10) + delta; } delta = ~~(data.pt1[1] - data.pt0[1]); - height = parseInt(element.elementModel.getProperty("h")) - delta; + height = parseInt(element.elementModel.getProperty("h"), 10) - delta; if(height <= 0) { height = 1; - top = parseInt(element.elementModel.getProperty("y")) + parseInt(element.elementModel.getProperty("h")) - 1; + top = parseInt(element.elementModel.getProperty("y"), 10) + parseInt(element.elementModel.getProperty("h"), 10) - 1; } else { - top = parseInt(element.elementModel.getProperty("y")) + delta; + top = parseInt(element.elementModel.getProperty("y"), 10) + delta; } modObject.push({element:element, properties:{width: width + "px", height: height + "px", left: left + "px", top: top + "px"}}); }); @@ -475,12 +474,12 @@ var SelectionTool = exports.SelectionTool = Montage.create(ModifierToolBase, { // Resize West this.application.ninja.selectedElements.forEach(function(element) { delta = ~~(data.pt1[0] - data.pt0[0]); - width = parseInt(element.elementModel.getProperty("w")) - delta; + width = parseInt(element.elementModel.getProperty("w"), 10) - delta; if(width <= 0) { width = 1; - left = parseInt(element.elementModel.getProperty("x")) + parseInt(element.elementModel.getProperty("w")) - 1; + left = parseInt(element.elementModel.getProperty("x"), 10) + parseInt(element.elementModel.getProperty("w"), 10) - 1; } else { - left = parseInt(element.elementModel.getProperty("x")) + delta; + left = parseInt(element.elementModel.getProperty("x"), 10) + delta; } modObject.push({element:element, properties:{left: left + "px", width: width + "px"}}); }); @@ -489,15 +488,15 @@ var SelectionTool = exports.SelectionTool = Montage.create(ModifierToolBase, { // Resize South-West this.application.ninja.selectedElements.forEach(function(element) { delta = ~~(data.pt1[0] - data.pt0[0]); - width = parseInt(element.elementModel.getProperty("w")) - delta; + width = parseInt(element.elementModel.getProperty("w"), 10) - delta; if(width <= 0) { width = 1; - left = parseInt(element.elementModel.getProperty("x")) + parseInt(element.elementModel.getProperty("w")) - 1; + left = parseInt(element.elementModel.getProperty("x"), 10) + parseInt(element.elementModel.getProperty("w"), 10) - 1; } else { - left = parseInt(element.elementModel.getProperty("x")) + delta; + left = parseInt(element.elementModel.getProperty("x"), 10) + delta; } delta = ~~(data.pt1[1] - data.pt0[1]); - height = parseInt(element.elementModel.getProperty("h")) + delta; + height = parseInt(element.elementModel.getProperty("h"), 10) + delta; if(height <= 0) { height = 1; } @@ -508,7 +507,7 @@ var SelectionTool = exports.SelectionTool = Montage.create(ModifierToolBase, { // Resize South this.application.ninja.selectedElements.forEach(function(element) { delta = ~~(data.pt1[1] - data.pt0[1]); - height = parseInt(element.elementModel.getProperty("h")) + delta; + height = parseInt(element.elementModel.getProperty("h"), 10) + delta; if(height <= 0) { height = 1; } @@ -519,12 +518,12 @@ var SelectionTool = exports.SelectionTool = Montage.create(ModifierToolBase, { // Resize South-East this.application.ninja.selectedElements.forEach(function(element) { delta = ~~(data.pt1[0] - data.pt0[0]); - width = parseInt(element.elementModel.getProperty("w")) + delta; + width = parseInt(element.elementModel.getProperty("w"), 10) + delta; if(width <= 0) { width = 1; } delta = ~~(data.pt1[1] - data.pt0[1]); - height = parseInt(element.elementModel.getProperty("h")) + delta; + height = parseInt(element.elementModel.getProperty("h"), 10) + delta; if(height <= 0) { height = 1; } @@ -535,7 +534,7 @@ var SelectionTool = exports.SelectionTool = Montage.create(ModifierToolBase, { // Resize East this.application.ninja.selectedElements.forEach(function(element) { delta = ~~(data.pt1[0] - data.pt0[0]); - width = parseInt(element.elementModel.getProperty("w")) + delta; + width = parseInt(element.elementModel.getProperty("w"), 10) + delta; if(width <= 0) { width = 1; } @@ -546,17 +545,17 @@ var SelectionTool = exports.SelectionTool = Montage.create(ModifierToolBase, { // Resize North-East this.application.ninja.selectedElements.forEach(function(element) { delta = ~~(data.pt1[0] - data.pt0[0]); - width = parseInt(element.elementModel.getProperty("w")) + delta; + width = parseInt(element.elementModel.getProperty("w"), 10) + delta; if(width <= 0) { width = 1; } delta = ~~(data.pt1[1] - data.pt0[1]); - height = parseInt(element.elementModel.getProperty("h")) - delta; + height = parseInt(element.elementModel.getProperty("h"), 10) - delta; if(height <= 0) { height = 1; - top = parseInt(element.elementModel.getProperty("y")) + parseInt(element.elementModel.getProperty("h")) - 1; + top = parseInt(element.elementModel.getProperty("y"), 10) + parseInt(element.elementModel.getProperty("h"), 10) - 1; } else { - top = parseInt(element.elementModel.getProperty("y")) + delta; + top = parseInt(element.elementModel.getProperty("y"), 10) + delta; } modObject.push({element:element, properties:{width: width + "px", height: height + "px", top: top + "px"}}); }); @@ -565,12 +564,12 @@ var SelectionTool = exports.SelectionTool = Montage.create(ModifierToolBase, { // Resize North this.application.ninja.selectedElements.forEach(function(element) { delta = ~~(data.pt1[1] - data.pt0[1]); - height = parseInt(element.elementModel.getProperty("h")) - delta; + height = parseInt(element.elementModel.getProperty("h"), 10) - delta; if(height <= 0) { height = 1; - top = parseInt(element.elementModel.getProperty("y")) + parseInt(element.elementModel.getProperty("h")) - 1; + top = parseInt(element.elementModel.getProperty("y"), 10) + parseInt(element.elementModel.getProperty("h"), 10) - 1; } else { - top = parseInt(element.elementModel.getProperty("y")) + delta; + top = parseInt(element.elementModel.getProperty("y"), 10) + delta; } modObject.push({element:element, properties:{height: height + "px", top: top + "px"}}); }); @@ -657,10 +656,12 @@ var SelectionTool = exports.SelectionTool = Montage.create(ModifierToolBase, { y0 = bounds[0][1], y1 = bounds[1][1]; var dx = x1 - x0, dy = y1 - y0; var u = 0, v = 0; - if (MathUtils.fpSign(dx) != 0) + if (MathUtils.fpSign(dx) !== 0) { u = (scrPt[0] - x0) / dx; - if (MathUtils.fpSign(dy) != 0) + } + if (MathUtils.fpSign(dy) !== 0) { v = (scrPt[1] - y0) / dy; + } paramPt[0] = u; paramPt[1] = v; diff --git a/js/tools/ShapeTool.js b/js/tools/ShapeTool.js index ecc0dca3..e1ca31e6 100755 --- a/js/tools/ShapeTool.js +++ b/js/tools/ShapeTool.js @@ -167,13 +167,13 @@ exports.ShapeTool = Montage.create(DrawingTool, { }, getGLWorld: { - value: function (canvas, use3D) - { - var world = this.application.ninja.elementMediator.getShapeProperty(canvas, "GLWorld"); - if(!world) - { + value: function (canvas, use3D) { + var world; + + world = this.application.ninja.elementMediator.getShapeProperty(canvas, "GLWorld"); + if(!world) { // create all the GL stuff - var world = new World(canvas, use3D); + world = new World(canvas, use3D); this.application.ninja.elementMediator.setShapeProperty(canvas, "GLWorld", world); } diff --git a/js/tools/TextTool.js b/js/tools/TextTool.js index b98da3e6..d04254b0 100755 --- a/js/tools/TextTool.js +++ b/js/tools/TextTool.js @@ -30,8 +30,7 @@ POSSIBILITY OF SUCH DAMAGE. */ var Montage = require("montage/core/core").Montage, - DrawingTool = require("js/tools/drawing-tool").DrawingTool, - ElementsMediator = require("js/mediators/element-mediator").ElementMediator; + DrawingTool = require("js/tools/drawing-tool").DrawingTool; exports.TextTool = Montage.create(DrawingTool, { drawingFeedback: { @@ -175,8 +174,7 @@ exports.TextTool = Montage.create(DrawingTool, { self.applyElementStyles(self.selectedElement, self.application.ninja.stage.textTool.element, ["font","padding-left","padding-top","padding-right","padding-bottom", "color"]); this.selectAll(); this.didDraw = function() {}; - } - + }; } }, diff --git a/js/tools/TranslateObject3DTool.js b/js/tools/TranslateObject3DTool.js index 284ba417..a3ece1f9 100755 --- a/js/tools/TranslateObject3DTool.js +++ b/js/tools/TranslateObject3DTool.js @@ -32,7 +32,6 @@ POSSIBILITY OF SUCH DAMAGE. var Montage = require("montage/core/core").Montage, Translate3DToolBase = require("js/tools/Translate3DToolBase").Translate3DToolBase, drawUtils = require("js/helper-classes/3D/draw-utils").DrawUtils, - vecUtils = require("js/helper-classes/3D/vec-utils").VecUtils, viewUtils = require("js/helper-classes/3D/view-utils").ViewUtils, vecUtils = require("js/helper-classes/3D/vec-utils").VecUtils, snapManager = require("js/helper-classes/3D/snap-manager").SnapManager; @@ -48,8 +47,7 @@ exports.TranslateObject3DTool = Montage.create(Translate3DToolBase, { }, initializeSnapping : { - value : function(event) - { + value : function(event) { // console.log( "initializeSnapping" ); this._mouseDownHitRec = null; @@ -79,8 +77,7 @@ exports.TranslateObject3DTool = Montage.create(Translate3DToolBase, { else { this._delta = null; - //if(this._handleMode === 2) - { + //if(this._handleMode === 2) { this._dragPlane = viewUtils.getNormalToUnprojectedElementPlane(this._target, this._handleMode, this._inLocalMode); //console.log( "dragPlane: " + this._dragPlane ); snapManager.setupDragPlaneFromPlane(this._dragPlane); @@ -88,7 +85,7 @@ exports.TranslateObject3DTool = Montage.create(Translate3DToolBase, { snapManager.enableElementSnap ( false ); snapManager.enableGridSnap ( false ); - } + //} } if(this.application.ninja.selectedElements.length) { @@ -161,7 +158,7 @@ exports.TranslateObject3DTool = Montage.create(Translate3DToolBase, { // only do quadrant snapping if the 4 corners of the element are in the drag plane var sign = MathUtils.fpSign( vecUtils.vecDot(3,this._dragPlane,[0,0,1]) + this._dragPlane[3] - 1.0); - this._shouldUseQuadPt = (sign == 0); + this._shouldUseQuadPt = (sign === 0); var wpHitRec = hitRec.convertToWorkingPlane( this._dragPlane ); this._mouseDownHitRec = wpHitRec; 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; - + } } - } - } } - - }); diff --git a/js/tools/drawing-tool-base.js b/js/tools/drawing-tool-base.js index 92646894..cb094b85 100755 --- a/js/tools/drawing-tool-base.js +++ b/js/tools/drawing-tool-base.js @@ -300,7 +300,7 @@ exports.DrawingToolBase = Montage.create(Component, { s1Offset[1] += snapManager.getStageHeight() / 2.0; return ({ "width": w, "height": h, "planeMat": planeMat, "midPt": midPt, "mouseDownPos": s0Offset, "mouseUpPos": s1Offset }); } else { - return null + return null; } } }, @@ -516,7 +516,7 @@ exports.DrawingToolBase = Montage.create(Component, { value: function( s0In, s1In, planeMat, planeMatInv, fixedS1 ) { var s0 = s0In.slice(0); var s2 = s1In.slice(0); - + var pt0, pt1; // calculate the mid point of the rectangle var midPt = vecUtils.vecAdd(3, s0, s2); @@ -571,7 +571,8 @@ exports.DrawingToolBase = Montage.create(Component, { { p0 = ptArr[0]; p1 = ptArr[1]; p2 = ptArr[2]; p3 = ptArr[3]; z = p0[2]; - var pt0 = p0.slice(0), pt1 = p2.slice(0); + pt0 = p0.slice(0); + pt1 = p2.slice(0); if (p0[0] < p2[0]){ pt0[0] = Math.max(p0[0],p1[0]); pt1[0] = Math.min(p2[0],p3[0]); diff --git a/js/tools/modifier-tool-base.js b/js/tools/modifier-tool-base.js index d12ba7d2..18a08b5a 100755 --- a/js/tools/modifier-tool-base.js +++ b/js/tools/modifier-tool-base.js @@ -200,7 +200,7 @@ exports.ModifierToolBase = Montage.create(DrawingTool, { // only do quadrant snapping if the 4 corners of the element are in the drag plane var sign = MathUtils.fpSign( vecUtils.vecDot(3,this._dragPlane,[0,0,1]) + this._dragPlane[3] - 1.0); - this._shouldUseQuadPt = (sign == 0) + this._shouldUseQuadPt = (sign === 0); var wpHitRec = hitRec.convertToWorkingPlane( this._dragPlane ); this._mouseDownHitRec = wpHitRec; @@ -252,10 +252,12 @@ exports.ModifierToolBase = Montage.create(DrawingTool, { y0 = bounds[0][1], y1 = bounds[1][1]; var dx = x1 - x0, dy = y1 - y0; var u = 0, v = 0; - if (MathUtils.fpSign(dx) != 0) + if (MathUtils.fpSign(dx) !== 0) { u = (scrPt[0] - x0) / dx; - if (MathUtils.fpSign(dy) != 0) + } + if (MathUtils.fpSign(dy) !== 0) { v = (scrPt[1] - y0) / dy; + } paramPt[0] = u; paramPt[1] = v; -- cgit v1.2.3