aboutsummaryrefslogtreecommitdiff
path: root/node_modules/montage/ui/scroller.reel/scroller.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 /node_modules/montage/ui/scroller.reel/scroller.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 'node_modules/montage/ui/scroller.reel/scroller.js')
-rw-r--r--node_modules/montage/ui/scroller.reel/scroller.js268
1 files changed, 268 insertions, 0 deletions
diff --git a/node_modules/montage/ui/scroller.reel/scroller.js b/node_modules/montage/ui/scroller.reel/scroller.js
new file mode 100644
index 00000000..01df7d9c
--- /dev/null
+++ b/node_modules/montage/ui/scroller.reel/scroller.js
@@ -0,0 +1,268 @@
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 Scroll = require("ui/scroll").Scroll,
9 Component = require("ui/component").Component;
10
11var Scroller = exports.Scroller = Montage.create(Component, {
12
13 _scroll: {
14 enumerable: false,
15 value: null
16 },
17
18 _scrollX: {
19 enumerable: false,
20 value: 0
21 },
22
23 scrollX: {
24 get: function () {
25 return this._scrollX;
26 },
27 set: function (value) {
28 this._scrollX = value;
29 this.needsDraw = true;
30 }
31 },
32
33 _scrollY: {
34 enumerable: false,
35 value: 0
36 },
37
38 scrollY: {
39 get: function () {
40 return this._scrollY;
41 },
42 set: function (value) {
43 this._scrollY = value;
44 this.needsDraw = true;
45 }
46 },
47
48 _axis: {
49 enumerable: false,
50 value: "auto"
51 },
52
53 axis: {
54 get: function () {
55 return this._axis;
56 },
57 set: function (value) {
58 this._axis = value;
59 this.needsDraw = true;
60 }
61 },
62
63 _displayScrollbars: {
64 enumerable: false,
65 value: "auto"
66 },
67
68 displayScrollbars: {
69 get: function () {
70 return this._displayScrollbars;
71 },
72 set: function (value) {
73 switch (value) {
74 case "vertical":
75 case "horizontal":
76 case "both":
77 case "auto":
78 this._displayScrollbars = value;
79 break;
80 default:
81 this._displayScrollbars = "none";
82 break;
83 }
84 this.needsDraw = true;
85 }
86 },
87
88 _hasMomentum: {
89 enumerable: false,
90 value: true
91 },
92
93 hasMomentum: {
94 get: function () {
95 return this._hasMomentum;
96 },
97 set: function (value) {
98 this._hasMomentum = value;
99 }
100 },
101
102 _hasBouncing: {
103 enumerable: false,
104 value: true
105 },
106
107 hasBouncing: {
108 get: function () {
109 return this._hasBouncing;
110 },
111 set: function (value) {
112 this._hasBouncing = value;
113 }
114 },
115
116 _momentumDuration: {
117 enumerable: false,
118 value: 650
119 },
120
121 momentumDuration: {
122 get: function () {
123 return this._momentumDuration;
124 },
125 set: function (value) {
126 this._momentumDuration = value;
127 }
128 },
129
130 _bouncingDuration: {
131 enumerable: false,
132 value: 750
133 },
134
135 bouncingDuration: {
136 get: function () {
137 return this._bouncingDuration;
138 },
139 set: function (value) {
140 this._bouncingDuration = value;
141 }
142 },
143
144 _content: {
145 enumerable: false,
146 value: null
147 },
148
149 templateDidLoad: {
150 value: function () {
151 var orphanedFragment,
152 currentContentRange = this.element.ownerDocument.createRange();
153
154 currentContentRange.selectNodeContents(this.element);
155 orphanedFragment = currentContentRange.extractContents();
156 this._content.appendChild(orphanedFragment);
157 }
158 },
159
160 prepareForDraw: {
161 value: function () {
162 var self = this;
163
164 this._scroll = Montage.create(Scroll);
165 this._scroll.element = this._element;
166 this._scroll.component = this;
167 Object.defineBinding(this._scroll, "scrollX", {boundObject: this, boundObjectPropertyPath: "scrollX", oneway: false});
168 Object.defineBinding(this._scroll, "scrollY", {boundObject: this, boundObjectPropertyPath: "scrollY", oneway: false});
169 Object.defineBinding(this._scroll, "axis", {boundObject: this, boundObjectPropertyPath: "axis", oneway: false});
170 Object.defineBinding(this._scroll, "hasBouncing", {boundObject: this, boundObjectPropertyPath: "hasBouncing", oneway: false});
171 Object.defineBinding(this._scroll, "hasMomentum", {boundObject: this, boundObjectPropertyPath: "hasMomentum", oneway: false});
172 Object.defineBinding(this._scroll, "bouncingDuration", {boundObject: this, boundObjectPropertyPath: "bouncingDuration", oneway: false});
173 Object.defineBinding(this._scroll, "momentumDuration", {boundObject: this, boundObjectPropertyPath: "momentumDuration", oneway: false});
174 this._scroll.deserializedFromTemplate();
175 this._scroll.addEventListener("scrollStart", function () {
176 self._scrollBars.opacity = .5;
177 }, false);
178 this._scroll.addEventListener("scrollEnd", function () {
179 self._scrollBars.opacity = 0;
180 }, false);
181 }
182 },
183
184 willDraw: {
185 enumerable: false,
186 value: function () {
187 this._left = this._element.offsetLeft;
188 this._top = this._element.offsetTop;
189 this._width = this._element.offsetWidth;
190 this._height = this._element.offsetHeight;
191 this._scroll.maxScrollX = this._content.scrollWidth - this._width;
192 if (this._scroll.maxScrollX < 0) {
193 this._scroll.maxScrollX = 0;
194 }
195 this._scroll.maxScrollY = this._content.offsetHeight - this._height;
196 if (this._scroll.maxScrollY < 0) {
197 this._scroll.maxScrollY = 0;
198 }
199 var delegateValue = this.callDelegateMethod("didSetMaxScroll", {x: this._scroll.maxScrollX, y: this._scroll.maxScrollY});
200 if (delegateValue) {
201 this._scroll.maxScrollX = delegateValue.x;
202 this._scroll.maxScrollY = delegateValue.y;
203 }
204 switch (this._displayScrollbars) {
205 case "horizontal":
206 this._scrollBars.displayHorizontal = true;
207 this._scrollBars.displayVertical = false;
208 break;
209 case "vertical":
210 this._scrollBars.displayHorizontal = false;
211 this._scrollBars.displayVertical = true;
212 break;
213 case "both":
214 this._scrollBars.displayHorizontal = true;
215 this._scrollBars.displayVertical = true;
216 break;
217 case "auto":
218 if (this._scroll._maxScrollX && this._scroll._maxScrollY) {
219 this._scrollBars.displayHorizontal = true;