diff options
author | hwc487 | 2012-04-04 16:32:53 -0700 |
---|---|---|
committer | hwc487 | 2012-04-04 16:32:53 -0700 |
commit | 6ee8b65742fbe61b4429dc8c7dc9ca33a3e43600 (patch) | |
tree | f267e05f623ed90d1cc841b8c79a338d6d8e807c /js/mediators | |
parent | 16f62ca09cc428043e8fef8bdeea11a989e62bc0 (diff) | |
parent | 17ca01f54591187f5c0812c0fd2cb7260afa9639 (diff) | |
download | ninja-6ee8b65742fbe61b4429dc8c7dc9ca33a3e43600.tar.gz |
Merge branch 'master' of github.com:Motorola-Mobility/ninja-internal into Snapping
Conflicts:
js/panels/presets/animations-presets.reel/animations-presets.js
js/panels/presets/style-presets.reel/style-presets.js
js/panels/presets/transitions-presets.reel/transitions-presets.js
Diffstat (limited to 'js/mediators')
-rwxr-xr-x | js/mediators/drag-drop-mediator.js | 8 | ||||
-rwxr-xr-x | js/mediators/element-mediator.js | 218 | ||||
-rw-r--r-- | js/mediators/io-mediator.js | 1096 | ||||
-rwxr-xr-x | js/mediators/keyboard-mediator.js | 37 | ||||
-rwxr-xr-x | js/mediators/mouse-mediator.js | 4 |
5 files changed, 626 insertions, 737 deletions
diff --git a/js/mediators/drag-drop-mediator.js b/js/mediators/drag-drop-mediator.js index 8663b06e..9d1b69a9 100755 --- a/js/mediators/drag-drop-mediator.js +++ b/js/mediators/drag-drop-mediator.js | |||
@@ -111,6 +111,7 @@ exports.DragDropMediator = Montage.create(Component, { | |||
111 | fileName = tempName; | 111 | fileName = tempName; |
112 | } | 112 | } |
113 | if (save && save.success && save.status === 201) { | 113 | if (save && save.success && save.status === 201) { |
114 | var self = this; | ||
114 | // | 115 | // |
115 | if (e.currentTarget.fileType.indexOf('svg') !== -1) { | 116 | if (e.currentTarget.fileType.indexOf('svg') !== -1) { |
116 | element = NJUtils.makeNJElement('embed', 'SVG', 'block');//TODO: Verify this is proper | 117 | element = NJUtils.makeNJElement('embed', 'SVG', 'block');//TODO: Verify this is proper |
@@ -121,9 +122,10 @@ exports.DragDropMediator = Montage.create(Component, { | |||
121 | element.src = url+'/'+fileName; | 122 | element.src = url+'/'+fileName; |
122 | } | 123 | } |
123 | //TODO: Remove temp fix for elements to redraw on drop | 124 | //TODO: Remove temp fix for elements to redraw on drop |
125 | |||
124 | element.onload = function () { | 126 | element.onload = function () { |
125 | NJevent("elementAdding", {el: element, data: rules}); | 127 | self.application.ninja.elementMediator.addElements(element, rules); |
126 | } | 128 | }; |
127 | // | 129 | // |
128 | rules = { | 130 | rules = { |
129 | 'position': 'absolute', | 131 | 'position': 'absolute', |
@@ -133,7 +135,7 @@ exports.DragDropMediator = Montage.create(Component, { | |||
133 | '-webkit-transform' : 'perspective(1400) matrix3d(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)' | 135 | '-webkit-transform' : 'perspective(1400) matrix3d(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)' |
134 | }; | 136 | }; |
135 | // | 137 | // |
136 | NJevent("elementAdding", {el: element, data: rules}); | 138 | self.application.ninja.elementMediator.addElements(element, rules); |
137 | } else { | 139 | } else { |
138 | //TODO: HANDLE ERROR ON SAVING FILE TO BE ADDED AS ELEMENT | 140 | //TODO: HANDLE ERROR ON SAVING FILE TO BE ADDED AS ELEMENT |
139 | } | 141 | } |
diff --git a/js/mediators/element-mediator.js b/js/mediators/element-mediator.js index d62fa1f8..09f2aeed 100755 --- a/js/mediators/element-mediator.js +++ b/js/mediators/element-mediator.js | |||
@@ -5,147 +5,82 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot | |||
5 | </copyright> */ | 5 | </copyright> */ |
6 | 6 | ||
7 | var Montage = require("montage/core/core").Montage, | 7 | var Montage = require("montage/core/core").Montage, |
8 | NJComponent = require("js/lib/nj-base").NJComponent; | 8 | Component = require("montage/ui/component").Component; |
9 | 9 | ||
10 | var ElementController = require("js/controllers/elements/element-controller").ElementController, | 10 | var ElementController = require("js/controllers/elements/element-controller").ElementController, |
11 | Command = require("js/controllers/undo-controller").Command, | 11 | Command = require("js/controllers/undo-controller").Command, |
12 | GroupCommand = require("js/controllers/undo-controller").GroupCommand, | ||
13 | NJUtils = require("js/lib/NJUtils").NJUtils; | 12 | NJUtils = require("js/lib/NJUtils").NJUtils; |
14 | 13 | ||
15 | exports.ElementMediator = Montage.create(NJComponent, { | 14 | exports.ElementMediator = Montage.create(Component, { |
16 | 15 | ||
17 | deleteDelegate: { | ||
18 | value: null | ||
19 | }, | ||
20 | 16 | ||
21 | deserializedFromTemplate: { | 17 | addDelegate: { |
22 | value: function () { | 18 | enumerable: false, |
23 | this.eventManager.addEventListener("elementAdding", this, false); | 19 | value: null |
24 | this.eventManager.addEventListener("deleting", this, false); | ||
25 | } | ||
26 | }, | 20 | }, |
27 | 21 | ||
28 | // TODO use the specific controller to be able to subclass the functionality | 22 | deleteDelegate: { |
29 | handleElementAdding: { | 23 | enumerable: false, |
30 | value: function(event) { | 24 | value: null |
31 | this.addElement(event.detail.el, event.detail.data); | ||
32 | } | ||
33 | }, | 25 | }, |
34 | 26 | ||
35 | handleDeleting: { | 27 | addElements: { |
36 | value: function(event) { | 28 | value: function(elements, rules, notify) { |
37 | if(this.deleteDelegate && (typeof this.deleteDelegate.handleDelete === 'function')) { | 29 | if(Array.isArray(elements)) { |
38 | this.deleteDelegate.handleDelete(); | 30 | elements.forEach(function(element) { |
31 | element = element; | ||
32 | ElementController.addElement(element, rules); | ||
33 | }); | ||
39 | } else { | 34 | } else { |
40 | // Add the Undo/Redo | 35 | ElementController.addElement(elements, rules); |
41 | var els = [], | ||
42 | len = this.application.ninja.selectedElements.length; | ||
43 | 36 | ||
44 | if(len) { | 37 | // TODO - Check with webgl branch - Props seem to be already there. |
45 | for(var i = 0; i<len; i++) { | 38 | var prop3d = this.get3DProperties(elements); |
46 | els.push(this.application.ninja.selectedElements[i]); | 39 | if(prop3d) { |
47 | } | 40 | elements.elementModel.controller["set3DProperties"](elements, [prop3d], 0, true); |
48 | |||
49 | for(i=0; i<len; i++) { | ||
50 | this._removeElement(els[i]._element); | ||
51 | } | ||
52 | |||
53 | NJevent( "deleteSelection", els ); | ||
54 | } | 41 | } |
55 | } | 42 | } |
56 | } | ||
57 | }, | ||
58 | |||
59 | addElement: { | ||
60 | value: function(el, rules, noEvent) { | ||
61 | var command = Montage.create(Command, { | ||
62 | _el: { value: el }, | ||
63 | _rules: { value: rules }, | ||
64 | _noEvent: { value: noEvent }, | ||
65 | 43 | ||
66 | description: { value: "Adding Element"}, | 44 | if(this.addDelegate && typeof (this.addDelegate['onAddElements']) === "function") { |
45 | this.addDelegate['onAddElements'].call(this.addDelegate, elements); | ||
46 | } | ||
67 | 47 | ||
68 | receiver: { value: this}, | 48 | var undoLabel = "add element"; |
69 | 49 | ||
70 | execute: { | 50 | document.application.undoManager.add(undoLabel, this.removeElements, this, elements, notify); |
71 | value: function() { | ||
72 | this.receiver._addElement(this._el, this._rules, this._noEvent); | ||
73 | return this._el; | ||
74 | } | ||
75 | }, | ||
76 | |||
77 | unexecute: { | ||
78 | value: function() { | ||
79 | this.receiver._removeElement(this._el, this._rules, this._noEvent); | ||
80 | return this._el; | ||
81 | } | ||
82 | } | ||
83 | }); | ||
84 | 51 | ||
85 | NJevent("sendToUndo", command); | 52 | this.application.ninja.documentController.activeDocument.needsSave = true; |
86 | command.execute(); | ||
87 | } | ||
88 | }, | ||
89 | 53 | ||
90 | _addElement: { | 54 | if(notify || notify === undefined) { |
91 | value: function(el, rules, noEvent) { | 55 | NJevent("elementAdded", elements); |
92 | ElementController.addElement(el, rules); | ||
93 | var p3d = this.get3DProperties(el); | ||
94 | if(p3d) { | ||
95 | el.elementModel.controller["set3DProperties"](el, [p3d], 0, true); | ||
96 | } | ||
97 | if(!noEvent) { | ||
98 | this.application.ninja.documentController.activeDocument.needsSave = true; | ||
99 | NJevent("elementAdded", el); | ||
100 | } | 56 | } |
101 | } | 57 | } |
102 | }, | 58 | }, |
103 | 59 | ||
104 | deleteElements: { | 60 | removeElements: { |
105 | value: function(items) { | 61 | value: function(elements, notify /* Used for the add undo */) { |
106 | // Add the Undo/Redo | ||
107 | var len, el; | ||
108 | 62 | ||
109 | len = items.length; | 63 | if(this.deleteDelegate && (typeof this.deleteDelegate.handleDelete === 'function')) { |
64 | return this.deleteDelegate.handleDelete(); | ||
65 | // this.handleDelete.call(deleteDelegate); | ||
66 | } | ||
110 | 67 | ||
111 | if(len) { | 68 | if(Array.isArray(elements)) { |
69 | elements = Array.prototype.slice.call(elements, 0); | ||
70 | elements.forEach(function(element) { | ||
71 | ElementController.removeElement(element); | ||
72 | }); | ||
73 | } else { | ||
74 | ElementController.removeElement(elements); | ||
75 | } | ||
112 | 76 | ||
113 | for(var i = len - 1; i >= 0; i--) { | 77 | var undoLabel = "add element"; |
114 | el = items[i]._element || items[i]; | ||
115 | this._removeElement(el); | ||
116 | } | ||
117 | 78 | ||
118 | NJevent( "deleteSelection", items ); | 79 | document.application.undoManager.add(undoLabel, this.addElements, this, elements, null, notify); |
119 | } | ||
120 | } | ||
121 | }, | ||
122 | 80 | ||
123 | _removeElement: { | ||
124 | value: function(el, rules) { | ||
125 | ElementController.removeElement(el, rules); | ||
126 | this.application.ninja.documentController.activeDocument.needsSave = true; | 81 | this.application.ninja.documentController.activeDocument.needsSave = true; |