sproutcore 0.9.4 → 0.9.5
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +70 -2
- data/Manifest.txt +3 -15
- data/config/hoe.rb +1 -1
- data/frameworks/sproutcore/animation/animation.js +411 -0
- data/frameworks/sproutcore/controllers/array.js +68 -21
- data/frameworks/sproutcore/controllers/object.js +21 -2
- data/frameworks/sproutcore/drag/drag.js +13 -4
- data/frameworks/sproutcore/drag/drop_target.js +26 -19
- data/frameworks/sproutcore/english.lproj/core.css +4 -0
- data/frameworks/sproutcore/english.lproj/strings.js +5 -0
- data/frameworks/sproutcore/english.lproj/theme.css +5 -0
- data/frameworks/sproutcore/foundation/application.js +1 -2
- data/frameworks/sproutcore/foundation/set.js +31 -12
- data/frameworks/sproutcore/foundation/sorted_set.js +590 -0
- data/frameworks/sproutcore/foundation/string.js +43 -9
- data/frameworks/sproutcore/globals/window.js +34 -9
- data/frameworks/sproutcore/lib/button_views.rb +1 -0
- data/frameworks/sproutcore/lib/collection_view.rb +1 -0
- data/frameworks/sproutcore/lib/core_views.rb +3 -0
- data/frameworks/sproutcore/lib/index.rhtml +1 -1
- data/frameworks/sproutcore/mixins/collection_view_delegate.js +201 -0
- data/frameworks/sproutcore/mixins/observable.js +2 -7
- data/frameworks/sproutcore/models/record.js +1 -1
- data/frameworks/sproutcore/models/store.js +81 -28
- data/frameworks/sproutcore/tests/views/view/clippingFrame.rhtml +9 -6
- data/frameworks/sproutcore/views/collection/collection.js +649 -211
- data/frameworks/sproutcore/views/collection/grid.js +62 -26
- data/frameworks/sproutcore/views/collection/list.js +57 -21
- data/frameworks/sproutcore/views/collection/source_list.js +61 -13
- data/frameworks/sproutcore/views/image.js +7 -0
- data/frameworks/sproutcore/views/inline_text_field.js +4 -5
- data/frameworks/sproutcore/views/slider.js +2 -0
- data/frameworks/sproutcore/views/view.js +2 -2
- data/lib/sproutcore/build_tools/html_builder.rb +4 -6
- data/lib/sproutcore/build_tools/resource_builder.rb +32 -20
- data/lib/sproutcore/bundle.rb +130 -32
- data/lib/sproutcore/bundle_manifest.rb +24 -21
- data/lib/sproutcore/helpers/static_helper.rb +22 -9
- data/lib/sproutcore/merb/bundle_controller.rb +4 -3
- data/lib/sproutcore/version.rb +1 -1
- metadata +14 -17
- data/clients/view_builder/builders/builder.js +0 -339
- data/clients/view_builder/builders/button.js +0 -81
- data/clients/view_builder/controllers/document.js +0 -21
- data/clients/view_builder/core.js +0 -19
- data/clients/view_builder/english.lproj/body.css +0 -77
- data/clients/view_builder/english.lproj/body.rhtml +0 -39
- data/clients/view_builder/english.lproj/controls.css +0 -0
- data/clients/view_builder/english.lproj/strings.js +0 -14
- data/clients/view_builder/main.js +0 -38
- data/clients/view_builder/mixins/design_mode.js +0 -92
- data/clients/view_builder/tests/controllers/document.rhtml +0 -20
- data/clients/view_builder/tests/views/builder.rhtml +0 -20
- data/clients/view_builder/tests/views/palette.rhtml +0 -21
- data/clients/view_builder/views/builder.js +0 -26
- data/clients/view_builder/views/palette.js +0 -30
data/History.txt
CHANGED
@@ -1,5 +1,73 @@
|
|
1
1
|
== SVN HEAD
|
2
2
|
|
3
|
+
== SproutCore 0.9.5
|
4
|
+
|
5
|
+
* Build Tools will now remove any loc strings from the strings.js file beginning with "@@" for the key name when building the JS file to send to the client. This allows you to include strings in the strings.js file that you only want to use for server-side localization.
|
6
|
+
|
7
|
+
* Build Tools now support the "loc()" ruby helper, which will include a server-side loc string pulled from the strings.js file for the current bundle.
|
8
|
+
|
9
|
+
* Collection View now supports selectOnMouseDown which can be turned off to provide better drag and drop behavior on SourceList. SC.SourceListView now turns this off by default.
|
10
|
+
|
11
|
+
* Requesting a resource that should be available in production mode while
|
12
|
+
running your server in dev mode will now work. Bundles now build one manifest per language/build_mode combination.
|
13
|
+
|
14
|
+
* Build tools now automatically set String.preferredLanguage to the current
|
15
|
+
build language. This will ensure we start using the current strings when you
|
16
|
+
load the loc'd interface.
|
17
|
+
|
18
|
+
* Build tools no longer automatically merge .html files into the bundle.
|
19
|
+
Instead they are treated like static resources. If you want to have your html merged into the index, name it .rhtml or .html.erb
|
20
|
+
|
21
|
+
* Initial changes to SampleControls to add a form-view demo. None of the controls are wired up yet.
|
22
|
+
|
23
|
+
* Added mongrel as a required dependency of SproutCore. If you have something
|
24
|
+
like thin installed this is technically not required, but several people were
|
25
|
+
experiencing trouble installing the gem.
|
26
|
+
|
27
|
+
* Lots of Safari-specific features for Photos just to demo some of its capabilities. Client-side storage support is also provided but currently does not save changes you make.
|
28
|
+
|
29
|
+
* SC.CollectionView now supports selectAll (Ctrl+A)
|
30
|
+
|
31
|
+
* SC.CollectionView now supports the delete key to remove items. Also added delegate methods to the collection view delegate to give you control over how deletions happen.
|
32
|
+
|
33
|
+
* SC.window can now properly capture the backspace key in Firefox. To
|
34
|
+
activate this feature you must declare SC.CAPTURE_BACKSPACE_KEY = YES in your
|
35
|
+
core.js file. Capturing the backspace key will prevent the browser from going to previous page when the user hits backspace, which can lead to data loss. To capture this key, SC.window will directly set the document.onkeypress handler.
|
36
|
+
|
37
|
+
* SC.GridView now supports dropping ON items.
|
38
|
+
|
39
|
+
* SC.ListView now supports dropping ON items.
|
40
|
+
|
41
|
+
* Removed the try/catch() that was placed around property notifiers. This is not only faster but it will make it easier to debug these exceptions in Firebug and IE.
|
42
|
+
|
43
|
+
* [FIX] SC.InlineTextFieldView was using the _frame property even though that
|
44
|
+
is used by a parent class. Changed to _optframe
|
45
|
+
|
46
|
+
* Improved some documentation here and there.
|
47
|
+
|
48
|
+
* [FIX] SC.View will recache its frames when isVisibleInWindow changes. This will help to ensure we always have the correct dimensions when bringing views on and offscreen. -- All unit tests now pass again.
|
49
|
+
|
50
|
+
* Improves Photos sample to include support for adding/deleting albums and drag and drop into albums.
|
51
|
+
|
52
|
+
* Collection View now supports dropping items ON item views as well as between
|
53
|
+
them.
|
54
|
+
|
55
|
+
* Collection Views now support a delegate object that can be used to control
|
56
|
+
drag and drop and selection behavior. See mixins/collection_view_delegate.js
|
57
|
+
for a complete description of the new methods.
|
58
|
+
|
59
|
+
* SC.ArrayController now supports the useControllersForContent property. If
|
60
|
+
set to YES, then getting an objectAt() will return a controller for the value
|
61
|
+
instead of the value itself. This is useful for those times you are using an
|
62
|
+
array controller to manage a set of objects you want to control. Previously
|
63
|
+
this feature was always used by array controllers and could not be disabled.
|
64
|
+
This is now off by default.
|
65
|
+
|
66
|
+
* [FIX] SC.ArrayController and SC.ObjectController now will properly observe
|
67
|
+
their own content, even when the content is set on init.
|
68
|
+
|
69
|
+
== SproutCore 0.9.4
|
70
|
+
|
3
71
|
* [FIX] Build system now generates index.html files for client bundles, even
|
4
72
|
if they do not include .rhtml resources.
|
5
73
|
|
@@ -19,6 +87,8 @@ notification system.
|
|
19
87
|
* [FIX] The build system now ignored any rhtml files that does not appear in
|
20
88
|
an lproj directory since this is where templates are stored.
|
21
89
|
|
90
|
+
== SproutCore 0.9.3
|
91
|
+
|
22
92
|
* Basic changes to get IE working. All non-view tests now pass and the doc app and test runner both load and run in IE7. Lots of visual fixes are still required for the sc-theme as well as IE-specific perf optimization and bug fixes.
|
23
93
|
|
24
94
|
* [BUG] Default template for both client and template included a stray comma in their core.js file that breaks IE and Safari 2. This is fixed in the templates and in the clients included with the framework, though you will need to make this change manually in your own apps.
|
@@ -46,8 +116,6 @@ will need to implement the InlineEditorDelegate (see documentation).
|
|
46
116
|
|
47
117
|
* Inline editor now displays with a fixed width and grows downward as you type instead of stretching out to the end.
|
48
118
|
|
49
|
-
--
|
50
|
-
|
51
119
|
* Added hello world sample app.
|
52
120
|
|
53
121
|
* Updated contacts sample app. It is much nicer now.
|
data/Manifest.txt
CHANGED
@@ -39,24 +39,10 @@ clients/sc_test_runner/main.js
|
|
39
39
|
clients/sc_test_runner/models/test.js
|
40
40
|
clients/sc_test_runner/views/runner_frame.js
|
41
41
|
clients/sc_test_runner/views/test_label.js
|
42
|
-
clients/view_builder/builders/builder.js
|
43
|
-
clients/view_builder/builders/button.js
|
44
|
-
clients/view_builder/controllers/document.js
|
45
|
-
clients/view_builder/core.js
|
46
|
-
clients/view_builder/english.lproj/body.css
|
47
|
-
clients/view_builder/english.lproj/body.rhtml
|
48
|
-
clients/view_builder/english.lproj/controls.css
|
49
|
-
clients/view_builder/english.lproj/strings.js
|
50
|
-
clients/view_builder/main.js
|
51
|
-
clients/view_builder/mixins/design_mode.js
|
52
|
-
clients/view_builder/tests/controllers/document.rhtml
|
53
|
-
clients/view_builder/tests/views/builder.rhtml
|
54
|
-
clients/view_builder/tests/views/palette.rhtml
|
55
|
-
clients/view_builder/views/builder.js
|
56
|
-
clients/view_builder/views/palette.js
|
57
42
|
config/hoe.rb
|
58
43
|
config/requirements.rb
|
59
44
|
frameworks/prototype/prototype.js
|
45
|
+
frameworks/sproutcore/animation/animation.js
|
60
46
|
frameworks/sproutcore/controllers/array.js
|
61
47
|
frameworks/sproutcore/controllers/collection.js
|
62
48
|
frameworks/sproutcore/controllers/controller.js
|
@@ -112,6 +98,7 @@ frameworks/sproutcore/foundation/routes.js
|
|
112
98
|
frameworks/sproutcore/foundation/run_loop.js
|
113
99
|
frameworks/sproutcore/foundation/server.js
|
114
100
|
frameworks/sproutcore/foundation/set.js
|
101
|
+
frameworks/sproutcore/foundation/sorted_set.js
|
115
102
|
frameworks/sproutcore/foundation/string.js
|
116
103
|
frameworks/sproutcore/foundation/timer.js
|
117
104
|
frameworks/sproutcore/foundation/undo_manager.js
|
@@ -127,6 +114,7 @@ frameworks/sproutcore/lib/form_views.rb
|
|
127
114
|
frameworks/sproutcore/lib/index.rhtml
|
128
115
|
frameworks/sproutcore/lib/menu_views.rb
|
129
116
|
frameworks/sproutcore/mixins/array.js
|
117
|
+
frameworks/sproutcore/mixins/collection_view_delegate.js
|
130
118
|
frameworks/sproutcore/mixins/control.js
|
131
119
|
frameworks/sproutcore/mixins/delegate_support.js
|
132
120
|
frameworks/sproutcore/mixins/editable.js
|
data/config/hoe.rb
CHANGED
@@ -60,7 +60,7 @@ hoe = Hoe.new(GEM_NAME, VERS) do |p|
|
|
60
60
|
|
61
61
|
# == Optional
|
62
62
|
p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
|
63
|
-
p.extra_deps = [['activesupport', '>= 2.0.2'], ['merb-core', '>= 0.9.1'], ['erubis'], ['rubigen'], ]
|
63
|
+
p.extra_deps = [['activesupport', '>= 2.0.2'], ['merb-core', '>= 0.9.1'], ['erubis'], ['rubigen'], ['mongrel']]
|
64
64
|
|
65
65
|
#p.spec_extras = {} # A hash of extra values to set in the gemspec.
|
66
66
|
|
@@ -0,0 +1,411 @@
|
|
1
|
+
// ========================================================================
|
2
|
+
// SproutCore
|
3
|
+
// copyright 2006-2008 Sprout Systems, Inc.
|
4
|
+
// ========================================================================
|
5
|
+
|
6
|
+
require('Core') ;
|
7
|
+
require('foundation/timer') ;
|
8
|
+
|
9
|
+
/**
|
10
|
+
@class
|
11
|
+
|
12
|
+
An animator is a special timer that will transition its value property from
|
13
|
+
0 to 1 according to a transform function you define. You can also specify
|
14
|
+
one or more "subjects" that will be invoked whenever the animation value
|
15
|
+
changes, which can apply the animation to any target you like.
|
16
|
+
|
17
|
+
This class and its related classes are based on Bernie's Better Animator
|
18
|
+
class.
|
19
|
+
|
20
|
+
Use Cases:
|
21
|
+
|
22
|
+
1. I just want to transition from x=0 -> x=20.
|
23
|
+
v.transitionTo('styleLeft', 20) ;
|
24
|
+
-> creates an animation for styleLeft. If you add a new animation for
|
25
|
+
the same effect, it will cancel the old one automatically.
|
26
|
+
|
27
|
+
2. I want to have an 'animation behavior' attached to some property.
|
28
|
+
whenever I change it, it should automatically transition the property
|
29
|
+
instead of just updating it. i.e. a "Tracker".
|
30
|
+
|
31
|
+
-> I may want the tracker to update several things at once. But that
|
32
|
+
could be done through changing one property which will in turn
|
33
|
+
update everything else. Better idea.
|
34
|
+
|
35
|
+
Tracker simply stores some animation properties and calls transitionTo
|
36
|
+
whenever your target value changes.
|
37
|
+
|
38
|
+
3. I want to have some property animating on its own. For example a
|
39
|
+
throbbing button
|
40
|
+
|
41
|
+
a = v.addAnimation('opacity', {
|
42
|
+
repeatCount: ,
|
43
|
+
autoreverses: YES,
|
44
|
+
end: 1.0,
|
45
|
+
start: 0.0,
|
46
|
+
property: 'opacity'
|
47
|
+
}) ;
|
48
|
+
|
49
|
+
a.set('isPaused', YES) ;
|
50
|
+
v.removeAnimation('opacity');
|
51
|
+
|
52
|
+
--
|
53
|
+
We will need an animation builder. It would be nice if I could have a
|
54
|
+
complete timeline for an animation setup and you just tell it to run. Set
|
55
|
+
the timecode to anytime that you want, tell it to start or stop.
|
56
|
+
|
57
|
+
@extends SC.Timer
|
58
|
+
@author Charles Jolley
|
59
|
+
@since SproutCore 1.0
|
60
|
+
*/
|
61
|
+
SC.Animation = SC.Timer.extend(
|
62
|
+
/** @scope SC.Animation.prototype */ {
|
63
|
+
|
64
|
+
/**
|
65
|
+
The target frame rate. This is used to determine the interval of the
|
66
|
+
timer.
|
67
|
+
|
68
|
+
@type {Number}
|
69
|
+
@field
|
70
|
+
*/
|
71
|
+
frameRate: 60,
|
72
|
+
|
73
|
+
/**
|
74
|
+
The interval between frames. Calculated automatically from the frameRate.
|
75
|
+
This property is read only.
|
76
|
+
|
77
|
+
@type {Number}
|
78
|
+
@field
|
79
|
+
*/
|
80
|
+
interval: function() {
|
81
|
+
return 1000 / this.get('frameRate') ;
|
82
|
+
}.property('frameRate'),
|
83
|
+
|
84
|
+
/**
|
85
|
+
The total amount of time in msec you want to take for the animation to
|
86
|
+
go from 0-1.
|
87
|
+
*/
|
88
|
+
duration: 0,
|
89
|
+
|
90
|
+
/**
|
91
|
+
The speed at which the timecode for the animation will progress. 1.0
|
92
|
+
means it will progress in real time, 2.0 means twice as fast, etc.
|
93
|
+
*/
|
94
|
+
speed: 1.0,
|
95
|
+
|
96
|
+
/**
|
97
|
+
The total number of times you want the animation to repeat.
|
98
|
+
|
99
|
+
This can be any number, including partial numbers. If you set this
|
100
|
+
value you must not set repeatDuration as well. This will be ignored
|
101
|
+
if the value is 0, which is the default.
|
102
|
+
|
103
|
+
If you set this property to -1, then the animation will repeat
|
104
|
+
indefinitely.
|
105
|
+
|
106
|
+
Setting this property will update the targetTimecode.
|
107
|
+
|
108
|
+
@type {Number}
|
109
|
+
@field
|
110
|
+
*/
|
111
|
+
repeatCount: 0,
|
112
|
+
|
113
|
+
/**
|
114
|
+
The total amount of time the animation should run, repeating itself, in
|
115
|
+
msec.
|
116
|
+
|
117
|
+
If you set this value you must not set repeatCount as well. This will
|
118
|
+
be ignored if the value is 0, which is the default.
|
119
|
+
|
120
|
+
Setting this property will update the targetTimecode.
|
121
|
+
|
122
|
+
@type {Number}
|
123
|
+
@field
|
124
|
+
*/
|
125
|
+
repeatDuration: 0,
|
126
|
+
|
127
|
+
/**
|
128
|
+
If YES, then the animation will automatically reverse itself on each
|
129
|
+
repeat.
|
130
|
+
|
131
|
+
@type {Boolean}
|
132
|
+
@field
|
133
|
+
*/
|
134
|
+
autoreverses: NO,
|
135
|
+
|
136
|
+
/**
|
137
|
+
A transition function. This is used to convert the progress into a
|
138
|
+
state value. You can supply your own transition function to provide
|
139
|
+
varied behaviors such as ease in, ease out, etc.
|
140
|
+
|
141
|
+
The function must have a signature like:
|
142
|
+
|
143
|
+
transition: function(value, animator)
|
144
|
+
|
145
|
+
It must accept a value from 0-1 indicating the current animation progress
|
146
|
+
and return a value from 0-1 indication the current transition progress.
|
147
|
+
|
148
|
+
@type {Function}
|
149
|
+
@field
|
150
|
+
*/
|
151
|
+
transition: null,
|
152
|
+
|
153
|
+
/**
|
154
|
+
This is the current timecode for the animation, in msec. You can set
|
155
|
+
this to any value that you want and the animation to compute the current
|
156
|
+
transition value from it.
|
157
|
+
|
158
|
+
To move instantly to any part of your animation, you can simply set this
|
159
|
+
timecode or use jumpTo().
|
160
|
+
|
161
|
+
@type {Number}
|
162
|
+
@field
|
163
|
+
*/
|
164
|
+
currentTimecode: 0,
|
165
|
+
|
166
|
+
/**
|
167
|
+
This is the target timecode. Whenever the target timecode and the
|
168
|
+
current timecode do not match, the animation will animate until it
|
169
|
+
reaches the target timecode.
|
170
|
+
|
171
|
+
To transition the animation to a new state, set the timecode to any
|
172
|
+
value that you want.
|
173
|
+
|
174
|
+
@type {Number}
|
175
|
+
*/
|
176
|
+
targetTimecode: 0,
|
177
|
+
|
178
|
+
/**
|
179
|
+
The current animation progress.
|
180
|
+
|
181
|
+
This value will loop from 0-1 based on the current timecode and the
|
182
|
+
setting of autoreverses. You generally do not want to use this value.
|
183
|
+
Instead use the value property to compute the current transition.
|
184
|
+
|
185
|
+
@type {Number}
|
186
|
+
@field
|
187
|
+
*/
|
188
|
+
progress: function() {
|
189
|
+
|
190
|
+
// current progress is calculated from the currentTimecode by dividing
|
191
|
+
// it by the animation duration and autoreverses.
|
192
|
+
var currentTimecode = this.get('currentTimecode') ;
|
193
|
+
var duration = this.get('duration') ;
|
194
|
+
var reverses = this.get('autoreverses') ;
|
195
|
+
|
196
|
+
// find the progress through the current cycle.
|
197
|
+
var cycle = Math.floor(currentTimecode / duration) ;
|
198
|
+
var progress = (currentTimecode - (duration * cycle)) / duration;
|
199
|
+
|
200
|
+
// if we autoreverse and the cycle is odd numbered, invert.
|
201
|
+
if (reverses && (cycle % 2) > 0) progress = 1 - progress ;
|
202
|
+
return progress ;
|
203
|
+
}.property('currentTimecode', 'duration', 'autoreverses'),
|
204
|
+
|
205
|
+
/**
|
206
|
+
The current animation value. Transform functions can observe this
|
207
|
+
property and update the target object accordingly.
|
208
|
+
|
209
|
+
@type {Number}
|
210
|
+
@field
|
211
|
+
*/
|
212
|
+
value: function() {
|
213
|
+
var value = this.get('progress');
|
214
|
+
if (this.transition) value = this.transition(value, this) ;
|
215
|
+
return value ;
|
216
|
+
}.property('progress'),
|
217
|
+
|
218
|
+
/**
|
219
|
+
The target object of the animation. This is often used by transform
|
220
|
+
functions as the target of their change. It is not strictly required.
|
221
|
+
|
222
|
+
@type {Object}
|
223
|
+
@field
|
224
|
+
*/
|
225
|
+
target: null,
|
226
|
+
|
227
|
+
|
228
|
+
/**
|
229
|
+
This method must be called once when the animation is created to schedule
|
230
|
+
it with the run loop. Once animation has been started, you should can
|
231
|
+
pause it to remove it from the runloop temporarily.
|
232
|
+
|
233
|
+
@returns {void}
|
234
|
+
*/
|
235
|
+
play: function() {
|
236
|
+
this.beginPropertyChanges() ;
|
237
|
+
if (!this.get('isScheduled')) {
|
238
|
+
this.schedule() ;
|
239
|
+
this._lastActionTime = SC.runLoop.get('startTime') ;
|
240
|
+
}
|
241
|
+
|
242
|
+
if (this.get('isPaused')) this.set('isPaused', NO) ;
|
243
|
+
this.endPropertyChanges() ;
|
244
|
+
},
|
245
|
+
|
246
|
+
/**
|
247
|
+
Once an animation has been started, you can pause it anytime with this
|
248
|
+
method. Call start() to restart it or set isPaused to NO.
|
249
|
+
|
250
|
+
@returns {void}
|
251
|
+
*/
|
252
|
+
pause: function() {
|
253
|
+
this.set('isPaused', YES) ;
|
254
|
+
},
|
255
|
+
|
256
|
+
/**
|
257
|
+
Immediately changes the currentTimecode to reflect the requested amount
|
258
|
+
of progress through a single cycle of the animation.
|
259
|
+
|
260
|
+
@param progress {Number} a progress value from 0 to 1.
|
261
|
+
@returns {void}
|
262
|
+
*/
|
263
|
+
jumpTo: function(progress) {
|
264
|
+
// get the current progress.
|
265
|
+
var cur = this.get('progress') ;
|
266
|
+
var diff = progress - cur ;
|
267
|
+
var duration = this.get('duration') ;
|
268
|
+
diff *= duration ;
|
269
|
+
|
270
|
+
var timecode = this.get('currentTimecode') ;
|
271
|
+
if (diff !== 0) this.set('currentTimecode', timecode + diff) ;
|
272
|
+
},
|
273
|
+
|
274
|
+
/**
|
275
|
+
Changes the targetTimecode to reflect the request amount of progress
|
276
|
+
through the current cycle of the animation. If the animation is in
|
277
|
+
reverse, this could move the timecode in the opposite direction.
|
278
|
+
|
279
|
+
@param progress {Number} a progress value from 0 to 1.
|
280
|
+
@returns {void}
|
281
|
+
*/
|
282
|
+
seekTo: function(progress) {
|
283
|
+
// get the current progress.
|
284
|
+
var cur = this.get('progress') ;
|
285
|
+
var diff = progress - cur ;
|
286
|
+
var duration = this.get('duration') ;
|
287
|
+
diff *= duration ;
|
288
|
+
|
289
|
+
var timecode = this.get('currentTimecode') ;
|
290
|
+
if (diff !== 0) this.set('targetTimecode', timecode + diff) ;
|
291
|
+
},
|
292
|
+
|
293
|
+
/**
|
294
|
+
Changes the currentTimecode and targetTimecode to reflect the requested
|
295
|
+
amount of progress through the current cycle of the animation. If the
|
296
|
+
animation is in reverse, this could move the timecode in the opposite
|
297
|
+
direction.
|
298
|
+
|
299
|
+
@param fromProgress {Number} a progress value from 0 to 1
|
300
|
+
@param toProgress {Number} a progress value from 0 to 1
|
301
|
+
@returns {void}
|
302
|
+
*/
|
303
|
+
seekFromTo: function(fromProgress, toProgress) {
|
304
|
+
// get the current progress.
|
305
|
+
var timecode = this.get('currentTimecode') ;
|
306
|
+
var cur = this.get('progress') ;
|
307
|
+
var duration = this.get('duration') ;
|
308
|
+
|
309
|
+
this.beginPropertyChanges() ;
|
310
|
+
|
311
|
+
var diff = fromProgress - cur ;
|
312
|
+
diff *= duration ;
|
313
|
+
if (diff !== 0) this.set('currentTimecode', timecode + diff) ;
|
314
|
+
|
315
|
+
diff = toProgress - cur ;
|
316
|
+
diff *= duration ;
|
317
|
+
if (diff !== 0) this.set('targetTimecode', timecode + diff) ;
|
318
|
+
|
319
|
+
this.endPropertyChanges() ;
|
320
|
+
},
|
321
|
+
|
322
|
+
/**
|
323
|
+
Changes the targetTimecode to invert the direction of the animation.
|
324
|
+
If the progress value is currently headed towards 1.0, it will be instead
|
325
|
+
headed to 0.
|
326
|
+
|
327
|
+
@returns {Number} the new progress
|
328
|
+
*/
|
329
|
+
toggle: function() {
|
330
|
+
throw "toggle not yet implemented" ;
|
331
|
+
},
|
332
|
+
|
333
|
+
/**
|
334
|
+
The core action executed by the timer.
|
335
|
+
*/
|
336
|
+
performAction: function() {
|
337
|
+
|
338
|
+
// if timecodes match, then we suspend the animation and return, there
|
339
|
+
// is nothing more to do.
|
340
|
+
var cur = this.get('currentTimecode') ;
|
341
|
+
var target = this.get('targetTimecode') ;
|
342
|
+
if (cur == target) {
|
343
|
+
this.set('isPaused', YES) ;
|
344
|
+
return ;
|
345
|
+
}
|
346
|
+
|
347
|
+
// determine the amount of time that has elapsed since the last time
|
348
|
+
// we were called.
|
349
|
+
var curTime = SC.runLoop.get('startTime') ;
|
350
|
+
var lapsed = (curTime - this._lastActionTime) * this.get('speed') ;
|
351
|
+
this._lastActionTime = curTime ;
|
352
|
+
|
353
|
+
// update the current timecode. Moving in the direction of the target
|
354
|
+
// timecode. If timecodes match, there is nothing to do.
|
355
|
+
if (target > cur) {
|
356
|
+
cur += lapsed ;
|
357
|
+
if (cur > target) cur = target ;
|
358
|
+
} else {
|
359
|
+
cur -= lapsed ;
|
360
|
+
if (cur < target) cur = target ;
|
361
|
+
}
|
362
|
+
|
363
|
+
// now set the new timecode, this should trigger other observers to
|
364
|
+
// update.
|
365
|
+
this.set('currentTimecode', cur) ;
|
366
|
+
},
|
367
|
+
|
368
|
+
// ......................................
|
369
|
+
// INTERNAL METHODS
|
370
|
+
//
|
371
|
+
|
372
|
+
/** @private
|
373
|
+
Observes changes to repeatCount; updates the targetTimecode.
|
374
|
+
*/
|
375
|
+
_repeatCountObserver: function() {
|
376
|
+
var repeatCount = this.get('repeatCount') ;
|
377
|
+
var target ;
|
378
|
+
if (repeatCount < 0) {
|
379
|
+
target = Date.now() * 2 ;
|
380
|
+
} else if (repeatCount > 0) {
|
381
|
+
target = this.get('duration') * repeatCount ;
|
382
|
+
} else return ; // nothing to do.
|
383
|
+
this.set('targetTimecode', target) ;
|
384
|
+
}.observes('repeatCount'),
|
385
|
+
|
386
|
+
/** @private
|
387
|
+
Observes changes to the repeatDuration; updates the targetTimecode.
|
388
|
+
*/
|
389
|
+
_repeatDurationObserver: function() {
|
390
|
+
var dur = this.get('repeatDuration') ;
|
391
|
+
if (dur < 0) {
|
392
|
+
dur = Date.now() * 2 ;
|
393
|
+
} else if (dur == 0) return; // nothing to do
|
394
|
+
this.set('targetTimecode', dur) ;
|
395
|
+
}.observes('repeatDuration'),
|
396
|
+
|
397
|
+
init: function() {
|
398
|
+
arguments.callee.base.call(this) ;
|
399
|
+
|
400
|
+
this.targetTimecode = this.get('duration') ;
|
401
|
+
this._repeatDurationObserver() ;
|
402
|
+
this._repeatCountObserver() ;
|
403
|
+
},
|
404
|
+
|
405
|
+
repeats: YES, // for timer
|
406
|
+
|
407
|
+
_logValueObserver: function() {
|
408
|
+
console.log('value did change to: %@'.fmt(this.get('value')));
|
409
|
+
}.observes('value')
|
410
|
+
|
411
|
+
});
|