From 17c5d44cf42f6c99786efbc45b788d910fb4c4be Mon Sep 17 00:00:00 2001 From: Matt Haley Date: Tue, 11 Jun 2013 22:54:32 -0600 Subject: [PATCH] Load selected feed after a short timeout Avoid firing multiple server requests if the user quickly clicks another feed or is navigating up/down the tree list with the keyboard. --- js/feedlist.js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/js/feedlist.js b/js/feedlist.js index 84b56122..d3418176 100644 --- a/js/feedlist.js +++ b/js/feedlist.js @@ -2,6 +2,7 @@ var _infscroll_disable = 0; var _infscroll_request_sent = 0; var _search_query = false; var _viewfeed_last = 0; +var _viewfeed_timeout = false; var counters_last_request = 0; @@ -132,15 +133,21 @@ function viewfeed(feed, method, is_cat, offset, background, infscroll_req) { console.log(query); + if (_viewfeed_timeout) { + setFeedExpandoIcon(getActiveFeedId(), activeFeedIsCat(), 'images/blank_icon.gif'); + clearTimeout(_viewfeed_timeout); + } setActiveFeedId(feed, is_cat); + _viewfeed_timeout = setTimeout(function()) { new Ajax.Request("backend.php", { - parameters: query, - onComplete: function(transport) { - setFeedExpandoIcon(feed, is_cat, 'images/blank_icon.gif'); - headlines_callback2(transport, offset, background, infscroll_req); - PluginHost.run(PluginHost.HOOK_FEED_LOADED, [feed, is_cat]); - } }); + parameters: query, + onComplete: function(transport) { + setFeedExpandoIcon(feed, is_cat, 'images/blank_icon.gif'); + headlines_callback2(transport, offset, background, infscroll_req); + PluginHost.run(PluginHost.HOOK_FEED_LOADED, [feed, is_cat]); + } }); + }, 250); // 250ms delay } catch (e) { exception_error("viewfeed", e);