var cgFeedSearchATO = null; var cgFeedSearchXHR = null; var cgFeedAppleSearchXHR = null; var cgLastSearchString = ""; $(document).ready(function () { $(document).on('click', 'div#divSearch a.backButton', function () { var backHash = $(this).data('backhash'); $('div#divSearch input.feedSearch').val(backHash); $('button.search').trigger('click'); return false; }); window.addEventListener("hashchange", function (e) { var backHash = $(this).data('backhash'); $('div#divSearch input.feedSearch').val(backHash); $('button.search').trigger('click'); }) //Focus the feed search box $('div#divSearch input.feedSearch').focus(); //Attach lookup handler to search box $(document).on('click', 'div#divSearch button.search', function () { var searchString = $('input.feedSearch').val(); if (searchString === cgLastSearchString) return false; //Don't search for nothing if (isEmpty(searchString)) return false; searchForFeeds(searchString); }); //Enter press on search box triggers search button $(document).on('keyup', 'div#divSearch input.feedSearch', function (event) { if (event.keyCode === 13) { event.preventDefault(); $('button.search').trigger('click'); } }); //Attach get podcast info handler to episode title link $(document).on('click', 'div#divSearch a.openPodcastInfo', function () { var feedId = $(this).data('id'); var feedUrl = $(this).data('url'); var feedTitle = $(this).text(); $('div#divMain span.feedDisplayTitle').text(feedTitle); getPodcastInfo(feedId, feedUrl); return false; }); //Add feed handler $(document).on('click', 'div#divMain a.addFeed', function () { //Add a feed to the index bootbox.prompt({ size: "large", title: "Add a podcast...", placeholder: "Podcast feed url", centerVertical: true, callback: function (result) { console.log(result); if (result !== null && result !== "") { if (result.indexOf('http') !== 0) { bootbox.alert("You must give the full feed address."); } else { console.log(result); sendApiRequest('/api/1.0/add/byfeedurl', {url: result}, function (data) { bootbox.alert(data.description); }); } } } }); return false; }); }); function searchForFeeds(searchString) { $('div#divMain span.feedDisplayTitle').empty(); //Send a search request sendApiRequest('/api/1.0/search/byterm', { q: searchString }, function (data) { $('div.searchResults a.backButton').data('backhash', searchString); $('div.searchResults a.backButton').addClass('d-none'); window.location.hash = 'sc-' + searchString; $('div.searchResults ul').empty(); data.feeds.forEach(function (item, index, value) { $('div.searchResults ul').append('' + '
' + item.description + '
' + '' + item.description + '
' + '' + '