aboutsummaryrefslogtreecommitdiff
path: root/js/panels/properties.reel/sections/position-size.reel/position-size.js
diff options
context:
space:
mode:
authorArmen Kesablyan2012-05-15 16:34:46 -0700
committerArmen Kesablyan2012-05-15 16:34:46 -0700
commitc8d61c8e72e0eba266575f9df54325fa77fde73d (patch)
tree556cafd76ab9b2cf4cc2b4cc3ea17b12ce690b69 /js/panels/properties.reel/sections/position-size.reel/position-size.js
parent15a3aaebb56cb2c9409bfe55c862868726c7fd44 (diff)
parent46bd3712329cd3c9311e50ed9ee4c2245bd1be5a (diff)
downloadninja-c8d61c8e72e0eba266575f9df54325fa77fde73d.tar.gz
Merge branch 'dom-architecture' of github.com:Motorola-Mobility/ninja-internal into binding
Diffstat (limited to 'js/panels/properties.reel/sections/position-size.reel/position-size.js')
-rwxr-xr-xjs/panels/properties.reel/sections/position-size.reel/position-size.js276
1 files changed, 276 insertions, 0 deletions
diff --git a/js/panels/properties.reel/sections/position-size.reel/position-size.js b/js/panels/properties.reel/sections/position-size.reel/position-size.js
new file mode 100755
index 00000000..10e084be
--- /dev/null
+++ b/js/panels/properties.reel/sections/position-size.reel/position-size.js
@@ -0,0 +1,276 @@
1/* <copyright>
2This file contains proprietary software owned by Motorola Mobility, Inc.<br/>
3No 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
7var Montage = require("montage/core/core").Montage;
8var Component = require("montage/ui/component").Component;
9
10exports.PositionSize = Montage.create(Component, {
11 leftPosition: {
12 value: 0
13 },
14
15 topPosition: {
16 value: 0
17 },
18
19 heightSize: {
20 value: 0
21 },
22
23 widthSize: {
24 value: 0
25 },
26/*
27 widthSize: {
28 get: function() { return this._widthSize;},
29 set: function(value) {
30 this._widthSize = parseInt(value);
31 this.widthUnit = value;
32 }
33 },
34
35 widthUnit: {
36 value: "px"
37 },
38*/
39 savedPosition: {
40 value: null
41 },
42
43 aspectRatioWidth: {
44 value: null
45 },
46
47 aspectRatioHeight: {
48 value: null
49 },
50
51 _disablePosition: {
52 value: true
53 },
54
55 disablePosition: {
56 get: function () {
57 return this._disablePosition;
58 },
59 set: function (value) {
60 if(value !== this._disablePosition) {
61 this._disablePosition = value;
62 this.needsDraw = true;
63 }
64 }
65 },
66
67 prepareForDraw: {
68 value: function() {
69 this.leftControl.identifier = "left";
70 this.leftControl.addEventListener("change", this, false);
71 this.leftControl.addEventListener("changing", this, false);
72
73 this.topControl.identifier = "top";
74 this.topControl.addEventListener("change", this, false);
75 this.topControl.addEventListener("changing", this, false);
76
77 this.heightControl.identifier = "height";
78 this.heightControl.addEventListener("change", this, false);
79 this.heightControl.addEventListener("changing", this, false);
80
81 this.widthControl.identifier = "width";
82 this.widthControl.addEventListener("change", this, false);
83 this.widthControl.addEventListener("changing", this, false);
84
85 this.bindButton.identifier = "ratio";
86 this.bindButton.addEventListener("action", this, false);
87
88 }
89 },
90
91 draw: {
92 value: function() {
93 if(this._disablePosition) {
94 this.leftPosition = 0;
95 this.leftControl.enabled = false;
96 this.topPosition = 0;
97 this.topControl.enabled = false;
98 this.leftLabel.classList.add("disabled");
99 this.topLabel.classList.add("disabled");
100 } else {
101 this.leftControl.enabled = true;
102 this.topControl.enabled = true;
103 this.leftLabel.classList.remove("disabled");
104 this.topLabel.classList.remove("disabled");
105 }
106 }
107 },
108
109 /**
110 * Calculate the current aspect ration when the bind button is pressed.
111 * If one of the values is 0, then use 1:1 as the ratio;
112 */
113 handleRatioAction: {
114 value: function() {
115 if(this.bindButton.pressed) {
116 this.aspectRatioWidth = this.heightControl.value / this.widthControl.value;
117 if(isNaN(this.aspectRatioWidth) || !isFinite(this.aspectRatioWidth) || this.aspectRatioWidth === 0) this.aspectRatioWidth = 1;
118
119 this.aspectRatioHeight = this.widthControl.value / this.heightControl.value;
120 if(isNaN(this.aspectRatioHeight) || !isFinite(this.aspectRatioHeight) || this.aspectRatioHeight === 0) this.aspectRatioHeight = 1;
121 } else {
122 this.aspectRatioWidth = 1;
123 this.aspectRatioHeight = 1;
124 }
125 }
126 },
127
128 handleLeftChange: {
129 value: function(event) {
130 var prevPosition;
131
132 if(!event.wasSetByCode) {
133 if(this.savedPosition) prevPosition = [this.savedPosition + "px"];
134
135 this.application.ninja.elementMediator.setProperty(this.application.ninja.selectedElements, "left", [this.leftControl.value + "px"] , "Change", "pi", prevPosition);
136 this.savedPosition = null;
137 }
138 }
139 },
140
141 handleTopChange: {
142 value: function(event) {
143 var prevPosition;
144
145 if(!event.wasSetByCode) {
146 if(this.savedPosition) prevPosition = [this.savedPosition + "px"];
147
148 this.application.ninja.elementMediator.setProperty(this.application.ninja.selectedElements, "top", [this.topControl.value + "px"] , "Change", "pi", prevPosition);
149 this.savedPosition = null;
150 }
151 }
152 },
153
154 handleHeightChange: {
155 value: function(event) {
156 var prevPosition, items;
157
158 if(!event.wasSetByCode) {
159 if(this.savedPosition) prevPosition = [this.savedPosition + "px"];
160
161 this.application.ninja.selectedElements.length ? items = this.application.ninja.selectedElements : items = [this.application.ninja.currentDocument.documentRoot];
162
163 if(this.bindButton.pressed) {
164
165 var newWidth = Math.round(this.aspectRatioHeight * this.heightControl.value);
166
167 if(!isFinite(newWidth)) newWidth = this.heightControl.value;
168
169 this.widthControl.value = newWidth;
170 this.application.ninja.elementMediator.setProperty(items, "width", [newWidth + "px"] , "Change", "pi");
171 }
172
173 this.application.ninja.elementMediator.setProperty(items, "height", [this.heightControl.value + "px"] , "Change", "pi", prevPosition);
174 this.savedPosition = null;
175 }
176 }
177 },
178
179 handleWidthChange: {
180 value: function(event) {
181 var prevPosition, items;
182
183 if(!event.wasSetByCode) {
184 if(this.savedPosition) prevPosition = [this.savedPosition + "px"];
185
186 this.application.ninja.selectedElements.length ? items = this.application.ninja.selectedElements : items = [this.application.ninja.currentDocument.documentRoot];
187
188 if(this.bindButton.pressed) {
189
190 var newHeight = Math.round(this.aspectRatioWidth * this.widthControl.value);
191
192 if(!isFinite(newHeight)) newHeight = this.widthControl.value;
193
194 this.heightControl.value = newHeight;
195 this.application.ninja.elementMediator.setProperty(items, "height", [newHeight + "px"] , "Change", "pi");
196