diff options
Diffstat (limited to 'js/panels/properties/content.reel/content.js')
-rw-r--r-- | js/panels/properties/content.reel/content.js | 328 |
1 files changed, 328 insertions, 0 deletions
diff --git a/js/panels/properties/content.reel/content.js b/js/panels/properties/content.reel/content.js new file mode 100644 index 00000000..fe6faef8 --- /dev/null +++ b/js/panels/properties/content.reel/content.js | |||
@@ -0,0 +1,328 @@ | |||
1 | /* <copyright> | ||
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/> | ||
4 | (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. | ||
5 | </copyright> */ | ||
6 | |||
7 | var Montage = require("montage/core/core").Montage, | ||
8 | Component = require("montage/ui/component").Component, | ||
9 | PiData = require("js/data/pi/pi-data").PiData, | ||
10 | CustomSection = require("js/panels/properties/sections/custom.reel").CustomSection; | ||
11 | |||
12 | var ElementsMediator = require("js/mediators/element-mediator").ElementMediator; | ||
13 | |||
14 | exports.Content = Montage.create(Component, { | ||
15 | |||
16 | elementName: { | ||
17 | value: null | ||
18 | }, | ||
19 | |||
20 | elementID: { | ||
21 | value: null | ||
22 | }, | ||
23 | |||
24 | elementClassName: { | ||
25 | value: null | ||
26 | }, | ||
27 | |||
28 | customSections: { | ||
29 | value: [] | ||
30 | }, | ||
31 | |||
32 | _customPi: { | ||
33 | value: null | ||
34 | }, | ||
35 | |||
36 | customPi: { | ||
37 | get: function() { | ||
38 | return this._customPi; | ||
39 | }, | ||
40 | set: function(value) { | ||
41 | if(this._customPi !== value) { | ||
42 | this._customPi = value; | ||
43 | } | ||
44 | } | ||
45 | }, | ||
46 | |||
47 | prepareForDraw: { | ||
48 | value : function() { | ||
49 | |||
50 | this.eventManager.addEventListener("selectionChange", this, false); | ||
51 | |||
52 | // This will be a toggle option | ||
53 | if(this.application.ninja.appData.PILiveUpdate) { | ||
54 | this.eventManager.addEventListener( "elementChanging", this, false); | ||
55 | } | ||
56 | |||
57 | this.eventManager.addEventListener( "elementChange", this, false); | ||
58 | |||
59 | if(this.application.ninja.selectedElements.length === 0) { | ||
60 | this.displayStageProperties(); | ||
61 | } | ||
62 | |||
63 | this.elementId.element.addEventListener("blur", this, false); | ||
64 | this.elementId.element.addEventListener("keyup", this, false); | ||
65 | } | ||
66 | }, | ||
67 | |||
68 | /** | ||
69 | * Blur and Key up to handle change in the Element ID field. | ||
70 | */ | ||
71 | handleBlur: { | ||
72 | value: function(event) { | ||
73 | if(this.application.ninja.selectedElements.length) { | ||
74 | ElementsMediator.setAttribute(this.application.ninja.selectedElements[0], "id", this.elementId.value, "Change", "pi"); | ||
75 | } else { | ||
76 | ElementsMediator.setAttribute(this.application.ninja.currentDocument.documentRoot, "id", this.elementId.value, "Change", "pi", this.application.ninja.currentDocument.documentRoot.elementModel.id); | ||
77 | } | ||
78 | } | ||
79 | }, | ||
80 | |||
81 | handleKeyup: { | ||
82 | value: function(event) { | ||
83 | if(event.keyCode === 13) { | ||
84 | this.elementId.element.blur(); | ||
85 | } | ||
86 | } | ||
87 | }, | ||
88 | |||
89 | handleElementChanging: { | ||
90 | value: function(event) { | ||
91 | // this.positionSize.leftPosition = parseFloat(ElementsMediator.getProperty(this.application.ninja.selectedElements[0]._element, "left")); | ||
92 | // this.positionSize.topPosition = parseFloat(ElementsMediator.getProperty(this.application.ninja.selectedElements[0]._element, "top")); | ||
93 | } | ||
94 | }, | ||
95 | |||
96 | handleElementChange: { | ||
97 | value: function(event) { | ||
98 | // console.log("Element Change PI ", event.detail.source); // If the event comes from the pi don't need to update | ||
99 | if(event.detail.source && event.detail.source !== "pi") { | ||
100 | this.positionSize.leftPosition = parseFloat(ElementsMediator.getProperty(this.application.ninja.selectedElements[0]._element, "left")); | ||
101 | this.positionSize.topPosition = parseFloat(ElementsMediator.getProperty(this.application.ninja.selectedElements[0]._element, "top")); | ||
102 | } | ||
103 | } | ||
104 | }, | ||
105 | |||
106 | handleSelectionChange: { | ||
107 | value: function(event) { | ||
108 | if(event.detail.isDocument) { | ||
109 | this.displayStageProperties(); | ||
110 | } else { | ||
111 | if(this.application.ninja.selectedElements.length === 1) { | ||
112 | this.displayElementProperties(this.application.ninja.selectedElements[0]._element); | ||
113 | } else { | ||
114 | this.displayGroupProperties(this.application.ninja.selectedElements); | ||
115 | } | ||
116 | |||
117 | } | ||
118 | } | ||
119 | }, | ||
120 | |||
121 | displayStageProperties: { | ||
122 | value: function() { | ||
123 | var stage = this.application.ninja.currentDocument.documentRoot; | ||
124 | //this is test code please remove | ||
125 | this.elementName = "Stage"; | ||
126 | this.elementId.value = stage.elementModel.id; | ||
127 | this.elementClassName = ""; | ||
128 | |||
129 | this.positionSize.disablePosition = true; | ||
130 | this.threeD.disableTranslation = true; | ||
131 | |||
132 | this.positionSize.heightSize = parseFloat(ElementsMediator.getProperty(stage, "height")); | ||
133 | this.positionSize.widthSize = parseFloat(ElementsMediator.getProperty(stage, "width")); | ||
134 | |||
135 | if(this.customPi !== stage.elementModel.pi) { | ||
136 | this.customPi = stage.elementModel.pi; | ||
137 | this.displayCustomProperties(stage, stage.elementModel.pi); | ||
138 | } | ||
139 | } | ||
140 | }, | ||
141 | |||
142 | displayElementProperties: { | ||
143 | value: function (el) { | ||
144 | var customPI; | ||
145 | |||
146 | this.elementName = el.elementModel.selection; | ||
147 | this.elementId.value = el.getAttribute("id") || ""; | ||
148 | this.elementClassName = el.getAttribute("class"); | ||
149 | |||
150 | this.positionSize.disablePosition = false; | ||
151 | this.threeD.disableTranslation = false; | ||
152 | |||
153 | this.positionSize.leftPosition = parseFloat(ElementsMediator.getProperty(el, "left")); | ||
154 | this.positionSize.topPosition = parseFloat(ElementsMediator.getProperty(el, "top")); | ||
155 | this.positionSize.heightSize = parseFloat(ElementsMediator.getProperty(el, "height")); | ||
156 | this.positionSize.widthSize = parseFloat(ElementsMediator.getProperty(el, "width")); | ||
157 | |||
158 | |||
159 | if(this.threeD.inGlobalMode) | ||
160 | { | ||
161 | this.threeD.x3D = ElementsMediator.get3DProperty(el, "x3D"); | ||
162 | this.threeD.y3D = ElementsMediator.get3DProperty(el, "y3D"); | ||
163 | this.threeD.z3D = ElementsMediator.get3DProperty(el, "z3D"); | ||
164 | this.threeD.xAngle = ElementsMediator.get3DProperty(el, "xAngle"); | ||
165 | this.threeD.yAngle = ElementsMediator.get3DProperty(el, "yAngle"); | ||
166 | this.threeD.zAngle = ElementsMediator.get3DProperty(el, "zAngle"); | ||
167 | } | ||
168 | |||
169 | // Custom Section | ||
170 | if(this.customPi !== el.elementModel.pi) { | ||
171 | this.customPi = el.elementModel.pi; | ||
172 | this.displayCustomProperties(el, el.elementModel.pi); | ||
173 | } | ||
174 | |||
175 | customPI = PiData[this.customPi]; | ||
176 | // Get all the custom section for the custom PI | ||
177 | for(var i = 0, customSec; customSec = customPI[i]; i++) { | ||
178 | |||
179 | // Now set the Fields for the custom PI | ||
180 | for(var j = 0, fields; fields = customSec.Section[j]; j++) { | ||
181 | for(var k = 0, control; control = fields[k]; k++) { | ||
182 | |||
183 | if(control.prop !== "border-color" && control.prop !== "background-color") { | ||
184 | var currentValue = ElementsMediator.getProperty(el, control.prop, control.valueMutator); | ||
185 | currentValue ? currentValue = currentValue : currentValue = control.defaultValue; | ||
186 | this.customSections[0].content.controls[control.id] = currentValue; | ||
187 | } | ||
188 | } | ||
189 | } | ||
190 | } | ||
191 | |||
192 | |||
193 | //TODO: Once logic for color and gradient is established, this needs to be revised | ||
194 | |||
195 | var color, background, backgroundImage, borderColor = ElementsMediator.getProperty(el, "border-color"), borderImage = ElementsMediator.getProperty(el, "border-image"); | ||
196 | this.application.ninja.colorController.colorModel.input = "stroke"; | ||
197 | if(borderColor || borderImage) { | ||
198 | if (borderImage && borderImage !== 'none' && borderImage.indexOf('-webkit') >= 0) { | ||
199 | //Gradient | ||
200 | color = this.application.ninja.colorController.getColorObjFromCss(borderImage); | ||
201 | if (color && color.value) { | ||
202 | this.application.ninja.colorController.colorModel[color.mode] = {value: color.value, wasSetByCode: true, type: 'change'}; | ||
203 | } else { | ||
204 | this.application.ninja.colorController.colorModel.alpha = {value: 1, wasSetByCode: true, type: 'change'}; | ||
205 | this.application.ninja.colorController.colorModel.applyNoColor(); | ||
206 | } | ||
207 | } else { | ||
208 | //Solid | ||
209 | color = this.application.ninja.colorController.getColorObjFromCss(borderColor); | ||
210 | if (color && color.value) { | ||
211 | color.value.wasSetByCode = true; | ||
212 | color.value.type = 'change'; | ||
213 | if (color.value.a) { | ||
214 | this.application.ninja.colorController.colorModel.alpha = {value: color.value.a, wasSetByCode: true, type: 'change'}; | ||
215 | } | ||
216 | this.application.ninja.colorController.colorModel[color.mode] = color.value; | ||
217 | } else { | ||
218 | this.application.ninja.colorController.colorModel.alpha = {value: 1, wasSetByCode: tr |