Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
press enter from search to add all to playlist. implemented fisher-ya…
…tes shuffle and a clear button
  • Loading branch information
antimatter15 committed Mar 27, 2011
1 parent a72d8dd commit 44857b7
Showing 1 changed file with 47 additions and 5 deletions.
52 changes: 47 additions & 5 deletions player.html
Expand Up @@ -149,6 +149,21 @@
padding-left: 20px;
}

#listtools {
position: fixed;
bottom: 40px;
right: 5px;
color: #ddd;
}
#listtools a {
color: white;
text-decoration: none;
}

tr.hidden {
display:none;
}

</style>
<script src="id3v2.js"></script>
<script>
Expand Down Expand Up @@ -180,13 +195,13 @@
}

function runSearch(query){
//console.log(query);
console.log(query);
var regex = new RegExp(query.trim().replace(/\s+/g, '.*'), 'ig');
for(var i = $('songtable').getElementsByTagName('tr'), l = i.length; l--;){
if(regex.test(i[l].innerHTML)){
i[l].style.display = ''
i[l].className = 'visible'
}else{
i[l].style.display = 'none';
i[l].className = 'hidden';
}
}
}
Expand Down Expand Up @@ -248,6 +263,7 @@
pl.appendChild(st);
$("playtable").appendChild(pl);
pl.file = f;
pl.className = 'visible';
pl.onclick = function(e){
if(e && e.button == 1){
pl.parentNode.removeChild(pl);
Expand Down Expand Up @@ -301,6 +317,23 @@
}
}

function shuffle(){
var pt = document.getElementById('playtable');
//fisher yates shuffle. hopefully.
for(var i = document.querySelectorAll("#playtable tr"), l = i.length; l--;){
var j = Math.floor(Math.random() * l);
var jel = i[j], iel = i[l];
var jref = jel.nextSibling, iref = iel.nextSibling;
pt.insertBefore(jel, iref);
pt.insertBefore(iel, jref);
}
}

function empty(){
var pt = document.getElementById('playtable');
pt.innerHTML = '';
}

onload = function(){
//with no dependencies, it should be fine to use this instead of ondomcontentloaded
var a = document.createElement('audio');
Expand All @@ -318,6 +351,13 @@
$("support").innerHTML += "Your browser probably does not support Object URLs<br>";
}

document.querySelector('#search input').onkeydown = function(e){
if(e.keyCode == 13){
for(var i = document.querySelectorAll('#songtable tr.visible'), l = i.length; l--;){
i[l].onclick();
}
}
}
}
</script>
</head>
Expand Down Expand Up @@ -346,8 +386,10 @@
<div id="playlist">
<table id="playtable"></table>
</div>


<div id="listtools">
<a href="javascript:shuffle()">Shuffle</a> /
<a href="javascript:empty()">Clear</a>
</div>
<div id="songs">
<table id="songtable" cellspacing=0 cellpadding=0>
</table>
Expand Down

0 comments on commit 44857b7

Please sign in to comment.