diff options
Diffstat (limited to 'node_modules/montage/ui/bluemoon/progress.reel/progress.js')
-rw-r--r-- | node_modules/montage/ui/bluemoon/progress.reel/progress.js | 139 |
1 files changed, 139 insertions, 0 deletions
diff --git a/node_modules/montage/ui/bluemoon/progress.reel/progress.js b/node_modules/montage/ui/bluemoon/progress.reel/progress.js new file mode 100644 index 00000000..8bc68b05 --- /dev/null +++ b/node_modules/montage/ui/bluemoon/progress.reel/progress.js | |||
@@ -0,0 +1,139 @@ | |||
1 | /* <copyright> | ||
2 | This file contains proprietary software owned by Motorola Mobility, Inc.<br/> | ||
3 | No 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 | /** | ||
7 | @module "montage/ui/bluemoon/progress.reel" | ||
8 | @requires montage/core/core | ||
9 | @requires montage/ui/component | ||
10 | */ | ||
11 | var Montage = require("montage").Montage, | ||
12 | Component = require("ui/component").Component; | ||
13 | /** | ||
14 | @class module:montage/ui/progress.Progress | ||
15 | @extends module:montage/ui/component.Component | ||
16 | */ | ||
17 | exports.Progress = Montage.create(Component,/** @lends module:"montage/ui/bluemoon/progress.reel".Progress# */ { | ||
18 | /** | ||
19 | Description TODO | ||
20 | @private | ||
21 | */ | ||
22 | _barElement: { | ||
23 | enumerable: false, | ||
24 | value: null | ||
25 | }, | ||
26 | /** | ||
27 | Description TODO | ||
28 | @private | ||
29 | */ | ||
30 | _value: { | ||
31 | enumerable: false, | ||
32 | value: 0 | ||
33 | }, | ||
34 | /** | ||
35 | Description TODO | ||
36 | @type {Function} | ||
37 | @default {Number} 0 | ||
38 | */ | ||
39 | value: { | ||
40 | get: function() { | ||
41 | return this._value; | ||
42 | }, | ||
43 | set: function(val) { | ||
44 | if(val !== this._value) { | ||
45 | this._value = val; | ||
46 | if(this._value > this._maximumValue) { | ||
47 | this._value = this._maximumValue; | ||
48 | } | ||
49 | if(this._value < 0) { | ||
50 | this._value = 0; | ||
51 | } | ||
52 | this.needsDraw = true; | ||
53 | } | ||
54 | } | ||
55 | }, | ||
56 | /** | ||
57 | Description TODO | ||
58 | @private | ||
59 | */ | ||
60 | _maximumValue: { | ||
61 | enumerable: false, | ||
62 | value: 100 | ||
63 | }, | ||
64 | /** | ||
65 | Description TODO | ||
66 | @type {Function} | ||
67 | @default {Number} 100 | ||
68 | */ | ||
69 | maximumValue: { | ||
70 | get: function() { | ||
71 | return this._maximumValue; | ||
72 | }, | ||
73 | set: function(val) { | ||
74 | if(val !== this._maximumValue) { | ||
75 | this._maximumValue = val; | ||
76 | if(this._maximumValue <= 0) { | ||
77 | this._maximumValue = 1; // Prevent divide by zero errors | ||
78 | } | ||
79 | this.needsDraw = true; | ||
80 | } | ||
81 | } | ||
82 | }, | ||
83 | /** | ||
84 | Description TODO | ||
85 | @private | ||
86 | */ | ||
87 | _scrollingChanged: { | ||
88 | enumerable: false, | ||
89 | value: true | ||
90 | }, | ||
91 | /** | ||
92 | Description TODO | ||
93 | @private | ||
94 | */ | ||
95 | _scrolling: { | ||
96 | enumerable: false, | ||
97 | value: false | ||
98 | }, | ||
99 | /** | ||
100 | Description TODO | ||
101 | @type {Function} | ||
102 | @default {Boolean} false | ||
103 | */ | ||
104 | scrolling: { | ||
105 | get: function() { | ||
106 | return this._scrolling; | ||
107 | }, | ||
108 | set: function(value) { | ||
109 | if(this._scrolling !== value) { | ||
110 | this._scrollingChanged = true; | ||
111 | this._scrolling = value; | ||
112 | this.needsDraw = true; | ||
113 | } | ||
114 | } | ||
115 | }, | ||
116 | /** | ||
117 | Description TODO | ||
118 | @function | ||
119 | */ | ||
120 | draw: { | ||
121 | enumerable: false, | ||
122 | value: function() { | ||
123 | var ratio = this._value / this._maximumValue; | ||
124 | // constrain to interval [0, 1] | ||
125 | ratio = Math.min(Math.max(ratio, 0), 1); | ||
126 | // map into [0, 100] | ||
127 | var percentage = ratio * 100; | ||
128 | this._barElement.style.width = percentage + '%'; | ||
129 | if(this._scrollingChanged) { | ||
130 | if(this._scrolling) { | ||
131 | this._barElement.classList.add("scrolling"); | ||
132 | } else { | ||
133 | this._barElement.classList.remove("scrolling"); | ||
134 | } | ||
135 | this._scrollingChanged = false; | ||
136 | } | ||
137 | } | ||
138 | } | ||
139 | }); | ||