From a3e86f3be768c8fa1fc2af12d5e5d66d9d9b82e8 Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Tue, 16 Aug 2011 14:49:40 +0200 Subject: Implemented basic cuesheet support, some playlist fixes. --- static/playlist.js | 52 ++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 46 insertions(+), 6 deletions(-) (limited to 'static/playlist.js') diff --git a/static/playlist.js b/static/playlist.js index 38db463..d2ac424 100644 --- a/static/playlist.js +++ b/static/playlist.js @@ -3,12 +3,15 @@ function Playlist(pl, audio) { this.audio = audio; this.current = null; - this.get = function(path) { + this.get = function(path, track) { var li = this.pl.getElementsByTagName('li')[0]; while(li) { - var a = li.getElementsByTagName('a')[0]; - if(a.ml.path == path) - return li; + var as = li.getElementsByTagName('a'); + if(as.length > 0) { + var a = as[0]; + if(a.ml.path == path && (!track || a.ml.track == track)) + return li; + } li = li.nextElementSibling; } return null; @@ -17,7 +20,10 @@ function Playlist(pl, audio) { this.add = function(ml) { var a = document.createElement('a'); a.setAttribute('href', '#'); - a.appendChild(document.createTextNode(ml.path)); + var name = ml.name; + if(ml.track) + name += ' (track ' + ml.track + ')'; + a.appendChild(document.createTextNode(name)); a.ml = ml; var li = document.createElement('li'); var pl = this; @@ -30,9 +36,13 @@ function Playlist(pl, audio) { var nextsong = li.nextElementSibling; log('nextsong: ' + nextsong); + // avoid breaking when a track has been removed + while(nextsong && nextsong.childElementCount == 0) + 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(); } @@ -41,7 +51,34 @@ function Playlist(pl, audio) { } log(a.click); - li.appendChild(a); + var span = document.createElement('div'); + + // anchor to remove track from playlist + var a_del = document.createElement('a'); + a_del.setAttribute('class', 'delete'); + a_del.setAttribute('href', '#'); + a_del.setAttribute('title', 'Remove'); + var del_img = new Image(); + del_img.src = '/static/icons/delete.png'; + a_del.appendChild(del_img); + a_del.onclick = function() { + li.removeChild(span); + return false; + } + a_del.hidden = true; + + span.onmouseover = function() { + a_del.hidden = false; + } + span.onmouseout = function() { + a_del.hidden = true; + } + + span.appendChild(a); + span.appendChild(document.createTextNode(' ')); + span.appendChild(a_del); + + li.appendChild(span); this.pl.appendChild(li); if(this.pl.firstChild == li || (this.current && this.current.nextElementSibling == li)) @@ -58,6 +95,9 @@ function Playlist(pl, audio) { this.current = this.current.nextElementSibling; old.parentElement.removeChild(old); } + // avoid breaking when a track has been removed + while(this.current && this.current.childElementCount == 0) + this.current = this.current.nextElementSibling; if(this.current) { var a = this.current.getElementsByTagName('a')[0]; a.onclick(); -- cgit v1.2.3