From aba69b26f66ee1483ceb73316d412ce1f87d1744 Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Wed, 10 Aug 2011 19:43:09 +0200 Subject: Implemented a client-side song queue. --- static/playlist.js | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 static/playlist.js (limited to 'static/playlist.js') diff --git a/static/playlist.js b/static/playlist.js new file mode 100644 index 0000000..5e41de5 --- /dev/null +++ b/static/playlist.js @@ -0,0 +1,53 @@ +function Playlist(pl, audio) { + this.pl = pl; + this.audio = audio; + this.current = null; + + this.get = function(path) { + var li = this.current; + while(li) { + var a = li.getElementsByTagName('a')[0]; + if(a.ml.path == path) + return li; + li = li.nextElementSibling; + } + return null; + } + + this.add = function(ml) { + var a = document.createElement('a'); + a.setAttribute('href', '#'); + a.appendChild(document.createTextNode(ml.path)); + a.ml = ml; + var li = document.createElement('li'); + var pl = this; + a.onclick = function() { + while(li.previousElementSibling) + li.previousElementSibling.parentElement.removeChild(li.previousElementSibling); + a.setAttribute('class', 'playing'); + pl.current = li; + ml.play(); + return false; + } + log(a.click); + + li.appendChild(a); + this.pl.appendChild(li); + } + + this.next = function() { + log('next'); + log('this: ' + this); + log('current: ' + this.current); + if(this.current) { + var old = this.current; + log('old: ' + old); + this.current = this.current.nextElementSibling; + old.parentElement.removeChild(old); + } + if(this.current) { + var a = this.current.getElementsByTagName('a')[0]; + a.onclick(); + } + } +} -- cgit v1.2.3