Skip to content
This repository was archived by the owner on Mar 13, 2018. It is now read-only.

Commit b88dc31

Browse files
author
Yvonne Yip
committed
polymer-animation: refactor some event stuff
1 parent 6f743ed commit b88dc31

1 file changed

Lines changed: 20 additions & 10 deletions

File tree

polymer-animation/polymer-animation.html

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,12 @@
4646
* @class polymer-animation
4747
*/
4848
/**
49-
* Fired when an animation completes
50-
* @event complete
49+
* Fired when the animation starts
50+
* @event animation-start
51+
*
52+
* Fired when the animation completes
53+
* @event animation-end
54+
*
5155
*/
5256
Polymer('polymer-animation', {
5357
publish: {
@@ -145,12 +149,8 @@
145149
//this.animation && console.log('play', this.animation);
146150
if (this.animation) {
147151
this.cancel();
148-
if (!this.animation.onend) {
149-
this.animation.onend = this.complete.bind(this);
150-
}
152+
this.bindAnimationEvents();
151153
this.player = document.timeline.play(this.animation);
152-
this.player.paused = false;
153-
this.player.currentTime = 0;
154154
}
155155
});
156156
},
@@ -262,9 +262,19 @@
262262
}
263263
return new KeyframeAnimationEffect(frames, this.composite);
264264
},
265-
// intended for user implementation
266-
complete: function() {
267-
this.fire('complete');
265+
bindAnimationEvents: function() {
266+
if (!this.animation.onstart) {
267+
this.animation.onstart = this.animationStartHandler.bind(this);
268+
}
269+
if (!this.animation.onend) {
270+
this.animation.onend = this.animationEndHandler.bind(this);
271+
}
272+
},
273+
animationStartHandler: function() {
274+
this.fire('animation-start');
275+
},
276+
animationEndHandler: function() {
277+
this.fire('animation-end');
268278
}
269279
});
270280
})();

0 commit comments

Comments
 (0)