From e28eb9158a50d7e6d97dbc68066e591ac600c241 Mon Sep 17 00:00:00 2001 From: Valerio Virgillito Date: Tue, 5 Jun 2012 21:40:44 -0700 Subject: removing all model creators. The elementModel is now a getter that will create a new model when needed. Signed-off-by: Valerio Virgillito --- js/tools/ShapeTool.js | 1 - 1 file changed, 1 deletion(-) (limited to 'js/tools/ShapeTool.js') diff --git a/js/tools/ShapeTool.js b/js/tools/ShapeTool.js index 367ab78d..6956aea8 100755 --- a/js/tools/ShapeTool.js +++ b/js/tools/ShapeTool.js @@ -60,7 +60,6 @@ exports.ShapeTool = Montage.create(DrawingTool, { if(drawData) { if(!this._useExistingCanvas()) { canvas = document.application.njUtils.make("canvas", {"data-RDGE-id": NJUtils.generateRandom()}, this.application.ninja.currentDocument); - document.application.njUtils.createModelWithShape(canvas); var styles = document.application.njUtils.stylesFromDraw(canvas, ~~drawData.width, ~~drawData.height, drawData); this.application.ninja.elementMediator.addElements(canvas, styles); -- cgit v1.2.3 From e4e3ee77aa01f9b6e7592306ebfa9f123a60c624 Mon Sep 17 00:00:00 2001 From: Nivesh Rajbhandari Date: Wed, 6 Jun 2012 13:59:37 -0700 Subject: Do not create any tags or shapes with width or height of 0. Signed-off-by: Nivesh Rajbhandari --- js/tools/ShapeTool.js | 46 +++++++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 21 deletions(-) (limited to 'js/tools/ShapeTool.js') diff --git a/js/tools/ShapeTool.js b/js/tools/ShapeTool.js index 367ab78d..8886285d 100755 --- a/js/tools/ShapeTool.js +++ b/js/tools/ShapeTool.js @@ -55,24 +55,30 @@ exports.ShapeTool = Montage.create(DrawingTool, { HandleLeftButtonUp: { value: function (event) { - var canvas, drawData = this.getDrawingData(); - - if(drawData) { - if(!this._useExistingCanvas()) { - canvas = document.application.njUtils.make("canvas", {"data-RDGE-id": NJUtils.generateRandom()}, this.application.ninja.currentDocument); - document.application.njUtils.createModelWithShape(canvas); - - var styles = document.application.njUtils.stylesFromDraw(canvas, ~~drawData.width, ~~drawData.height, drawData); - this.application.ninja.elementMediator.addElements(canvas, styles); - } else { - canvas = this._targetedElement; - if (!canvas.getAttribute( "data-RDGE-id" )) - canvas.setAttribute( "data-RDGE-id", NJUtils.generateRandom() ); - canvas.elementModel.controller = ShapesController; - if(!canvas.elementModel.shapeModel) { - canvas.elementModel.shapeModel = Montage.create(ShapeModel); + var canvas, w, h; + this.drawData = this.getDrawingData(); + + if(this.drawData) { + w = Math.floor(this.drawData.width); + h = Math.floor(this.drawData.height); + + if( (w > 0) && (h > 0) ) { + if(!this._useExistingCanvas()) { + canvas = document.application.njUtils.make("canvas", {"data-RDGE-id": NJUtils.generateRandom()}, this.application.ninja.currentDocument); + document.application.njUtils.createModelWithShape(canvas); + + var styles = document.application.njUtils.stylesFromDraw(canvas, w, h, this.drawData); + this.application.ninja.elementMediator.addElements(canvas, styles); + } else { + canvas = this._targetedElement; + if (!canvas.getAttribute( "data-RDGE-id" )) + canvas.setAttribute( "data-RDGE-id", NJUtils.generateRandom() ); + canvas.elementModel.controller = ShapesController; + if(!canvas.elementModel.shapeModel) { + canvas.elementModel.shapeModel = Montage.create(ShapeModel); + } + this.RenderShape(w, h, this.drawData.planeMat, this.drawData.midPt, canvas); } - this.RenderShape(drawData.width, drawData.height, drawData.planeMat, drawData.midPt, canvas); } } @@ -87,10 +93,8 @@ exports.ShapeTool = Montage.create(DrawingTool, { onAddElements: { value: function(el) { - var drawData; - - if(drawData = this.getDrawingData()) { - this.RenderShape(drawData.width, drawData.height, drawData.planeMat, drawData.midPt, el); + if(this.drawData) { + this.RenderShape(this.drawData.width, this.drawData.height, this.drawData.planeMat, this.drawData.midPt, el); } } }, -- cgit v1.2.3