From d4394a532978e34176b886048b2f9f263b9fdcbb Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Tue, 23 Aug 2011 14:08:02 +0200 Subject: Improved client recode logic. --- static/playlist.js | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/static/playlist.js b/static/playlist.js index 44b72ae..e5513d1 100644 --- a/static/playlist.js +++ b/static/playlist.js @@ -47,9 +47,6 @@ function Playlist(pl, audio) { nextsong = nextsong.nextElementSibling; if(nextsong) { var nexta = nextsong.getElementsByTagName('a')[0]; - log('nexta: ' + nexta); - log(nexta.onclick); - log('next ml: ' + nexta.ml); nexta.ml.recode(); } @@ -79,12 +76,20 @@ function Playlist(pl, audio) { a_del.onclick = function() { log(li.previousElementSibling); log(li.nextElementSibling); + // remove previous element if it is an album header and we're at end of queue, + // or next element is an album header if(li.previousElementSibling && li.previousElementSibling.getAttribute('class') == 'album' && (!li.nextElementSibling || li.nextElementSibling.getAttribute('class') == 'album')) pl.pl.removeChild(li.previousElementSibling); pl.pl.removeChild(li); if(pl.pl.childElementCount == 0) pl.lastalbum = null; + + // recode next + var next = pl.get_next(); + if(next) + next.getElementsByTagName('a')[0].ml.recode(); + return false; } a_del.hidden = true; @@ -103,11 +108,28 @@ function Playlist(pl, audio) { li.appendChild(span); this.pl.appendChild(li); - if(this.pl.firstChild == li || (this.current && this.current.nextElementSibling == li) - || (this.pl.firstChild.getAttribute('class') == 'album' && this.pl.firstChild.nextElementSibling == li)) + if(this.get_next() == li) ml.recode(); } + // get the next queued song + this.get_next = function() { + var next = null; + if(this.current) + next = this.current.nextElementSibling; + else if(this.pl.firstChild) + next = this.pl.firstChild; + + if(!next) + return null; + + if(next.getAttribute('class') == 'album') + next = next.nextElementSibling; + + return next; + } + + // play the next queued song this.next = function() { log('next'); log('this: ' + this); -- cgit v1.2.3