summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGrant Shangreaux <shshoshin@protonmail.com>2020-01-12 23:41:00 -0600
committerGrant Shangreaux <shshoshin@protonmail.com>2020-01-12 23:41:00 -0600
commit165216bec230d979bb48666dd75d37fa4088ebbd (patch)
treedf15e25ed581327a1477629161e76bb2eeea5583
parenta9a1509405804be9f329a4168515a607b1bbea1e (diff)
Clean: add functions to TapeDeck object
-rw-r--r--tape-deck.js50
1 files changed, 19 insertions, 31 deletions
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;