aboutsummaryrefslogtreecommitdiff
path: root/js/components/slider.reel/slider.js
diff options
context:
space:
mode:
authorPierre Frisch2011-12-22 07:25:50 -0800
committerValerio Virgillito2012-01-27 11:18:17 -0800
commitb89a7ee8b956c96a1dcee995ea840feddc5d4b27 (patch)
tree0f3136ab0ecdbbbed6a83576581af0a53124d6f1 /js/components/slider.reel/slider.js
parent2401f05d1f4b94d45e4568b81fc73e67b969d980 (diff)
downloadninja-b89a7ee8b956c96a1dcee995ea840feddc5d4b27.tar.gz
First commit of Ninja to ninja-internal
Signed-off-by: Valerio Virgillito <rmwh84@motorola.com>
Diffstat (limited to 'js/components/slider.reel/slider.js')
-rw-r--r--js/components/slider.reel/slider.js250
1 files changed, 250 insertions, 0 deletions
diff --git a/js/components/slider.reel/slider.js b/js/components/slider.reel/slider.js
new file mode 100644
index 00000000..fced8aad
--- /dev/null
+++ b/js/components/slider.reel/slider.js
@@ -0,0 +1,250 @@
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 SliderBase = require("js/components/sliderbase").SliderBase;
9
10var Slider = exports.Slider = Montage.create(SliderBase, {
11
12 // "horizontal" or "vertical"
13 _direction: {
14 enumerable: true,
15 value: "horizontal"
16 },
17
18 direction: {
19 enumerable: true,
20 get: function() {
21 return this._direction;
22 },
23 set: function(value) {
24
25 if (value !== this._direction) {
26 this._direction = value;
27 this.needsDraw = true;
28 }
29 }
30 },
31
32 customBackground: {
33 enumerable: true,
34 serializable:true,
35 value: null
36 },
37
38 _sliderTrack: {
39 enumerable: false,
40 value: null
41 },
42
43 // Should support clicking on the track
44 _allowTrackClick: {
45 enumerable: true,
46 value: true
47 },
48
49 allowTrackClick: {
50 enumerable: true,
51 get: function() {
52 return this._allowTrackClick;
53 },
54 set: function(value) {
55
56 if (value !== this._allowTrackClick) {
57 this._allowTrackClick = value;
58 }
59 }
60 },
61
62 _knob: {
63 enumerable: false,
64 value: null
65 },
66
67 _positionValue: {
68 enumerable: false,
69 value: 0
70 },
71
72 _previousPositionValue: {
73 enumerable: false,
74 value: 0
75 },
76
77 _percentValue: {
78 enumerable: false,
79 value: 0
80 },
81
82 _knobPercentWidth: {
83 enumerable: false,
84 value: 0
85 },
86
87 _knobOffsetWidth: {
88 enumerable: false,
89 value: 0
90 },
91
92 _length: {
93 enumerable: false,
94 value: 0
95 },
96
97 _deltaLeft: {
98 enumerable: false,
99 value: 0
100 },
101
102 _valueFromPageOffset: {
103 value: function(offset, pageY, isShiftKeyPressed) {
104 var clickPoint;
105 if(this._direction === "horizontal")
106 {
107 clickPoint = webkitConvertPointFromPageToNode(this.element, new WebKitPoint(offset,pageY)).x;
108 }
109 else
110 {
111 clickPoint = webkitConvertPointFromPageToNode(this.element, new WebKitPoint(offset,pageY)).y;
112 }
113 this.value = (clickPoint*this._valueCoef)+this._minValue;
114
115 if(!this._isMouseDown && (this._previousValue !== this._value))
116 {
117 this._dispatchActionEvent();
118 }
119 }
120 },
121
122 setPercentValueFromValue: {
123 value: function () {
124 this._percentValue = (this._value-this._minValue)/(this._maxValue-this._minValue)*(100 - this._knobPercentWidth);
125 }
126 },
127
128 willDraw: {
129 enumerable: false,
130 value: function() {
131 if(this._firstTime)
132 {
133
134 if(this._direction === "horizontal")
135 {
136 this._length = parseInt(this.element.offsetWidth);
137 //this._length = this.element.offsetWidth;
138 this._knobPercentWidth = parseInt(document.defaultView.getComputedStyle(this.knob, null).getPropertyValue("margin-left")) / this._length;
139
140 }
141 else
142 {
143 this._length = this.element.offsetHeight;
144 this._knobPercentWidth = parseInt(document.defaultView.getComputedStyle(this.knob, null).getPropertyValue("margin-top")) / this._length;
145 }
146
147 this.track.width = parseInt(this.element.offsetWidth);
148 //this.track.width = this.element.offsetWidth;
149 this.track.height = parseInt(this.element.offsetHeight);
150 //this.track.height = this.element.offsetHeight;
151
152 this._valueCoef = (this._maxValue-this._minValue)/this._length;
153 this._firstTime = false;
154 }
155 }
156 },
157
158 draw: {
159 value: function() {
160 this.setPercentValueFromValue();
161
162 if(this._direction === "horizontal")
163 {
164 this.knob.style.left = this._percentValue +"%";
165 }
166 else
167 {
168 this.knob.style.top = this._percentValue +"%";
169 }
170 if(this.customBackground)
171 {
172 this.customBackground(this.track);
173 }
174 }
175 },
176
177 _handleTrackClick: {
178 enumerable: false,
179 value: function(event) {
180 event.preventDefault();
181 this._setEventFlags("change", false);
182 this._valueFromPageOffset(event.pageX,event.pageY,false);
183 }
184 },
185
186 prepareForDraw: {
187 enumerable: false,
188 value: function() {
189
190// var sliderParent = document.createElement('div');
191// this._sliderTrack = document.createElement('canvas');
192// this._knob = document.createElement('div');
193
194
195// sliderParent.classList.add("slider-parent");
196// this._sliderTrack.classList.add("slider-track");
197// this._knob.classList.add("knob");
198
199
200
201// sliderParent.appendChild(this._sliderTrack);
202// sliderParent.appendChild(this._knob);
203// this.element.appendChild(sliderParent);
204
205
206
207
208 if(this._direction === "horizontal")
209 {
210 this.parentDiv.classList.add("horizontal");
211 this.track.classList.add("horizontal");
212 this.knob.classList.add("horizontal");
213 //sliderParent.classList.add("horizontal");
214 //this._sliderTrack.classList.add("horizontal");
215 //this._knob.classList.add("horizontal");
216 }
217 else
218 {
219 this.parentDiv.classList.add("vertical");
220 this.track.classList.add("vertical");
221 this.knob.classList.add("vertical");
222
223 //sliderParent.classList.add("vertical");
224 //this._sliderTrack.classList.add("vertical");
225 //this._knob.classList.add("vertical");
226 }
227
228
229
230
231 if(this._enabled)
232 {
233 // if (window.Touch) {
234 this.knob.addEventListener("touchstart", this, false);
235 // } else {