diff --git a/js/main.js b/js/main.js index 0f1ff00..4d58a58 100644 --- a/js/main.js +++ b/js/main.js @@ -13,16 +13,10 @@ var MODULE = (function (radio) { if ( ( $(window).scrollTop() + $(window).height() ) == $(document).height() ) { if(!station_list.data("didfire")) { station_list.data("didfire", true); - if ($('li.nav-files').hasClass('active')){ - radio.radio_query(1, ""); - } else if ($('li.nav-recent').hasClass('active')) { - radio.radio_query(2, ""); - } else if ($('li.nav-favorites').hasClass('active')) { - console.log("todo"); - } else { - var query = $('#searchbox').val(); - radio.radio_query(0, query); - }; + + var hashurl = window.location.hash; + radio.radio_query(hashurl); + var ref = station_list; setTimeout(function(){ ref.data("didfire", false); @@ -112,14 +106,22 @@ var MODULE = (function (radio) { }; $.each(data, function(i, station) { - var isstarred = false; - for (var fav_station in fav_stations) { - if (fav_stations[fav_station]["stationid"] == station['id']) { - isstarred = true; - break; - } - }; - radio.render_entry("station", isstarred, '#station/'+station['id'], station['favicon'], station['name']); + if (typeof station['id'] == "undefined") { + var entry_type = "folder"; + var isstarred = false; + var hashurl = window.location.hash + "/" + station['name']; + } else { + var entry_type = "station"; + var isstarred = false; + for (var fav_station in fav_stations) { + if (fav_stations[fav_station]["stationid"] == station['id']) { + isstarred = true; + break; + } + }; + var hashurl = '#station/'+station['id']; + } + radio.render_entry(entry_type, isstarred, hashurl, station['favicon'], station['name']); }); }); @@ -178,7 +180,6 @@ var MODULE = (function (radio) { }; radio.radio_query = function(hashurl){ - console.log(hashurl); var offset = $('tbody > tr').length; var query = ""; var api_baseurl = "https://www.radio-browser.info/webservice/json/"; @@ -189,24 +190,32 @@ var MODULE = (function (radio) { case "#recent": var query_url = "stations/lastchange"; break; - case "#categories/countries": - var query_url = "countries"; - break; - case "#categories/states": - var query_url = "states"; - break; - case "#categories/languages": - var query_url = "languages"; - break; - case "#categories/tags": - var query_url = "tags"; + case (hashurl.match(/^#categories/) || {}).input: + var query_url = hashurl.substring(12); + if (query_url.split("/").length == 2) { + var subcategory = query_url.split("/")[1]; + switch (query_url.split("/")[0]) { + case "countries": + var query_url = "stations/bycountryexact/"+subcategory; + break; + case "states": + var query_url = "stations/bystateexact/"+subcategory; + break; + case "languages": + var query_url = "stations/bylanguageexact/"+subcategory; + break; + case "tags": + var query_url = "stations/bytagsexact/"+subcategory; + break; + } + } break; case (hashurl.match(/^#search/) || {}).input: var query_url = "stations/search"; var query = hashurl.substring(8); break; }; - console.log(api_baseurl + query_url, query); + console.log(query_url); $.ajax({ method: "POST", url: api_baseurl + query_url, @@ -218,7 +227,9 @@ var MODULE = (function (radio) { }, dataType: 'json', }).success( function(data){ - radio.parse_results(data); + if (data.length) { + radio.parse_results(data); + } }); }; @@ -226,9 +237,11 @@ var MODULE = (function (radio) { new OCA.Search(function (query) { $('#app-navigation').find('li').removeClass("active"); $("tbody > tr").remove(); - radio.radio_query("#search/"+query); + var hashurl = "#search/"+query; + history.pushState("", "", hashurl); + radio.radio_query(hashurl); }, function (arg) { - radio.switch_menu(0); + console.log("quit search dialog"); }); radio.render_entry = function(entry_type, starred, hashurl, iconurl, title){ diff --git a/js/navigation.js b/js/navigation.js index 575c30d..fa10f87 100644 --- a/js/navigation.js +++ b/js/navigation.js @@ -87,6 +87,9 @@ var MODULE = (function (radio) { $('li.nav-categories').addClass('active'); radio.radio_query(hashurl); break; + case (hashurl.match(/^#search/) || {}).input: + radio.radio_query(hashurl); + break; } }, 500); }; @@ -99,5 +102,11 @@ var MODULE = (function (radio) { radio.action_load_menu_state(); }; + window.addEventListener('hashchange', function(event) { + var hashurl = "#" + event.newURL.split("#")[1]; + console.log(hashurl); + radio.action_navigate(hashurl); + }, false); + return radio; }(MODULE || {}));