Load selected feed after a short timeout
Avoid firing multiple server requests if the user is navigating up/down the tree list with the keyboard. Instead, wait till the user has stopped navigating for at least 250ms.
This commit is contained in:
parent
b684a2e665
commit
a95e14fb4c
|
@ -2,6 +2,7 @@ var _infscroll_disable = 0;
|
||||||
var _infscroll_request_sent = 0;
|
var _infscroll_request_sent = 0;
|
||||||
var _search_query = false;
|
var _search_query = false;
|
||||||
var _viewfeed_last = 0;
|
var _viewfeed_last = 0;
|
||||||
|
var _viewfeed_timeout = false;
|
||||||
|
|
||||||
var counters_last_request = 0;
|
var counters_last_request = 0;
|
||||||
|
|
||||||
|
@ -52,7 +53,7 @@ function loadMoreHeadlines() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function viewfeed(feed, method, is_cat, offset, background, infscroll_req) {
|
function viewfeed(feed, method, is_cat, offset, background, infscroll_req, can_wait) {
|
||||||
try {
|
try {
|
||||||
if (is_cat == undefined)
|
if (is_cat == undefined)
|
||||||
is_cat = false;
|
is_cat = false;
|
||||||
|
@ -132,15 +133,24 @@ function viewfeed(feed, method, is_cat, offset, background, infscroll_req) {
|
||||||
|
|
||||||
console.log(query);
|
console.log(query);
|
||||||
|
|
||||||
|
if (can_wait && _viewfeed_timeout) {
|
||||||
|
setFeedExpandoIcon(getActiveFeedId(), activeFeedIsCat(), 'images/blank_icon.gif');
|
||||||
|
clearTimeout(_viewfeed_timeout);
|
||||||
|
}
|
||||||
|
|
||||||
setActiveFeedId(feed, is_cat);
|
setActiveFeedId(feed, is_cat);
|
||||||
|
|
||||||
new Ajax.Request("backend.php", {
|
timeout_ms = can_wait ? 250 : 0;
|
||||||
parameters: query,
|
_viewfeed_timeout = setTimeout(function() {
|
||||||
onComplete: function(transport) {
|
|
||||||
setFeedExpandoIcon(feed, is_cat, 'images/blank_icon.gif');
|
new Ajax.Request("backend.php", {
|
||||||
headlines_callback2(transport, offset, background, infscroll_req);
|
parameters: query,
|
||||||
PluginHost.run(PluginHost.HOOK_FEED_LOADED, [feed, is_cat]);
|
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]);
|
||||||
|
} });
|
||||||
|
}, timeout_ms); // Wait 250ms
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
exception_error("viewfeed", e);
|
exception_error("viewfeed", e);
|
||||||
|
|
|
@ -272,13 +272,13 @@ function init() {
|
||||||
var rv = dijit.byId("feedTree").getNextFeed(
|
var rv = dijit.byId("feedTree").getNextFeed(
|
||||||
getActiveFeedId(), activeFeedIsCat());
|
getActiveFeedId(), activeFeedIsCat());
|
||||||
|
|
||||||
if (rv) viewfeed(rv[0], '', rv[1]);
|
if (rv) viewfeed(rv[0], '', rv[1], null, null, null, true);
|
||||||
};
|
};
|
||||||
hotkey_actions["prev_feed"] = function() {
|
hotkey_actions["prev_feed"] = function() {
|
||||||
var rv = dijit.byId("feedTree").getPreviousFeed(
|
var rv = dijit.byId("feedTree").getPreviousFeed(
|
||||||
getActiveFeedId(), activeFeedIsCat());
|
getActiveFeedId(), activeFeedIsCat());
|
||||||
|
|
||||||
if (rv) viewfeed(rv[0], '', rv[1]);
|
if (rv) viewfeed(rv[0], '', rv[1], null, null, null, true);
|
||||||
};
|
};
|
||||||
hotkey_actions["next_article"] = function() {
|
hotkey_actions["next_article"] = function() {
|
||||||
moveToPost('next');
|
moveToPost('next');
|
||||||
|
|
Loading…
Reference in New Issue