diff options
author | Armen Kesablyan | 2012-06-11 11:04:29 -0700 |
---|---|---|
committer | Armen Kesablyan | 2012-06-11 11:04:29 -0700 |
commit | 0f040acabfb7a4bf3138debec5aff869487ceb11 (patch) | |
tree | 53eaa8ba54cf23a1c3ea0c8b39377773198c3e19 /js/mediators | |
parent | 7d3bdf39e6d1534de1848ca2744aed66dfeb5d2a (diff) | |
parent | 756cbfad2b98b300af8db3793aa21718b88dd950 (diff) | |
download | ninja-0f040acabfb7a4bf3138debec5aff869487ceb11.tar.gz |
Merge branch 'master' of github.com:Motorola-Mobility/ninja-internal
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 | 716 | ||||
-rwxr-xr-x | js/mediators/keyboard-mediator.js | 7 |
4 files changed, 97 insertions, 751 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 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 |