diff options
author | Jon Bergli Heier <snakebite@jvnv.net> | 2011-08-23 19:03:14 +0200 |
---|---|---|
committer | Jon Bergli Heier <snakebite@jvnv.net> | 2011-08-23 19:03:14 +0200 |
commit | 8f1b87a29af1526c6adbb16694dbb52aa8cce26e (patch) | |
tree | 92d84498ca9160c38d3518188283cb9d846827d4 /static/player.js | |
parent | 914761368f6a5f19df26019e8290b4e86fb76cfb (diff) |
Added search box.
Diffstat (limited to 'static/player.js')
-rw-r--r-- | static/player.js | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/static/player.js b/static/player.js index 3f98dce..b120fe1 100644 --- a/static/player.js +++ b/static/player.js @@ -145,6 +145,35 @@ function list(root) { xmlhttp.send(); } +function do_search(e) { + if(e.keyCode != 13) + return; + + var xmlhttp = new XMLHttpRequest(); + xmlhttp.onreadystatechange = function() { + if(xmlhttp.readyState == 4) { + var json = JSON.parse(xmlhttp.responseText); + document.getElementById('song-links').innerHTML = ''; + output_link(new MusicListing('dir', '/', 'Go to root directory')); + for(var i = 0; i < json.length; i++) { + var type = json[i]["type"]; + var path = json[i]["name"]; + var track = json[i]["track"]; + var name = path.substring(path.lastIndexOf('/')+1); + var cached = type == "file" ? json[i]["cached"] : false; + var metadata = json[i]["metadata"]; + var l = new MusicListing(type, path, name, track, metadata, cached); + output_link(l); + } + } + } + + var query = document.getElementById('search-query').value; + var path = '/search?query=' + encodeURIComponent(query); + xmlhttp.open('GET', path); + xmlhttp.send(); +} + function add_directory() { var songs = document.getElementById('song-links').getElementsByTagName('a'); for(var i = 0; i < songs.length; i++) { |