aboutsummaryrefslogtreecommitdiff
path: root/node_modules/ninja-components/flow-offset.js
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/ninja-components/flow-offset.js')
-rw-r--r--node_modules/ninja-components/flow-offset.js389
1 files changed, 389 insertions, 0 deletions
diff --git a/node_modules/ninja-components/flow-offset.js b/node_modules/ninja-components/flow-offset.js
new file mode 100644
index 00000000..e45a14f3
--- /dev/null
+++ b/node_modules/ninja-components/flow-offset.js
@@ -0,0 +1,389 @@
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").Montage;
8
9var FlowOffset = exports.FlowOffset = Montage.create(Montage, {
10
11 hasTemplate: {
12 value: false
13 },
14
15 isAnimating: {
16 enumerable: false,
17 value: false
18 },
19
20 component: {
21 value: null
22 },
23
24 draw: {
25 value: function () {
26 if (this.isAnimating) {
27 this._interval();
28 }
29 }
30 },
31
32 deserializedFromTemplate: {
33 value: function () {
34 var oldComponentDraw = this.component.draw,
35 self = this;
36
37 this.component.draw = function () {
38 self.draw();
39 oldComponentDraw.call(self.component);
40 };
41 }
42 },
43
44 _hasElasticScrolling: {
45 enumerable: false,
46 value: true
47 },
48
49 hasElasticScrolling: {
50 get: function () {
51 return this._hasElasticScrolling;
52 },
53 set: function (value) {
54 this._hasElasticScrolling=(value===true)?true:false;
55 }
56 },
57
58 _selectedSlideIndex: {
59 enumerable: false,
60 value: null
61 },
62
63 selectedSlideIndex: {
64 get: function () {
65 return this._selectedSlideIndex;
66 },
67 set: function (value) {
68 this._selectedSlideIndex=value;
69 if (typeof this.animatingHash[this._selectedSlideIndex] !== "undefined") {
70 var tmp=this.slide[this._selectedSlideIndex].x;
71 this.origin+=(this._selectedSlideIndex*this._scale)-tmp;
72 }
73 }
74 },
75
76 _selectedComponent: {
77 enumerable: false,
78 value: null
79 },
80
81 selectedComponent: {
82 get: function () {
83 return this._selectedComponent;
84 },
85 set: function (value) {
86 this._selectedComponent=value;
87 this.selectedSlideIndex=value;
88 }
89 },
90
91 _animating: {
92 enumerable: false,
93 value: null
94 },
95
96 animating: {
97 enumerable: false,
98 get: function () {
99 if (!this._animating) {
100 this._animating=[];
101 }
102 return this._animating;
103 },
104 set: function () {
105 }
106 },
107
108 _animatingHash: {
109 enumerable: false,
110 value: null
111 },
112
113 animatingHash: {
114 enumerable: false,
115 get: function () {
116 if (!this._animatingHash) {
117 this._animatingHash={};
118 }
119 return this._animatingHash;
120 },
121 set: function () {
122 }
123 },
124
125 _slide: {
126 enumerable: false,
127 value: null
128 },
129
130 slide: {
131 enumerable: false,
132 get: function () {
133 if (!this._slide) {
134 this._slide={};
135 }
136 return this._slide;
137 },
138 set: function () {
139 }
140 },
141
142 startAnimating: {
143 enumerable: false,
144 value: function (index, pos) {
145 if (typeof this.animatingHash[index] === "undefined") {
146 var length=this.animating.length;
147
148 this.animating[length]=index;
149 this.animatingHash[index]=length;
150 this.slide[index]={
151 speed: 0,
152 x: pos
153 };
154 } else {
155 this.slide[index].x=pos;
156 }
157 }
158 },
159
160 stopAnimating: {
161 enumerable: false,
162 value: function (index) {
163 if (typeof this.animatingHash[index] !== "undefined") {
164 this.animating[this.animatingHash[index]]=this.animating[this.animating.length-1];
165 this.animatingHash[this.animating[this.animating.length-1]]=this.animatingHash[index];
166 this.animating.pop();
167 delete this.animatingHash[index];
168 delete this.slide[index];
169 }
170 }
171 },
172
173 _range: {
174 value: 15
175 },
176
177 lastDrawTime: {
178 value: null
179 },
180
181 _origin: {
182 enumerable: false,
183 value: 0
184 },
185
186 origin: {
187 get: function () {
188 return this._origin;
189 },
190 set: function (value) {
191 if (this._hasElasticScrolling) {
192 var i,
193 n,
194 min=this._selectedSlideIndex-this._range,
195 max=this._selectedSlideIndex+this._range+1,
196 tmp,
197 j,
198 x,
199 self=this;
200
201 tmp=value-this._origin;
202 if (min<0) {
203 min=0;
204 }
205
206 if (!this.isAnimating) {
207 this.lastDrawTime=Date.now();
208 }
209 for (i=min; i<max; i++) {
210 if (i!=this._selectedSlideIndex) {
211 if (typeof this.animatingHash[i] === "undefined") {
212 x=i*this._scale;
213 } else {
214 x=this.slide[i].x;
215 }
216 x+=tmp;
217 if (i<this._selectedSlideIndex) {
218 if (x<i*this._scale) {
219 this.startAnimating(i, x);
220 }
221 } else {
222 if (x>i*this._scale) {
223 this.startAnimating(i, x);
224 }
225 }
226 }
227 }
228 this.stopAnimating(this._selectedSlideIndex);
229
230 if (!this.isAnimating) {
231 this._interval=function () {
232 var animatingLength=self.animating.length,
233 n, j, i, _iterations=8,