aboutsummaryrefslogtreecommitdiff
path: root/js/mediators
diff options
context:
space:
mode:
Diffstat (limited to 'js/mediators')
-rwxr-xr-xjs/mediators/drag-drop-mediator.js2
-rwxr-xr-xjs/mediators/element-mediator.js129
-rw-r--r--js/mediators/io-mediator.js703
-rwxr-xr-xjs/mediators/keyboard-mediator.js7
4 files changed, 100 insertions, 741 deletions
diff --git a/js/mediators/drag-drop-mediator.js b/js/mediators/drag-drop-mediator.js
index 59086ef6..14bdb0eb 100755
--- a/js/mediators/drag-drop-mediator.js
+++ b/js/mediators/drag-drop-mediator.js
@@ -115,12 +115,10 @@ exports.DragDropMediator = Montage.create(Component, {
115 // 115 //
116 if (e.currentTarget.fileType.indexOf('svg') !== -1) { 116 if (e.currentTarget.fileType.indexOf('svg') !== -1) {
117 element = NJUtils.make('embed', null, this.application.ninja.currentDocument);//TODO: Verify this is proper 117 element = NJUtils.make('embed', null, this.application.ninja.currentDocument);//TODO: Verify this is proper
118 NJUtils.createModelWithSelection(element, "SVG");
119 element.type = 'image/svg+xml'; 118 element.type = 'image/svg+xml';
120 element.src = url+'/'+fileName; 119 element.src = url+'/'+fileName;
121 } else { 120 } else {
122 element = NJUtils.make('image', null, this.application.ninja.currentDocument); 121 element = NJUtils.make('image', null, this.application.ninja.currentDocument);
123 NJUtils.createModel(element);
124 element.src = url+'/'+fileName; 122 element.src = url+'/'+fileName;
125 } 123 }
126 //Adding element once it is loaded 124 //Adding element once it is loaded
diff --git a/js/mediators/element-mediator.js b/js/mediators/element-mediator.js
index f71a6f4d..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);
@@ -48,7 +45,7 @@ exports.ElementMediator = Montage.create(Component, {
48 45
49 document.application.undoManager.add(undoLabel, this.removeElements, this, elements, notify); 46 document.application.undoManager.add(undoLabel, this.removeElements, this, elements, notify);
50 47
51 this.application.ninja.documentController.activeDocument.model.needsSave = true; 48 this.application.ninja.currentDocument.model.needsSave = true;
52 49
53 if(notify || notify === undefined) { 50 if(notify || notify === undefined) {
54 NJevent("elementAdded", elements); 51 NJevent("elementAdded", elements);
@@ -77,7 +74,7 @@ exports.ElementMediator = Montage.create(Component, {
77 74
78 document.application.undoManager.add(undoLabel, this.addElements, this, elements, null, notify); 75 document.application.undoManager.add(undoLabel, this.addElements, this, elements, null, notify);
79 76
80 this.application.ninja.documentController.activeDocument.model.needsSave = true; 77 this.application.ninja.currentDocument.model.needsSave = true;
81 78
82 NJevent("elementsRemoved", elements); 79 NJevent("elementsRemoved", elements);
83 } 80 }
@@ -92,7 +89,7 @@ exports.ElementMediator = Montage.create(Component, {
92 89
93 document.application.undoManager.add(undoLabel, this.replaceElement, this, oldChild, newChild); 90 document.application.undoManager.add(undoLabel, this.replaceElement, this, oldChild, newChild);
94 91
95 this.application.ninja.documentController.activeDocument.model.needsSave = true; 92 this.application.ninja.currentDocument.model.needsSave = true;
96 93
97 if(notify || notify === undefined) { 94 if(notify || notify === undefined) {
98 NJevent("elementReplaced", {type : "replaceElement", data: {"newChild": newChild, "oldChild": oldChild}}); 95 NJevent("elementReplaced", {type : "replaceElement", data: {"newChild": newChild, "oldChild": oldChild}});
@@ -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