From 945fac7b1593260757b6f2864810ca9916d7d698 Mon Sep 17 00:00:00 2001 From: Nivesh Rajbhandari Date: Tue, 5 Jun 2012 11:36:03 -0700 Subject: Updated ink bottle tool to support color-chip's checkbox and undo/redo for strokes/borders. Signed-off-by: Nivesh Rajbhandari --- js/mediators/element-mediator.js | 61 ++++++++-------------------------------- 1 file changed, 11 insertions(+), 50 deletions(-) (limited to 'js/mediators') diff --git a/js/mediators/element-mediator.js b/js/mediators/element-mediator.js index 7244b58e..da8cbb76 100755 --- a/js/mediators/element-mediator.js +++ b/js/mediators/element-mediator.js @@ -373,17 +373,13 @@ exports.ElementMediator = Montage.create(Component, { }, getStroke: { - value: function(el) { - if(!el.elementModel) { - NJUtils.makeElementModel(el, "Div", "block"); - } - return el.elementModel.controller["getStroke"](el); + value: function(el, strokeProperties) { + return el.elementModel.controller["getStroke"](el, strokeProperties); } }, - /** - Set a property change command for an element or array of elements + Set stroke/border properties on an element or array of elements @param els: Array of elements. Can contain 1 or more elements @param value: Value to be set. This is the stroke info @param eventType: Change/Changing. Will be passed to the dispatched event @@ -393,54 +389,20 @@ exports.ElementMediator = Montage.create(Component, { setStroke: { value: function(els, value, eventType, source, currentValue) { - if(eventType === "Changing") { - this._setStroke(els, value, isFill, eventType, source); - } else { + if(eventType !== "Changing") { // Calculate currentValue if not found for each element if(!currentValue) { - var that = this; + var that = this, + val = value; currentValue = els.map(function(item) { - return that.getStroke(item); + return that.getStroke(item, val); }); } - - var command = Montage.create(Command, { - _els: { value: els }, - _value: { value: value }, - _previous: { value: currentValue }, - _eventType: { value: eventType}, - _source: { value: "undo-redo"}, - description: { value: "Set Color"}, - receiver: { value: this}, - - execute: { - value: function(senderObject) { - if(senderObject) this._source = senderObject; - this.receiver._setStroke(this._els, this._value, this._eventType, this._source); - this._source = "undo-redo"; - return ""; - } - }, - - unexecute: { - value: function() { - this.receiver._setStroke(this._els, this._previous, this._eventType, this._source); - return ""; - } - } - }); - - NJevent("sendToUndo", command); - command.execute(source); + document.application.undoManager.add("Set stroke", this.setStroke, this, els, currentValue, eventType, source, value); } - } - }, - - _setStroke: { - value: function(els, value, eventType, source) { for(var i=0, item; item = els[i]; i++) { - item.elementModel.controller["setStroke"](item, value); + item.elementModel.controller["setStroke"](item, (value[i] || value), eventType, source); } NJevent("element" + eventType, {type : "setStroke", source: source, data: {"els": els, "prop": "stroke", "value": value}, redraw: null}); @@ -453,9 +415,8 @@ exports.ElementMediator = Montage.create(Component, { } }, - /** - Set a property change command for an element or array of elements + Set fill/background properties for an element or array of elements @param els: Array of elements. Can contain 1 or more elements @param value: Value to be set. This is the fill info @param eventType: Change/Changing. Will be passed to the dispatched event @@ -478,7 +439,7 @@ exports.ElementMediator = Montage.create(Component, { } for(var i=0, item; item = els[i]; i++) { - item.elementModel.controller["setFill"](item, (value[i] || value), eventType, source); + item.elementModel.controller["setFill"](item, (value[i] || value)); } NJevent("element" + eventType, {type : "setFill", source: source, data: {"els": els, "prop": "fill", "value": value}, redraw: null}); -- cgit v1.2.3