Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(542)

Side by Side Diff: polymer_0.5.0/bower_components/web-animations-js/src/effect-callback.js

Issue 786953007: npm_modules: Fork bower_components into Polymer 0.4.0 and 0.5.0 versions (Closed) Base URL: https://chromium.googlesource.com/infra/third_party/npm_modules.git@master
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2014 Google Inc. All rights reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 (function(shared, scope, testing) {
15
16 var nullTarget = document.createElement('div');
17
18 var sequenceNumber = 0;
19 scope.bindPlayerForCustomEffect = function(player) {
20 var target = player.source.target;
21 var effect = player.source.effect;
22 var timing = player.source.timing;
23 var last = undefined;
24 timing = shared.normalizeTimingInput(timing);
25 var callback = function() {
26 var t = callback._player ? callback._player.currentTime : null;
27 if (t !== null) {
28 t = shared.calculateTimeFraction(shared.calculateActiveDuration(timing), t, timing);
29 if (isNaN(t))
30 t = null;
31 }
32 // FIXME: There are actually more conditions under which the effect
33 // should be called.
34 if (t !== last)
35 effect(t, target, player.source);
36 last = t;
37 };
38
39 callback._player = player;
40 callback._registered = false;
41 callback._sequenceNumber = sequenceNumber++;
42 player._callback = callback;
43 register(callback);
44 };
45
46 var callbacks = [];
47 var ticking = false;
48 function register(callback) {
49 if (callback._registered)
50 return;
51 callback._registered = true;
52 callbacks.push(callback);
53 if (!ticking) {
54 ticking = true;
55 requestAnimationFrame(tick);
56 }
57 }
58
59 function tick(t) {
60 var updating = callbacks;
61 callbacks = [];
62 updating.sort(function(left, right) {
63 return left._sequenceNumber - right._sequenceNumber;
64 });
65 updating.filter(function(callback) {
66 callback();
67 if (!callback._player || callback._player.finished || callback._player.pau sed)
68 callback._registered = false;
69 return callback._registered;
70 });
71 callbacks.push.apply(callbacks, updating);
72
73 if (callbacks.length) {
74 ticking = true;
75 requestAnimationFrame(tick);
76 } else {
77 ticking = false;
78 }
79 }
80
81 scope.Player.prototype._register = function() {
82 if (this._callback)
83 register(this._callback);
84 };
85
86 })(webAnimationsShared, webAnimationsMaxifill, webAnimationsTesting);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698