aboutsummaryrefslogtreecommitdiff
path: root/js/mediators/element-mediator.js
diff options
context:
space:
mode:
authorAnanya Sen2012-06-07 11:59:32 -0700
committerAnanya Sen2012-06-07 11:59:32 -0700
commit7378b6846f140106490f10c02cd7cec6a19023aa (patch)
tree90b60c007696b4a73c29abbae82562f69f15c11a /js/mediators/element-mediator.js
parentaea0e6879abfef02a827ed239ef091c3b96d6eb2 (diff)
parentb75fe9369f7caec0351d298f7106c8d59572b440 (diff)
downloadninja-7378b6846f140106490f10c02cd7cec6a19023aa.tar.gz
Merge branch 'refs/heads/ninja-internal-master' into cut-copy-paste
Diffstat (limited to 'js/mediators/element-mediator.js')
-rwxr-xr-xjs/mediators/element-mediator.js123
1 files changed, 44 insertions, 79 deletions
diff --git a/js/mediators/element-mediator.js b/js/mediators/element-mediator.js
index 1d5e9ade..40e94cca 100755
--- a/js/mediators/element-mediator.js
+++ b/js/mediators/element-mediator.js
@@ -29,16 +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 if(element.elementModel && element.elementModel.props3D) {
33 element.elementModel.props3D.init(element, false); 32 element.elementModel.props3D.init(element, false);
34 }
35 }); 33 });
36 } else { 34 } else {
37 ElementController.addElement(elements, rules); 35 ElementController.addElement(elements, rules);
38 if(elements.elementModel && elements.elementModel.props3D) {
39 elements.elementModel.props3D.init(elements, false); 36 elements.elementModel.props3D.init(elements, false);
37
40 } 38 }
41 }
42 39
43 if(this.addDelegate && typeof (this.addDelegate['onAddElements']) === "function") { 40 if(this.addDelegate && typeof (this.addDelegate['onAddElements']) === "function") {
44 this.addDelegate['onAddElements'].call(this.addDelegate, elements); 41 this.addDelegate['onAddElements'].call(this.addDelegate, elements);
@@ -102,11 +99,6 @@ exports.ElementMediator = Montage.create(Component, {
102 99
103 getProperty: { 100 getProperty: {
104 value: function(el, prop, valueMutator) { 101 value: function(el, prop, valueMutator) {
105 if(!el.elementModel) {
106 console.log("Element has no Model -> One should have been created");
107 NJUtils.makeElementModel(el, "Div", "block");
108 }
109
110 if(valueMutator && typeof valueMutator === "function") { 102 if(valueMutator && typeof valueMutator === "function") {
111 return valueMutator(el.elementModel.controller["getProperty"](el, prop)); 103 return valueMutator(el.elementModel.controller["getProperty"](el, prop));
112 } else { 104 } else {
@@ -117,22 +109,12 @@ exports.ElementMediator = Montage.create(Component, {
117 109
118 getShapeProperty: { 110 getShapeProperty: {
119 value: function(el, prop) { 111 value: function(el, prop) {
120 if(!el.elementModel) {
121 console.log("Element has no Model -> One should have been created");
122 NJUtils.makeElementModel(el, "Canvas", "block", true);
123 }
124
125 return el.elementModel.controller["getShapeProperty"](el, prop); 112 return el.elementModel.controller["getShapeProperty"](el, prop);
126 } 113 }
127 }, 114 },
128 115
129 setShapeProperty: { 116 setShapeProperty: {
130 value: function(el, prop, value) { 117 value: function(el, prop, value) {
131 if(!el.elementModel) {
132 console.log("Element has no Model -> One should have been created");
133 NJUtils.makeElementModel(el, "Canvas", "block", true);
134 }
135
136 return el.elementModel.controller["setShapeProperty"](el, prop, value); 118 return el.elementModel.controller["setShapeProperty"](el, prop, value);
137 } 119 }
138 }, 120 },
@@ -297,9 +279,6 @@ exports.ElementMediator = Montage.create(Component, {
297 // Routines to get/set color 279 // Routines to get/set color
298 getColor: { 280 getColor: {
299 value: function(el, isFill, borderSide) { 281 value: function(el, isFill, borderSide) {
300 if(!el.elementModel) {
301 NJUtils.makeModelFromElement(el);
302 }
303 return el.elementModel.controller["getColor"](el, isFill, borderSide); 282 return el.elementModel.controller["getColor"](el, isFill, borderSide);
304 } 283 }
305 }, 284 },
@@ -373,78 +352,76 @@ exports.ElementMediator = Montage.create(Component, {
373 }, 352 },
374 353
375 getStroke: { 354 getStroke: {
376 value: function(el) { 355 value: function(el, strokeProperties) {
377 if(!el.elementModel) { 356 return el.elementModel.controller["getStroke"](el, strokeProperties);
378 NJUtils.makeElementModel(el, "Div", "block");
379 }
380 return el.elementModel.controller["getStroke"](el);
381 } 357 }
382 }, 358 },
383 359
384
385 /** 360 /**
386 Set a property change command for an element or array of elements 361 Set stroke/border properties on an element or array of elements
387 @param els: Array of elements. Can contain 1 or more elements 362 @param els: Array of elements. Can contain 1 or more elements
388 @param value: Value to be set. This is the stroke info 363 @param value: Value to be set. This is the stroke info
389 @param eventType: Change/Changing. Will be passed to the dispatched event 364 @param eventType: Change/Changing. Will be passed to the dispatched event
390 @param source: String for the source object making the call 365 @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 366 @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 */ 367 */
394 setStroke: { 368 setStroke: {
395 value: function(els, value, eventType, source, currentValue) { 369 value: function(els, value, eventType, source, currentValue) {
396 370
397 if(eventType === "Changing") { 371 if(eventType !== "Changing") {
398 this._setStroke(els, value, isFill, eventType, source);
399 } else {
400 // Calculate currentValue if not found for each element 372 // Calculate currentValue if not found for each element
401 if(!currentValue) { 373 if(!currentValue) {
402 var that = this; 374 var that = this,
375 val = value;
403 currentValue = els.map(function(item) { 376 currentValue = els.map(function(item) {
404 return that.getStroke(item); 377 return that.getStroke(item, val);
405 }); 378 });
406 } 379 }
380 document.application.undoManager.add("Set stroke", this.setStroke, this, els, currentValue, eventType, source, value);
381 }
407 382
408 var command = Montage.create(Command, { 383 for(var i=0, item; item = els[i]; i++) {
409 _els: { value: els }, 384 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 } 385 }
437 386
387 NJevent("element" + eventType, {type : "setStroke", source: source, data: {"els": els, "prop": "stroke", "value": value}, redraw: null});
438 } 388 }
439 }, 389 },
440 390
441 _setStroke: { 391 getFill: {
442 value: function(els, value, eventType, source) { 392 value: function(el, fillProperties) {
393 return el.elementModel.controller["getFill"](el, fillProperties);
394 }
395 },
396
397 /**
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
443 for(var i=0, item; item = els[i]; i++) { 420 for(var i=0, item; item = els[i]; i++) {
444 item.elementModel.controller["setStroke"](item, value); 421 item.elementModel.controller["setFill"](item, (value[i] || value));
445 } 422 }
446 423
447 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});
448 } 425 }
449 }, 426 },
450 427
@@ -452,18 +429,12 @@ exports.ElementMediator = Montage.create(Component, {
452 // Routines to get/set 3D properties 429 // Routines to get/set 3D properties
453 get3DProperty: { 430 get3DProperty: {
454 value: function(el, prop) { 431 value: function(el, prop) {
455 if(!el.elementModel) {
456 NJUtils.makeModelFromElement(el);