From fdd0317e1c4bc3f40cb6f30f74d5bffe9a172b91 Mon Sep 17 00:00:00 2001 From: Henrik Kjelsberg Date: Tue, 30 Jul 2013 13:13:29 +0200 Subject: [PATCH] Return to initial state when audio ends. Replaces the css-idents of the canvas upon end of audio and returns progress-indicator to position 0. --- component.json | 2 +- index.js | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/component.json b/component.json index 0410afc..729554e 100644 --- a/component.json +++ b/component.json @@ -2,7 +2,7 @@ "name": "audio", "repo": "component/audio", "description": "Sexy audio player (requires audio tag support)", - "version": "0.1.0", + "version": "0.1.1", "keywords": ["audio", "player", "music"], "dependencies": { "component/domify": "0.1.0", diff --git a/index.js b/index.js index a9192b1..4a22428 100644 --- a/index.js +++ b/index.js @@ -30,6 +30,7 @@ function Audio(el) { el.parentNode.insertBefore(this.el, this.audio); event.bind(this.el, 'click', this.toggle.bind(this)); event.bind(el, 'timeupdate', this.ontimeupdate.bind(this)); + event.bind(el, 'ended', this.onended.bind(this)); } /** @@ -44,6 +45,16 @@ Audio.prototype.ontimeupdate = function(){ this.progress.update(n); }; +/** + * Return to initial state when audio ends. + * + * @api private + */ +Audio.prototype.onended = function(){ + this.el.className = 'audio stopped'; + this.progress.update(0); +}; + /** * Toggle play state. * @@ -71,7 +82,7 @@ Audio.prototype.play = function(){ }; /** - * Start playing the audio. + * Pause playback of audio. * * @api public */