From 8f1b87a29af1526c6adbb16694dbb52aa8cce26e Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Tue, 23 Aug 2011 19:03:14 +0200 Subject: Added search box. --- static/icons/magnifier.png | Bin 0 -> 615 bytes static/index.html | 3 +++ static/player.js | 29 +++++++++++++++++++++++++++++ static/style.css | 1 + 4 files changed, 33 insertions(+) create mode 100644 static/icons/magnifier.png diff --git a/static/icons/magnifier.png b/static/icons/magnifier.png new file mode 100644 index 0000000..cf3d97f Binary files /dev/null and b/static/icons/magnifier.png differ diff --git a/static/index.html b/static/index.html index c1d75db..e2f2312 100644 --- a/static/index.html +++ b/static/index.html @@ -14,6 +14,9 @@ +
+ +
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++) { diff --git a/static/style.css b/static/style.css index 3213dec..1061c64 100644 --- a/static/style.css +++ b/static/style.css @@ -20,3 +20,4 @@ ul#playlist li.album { border-top: 1px solid; margin-bottom: .2em; color: #666; ul#playlist li.album span { margin-left: 1em; } .right { float: right; } ul#playlist li div:hover { background: #eee; } +input#search-query { padding-left: 16px; background-repeat: no-repeat; background-image: url('/static/icons/magnifier.png'); } -- cgit v1.2.3