From 165216bec230d979bb48666dd75d37fa4088ebbd Mon Sep 17 00:00:00 2001 From: Grant Shangreaux Date: Sun, 12 Jan 2020 23:41:00 -0600 Subject: Clean: add functions to TapeDeck object --- tape-deck.js | 50 +++++++++++++++++++------------------------------- 1 file changed, 19 insertions(+), 31 deletions(-) (limited to 'tape-deck.js') diff --git a/tape-deck.js b/tape-deck.js index 7362feb..14524de 100644 --- a/tape-deck.js +++ b/tape-deck.js @@ -13,11 +13,26 @@ let TapeDeck = { go: function () { this.elem.src = this.images.go; this.isPlaying = true; + this.playButton.toggle(); }, - stop: function () { + start: function () { + this.hasStarted = true; + this.playButton.initSound.onended = (event) => { Cassette.play(); }; + this.playButton.initSound.play(); + this.go(); + }, + pause: function () { + this.playButton.toggle(); + this.playButton.pressSound.play(); + Cassette.pause(); this.elem.src = this.images.stop; this.isPlaying = false; }, + resume: function () { + this.playButton.pressSound.play(); + this.go(); + Cassette.play(); + }, playButton: { elem: document.getElementById("play-button"), state: "off", @@ -37,38 +52,11 @@ let TapeDeck = { } }; -function start() { - const btn = TapeDeck.playButton; - - TapeDeck.hasStarted = true; - btn.toggle(); - btn.initSound.onended = (event) => { Cassette.play(); }; - btn.initSound.play(); -} - -function pause() { - const btn = TapeDeck.playButton; - - btn.toggle(); - btn.pressSound.play(); - Cassette.pause(); - TapeDeck.stop(); -} - -function resume() { - const btn = TapeDeck.playButton; - - btn.pressSound.play(); - btn.toggle(); - Cassette.play(); -} - // button onclick points here function play() { - if (TapeDeck.isPlaying) { pause(); return; } + if (TapeDeck.isPlaying) { TapeDeck.pause(); return; } - TapeDeck.hasStarted ? resume() : start(); - TapeDeck.go(); + TapeDeck.hasStarted ? TapeDeck.resume() : TapeDeck.start(); } function reset() { @@ -102,7 +90,7 @@ function formatTrackData(track) { } if (track.link) { - string = string.concat(` - ${track.link}`) + string = string.concat(` - ${track.link}`); } return string; -- cgit v1.2.3