diff options
author | Valerio Virgillito | 2012-06-05 21:43:48 -0700 |
---|---|---|
committer | Valerio Virgillito | 2012-06-05 21:43:48 -0700 |
commit | fb684fb27c2cef04251655d86e55eceed9da3132 (patch) | |
tree | a7773e4d8ee6cb3d047e5aa5f8c4f33403099574 /js/mediators | |
parent | e28eb9158a50d7e6d97dbc68066e591ac600c241 (diff) | |
parent | 18e212dca48066d1ddaca96875a3f40adcc859b6 (diff) | |
download | ninja-fb684fb27c2cef04251655d86e55eceed9da3132.tar.gz |
Merge branch 'refs/heads/master' into element-model-fixes
Conflicts:
js/mediators/element-mediator.js
Signed-off-by: Valerio Virgillito <valerio@motorola.com>
Diffstat (limited to 'js/mediators')
-rwxr-xr-x | js/mediators/element-mediator.js | 91 |
1 files changed, 46 insertions, 45 deletions
diff --git a/js/mediators/element-mediator.js b/js/mediators/element-mediator.js index cecb4392..40e94cca 100755 --- a/js/mediators/element-mediator.js +++ b/js/mediators/element-mediator.js | |||
@@ -29,13 +29,13 @@ exports.ElementMediator = Montage.create(Component, { | |||
29 | if(Array.isArray(elements)) { | 29 | if(Array.isArray(elements)) { |
30 | elements.forEach(function(element) { | 30 | elements.forEach(function(element) { |
31 | ElementController.addElement(element, rules); | 31 | ElementController.addElement(element, rules); |
32 | element.elementModel.props3D.init(element, false); | 32 | element.elementModel.props3D.init(element, false); |
33 | }); | 33 | }); |
34 | } else { | 34 | } else { |
35 | ElementController.addElement(elements, rules); | 35 | ElementController.addElement(elements, rules); |
36 | elements.elementModel.props3D.init(elements, false); | 36 | elements.elementModel.props3D.init(elements, false); |
37 | 37 | ||
38 | } | 38 | } |
39 | 39 | ||
40 | if(this.addDelegate && typeof (this.addDelegate['onAddElements']) === "function") { | 40 | if(this.addDelegate && typeof (this.addDelegate['onAddElements']) === "function") { |
41 | this.addDelegate['onAddElements'].call(this.addDelegate, elements); | 41 | this.addDelegate['onAddElements'].call(this.addDelegate, elements); |
@@ -352,75 +352,76 @@ exports.ElementMediator = Montage.create(Component, { | |||
352 | }, | 352 | }, |
353 | 353 | ||
354 | getStroke: { | 354 | getStroke: { |
355 | value: function(el) { | 355 | value: function(el, strokeProperties) { |
356 | return el.elementModel.controller["getStroke"](el); | 356 | return el.elementModel.controller["getStroke"](el, strokeProperties); |
357 | } | 357 | } |
358 | }, | 358 | }, |
359 | 359 | ||
360 | |||
361 | /** | 360 | /** |
362 | Set a property change command for an element or array of elements | 361 | Set stroke/border properties on an element or array of elements |
363 | @param els: Array of elements. Can contain 1 or more elements | 362 | @param els: Array of elements. Can contain 1 or more elements |
364 | @param value: Value to be set. This is the stroke info | 363 | @param value: Value to be set. This is the stroke info |
365 | @param eventType: Change/Changing. Will be passed to the dispatched event | 364 | @param eventType: Change/Changing. Will be passed to the dispatched event |
366 | @param source: String for the source object making the call | 365 | @param source: String for the source object making the call |
367 | @param currentValue *OPTIONAL*: current value array. If not found the current value is calculated | 366 | @param currentValue *OPTIONAL*: current value array. If not found the current value is calculated |
368 | @param stageRedraw: *OPTIONAL*: True. If set to false the stage will not redraw the selection/outline | ||
369 | */ | 367 | */ |
370 | setStroke: { | 368 | setStroke: { |
371 | value: function(els, value, eventType, source, currentValue) { | 369 | value: function(els, value, eventType, source, currentValue) { |
372 | 370 | ||
373 | if(eventType === "Changing") { | 371 | if(eventType !== "Changing") { |
374 | this._setStroke(els, value, isFill, eventType, source); | ||
375 | } else { | ||
376 | // Calculate currentValue if not found for each element | 372 | // Calculate currentValue if not found for each element |
377 | if(!currentValue) { | 373 | if(!currentValue) { |
378 | var that = this; | 374 | var that = this, |
375 | val = value; | ||
379 | currentValue = els.map(function(item) { | 376 | currentValue = els.map(function(item) { |
380 | return that.getStroke(item); | 377 | return that.getStroke(item, val); |
381 | }); | 378 | }); |
382 | } | 379 | } |
380 | document.application.undoManager.add("Set stroke", this.setStroke, this, els, currentValue, eventType, source, value); | ||
381 | } | ||
383 | 382 | ||
384 | var command = Montage.create(Command, { | 383 | for(var i=0, item; item = els[i]; i++) { |
385 | _els: { value: els }, | 384 | item.elementModel.controller["setStroke"](item, (value[i] || value), eventType, source); |
386 | _value: { value: value }, | ||
387 | _previous: { value: currentValue }, | ||
388 | _eventType: { value: eventType}, | ||
389 | _source: { value: "undo-redo"}, | ||
390 | description: { value: "Set Color"}, | ||
391 | receiver: { value: this}, | ||
392 | |||
393 | execute: { | ||
394 | value: function(senderObject) { | ||
395 | if(senderObject) this._source = senderObject; | ||
396 | this.receiver._setStroke(this._els, this._value, this._eventType, this._source); | ||
397 | this._source = "undo-redo"; | ||
398 | return ""; | ||
399 | } | ||
400 | }, | ||
401 | |||
402 | unexecute: { | ||
403 | value: function() { | ||
404 | this.receiver._setStroke(this._els, this._previous, this._eventType, this._source); | ||
405 | return ""; | ||
406 | } | ||
407 | } | ||
408 | }); | ||
409 | |||
410 | NJevent("sendToUndo", command); | ||
411 | command.execute(source); | ||
412 | } | 385 | } |
413 | 386 | ||
387 | NJevent("element" + eventType, {type : "setStroke", source: source, data: {"els": els, "prop": "stroke", "value": value}, redraw: null}); | ||
388 | } | ||
389 | }, | ||
390 | |||
391 | getFill: { | ||
392 | value: function(el, fillProperties) { | ||
393 | return el.elementModel.controller["getFill"](el, fillProperties); | ||
414 | } | 394 | } |
415 | }, | 395 | }, |
416 | 396 | ||
417 | _setStroke: { | 397 | /** |
418 | value: function(els, value, eventType, source) { | 398 | Set fill/background properties for an element or array of elements |
399 | @param els: Array of elements. Can contain 1 or more elements | ||
400 | @param value: Value to be set. This is the fill info | ||
401 | @param eventType: Change/Changing. Will be passed to the dispatched event | ||
402 | @param source: String for the source object making the call | ||
403 | @param currentValue *OPTIONAL*: current value array. If not found the current value is calculated | ||
404 | */ | ||
405 | setFill: { | ||
406 | value: function(els, value, eventType, source, currentValue) { | ||
407 | |||
408 | if(eventType !== "Changing") { | ||
409 | // Calculate currentValue if not found for each element | ||
410 | if(!currentValue) { | ||
411 | var that = this, | ||
412 | val = value; | ||
413 | currentValue = els.map(function(item) { | ||
414 | return that.getFill(item, val); | ||
415 | }); | ||
416 | } | ||
417 | document.application.undoManager.add("Set fill", this.setFill, this, els, currentValue, eventType, source, value); | ||
418 | } | ||
419 | |||
419 | for(var i=0, item; item = els[i]; i++) { | 420 | for(var i=0, item; item = els[i]; i++) { |
420 | item.elementModel.controller["setStroke"](item, value); | 421 | item.elementModel.controller["setFill"](item, (value[i] || value)); |
421 | } | 422 | } |
422 | 423 | ||
423 | NJevent("element" + eventType, {type : "setStroke", source: source, data: {"els": els, "prop": "stroke", "value": value}, redraw: null}); | 424 | NJevent("element" + eventType, {type : "setFill", source: source, data: {"els": els, "prop": "fill", "value": value}, redraw: null}); |
424 | } | 425 | } |
425 | }, | 426 | }, |
426 | 427 | ||