2016-11-17 22:07:22 +00:00
|
|
|
$(window).on('load', function(){
|
|
|
|
|
|
|
|
$('body').on('click', 'tr', function() {
|
2017-01-08 08:36:13 +00:00
|
|
|
var stationid = $(this).attr('data-id');
|
|
|
|
play_station(stationid);
|
2016-11-17 22:07:22 +00:00
|
|
|
});
|
|
|
|
|
2017-01-08 08:36:13 +00:00
|
|
|
function play_station(stationid){
|
|
|
|
$.ajax({
|
|
|
|
method: "GET",
|
|
|
|
url: "http://www.radio-browser.info/webservice/v2/json/url/"+stationid,
|
|
|
|
dataType: 'json',
|
|
|
|
success: function(data){
|
|
|
|
var sourceUrl = data['url'];
|
|
|
|
$("#player").attr("src", sourceUrl);
|
|
|
|
$('#player').trigger('play');
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2017-01-06 09:52:12 +00:00
|
|
|
function render_result(data){
|
2016-11-17 22:07:22 +00:00
|
|
|
$.each(data, function(i, station) {
|
2017-01-06 08:59:20 +00:00
|
|
|
$('tbody').append('<tr data-src='+station['url']+' data-id='+station['id']+'>\
|
2017-01-04 17:54:04 +00:00
|
|
|
<td class="filename">\
|
|
|
|
<a href="#" class="action action-favorite" data-original-title="" title="">\
|
|
|
|
<span class="icon icon-star"></span>\
|
|
|
|
<span class="hidden-visually">Favorite</span>\
|
|
|
|
</a>\
|
|
|
|
<label for="select-files-3">\
|
|
|
|
<div class="thumbnail" style="background-image:url('+station['favicon']+'); background-size: 32px;"></div>\
|
|
|
|
</label>\
|
|
|
|
<a class="name" href="#">\
|
|
|
|
<span class="nametext"><span class="innernametext">'+station['name']+'</span></span>\
|
|
|
|
</a>\
|
|
|
|
</td>\
|
2016-11-18 21:45:53 +00:00
|
|
|
</tr>');
|
2016-11-17 22:07:22 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-01-08 08:36:13 +00:00
|
|
|
function get_station_ids(){
|
|
|
|
return ["89920","44707"]
|
|
|
|
};
|
|
|
|
|
|
|
|
function render_stations(station_ids){
|
|
|
|
for (stationid in station_ids){
|
|
|
|
$.ajax({
|
|
|
|
method: "GET",
|
|
|
|
url: "https://www.radio-browser.info/webservice/json/stations/byid/"+station_ids[stationid],
|
|
|
|
dataType: 'json',
|
|
|
|
success: render_result
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2017-01-06 09:52:12 +00:00
|
|
|
function radio_query(type, query){
|
|
|
|
switch (type) {
|
|
|
|
case 0:
|
|
|
|
var url = "https://www.radio-browser.info/webservice/json/stations/search";
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
var url = "https://www.radio-browser.info/webservice/json/stations/topclick/20";
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
var url = "https://www.radio-browser.info/webservice/json/stations/lastchange/20";
|
|
|
|
break;
|
|
|
|
};
|
2016-11-17 22:07:22 +00:00
|
|
|
$.ajax({
|
|
|
|
method: "POST",
|
2017-01-06 09:52:12 +00:00
|
|
|
url: url,
|
2016-11-17 22:07:22 +00:00
|
|
|
data: {
|
|
|
|
name: query
|
|
|
|
},
|
|
|
|
dataType: 'json',
|
2017-01-06 09:52:12 +00:00
|
|
|
success: render_result
|
2016-11-17 22:07:22 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2017-01-06 09:52:12 +00:00
|
|
|
function switch_menu(type) {
|
2017-01-08 08:36:13 +00:00
|
|
|
$('#app-navigation').find('li').removeClass("active");
|
|
|
|
$("tbody > tr").remove();
|
2017-01-06 09:52:12 +00:00
|
|
|
switch (type) {
|
|
|
|
case 0:
|
|
|
|
$('li.nav-files').addClass('active');
|
|
|
|
radio_query(1);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
$('li.nav-recent').addClass('active');
|
|
|
|
radio_query(2);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
$('li.nav-favorite').addClass('active');
|
2017-01-08 08:36:13 +00:00
|
|
|
station_ids = get_station_ids()
|
|
|
|
render_stations(station_ids)
|
2017-01-06 09:52:12 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-18 21:45:53 +00:00
|
|
|
$('#radiosearch').submit(function() {
|
2017-01-08 08:36:13 +00:00
|
|
|
$("tbody > tr").remove();
|
2016-11-18 21:45:53 +00:00
|
|
|
var query = $('#radioquery').val();
|
2017-01-06 09:52:12 +00:00
|
|
|
radio_query(0, query);
|
|
|
|
});
|
|
|
|
|
|
|
|
$('a.nav-icon-files').click(function() {
|
|
|
|
switch_menu(0);
|
2016-11-17 22:07:22 +00:00
|
|
|
});
|
2017-01-06 09:52:12 +00:00
|
|
|
|
|
|
|
$('a.nav-icon-recent').click(function() {
|
|
|
|
switch_menu(1);
|
|
|
|
});
|
|
|
|
|
2017-01-08 08:36:13 +00:00
|
|
|
$('a.nav-icon-favorites').click(function() {
|
|
|
|
switch_menu(2);
|
|
|
|
});
|
|
|
|
|
2017-01-06 09:52:12 +00:00
|
|
|
switch_menu(0);
|
2016-11-17 22:07:22 +00:00
|
|
|
});
|