headlines_callback: async

This commit is contained in:
Andrew Dolgov 2007-08-24 05:59:12 +01:00
parent 0df398da2c
commit a49f5e055e
2 changed files with 94 additions and 91 deletions

View File

@ -1,6 +1,6 @@
//var xmlhttp = Ajax.getTransport(); //var xmlhttp = Ajax.getTransport();
var feed_cur_page = 0; var _feed_cur_page = 0;
function viewCategory(cat) { function viewCategory(cat) {
active_feed_is_cat = true; active_feed_is_cat = true;
@ -50,10 +50,10 @@ function viewNextFeedPage() {
try { try {
if (!getActiveFeedId()) return; if (!getActiveFeedId()) return;
feed_cur_page++; _feed_cur_page++;
viewfeed(getActiveFeedId(), undefined, undefined, undefined, viewfeed(getActiveFeedId(), undefined, undefined, undefined,
undefined, feed_cur_page); undefined, _feed_cur_page);
} catch (e) { } catch (e) {
exception_error(e, "viewFeedGoPage"); exception_error(e, "viewFeedGoPage");
@ -71,11 +71,11 @@ function viewfeed(feed, subop, is_cat, subop_param, skip_history, offset) {
page_offset = offset; page_offset = offset;
} else { } else {
page_offset = 0; page_offset = 0;
feed_cur_page = 0; _feed_cur_page = 0;
} }
if (getActiveFeedId() != feed) { if (getActiveFeedId() != feed) {
feed_cur_page = 0; _feed_cur_page = 0;
active_post_id = 0; active_post_id = 0;
} }
@ -178,13 +178,18 @@ function viewfeed(feed, subop, is_cat, subop_param, skip_history, offset) {
// xmlhttp.abort(); // xmlhttp.abort();
if (xmlhttp_ready(xmlhttp)) { /* if (xmlhttp_ready(xmlhttp)) {
xmlhttp.open("GET", query, true); xmlhttp.open("GET", query, true);
xmlhttp.onreadystatechange=headlines_callback; xmlhttp.onreadystatechange=headlines_callback;
xmlhttp.send(null); xmlhttp.send(null);
} else { } else {
debug("xmlhttp busy (@feeds)"); debug("xmlhttp busy (@feeds)");
} } */
new Ajax.Request(query, {
onComplete: function(transport) {
headlines_callback2(transport, feed, is_cat, _feed_cur_page);
} });
} catch (e) { } catch (e) {
exception_error("viewfeed", e); exception_error("viewfeed", e);

View File

@ -45,104 +45,102 @@ function catchup_callback2(transport, callback) {
} }
} }
function headlines_callback() { function headlines_callback2(transport, active_feed_id, active_feed_is_cat, feed_cur_page) {
if (xmlhttp.readyState == 4) { debug("headlines_callback2");
debug("headlines_callback"); var f = document.getElementById("headlines-frame");
var f = document.getElementById("headlines-frame"); try {
try { if (feed_cur_page == 0) {
if (feed_cur_page == 0) { debug("resetting headlines scrollTop");
debug("resetting headlines scrollTop"); f.scrollTop = 0;
f.scrollTop = 0; }
} } catch (e) { };
} catch (e) { };
if (xmlhttp.responseXML) { if (transport.responseXML) {
var headlines = xmlhttp.responseXML.getElementsByTagName("headlines")[0]; var headlines = transport.responseXML.getElementsByTagName("headlines")[0];
var counters = xmlhttp.responseXML.getElementsByTagName("counters")[0]; var counters = transport.responseXML.getElementsByTagName("counters")[0];
var articles = xmlhttp.responseXML.getElementsByTagName("article"); var articles = transport.responseXML.getElementsByTagName("article");
var runtime_info = xmlhttp.responseXML.getElementsByTagName("runtime-info"); var runtime_info = transport.responseXML.getElementsByTagName("runtime-info");
if (feed_cur_page == 0) { if (feed_cur_page == 0) {
if (headlines) { if (headlines) {
f.innerHTML = headlines.firstChild.nodeValue; f.innerHTML = headlines.firstChild.nodeValue;
} else {
debug("headlines_callback: returned no data");
f.innerHTML = "<div class='whiteBox'>" + __('Could not update headlines (missing XML data)') + "</div>";
}
} else { } else {
if (headlines) { debug("headlines_callback: returned no data");
debug("adding some more headlines..."); f.innerHTML = "<div class='whiteBox'>" + __('Could not update headlines (missing XML data)') + "</div>";
var c = document.getElementById("headlinesList");
if (!c) {
c = document.getElementById("headlinesInnerContainer");
}
c.innerHTML = c.innerHTML + headlines.firstChild.nodeValue;
} else {
debug("headlines_callback: returned no data");
notify_error("Error while trying to load more headlines");
}
} }
if (articles) {
for (var i = 0; i < articles.length; i++) {
var a_id = articles[i].getAttribute("id");
debug("found id: " + a_id);
cache_inject(a_id, articles[i].firstChild.nodeValue);
}
} else {
debug("no cached articles received");
}
if (counters) {
debug("parsing piggybacked counters: " + counters);
parse_counters(counters, false);
} else {
debug("counters container not found in reply");
}
if (runtime_info) {
debug("parsing runtime info: " + runtime_info[0]);
parse_runtime_info(runtime_info[0]);
} else {
debug("counters container not found in reply");
}
} else { } else {
debug("headlines_callback: returned no XML object"); if (headlines) {
f.innerHTML = "<div class='whiteBox'>" + __('Could not update headlines (missing XML object)') + "</div>"; debug("adding some more headlines...");
var c = document.getElementById("headlinesList");
if (!c) {
c = document.getElementById("headlinesInnerContainer");
}
c.innerHTML = c.innerHTML + headlines.firstChild.nodeValue;
} else {
debug("headlines_callback: returned no data");
notify_error("Error while trying to load more headlines");
}
} }
if (typeof correctPNG != 'undefined') { if (articles) {
correctPNG(); for (var i = 0; i < articles.length; i++) {
} var a_id = articles[i].getAttribute("id");
debug("found id: " + a_id);
if (_cdm_wd_timeout) window.clearTimeout(_cdm_wd_timeout); cache_inject(a_id, articles[i].firstChild.nodeValue);
}
if (!document.getElementById("headlinesList") &&
getInitParam("cdm_auto_catchup") == 1) {
debug("starting CDM watchdog");
_cdm_wd_timeout = window.setTimeout("cdmWatchdog()", 5000);
_cdm_wd_vishist = new Array();
} else { } else {
debug("not in CDM mode or watchdog disabled"); debug("no cached articles received");
} }
if (_tag_cdm_scroll) { if (counters) {
try { debug("parsing piggybacked counters: " + counters);
document.getElementById("headlinesInnerContainer").scrollTop = _tag_cdm_scroll; parse_counters(counters, false);
_tag_cdm_scroll = false; } else {
debug("resetting headlinesInner scrollTop"); debug("counters container not found in reply");
} catch (e) { }
} }
notify(""); if (runtime_info) {
debug("parsing runtime info: " + runtime_info[0]);
parse_runtime_info(runtime_info[0]);
} else {
debug("counters container not found in reply");
}
} else {
debug("headlines_callback: returned no XML object");
f.innerHTML = "<div class='whiteBox'>" + __('Could not update headlines (missing XML object)') + "</div>";
} }
if (typeof correctPNG != 'undefined') {
correctPNG();
}
if (_cdm_wd_timeout) window.clearTimeout(_cdm_wd_timeout);
if (!document.getElementById("headlinesList") &&
getInitParam("cdm_auto_catchup") == 1) {
debug("starting CDM watchdog");
_cdm_wd_timeout = window.setTimeout("cdmWatchdog()", 5000);
_cdm_wd_vishist = new Array();
} else {
debug("not in CDM mode or watchdog disabled");
}
if (_tag_cdm_scroll) {
try {
document.getElementById("headlinesInnerContainer").scrollTop = _tag_cdm_scroll;
_tag_cdm_scroll = false;
debug("resetting headlinesInner scrollTop");
} catch (e) { }
}
notify("");
} }
function render_article(article) { function render_article(article) {