Commit 15286b24 authored by Jonas Haraldsson's avatar Jonas Haraldsson

clickable tags for logged in users

clicking a tag tunes to station for that tag
parent 6f21da6d
......@@ -100,6 +100,11 @@ function playerReady() {
$("#player > #interface").show();
$("#tags").placeholdr({placeholderText: example_tags});
$("#volume-slider").slider({range: "min", min: 0, max: 100, value: 60, slide: setVolume});
$('#tracktags ul').on('click', 'li', function(event) {
var tagname = event.target.textContent;
var tagstation = 'librefm://globaltags/' + tagname;
tune(tagstation);
});
loadVolume();
player_ready = true;
}
......@@ -258,6 +263,8 @@ function nowPlaying() {
}
timestamp = Math.round(new Date().getTime() / 1000);
$.post(base_url + "/scrobble-proxy.php?method=nowplaying", { "a" : artist, "b" : album, "t" : track, "l" : audio.duration, "s" : session_key}, function(data) {}, "text");
getTopTrackTags(); //TODO move this to updateProgress
}
/**
......@@ -276,6 +283,31 @@ function tune(station) {
}, 'json');
}
/**
* Get top tags for current track
*
*/
function getTopTrackTags() {
$.get(base_url + '/2.0/', {'method' : 'track.gettoptags', 'artist' : artist, 'track' : track, 'sk' : ws_key, 'format' : 'json'}, function(data) {
// remove old tags
$('#tracktags ul li').remove();
if('toptags' in data) {
var tag_items = data.toptags.tag;
if ('name' in tag_items) {
// not an array
var tagname = tag_items.name;
$('#tracktags ul').append('<li>' + tagname + '</li>');
}else{
var i;
for(i in tag_items) {
var tagname = tag_items[i].name;
$('#tracktags ul').append('<li>' + tagname + '</li>');
}
}
}
}, 'json');
}
/**
* Loads a song and beings playing it.
*
......
......@@ -14,6 +14,16 @@
<div id="trackinfo">
<span id="artistname"></span> - <span id="trackname"></span> <span id="showplaylist"><a href="#" onclick="togglePlaylist(); return false;"><img src="{$img_url}/player/show-playlist.png" alt="{t}Show playlist{/t}" title="{t}Show playlist{/t}" /></a></span><span id="hideplaylist"><a href="#" onclick="togglePlaylist(); return false;"><img src="{$img_url}/player/hide-playlist.png" alt="{t}Hide playlist{/t}" title="{t}Hide playlist{/t}" /></a></span>
{if $logged_in}
<div id="tracktags">
<style>
#tracktags ul { display:inline; margin:0px;}
#tracktags li { background:#ccc; display:inline; border-radius:2px; padding:0px 2px; margin:0px 2px;}
</style>
<ul>
</ul>
</div>
{/if}
<div id="playlist">
<br />
<strong><u>{t}Playlist{/t}</u></strong>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment