diff options
Diffstat (limited to 'js/mediators')
-rwxr-xr-x | js/mediators/drag-drop-mediator.js | 2 | ||||
-rwxr-xr-x | js/mediators/element-mediator.js | 123 | ||||
-rw-r--r-- | js/mediators/io-mediator.js | 10 | ||||
-rwxr-xr-x | js/mediators/keyboard-mediator.js | 7 |
4 files changed, 58 insertions, 84 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 88baf3d9..93a8dbce 100755 --- a/js/mediators/element-mediator.js +++ b/js/mediators/element-mediator.js | |||
@@ -35,16 +35,13 @@ exports.ElementMediator = Montage.create(Component, { | |||
35 | if(Array.isArray(elements)) { | 35 | if(Array.isArray(elements)) { |
36 | elements.forEach(function(element) { | 36 | elements.forEach(function(element) { |
37 | ElementController.addElement(element, rules); | 37 | ElementController.addElement(element, rules); |
38 | if(element.elementModel && element.elementModel.props3D) { | ||
39 | element.elementModel.props3D.init(element, false); | 38 | element.elementModel.props3D.init(element, false); |
40 | } | ||
41 | }); | 39 | }); |
42 | } else { | 40 | } else { |
43 | ElementController.addElement(elements, rules); | 41 | ElementController.addElement(elements, rules); |
44 | if(elements.elementModel && elements.elementModel.props3D) { | ||
45 | elements.elementModel.props3D.init(elements, false); | 42 | elements.elementModel.props3D.init(elements, false); |
43 | |||
46 | } | 44 | } |
47 | } | ||
48 | 45 | ||
49 | if(this.addDelegate && typeof (this.addDelegate['onAddElements']) === "function") { | 46 | if(this.addDelegate && typeof (this.addDelegate['onAddElements']) === "function") { |
50 | this.addDelegate['onAddElements'].call(this.addDelegate, elements); | 47 | this.addDelegate['onAddElements'].call(this.addDelegate, elements); |
@@ -108,11 +105,6 @@ exports.ElementMediator = Montage.create(Component, { | |||
108 | 105 | ||
109 | getProperty: { | 106 | getProperty: { |
110 | value: function(el, prop, valueMutator) { | 107 | value: function(el, prop, valueMutator) { |
111 | if(!el.elementModel) { | ||
112 | console.log("Element has no Model -> One should have been created"); | ||
113 | this._NJUtils.makeElementModel(el, "Div", "block"); | ||
114 | } | ||
115 | |||
116 | if(valueMutator && typeof valueMutator === "function") { | 108 | if(valueMutator && typeof valueMutator === "function") { |
117 | return valueMutator(el.elementModel.controller["getProperty"](el, prop)); | 109 | return valueMutator(el.elementModel.controller["getProperty"](el, prop)); |
118 | } else { | 110 | } else { |
@@ -123,22 +115,12 @@ exports.ElementMediator = Montage.create(Component, { | |||
123 | 115 | ||
124 | getShapeProperty: { | 116 | getShapeProperty: { |
125 | value: function(el, prop) { | 117 | value: function(el, prop) { |
126 | if(!el.elementModel) { | ||
127 | console.log("Element has no Model -> One should have been created"); | ||
128 | this._NJUtils.makeElementModel(el, "Canvas", "block", true); | ||
129 | } | ||
130 | |||
131 | return el.elementModel.controller["getShapeProperty"](el, prop); | 118 | return el.elementModel.controller["getShapeProperty"](el, prop); |
132 | } | 119 | } |
133 | }, | 120 | }, |
134 | 121 | ||
135 | setShapeProperty: { | 122 | setShapeProperty: { |
136 | value: function(el, prop, value) { | 123 | value: function(el, prop, value) { |
137 | if(!el.elementModel) { | ||
138 | console.log("Element has no Model -> One should have been created"); | ||
139 | this._NJUtils.makeElementModel(el, "Canvas", "block", true); | ||
140 | } | ||
141 | |||
142 | return el.elementModel.controller["setShapeProperty"](el, prop, value); | 124 | return el.elementModel.controller["setShapeProperty"](el, prop, value); |
143 | } | 125 | } |
144 | }, | 126 | }, |
@@ -303,9 +285,6 @@ exports.ElementMediator = Montage.create(Component, { | |||
303 | // Routines to get/set color | 285 | // Routines to get/set color |
304 | getColor: { | 286 | getColor: { |
305 | value: function(el, isFill, borderSide) { | 287 | value: function(el, isFill, borderSide) { |
306 | if(!el.elementModel) { | ||
307 | this._NJUtils.makeModelFromElement(el); | ||
308 | } | ||
309 | return el.elementModel.controller["getColor"](el, isFill, borderSide); | 288 | return el.elementModel.controller["getColor"](el, isFill, borderSide); |
310 | } | 289 | } |
311 | }, | 290 | }, |
@@ -379,78 +358,76 @@ exports.ElementMediator = Montage.create(Component, { | |||
379 | }, | 358 | }, |
380 | 359 | ||
381 | getStroke: { | 360 | getStroke: { |
382 | value: function(el) { | 361 | value: function(el, strokeProperties) { |
383 | if(!el.elementModel) { | 362 | return el.elementModel.controller["getStroke"](el, strokeProperties); |
384 | this._NJUtils.makeElementModel(el, "Div", "block"); | ||
385 | } | ||
386 | return el.elementModel.controller["getStroke"](el); | ||
387 | } | 363 | } |
388 | }, | 364 | }, |
389 | 365 | ||
390 | |||
391 | /** | 366 | /** |
392 | Set a property change command for an element or array of elements | 367 | Set stroke/border properties on an element or array of elements |
393 | @param els: Array of elements. Can contain 1 or more elements | 368 | @param els: Array of elements. Can contain 1 or more elements |
394 | @param value: Value to be set. This is the stroke info | 369 | @param value: Value to be set. This is the stroke info |
395 | @param eventType: Change/Changing. Will be passed to the dispatched event | 370 | @param eventType: Change/Changing. Will be passed to the dispatched event |
396 | @param source: String for the source object making the call | 371 | @param source: String for the source object making the call |
397 | @param currentValue *OPTIONAL*: current value array. If not found the current value is calculated | 372 | @param currentValue *OPTIONAL*: current value array. If not found the current value is calculated |
398 | @param stageRedraw: *OPTIONAL*: True. If set to false the stage will not redraw the selection/outline | ||
399 | */ | 373 | */ |
400 | setStroke: { | 374 | setStroke: { |
401 | value: function(els, value, eventType, source, currentValue) { | 375 | value: function(els, value, eventType, source, currentValue) { |
402 | 376 | ||
403 | if(eventType === "Changing") { | 377 | if(eventType !== "Changing") { |
404 | this._setStroke(els, value, isFill, eventType, source); | ||
405 | } else { | ||
406 | // Calculate currentValue if not found for each element | 378 | // Calculate currentValue if not found for each element |
407 | if(!currentValue) { | 379 | if(!currentValue) { |
408 | var that = this; | 380 | var that = this, |
381 | val = value; | ||
409 | currentValue = els.map(function(item) { | 382 | currentValue = els.map(function(item) { |
410 | return that.getStroke(item); | 383 | return that.getStroke(item, val); |
411 | }); | 384 | }); |
412 | } | 385 | } |
386 | document.application.undoManager.add("Set stroke", this.setStroke, this, els, currentValue, eventType, source, value); | ||
387 | } | ||
413 | 388 | ||
414 | var command = Montage.create(Command, { | 389 | for(var i=0, item; item = els[i]; i++) { |
415 | _els: { value: els }, | 390 | item.elementModel.controller["setStroke"](item, (value[i] || value), eventType, source); |
416 | _value: { value: value }, | ||
417 | _previous: { value: currentValue }, | ||
418 | _eventType: { value: eventType}, | ||
419 | _source: { value: "undo-redo"}, | ||
420 | description: { value: "Set Color"}, | ||
421 | receiver: { value: this}, | ||
422 | |||
423 | execute: { | ||
424 | value: function(senderObject) { | ||
425 | if(senderObject) this._source = senderObject; | ||
426 | this.receiver._setStroke(this._els, this._value, this._eventType, this._source); | ||
427 | this._source = "undo-redo"; | ||
428 | return ""; | ||
429 | } | ||
430 | }, | ||
431 | |||
432 | unexecute: { | ||
433 | value: function() { | ||
434 | this.receiver._setStroke(this._els, this._previous, this._eventType, this._source); | ||
435 | return ""; | ||
436 | } | ||
437 | } | ||
438 | }); | ||
439 | |||
440 | NJevent("sendToUndo", command); | ||
441 | command.execute(source); | ||
442 | } | 391 | } |
443 | 392 | ||
393 | NJevent("element" + eventType, {type : "setStroke", source: source, data: {"els": els, "prop": "stroke", "value": value}, redraw: null}); | ||
444 | } | 394 | } |
445 | }, | 395 | }, |
446 | 396 | ||
447 | _setStroke: { | 397 | getFill: { |
448 | value: function(els, value, eventType, source) { | 398 | value: function(el, fillProperties) { |
399 | return el.elementModel.controller["getFill"](el, fillProperties); | ||
400 | } | ||
401 | }, | ||
402 | |||
403 | /** | ||
404 | Set fill/background properties for an element or array of elements | ||
405 | @param els: Array of elements. Can contain 1 or more elements | ||
406 | @param value: Value to be set. This is the fill info | ||
407 | @param eventType: Change/Changing. Will be passed to the dispatched event | ||
408 | @param source: String for the source object making the call | ||
409 | @param currentValue *OPTIONAL*: current value array. If not found the current value is calculated | ||
410 | */ | ||
411 | setFill: { | ||
412 | value: function(els, value, eventType, source, currentValue) { | ||
413 | |||
414 | if(eventType !== "Changing") { | ||
415 | // Calculate currentValue if not found for each element | ||
416 | if(!currentValue) { | ||
417 | var that = this, | ||
418 | val = value; | ||
419 | currentValue = els.map(function(item) { | ||
420 | return that.getFill(item, val); | ||