From a49f5e055e0076e689924a992e87ad3503e67b3d Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Fri, 24 Aug 2007 05:59:12 +0100 Subject: [PATCH] headlines_callback: async --- feedlist.js | 19 ++++--- viewfeed.js | 146 ++++++++++++++++++++++++++-------------------------- 2 files changed, 84 insertions(+), 81 deletions(-) diff --git a/feedlist.js b/feedlist.js index ec1a653d..c78a47d5 100644 --- a/feedlist.js +++ b/feedlist.js @@ -1,6 +1,6 @@ //var xmlhttp = Ajax.getTransport(); -var feed_cur_page = 0; +var _feed_cur_page = 0; function viewCategory(cat) { active_feed_is_cat = true; @@ -50,10 +50,10 @@ function viewNextFeedPage() { try { if (!getActiveFeedId()) return; - feed_cur_page++; + _feed_cur_page++; viewfeed(getActiveFeedId(), undefined, undefined, undefined, - undefined, feed_cur_page); + undefined, _feed_cur_page); } catch (e) { exception_error(e, "viewFeedGoPage"); @@ -71,11 +71,11 @@ function viewfeed(feed, subop, is_cat, subop_param, skip_history, offset) { page_offset = offset; } else { page_offset = 0; - feed_cur_page = 0; + _feed_cur_page = 0; } if (getActiveFeedId() != feed) { - feed_cur_page = 0; + _feed_cur_page = 0; active_post_id = 0; } @@ -178,13 +178,18 @@ function viewfeed(feed, subop, is_cat, subop_param, skip_history, offset) { // xmlhttp.abort(); - if (xmlhttp_ready(xmlhttp)) { +/* if (xmlhttp_ready(xmlhttp)) { xmlhttp.open("GET", query, true); xmlhttp.onreadystatechange=headlines_callback; xmlhttp.send(null); } else { debug("xmlhttp busy (@feeds)"); - } + } */ + + new Ajax.Request(query, { + onComplete: function(transport) { + headlines_callback2(transport, feed, is_cat, _feed_cur_page); + } }); } catch (e) { exception_error("viewfeed", e); diff --git a/viewfeed.js b/viewfeed.js index 30af548c..197b7648 100644 --- a/viewfeed.js +++ b/viewfeed.js @@ -45,104 +45,102 @@ function catchup_callback2(transport, callback) { } } -function headlines_callback() { - if (xmlhttp.readyState == 4) { - debug("headlines_callback"); - var f = document.getElementById("headlines-frame"); - try { - if (feed_cur_page == 0) { - debug("resetting headlines scrollTop"); - f.scrollTop = 0; - } - } catch (e) { }; +function headlines_callback2(transport, active_feed_id, active_feed_is_cat, feed_cur_page) { + debug("headlines_callback2"); + var f = document.getElementById("headlines-frame"); + try { + if (feed_cur_page == 0) { + debug("resetting headlines scrollTop"); + f.scrollTop = 0; + } + } catch (e) { }; - if (xmlhttp.responseXML) { - var headlines = xmlhttp.responseXML.getElementsByTagName("headlines")[0]; - var counters = xmlhttp.responseXML.getElementsByTagName("counters")[0]; - var articles = xmlhttp.responseXML.getElementsByTagName("article"); - var runtime_info = xmlhttp.responseXML.getElementsByTagName("runtime-info"); + if (transport.responseXML) { + var headlines = transport.responseXML.getElementsByTagName("headlines")[0]; + var counters = transport.responseXML.getElementsByTagName("counters")[0]; + var articles = transport.responseXML.getElementsByTagName("article"); + var runtime_info = transport.responseXML.getElementsByTagName("runtime-info"); - if (feed_cur_page == 0) { - if (headlines) { - f.innerHTML = headlines.firstChild.nodeValue; - } else { - debug("headlines_callback: returned no data"); - f.innerHTML = "
" + __('Could not update headlines (missing XML data)') + "
"; - - } + if (feed_cur_page == 0) { + if (headlines) { + f.innerHTML = headlines.firstChild.nodeValue; } else { - if (headlines) { - debug("adding some more headlines..."); + debug("headlines_callback: returned no data"); + f.innerHTML = "
" + __('Could not update headlines (missing XML data)') + "
"; - var c = document.getElementById("headlinesList"); + } + } else { + if (headlines) { + debug("adding some more headlines..."); - if (!c) { - c = document.getElementById("headlinesInnerContainer"); - } + var c = document.getElementById("headlinesList"); - c.innerHTML = c.innerHTML + headlines.firstChild.nodeValue; - } else { - debug("headlines_callback: returned no data"); - notify_error("Error while trying to load more headlines"); + if (!c) { + c = document.getElementById("headlinesInnerContainer"); } - } - - 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); - } + c.innerHTML = c.innerHTML + headlines.firstChild.nodeValue; } else { - debug("no cached articles received"); + debug("headlines_callback: returned no data"); + notify_error("Error while trying to load more headlines"); } - 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"); + 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("headlines_callback: returned no XML object"); - f.innerHTML = "
" + __('Could not update headlines (missing XML object)') + "
"; + debug("no cached articles received"); } - if (typeof correctPNG != 'undefined') { - correctPNG(); + if (counters) { + debug("parsing piggybacked counters: " + counters); + parse_counters(counters, false); + } else { + debug("counters container not found in reply"); } - 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(); + if (runtime_info) { + debug("parsing runtime info: " + runtime_info[0]); + parse_runtime_info(runtime_info[0]); } else { - debug("not in CDM mode or watchdog disabled"); + debug("counters container not found in reply"); } - if (_tag_cdm_scroll) { - try { - document.getElementById("headlinesInnerContainer").scrollTop = _tag_cdm_scroll; - _tag_cdm_scroll = false; - debug("resetting headlinesInner scrollTop"); + } else { + debug("headlines_callback: returned no XML object"); + f.innerHTML = "
" + __('Could not update headlines (missing XML object)') + "
"; + } - } catch (e) { } - } + if (typeof correctPNG != 'undefined') { + correctPNG(); + } - notify(""); + 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) { -- 2.39.5