From 48d4dd0f0570f4ac3556f228846ed0fd98a674e5 Mon Sep 17 00:00:00 2001 From: Valerio Virgillito Date: Mon, 9 Apr 2012 16:47:56 -0700 Subject: setProperties to the montage undo/redo Signed-off-by: Valerio Virgillito --- js/controllers/elements/element-controller.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'js/controllers/elements/element-controller.js') diff --git a/js/controllers/elements/element-controller.js b/js/controllers/elements/element-controller.js index fda3a3c5..adac1420 100755 --- a/js/controllers/elements/element-controller.js +++ b/js/controllers/elements/element-controller.js @@ -47,9 +47,19 @@ exports.ElementController = Montage.create(Component, { }, setProperties: { - value: function(el, props, index) { - for(var p in props) { - this.application.ninja.stylesController.setElementStyle(el, p, props[p][index]); + value: function(element, properties) { + /* Array of properties is not supported yet + if(Array.isArray(properties)) { + + elements.forEach(function(property) { + this.application.ninja.stylesController.setElementStyle(element, p, props[p][index]); + }); + } else { + } + */ + + for(var property in properties) { + this.application.ninja.stylesController.setElementStyle(element, property, properties[property]); } } }, -- cgit v1.2.3 From 6885e66a1f668f34699145f0da231c5d4ecbe666 Mon Sep 17 00:00:00 2001 From: Valerio Virgillito Date: Tue, 10 Apr 2012 11:07:36 -0700 Subject: some code cleanup Signed-off-by: Valerio Virgillito --- js/controllers/elements/element-controller.js | 90 +++++++++------------------ 1 file changed, 29 insertions(+), 61 deletions(-) (limited to 'js/controllers/elements/element-controller.js') diff --git a/js/controllers/elements/element-controller.js b/js/controllers/elements/element-controller.js index adac1420..b8411ac0 100755 --- a/js/controllers/elements/element-controller.js +++ b/js/controllers/elements/element-controller.js @@ -75,37 +75,29 @@ exports.ElementController = Montage.create(Component, { // borderSide : "top", "right", "bottom", or "left" getColor: { value: function(el, isFill, borderSide) { - var colorObj, - color, - image; + var colorObj, color, image; // Return cached value if one exists - if(isFill) - { - if(el.elementModel.fill) - { + if(isFill) { + if(el.elementModel.fill) { return el.elementModel.fill; } //TODO: Once logic for color and gradient is established, this needs to be revised color = this.getProperty(el, "background-color"); image = this.getProperty(el, "background-image"); - } - else - { + } else { // Try getting border color from specific side first - if(borderSide) - { + if(borderSide) { color = this.getProperty(el, "border-" + borderSide + "-color"); image = this.getProperty(el, "border-" + borderSide + "-image"); } // If no color was found, look up the shared border color - if(!color && !image) - { - if(el.elementModel.stroke) - { + if(!color && !image) { + if(el.elementModel.stroke) { return el.elementModel.stroke; } + color = this.getProperty(el, "border-color"); image = this.getProperty(el, "border-image"); } @@ -122,17 +114,12 @@ exports.ElementController = Montage.create(Component, { } // Update cache - if(isFill) - { + if(isFill) { el.elementModel.fill = colorObj; - } - else if(!borderSide) - { + } else if(!borderSide) { // TODO - Need to update border style and width also el.elementModel.stroke = colorObj; - } - else - { + } else { // TODO - Should update specific border sides too } @@ -143,10 +130,9 @@ exports.ElementController = Montage.create(Component, { setColor: { value: function(el, color, isFill) { var mode = color.mode; - if(isFill) - { - if(mode) - { + + if(isFill) { + if(mode) { switch (mode) { case 'nocolor': this.setProperty(el, "background-image", "none"); @@ -162,12 +148,10 @@ exports.ElementController = Montage.create(Component, { this.setProperty(el, "background-color", color.color.css); } } + el.elementModel.fill = color; - } - else - { - if(mode) - { + } else { + if(mode) { switch (mode) { case 'nocolor': this.setProperty(el, "border-image", "none"); @@ -177,20 +161,16 @@ exports.ElementController = Montage.create(Component, { case 'gradient': this.setProperty(el, "border-image", color.color.css); this.setProperty(el, "border-color", "none"); - if(color.borderInfo) - { - this.setProperty(el, "border-width", color.borderInfo.borderWidth + - color.borderInfo.borderUnits); + if(color.borderInfo) { + this.setProperty(el, "border-width", color.borderInfo.borderWidth + color.borderInfo.borderUnits); this.setProperty(el, "border-style", color.borderInfo.borderStyle); } break; default: this.setProperty(el, "border-image", "none"); this.setProperty(el, "border-color", color.color.css); - if(color.borderInfo) - { - this.setProperty(el, "border-width", color.borderInfo.borderWidth + - color.borderInfo.borderUnits); + if(color.borderInfo) { + this.setProperty(el, "border-width", color.borderInfo.borderWidth + color.borderInfo.borderUnits); this.setProperty(el, "border-style", color.borderInfo.borderStyle); } } @@ -219,8 +199,7 @@ exports.ElementController = Montage.create(Component, { // Routines to get/set 3D properties get3DProperty: { value: function(el, prop) { - if(el.elementModel && el.elementModel.props3D) - { + if(el.elementModel && el.elementModel.props3D) { return el.elementModel.props3D[prop]; } } @@ -228,16 +207,12 @@ exports.ElementController = Montage.create(Component, { getMatrix: { value: function(el) { - if(el.elementModel && el.elementModel.props3D && el.elementModel.props3D.matrix3d) - { + if(el.elementModel && el.elementModel.props3D && el.elementModel.props3D.matrix3d) { return el.elementModel.props3D.matrix3d.slice(0); - } - else - { + } else { var mat; - if (el) - { + if (el) { mat = this.application.ninja.stylesController.getMatrixFromElement(el, false); if (!mat) { mat = Matrix.I(4); @@ -252,12 +227,9 @@ exports.ElementController = Montage.create(Component, { getPerspectiveDist: { value: function(el) { - if(el.elementModel && el.elementModel.props3D && el.elementModel.props3D.perspectiveDist) - { + if(el.elementModel && el.elementModel.props3D && el.elementModel.props3D.perspectiveDist) { return el.elementModel.props3D.perspectiveDist; - } - else - { + } else { var dist = this.application.ninja.stylesController.getPerspectiveDistFromElement(el, false); if(dist == null) { dist = 1400; @@ -274,16 +246,12 @@ exports.ElementController = Montage.create(Component, { value: function(el, props, index, update3DModel) { var dist = props[index]["dist"], mat = props[index]["mat"]; - this.application.ninja.stylesController.setElementStyle(el, - "-webkit-transform", - "perspective(" + dist + ") " + - "matrix3d(" + MathUtils.scientificToDecimal(mat, 5) + ")"); + this.application.ninja.stylesController.setElementStyle(el, "-webkit-transform", "perspective(" + dist + ") " + "matrix3d(" + MathUtils.scientificToDecimal(mat, 5) + ")"); el.elementModel.props3D.matrix3d = mat; el.elementModel.props3D.perspectiveDist = dist; - if(update3DModel) - { + if(update3DModel) { this._update3DProperties(el, mat, dist); } } -- cgit v1.2.3 From f91e64235eb03c889ff4f5577c3e3480cd0d787f Mon Sep 17 00:00:00 2001 From: Valerio Virgillito Date: Fri, 13 Apr 2012 00:30:19 -0700 Subject: removing _undo array and _targets array and use object instead of matching arrays to set properties Signed-off-by: Valerio Virgillito --- js/controllers/elements/element-controller.js | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) (limited to 'js/controllers/elements/element-controller.js') diff --git a/js/controllers/elements/element-controller.js b/js/controllers/elements/element-controller.js index 0f17dd46..35a543ac 100755 --- a/js/controllers/elements/element-controller.js +++ b/js/controllers/elements/element-controller.js @@ -48,16 +48,6 @@ exports.ElementController = Montage.create(Component, { setProperties: { value: function(element, properties) { - /* Array of properties is not supported yet - if(Array.isArray(properties)) { - - elements.forEach(function(property) { - this.application.ninja.stylesController.setElementStyle(element, p, props[p][index]); - }); - } else { - } - */ - for(var property in properties) { this.application.ninja.stylesController.setElementStyle(element, property, properties[property]); } @@ -239,15 +229,16 @@ exports.ElementController = Montage.create(Component, { // TODO - perspective distance needs to be passed in as "dist" and matrix3d needs to be passed in as "mat" set3DProperties: { - value: function(el, props, index, update3DModel) { - var dist = props[index]["dist"], - mat = props[index]["mat"]; + value: function(el, props, update3DModel) { + var dist = props["dist"], + mat = props["mat"]; + this.application.ninja.stylesController.setElementStyle(el, "-webkit-transform", "matrix3d(" + MathUtils.scientificToDecimal(mat, 5) + ")"); this.application.ninja.stylesController.setElementStyle(el, "-webkit-transform-style", "preserve-3d"); // TODO - We don't support perspective on individual elements yet -// this.application.ninja.stylesController.setElementStyle(el, "-webkit-perspective", dist); + // this.application.ninja.stylesController.setElementStyle(el, "-webkit-perspective", dist); el.elementModel.props3D.matrix3d = mat; el.elementModel.props3D.perspectiveDist = dist; -- cgit v1.2.3