diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2018-05-12 00:20:50 +0200 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2018-05-12 00:20:50 +0200 |
| commit | 20b98e565e704ab27d8745a8dcc852b4ee3effc4 (patch) | |
| tree | fa600aa188f1ea8fdfe78fe6b1f81c378254a29d /public/assets/js/lib/views/details/audio.js | |
| parent | 798890c4e73981153e856668e0181ef384dea2a5 (diff) | |
slightly cleaner audio/files behavior
Diffstat (limited to 'public/assets/js/lib/views/details/audio.js')
| -rw-r--r-- | public/assets/js/lib/views/details/audio.js | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/public/assets/js/lib/views/details/audio.js b/public/assets/js/lib/views/details/audio.js index c993a5c..aee8964 100644 --- a/public/assets/js/lib/views/details/audio.js +++ b/public/assets/js/lib/views/details/audio.js @@ -5,6 +5,7 @@ var audio = (function(){ var links, comment, parent var selected = false var playing = false + var built = false audio.init = function () { comment = document.querySelector("#comment") @@ -12,6 +13,7 @@ var audio = (function(){ audio.index() audio.build() + el.src = music[0] } audio.index = function () { music = [] @@ -29,11 +31,12 @@ var audio = (function(){ } } audio.build = function () { + if (built) return + built = true el = audio.el = document.createElement("audio") el.setAttribute("controls", true) el.addEventListener("loadeddata", () => { if (selected) el.play() }) el.addEventListener("ended", audio.next) - el.src = music[0] parent.appendChild(el) document.body.addEventListener("keydown", audio.keydown) } @@ -42,6 +45,7 @@ var audio = (function(){ el = null parent.removeChild(el) document.body.removeEventListener("keydown", audio.keydown) + built = false } audio.play = function (index) { playing = true |
