var MODULE = (function (radio) { /* Click on menus */ $('#app-navigation ul a').click(function(e) { e.preventDefault(); radio.action_navigate($(this).attr('href')); }); /* Click on a radio station (table entry) and play it */ $('body').on('click', '.filename', function(e) { e.preventDefault(); var entry_src = $(this).parent().attr('data-src'); if (entry_src.substring(0,9) == "#station/") { var stationid = entry_src.substring(9); var stationname = $(this).parent().find('.nametext').text(); radio.action_play(stationid, stationname); } else { radio.action_navigate(entry_src); } }); /* Save station to favorites */ $('body').on('click', '.favorite', function(e) { e.preventDefault(); var entry_src = $(this).parent().parent().attr('data-src'); var stationid = entry_src.substring(9); radio.action_favorite(stationid); }); radio.action_load_menu_state = function() { var baseUrl = OC.generateUrl('/apps/radio/getMenuState'); $.get(baseUrl, function ( data ) { if ("menu_state" in data) { var hashurl = data["menu_state"]; } radio.action_navigate(hashurl); return true; }); } radio.action_save_menu_state = function(hashurl) { var baseUrl = OC.generateUrl('/apps/radio/saveMenuState'); var settings = { "menu_state": hashurl }; $.ajax({ url: baseUrl, method: 'POST', contentType: 'application/json', data: JSON.stringify(settings) }).done(function(data){ return true; }); } radio.action_navigate = function(hashurl) { $('#filestable').hide(); $('#emptycontent').addClass('hidden'); $('.nofilterresults').addClass('hidden'); $('.loading').removeClass('hidden'); $('#app-navigation').find('li').removeClass("active"); $("tbody > tr").remove(); history.pushState("", "", hashurl); radio.action_save_menu_state(hashurl) clearTimeout(radio.searchTimeout); radio.searchTimeout = setTimeout(function(){ switch (hashurl) { case "#top": $('li.nav-files').addClass('active'); radio.radio_query(hashurl); break; case "#recent": $('li.nav-recent').addClass('active'); radio.radio_query(hashurl); break; case "#favorites": $('li.nav-favorites').addClass('active'); radio.action_load_favorites(); break; case "#categories": $('li.nav-categories').addClass('active'); radio.action_load_categories(); break; case (hashurl.match(/^#categories/) || {}).input: $('li.nav-categories').addClass('active'); radio.radio_query(hashurl); break; } }, 500); }; // On app start, load top list if(window.location.hash) { var hashurl = window.location.hash; radio.action_navigate(hashurl); } else { radio.action_load_menu_state(); }; return radio; }(MODULE || {}));