aboutsummaryrefslogtreecommitdiff
path: root/js/panels/Resizer.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/panels/Resizer.js')
-rw-r--r--js/panels/Resizer.js199
1 files changed, 199 insertions, 0 deletions
diff --git a/js/panels/Resizer.js b/js/panels/Resizer.js
new file mode 100644
index 00000000..69efd6ac
--- /dev/null
+++ b/js/panels/Resizer.js
@@ -0,0 +1,199 @@
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.Resizer = Montage.create(Component, {
11
12 hasTemplate: {
13 value: false
14 },
15
16 _isInversed: {
17 value: false
18 },
19
20 isInversed: {
21 get: function() {
22 return this._isInversed;
23 },
24 set: function(val) {
25 this._isInversed = val;
26 }
27 },
28
29 _isVertical: {
30 value: null
31 },
32
33 isVertical: {
34 get: function() {
35 return this._isVertical;
36 },
37 set: function(val) {
38 this._isVertical = val;
39 }
40 },
41
42 _isPanel: {
43 value: true
44 },
45 isPanel: {
46 get: function() {
47 return this._isPanel;
48 },
49 set: function(value) {
50 this._isPanel = value;
51 }
52 },
53 _panel : {
54 value: null
55 },
56
57 panel : {
58 get: function() {
59 return this._panel;
60 },
61 set: function(val) {
62 this._panel = val
63 }
64 },
65
66 handleClick: {
67 value: function() {
68
69 }
70 },
71
72 handleMousedown: {
73 value: function(e) {
74 e.preventDefault();
75 this.panel.addEventListener("webkitTransitionEnd", this, true);
76 if (this.isVertical) {
77 //console.log("y: " + e.y + " startPosition: " + this._startPosition + " initDimension: " + this._initDimension);
78 this._startPosition = e.y;
79 this._initDimension = this.panel.offsetHeight;
80 }
81 else {
82 this._startPosition = e.x;
83 this._initDimension = this.panel.offsetWidth;
84 }
85
86 this.panel.classList.add("disableTransition");
87 window.addEventListener("mousemove", this, false);
88 window.addEventListener("mouseup", this, false);
89 NJevent("panelResizedStart", this)
90 }
91 },
92
93 handleDblclick: {
94 value : function() {
95 this.panel.addEventListener("webkitTransitionEnd", this, true);
96 if (this.isVertical) {
97 this.panel.style.height = "";
98 } else {
99 this.panel.style.width = "";
100 }
101 this.application.ninja.settings.setSetting(this.element.id,"value", "");
102 }
103 },
104
105 captureWebkitTransitionEnd: {
106 value: function() {
107 if(this.redrawStage) {
108 this.application.ninja.stage.resizeCanvases = true;
109 }
110 this.panel.removeEventListener("webkitTransitionEnd");
111 }
112 },
113
114 prepareForDraw: {
115 value: function() {
116 if(this.value != null) {
117 if (this.isVertical) {
118 this.panel.style.height = this.value + "px";
119 } else {
120 this.panel.style.width = this.value + "px";
121 }
122 }
123 this.element.addEventListener("mousedown", this, false);
124 this.element.addEventListener("dblclick", this, false);
125 }
126 },
127
128 draw: {
129 value: function() {
130
131 }
132 },
133
134 handleMouseup: {
135 value: function(e) {
136 e.preventDefault();
137 window.removeEventListener("mousemove", this);
138 window.removeEventListener("mouseup", this);
139 this.panel.classList.remove("disableTransition");
140 if (this.isVertical) {
141 this.panel.style.height = this.panel.offsetHeight;
142 } else {
143 this.panel.style.width = this.panel.offsetWidth;
144 }
145 this.application.ninja.settings.setSetting(this.element.id,"value", this.value);
146 if(this.redrawStage) {
147 this.application.ninja.stage.resizeCanvases = true;
148 }
149 NJevent("panelResizedEnd", this)
150 }
151 },
152
153 handleMousemove: {
154 value: function(e) {
155 if(this.isVertical) {
156 this.value = this._isInversed ? this._initDimension + (this._startPosition - e.y) : this._initDimension + (e.y - this._startPosition);
157 //console.log("y: " + e.y + " startPosition: " + this._startPosition + " initDimension: " + this._initDimension + " finalPosition: " + pos);
158 this.panel.style.height = this.value + "px";
159 }
160 else {
161 if (this.isPanel) {
162 this.value = this._initDimension + (this._startPosition - e.x);
163 } else {
164 this.value = this._isInversed ? this._initDimension + (this._startPosition - e.x) : this._initDimension + (e.x - this._startPosition);
165 }
166 this.panel.style.width = this.value + "px";
167 }
168
169 if(this.redrawStage) {
170 this.application.ninja.stage.resizeCanvases = true;
171 }
172
173 NJevent("panelResizing", this);
174 }
175 },
176
177 _value: {
178 value: null
179 },
180
181 redrawStage: {
182 value:false
183 },
184
185 value: {
186 get: function() {
187 if(this.application.ninja.settings) {
188 var gottenValue = this.application.ninja.settings.getSetting(this.id, "value");
189 if (this._value == null && gottenValue !=null) {
190 this.value = gottenValue;
191 }
192 }
193 return this._value;
194 },
195 set: function(val) {
196 this._value = val;
197 }
198 }
199}); \ No newline at end of file