function Playlist(pl, audio) { this.pl = pl; this.audio = audio; this.current = null; this.get = function(path, track) { var li = this.pl.getElementsByTagName('li')[0]; while(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; } this.add = function(ml) { var a = document.createElement('a'); a.setAttribute('href', '#'); var name = ml.get_text(); a.appendChild(document.createTextNode(name)); 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(); 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(); } return false; } log(a.click); 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)) ml.recode(); } 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); } // 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(); } } }