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 | |
parent | 914761368f6a5f19df26019e8290b4e86fb76cfb (diff) |
Added search box.
Diffstat (limited to 'static')
-rw-r--r-- | static/icons/magnifier.png | bin | 0 -> 615 bytes | |||
-rw-r--r-- | static/index.html | 3 | ||||
-rw-r--r-- | static/player.js | 29 | ||||
-rw-r--r-- | static/style.css | 1 |
4 files changed, 33 insertions, 0 deletions
diff --git a/static/icons/magnifier.png b/static/icons/magnifier.png Binary files differnew file mode 100644 index 0000000..cf3d97f --- /dev/null +++ b/static/icons/magnifier.png 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 @@ <input type="button" value="Open event source" onclick="event_open()" /> <input type="button" value="Refresh directory" onclick="list(document.getElementById('current-dir').innerHTML.split(': ', 2)[1])" /> </div> + <div id="search-div"> + <input type="text" id="search-query" onkeypress="do_search(event)" /> + </div> <div id="current-dir"></div> <div id="hpanel"> <span "browser-span"> 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'); } |