aboutsummaryrefslogtreecommitdiff
path: root/js/mediators/element-mediator.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/mediators/element-mediator.js')
-rwxr-xr-xjs/mediators/element-mediator.js88
1 files changed, 43 insertions, 45 deletions
diff --git a/js/mediators/element-mediator.js b/js/mediators/element-mediator.js
index 1d5e9ade..da8cbb76 100755
--- a/js/mediators/element-mediator.js
+++ b/js/mediators/element-mediator.js
@@ -373,78 +373,76 @@ exports.ElementMediator = Montage.create(Component, {
373 }, 373 },
374 374
375 getStroke: { 375 getStroke: {
376 value: function(el) { 376 value: function(el, strokeProperties) {
377 if(!el.elementModel) { 377 return el.elementModel.controller["getStroke"](el, strokeProperties);
378 NJUtils.makeElementModel(el, "Div", "block");
379 }
380 return el.elementModel.controller["getStroke"](el);
381 } 378 }
382 }, 379 },
383 380
384
385 /** 381 /**
386 Set a property change command for an element or array of elements 382 Set stroke/border properties on an element or array of elements
387 @param els: Array of elements. Can contain 1 or more elements 383 @param els: Array of elements. Can contain 1 or more elements
388 @param value: Value to be set. This is the stroke info 384 @param value: Value to be set. This is the stroke info
389 @param eventType: Change/Changing. Will be passed to the dispatched event 385 @param eventType: Change/Changing. Will be passed to the dispatched event
390 @param source: String for the source object making the call 386 @param source: String for the source object making the call
391 @param currentValue *OPTIONAL*: current value array. If not found the current value is calculated 387 @param currentValue *OPTIONAL*: current value array. If not found the current value is calculated
392 @param stageRedraw: *OPTIONAL*: True. If set to false the stage will not redraw the selection/outline
393 */ 388 */
394 setStroke: { 389 setStroke: {
395 value: function(els, value, eventType, source, currentValue) { 390 value: function(els, value, eventType, source, currentValue) {
396 391
397 if(eventType === "Changing") { 392 if(eventType !== "Changing") {
398 this._setStroke(els, value, isFill, eventType, source);
399 } else {
400 // Calculate currentValue if not found for each element 393 // Calculate currentValue if not found for each element
401 if(!currentValue) { 394 if(!currentValue) {
402 var that = this; 395 var that = this,
396 val = value;
403 currentValue = els.map(function(item) { 397 currentValue = els.map(function(item) {
404 return that.getStroke(item); 398 return that.getStroke(item, val);
405 }); 399 });
406 } 400 }
401 document.application.undoManager.add("Set stroke", this.setStroke, this, els, currentValue, eventType, source, value);
402 }
407 403
408 var command = Montage.create(Command, { 404 for(var i=0, item; item = els[i]; i++) {
409 _els: { value: els }, 405 item.elementModel.controller["setStroke"](item, (value[i] || value), eventType, source);
410 _value: { value: value },
411 _previous: { value: currentValue },
412 _eventType: { value: eventType},
413 _source: { value: "undo-redo"},
414 description: { value: "Set Color"},
415 receiver: { value: this},
416
417 execute: {
418 value: function(senderObject) {
419 if(senderObject) this._source = senderObject;
420 this.receiver._setStroke(this._els, this._value, this._eventType, this._source);
421 this._source = "undo-redo";
422 return "";
423 }
424 },
425
426 unexecute: {
427 value: function() {
428 this.receiver._setStroke(this._els, this._previous, this._eventType, this._source);
429 return "";
430 }
431 }
432 });
433
434 NJevent("sendToUndo", command);
435 command.execute(source);
436 } 406 }
437 407
408 NJevent("element" + eventType, {type : "setStroke", source: source, data: {"els": els, "prop": "stroke", "value": value}, redraw: null});
438 } 409 }
439 }, 410 },
440 411
441 _setStroke: { 412 getFill: {
442 value: function(els, value, eventType, source) { 413 value: function(el, fillProperties) {
414 return el.elementModel.controller["getFill"](el, fillProperties);
415 }
416 },
417
418 /**
419 Set fill/background properties for an element or array of elements
420 @param els: Array of elements. Can contain 1 or more elements
421 @param value: Value to be set. This is the fill info
422 @param eventType: Change/Changing. Will be passed to the dispatched event
423 @param source: String for the source object making the call
424 @param currentValue *OPTIONAL*: current value array. If not found the current value is calculated
425 */
426 setFill: {
427 value: function(els, value, eventType, source, currentValue) {
428
429 if(eventType !== "Changing") {
430 // Calculate currentValue if not found for each element
431 if(!currentValue) {
432 var that = this,
433 val = value;
434 currentValue = els.map(function(item) {
435 return that.getFill(item, val);
436 });
437 }
438 document.application.undoManager.add("Set fill", this.setFill, this, els, currentValue, eventType, source, value);
439 }
440
443 for(var i=0, item; item = els[i]; i++) { 441 for(var i=0, item; item = els[i]; i++) {
444 item.elementModel.controller["setStroke"](item, value); 442 item.elementModel.controller["setFill"](item, (value[i] || value));
445 } 443 }
446 444
447 NJevent("element" + eventType, {type : "setStroke", source: source, data: {"els": els, "prop": "stroke", "value": value}, redraw: null}); 445 NJevent("element" + eventType, {type : "setFill", source: source, data: {"els": els, "prop": "fill", "value": value}, redraw: null});
448 } 446 }
449 }, 447 },
450 448