diff options
author | Jose Antonio Marquez | 2012-06-21 09:55:35 -0700 |
---|---|---|
committer | Jose Antonio Marquez | 2012-06-21 09:55:35 -0700 |
commit | 28aa1276ffb6cefca7f7d58906cf8380fc6253eb (patch) | |
tree | c9a4a6f5d18693c39fbc668567125211151c9213 /js/mediators | |
parent | 4eff115126ab946c5852d787fd596e07b156c9a5 (diff) | |
parent | c8fc6d15e1570e89243abe527cd149e354f7e11f (diff) | |
download | ninja-28aa1276ffb6cefca7f7d58906cf8380fc6253eb.tar.gz |
Merge branch 'refs/heads/Ninja-Internal' into Color
Diffstat (limited to 'js/mediators')
-rwxr-xr-x | js/mediators/element-mediator.js | 346 | ||||
-rwxr-xr-x | js/mediators/keyboard-mediator.js | 7 |
2 files changed, 178 insertions, 175 deletions
diff --git a/js/mediators/element-mediator.js b/js/mediators/element-mediator.js index 017ed20a..ca7aadaf 100755 --- a/js/mediators/element-mediator.js +++ b/js/mediators/element-mediator.js | |||
@@ -1,42 +1,42 @@ | |||
1 | /* <copyright> | 1 | /* <copyright> |
2 | This file contains proprietary software owned by Motorola Mobility, Inc.<br/> | 2 | This file contains proprietary software owned by Motorola Mobility, Inc.<br/> |
3 | No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/> | 3 | No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/> |
4 | (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. | 4 | (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. |
5 | </copyright> */ | 5 | </copyright> */ |
6 | 6 | ||
7 | var Montage = require("montage/core/core").Montage, | 7 | var Montage = require("montage/core/core").Montage, |
8 | Component = require("montage/ui/component").Component; | 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 | NJUtils = require("js/lib/NJUtils").NJUtils; | 12 | NJUtils = require("js/lib/NJUtils").NJUtils; |
13 | 13 | ||
14 | exports.ElementMediator = Montage.create(Component, { | 14 | exports.ElementMediator = Montage.create(Component, { |
15 | 15 | ||
16 | addDelegate: { | 16 | addDelegate:{ |
17 | enumerable: false, | 17 | enumerable:false, |
18 | value: null | 18 | value:null |
19 | }, | 19 | }, |
20 | 20 | ||
21 | deleteDelegate: { | 21 | deleteDelegate:{ |
22 | enumerable: false, | 22 | enumerable:false, |
23 | value: null | 23 | value:null |
24 | }, | 24 | }, |
25 | 25 | ||
26 | addElements: { | 26 | addElements:{ |
27 | value: function(elements, rules, notify) { | 27 | value:function (elements, rules, notify) { |
28 | if(Array.isArray(elements)) { | 28 | if (Array.isArray(elements)) { |
29 | elements.forEach(function(element) { | 29 | elements.forEach(function (element) { |
30 | ElementController.addElement(element, rules); | 30 | ElementController.addElement(element, rules); |
31 | element.elementModel.props3D.init(element, false); | 31 | element.elementModel.props3D.init(element, false); |
32 | }); | 32 | }); |
33 | } else { | 33 | } else { |
34 | ElementController.addElement(elements, rules); | 34 | ElementController.addElement(elements, rules); |
35 | elements.elementModel.props3D.init(elements, false); | 35 | elements.elementModel.props3D.init(elements, false); |
36 | 36 | ||
37 | } | 37 | } |
38 | 38 | ||
39 | if(this.addDelegate && typeof (this.addDelegate['onAddElements']) === "function") { | 39 | if (this.addDelegate && typeof (this.addDelegate['onAddElements']) === "function") { |
40 | this.addDelegate['onAddElements'].call(this.addDelegate, elements); | 40 | this.addDelegate['onAddElements'].call(this.addDelegate, elements); |
41 | } | 41 | } |
42 | 42 | ||
@@ -46,23 +46,23 @@ exports.ElementMediator = Montage.create(Component, { | |||
46 | 46 | ||
47 | this.application.ninja.currentDocument.model.needsSave = true; | 47 | this.application.ninja.currentDocument.model.needsSave = true; |
48 | 48 | ||
49 | if(notify || notify === undefined) { | 49 | if (notify || notify === undefined) { |
50 | NJevent("elementAdded", elements); | 50 | NJevent("elementAdded", elements); |
51 | } | 51 | } |
52 | } | 52 | } |
53 | }, | 53 | }, |
54 | 54 | ||
55 | removeElements: { | 55 | removeElements:{ |
56 | value: function(elements, notify /* Used for the add undo */) { | 56 | value:function (elements, notify /* Used for the add undo */) { |
57 | 57 | ||
58 | if(this.deleteDelegate && (typeof this.deleteDelegate.handleDelete === 'function')) { | 58 | if (this.deleteDelegate && (typeof this.deleteDelegate.handleDelete === 'function')) { |
59 | return this.deleteDelegate.handleDelete(); | 59 | return this.deleteDelegate.handleDelete(); |
60 | // this.handleDelete.call(deleteDelegate); | 60 | // this.handleDelete.call(deleteDelegate); |
61 | } | 61 | } |
62 | 62 | ||
63 | if(Array.isArray(elements)) { | 63 | if (Array.isArray(elements)) { |
64 | elements = Array.prototype.slice.call(elements, 0); | 64 | elements = Array.prototype.slice.call(elements, 0); |
65 | elements.forEach(function(element) { | 65 | elements.forEach(function (element) { |
66 | ElementController.removeElement(element); | 66 | ElementController.removeElement(element); |
67 | }); | 67 | }); |
68 | } else { | 68 | } else { |
@@ -79,8 +79,8 @@ exports.ElementMediator = Montage.create(Component, { | |||
79 | } | 79 | } |
80 | }, | 80 | }, |
81 | 81 | ||
82 | replaceElement: { | 82 | replaceElement:{ |
83 | value: function(newChild, oldChild, notify) { | 83 | value:function (newChild, oldChild, notify) { |
84 | 84 | ||
85 | this.application.ninja.currentDocument.model.documentRoot.replaceChild(newChild, oldChild); | 85 | this.application.ninja.currentDocument.model.documentRoot.replaceChild(newChild, oldChild); |
86 | if (newChild.getAttribute) newChild.setAttribute('data-ninja-node', 'true'); | 86 | if (newChild.getAttribute) newChild.setAttribute('data-ninja-node', 'true'); |
@@ -91,15 +91,15 @@ exports.ElementMediator = Montage.create(Component, { | |||
91 | 91 | ||
92 | this.application.ninja.currentDocument.model.needsSave = true; | 92 | this.application.ninja.currentDocument.model.needsSave = true; |
93 | 93 | ||
94 | if(notify || notify === undefined) { | 94 | if (notify || notify === undefined) { |
95 | NJevent("elementReplaced", {type : "replaceElement", data: {"newChild": newChild, "oldChild": oldChild}}); | 95 | NJevent("elementReplaced", {type:"replaceElement", data:{"newChild":newChild, "oldChild":oldChild}}); |
96 | } | 96 | } |
97 | } | 97 | } |
98 | }, | 98 | }, |
99 | 99 | ||
100 | getProperty: { | 100 | getProperty:{ |
101 | value: function(el, prop, valueMutator) { | 101 | value:function (el, prop, valueMutator) { |
102 | if(valueMutator && typeof valueMutator === "function") { | 102 | if (valueMutator && typeof valueMutator === "function") { |
103 | return valueMutator(el.elementModel.controller["getProperty"](el, prop)); | 103 | return valueMutator(el.elementModel.controller["getProperty"](el, prop)); |
104 | } else { | 104 | } else { |
105 | return el.elementModel.controller["getProperty"](el, prop, valueMutator); | 105 | return el.elementModel.controller["getProperty"](el, prop, valueMutator); |
@@ -107,28 +107,28 @@ exports.ElementMediator = Montage.create(Component, { | |||
107 | } | 107 | } |
108 | }, | 108 | }, |
109 | 109 | ||
110 | getShapeProperty: { | 110 | getShapeProperty:{ |
111 | value: function(el, prop) { | 111 | value:function (el, prop) { |
112 | return el.elementModel.controller["getShapeProperty"](el, prop); | 112 | return el.elementModel.controller["getShapeProperty"](el, prop); |
113 | } | 113 | } |
114 | }, | 114 | }, |
115 | 115 | ||
116 | setShapeProperty: { | 116 | setShapeProperty:{ |
117 | value: function(el, prop, value) { | 117 | value:function (el, prop, value) { |
118 | return el.elementModel.controller["setShapeProperty"](el, prop, value); | 118 | return el.elementModel.controller["setShapeProperty"](el, prop, value); |
119 | } | 119 | } |
120 | }, | 120 | }, |
121 | 121 | ||
122 | /** | 122 | /** |
123 | Set a property change command for an element or array of elements | 123 | Set a property change command for an element or array of elements |
124 | @param element: Element | 124 | @param element: Element |
125 | @param attribute: Attribute to set | 125 | @param attribute: Attribute to set |
126 | @param value: Value to be set. | 126 | @param value: Value to be set. |
127 | @param currentValue: current value | 127 | @param currentValue: current value |
128 | @param source: String for the source object making the call | 128 | @param source: String for the source object making the call |
129 | */ | 129 | */ |
130 | setAttribute: { | 130 | setAttribute:{ |
131 | value: function(element, attribute, value, currentValue, source) { | 131 | value:function (element, attribute, value, currentValue, source) { |
132 | element.elementModel.controller["setAttribute"](element, attribute, value); | 132 | element.elementModel.controller["setAttribute"](element, attribute, value); |
133 | 133 | ||
134 | // Add to the undo | 134 | // Add to the undo |
@@ -149,40 +149,40 @@ exports.ElementMediator = Montage.create(Component, { | |||
149 | @param currentValue *OPTIONAL*: current value array. If not found the current value is calculated | 149 | @param currentValue *OPTIONAL*: current value array. If not found the current value is calculated |
150 | @param stageRedraw: *OPTIONAL*: True. If set to false the stage will not redraw the selection/outline | 150 | @param stageRedraw: *OPTIONAL*: True. If set to false the stage will not redraw the selection/outline |
151 | */ | 151 | */ |
152 | setProperty: { | 152 | setProperty:{ |
153 | value: function(els, p, value, eventType, source, currentValue) { | 153 | value:function (els, p, value, eventType, source, currentValue) { |
154 | if(eventType === "Changing") { | 154 | if (eventType === "Changing") { |
155 | this._setProperty(els, p, value, eventType, source); | 155 | this._setProperty(els, p, value, eventType, source); |
156 | } else { | 156 | } else { |
157 | // Calculate currentValue if not found for each element | 157 | // Calculate currentValue if not found for each element |
158 | if(!currentValue) { | 158 | if (!currentValue) { |
159 | var that = this; | 159 | var that = this; |
160 | currentValue = els.map(function(item) { | 160 | currentValue = els.map(function (item) { |
161 | return that.getProperty((item), p); | 161 | return that.getProperty((item), p); |
162 | }); | 162 | }); |
163 | } | 163 | } |
164 | 164 | ||
165 | var command = Montage.create(Command, { | 165 | var command = Montage.create(Command, { |
166 | _els: { value: els }, | 166 | _els:{ value:els }, |
167 | _p: { value: p }, | 167 | _p:{ value:p }, |
168 | _value: { value: value }, | 168 | _value:{ value:value }, |
169 | _previous: { value: currentValue }, | 169 | _previous:{ value:currentValue }, |
170 | _eventType: { value: eventType}, | 170 | _eventType:{ value:eventType}, |
171 | _source: { value: "undo-redo"}, | 171 |