From 71d277deecb19bd354ddfd173fdf4b01e0b7966f Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Fri, 24 Aug 2007 08:53:35 +0100 Subject: switch view() to async --- viewfeed.js | 182 ++++++++++++++++++++++++++++-------------------------------- 1 file changed, 85 insertions(+), 97 deletions(-) diff --git a/viewfeed.js b/viewfeed.js index e898f84a1..21984467f 100644 --- a/viewfeed.js +++ b/viewfeed.js @@ -196,36 +196,58 @@ function render_article(article) { } } -function article_callback() { - if (xmlhttp.readyState == 4) { - debug("article_callback"); +function showArticleInHeadlines(id) { - try { - if (xmlhttp.responseXML) { - var reply = xmlhttp.responseXML.firstChild.firstChild; + cleanSelected("headlinesList"); - var articles = xmlhttp.responseXML.getElementsByTagName("article"); + var crow = document.getElementById("RROW-" + id); + var article_is_unread = crow.className.match("Unread"); + + crow.className = crow.className.replace("Unread", ""); + + var upd_img_pic = document.getElementById("FUPDPIC-" + id); + + if (upd_img_pic) { + upd_img_pic.src = "images/blank_icon.gif"; + } + + selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false); + markHeadline(id); - for (var i = 0; i < articles.length; i++) { - var a_id = articles[i].getAttribute("id"); +} - debug("found id: " + a_id); +function article_callback2(transport, id, feed_id) { + try { + debug("article_callback2 " + id); - if (a_id == active_post_id) { - debug("active article, rendering..."); - render_article(articles[i].firstChild.nodeValue); - } + if (transport.responseXML) { - cache_inject(a_id, articles[i].firstChild.nodeValue); + active_real_feed_id = feed_id; + active_post_id = id; + + showArticleInHeadlines(id); + + var reply = transport.responseXML.firstChild.firstChild; + + var articles = transport.responseXML.getElementsByTagName("article"); + + for (var i = 0; i < articles.length; i++) { + var a_id = articles[i].getAttribute("id"); + + debug("found id: " + a_id); + + if (a_id == active_post_id) { + debug("active article, rendering..."); + render_article(articles[i].firstChild.nodeValue); } - - } else { - debug("article_callback: returned no XML object"); - var f = document.getElementById("content-frame"); - f.innerHTML = "
" + __('Could not display article (missing XML object)') + "
"; + + cache_inject(a_id, articles[i].firstChild.nodeValue); } - } catch (e) { - exception_error("article_callback", e); + + } else { + debug("article_callback: returned no XML object"); + var f = document.getElementById("content-frame"); + f.innerHTML = "
" + __('Could not display article (missing XML object)') + "
"; } var date = new Date(); @@ -239,7 +261,7 @@ function article_callback() { setTimeout('updateFeedList(false, false)', 50); _reload_feedlist_after_view = false; } else { - var counters = xmlhttp.responseXML.getElementsByTagName("counters")[0]; + var counters = transport.responseXML.getElementsByTagName("counters")[0]; if (counters) { debug("parsing piggybacked counters: " + counters); @@ -250,6 +272,8 @@ function article_callback() { } notify(""); + } catch (e) { + exception_error("article_callback2", e); } } @@ -257,9 +281,7 @@ function view(id, feed_id, skip_history) { try { debug("loading article: " + id + "/" + feed_id); - - active_real_feed_id = feed_id; - + var cached_article = cache_find(id); debug("cache check result: " + (cached_article != false)); @@ -273,7 +295,7 @@ function view(id, feed_id, skip_history) { var date = new Date(); - if (!xmlhttp_ready(xmlhttp) && last_article_view < date.getTime() / 1000 - 15) { +/* if (!xmlhttp_ready(xmlhttp) && last_article_view < date.getTime() / 1000 - 15) { debug("xmlhttp seems to be stuck at view, aborting"); xmlhttp.abort(); if (is_safari()) { @@ -282,97 +304,63 @@ function view(id, feed_id, skip_history) { } } - if (xmlhttp_ready(xmlhttp)) { + if (xmlhttp_ready(xmlhttp)) { */ - active_post_id = id; - - cleanSelected("headlinesList"); - - var crow = document.getElementById("RROW-" + active_post_id); - - var article_is_unread = crow.className.match("Unread"); - debug("article is unread: " + article_is_unread); - - crow.className = crow.className.replace("Unread", ""); - - var upd_img_pic = document.getElementById("FUPDPIC-" + active_post_id); - - if (upd_img_pic) { - upd_img_pic.src = "images/blank_icon.gif"; - } + var neighbor_ids = getRelativePostIds(active_post_id); - selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false); - markHeadline(active_post_id); + /* only request uncached articles */ - var neighbor_ids = getRelativePostIds(active_post_id); + var cids_to_request = Array(); - /* only request uncached articles */ - - var cids_to_request = Array(); - - for (var i = 0; i < neighbor_ids.length; i++) { - if (!cache_check(neighbor_ids[i])) { - cids_to_request.push(neighbor_ids[i]); - } - } - - debug("additional ids: " + cids_to_request.toString()); - - /* additional info for piggyback counters */ - - if (tagsAreDisplayed()) { - query = query + "&omode=lt"; - } else { - query = query + "&omode=flc"; + for (var i = 0; i < neighbor_ids.length; i++) { + if (!cache_check(neighbor_ids[i])) { + cids_to_request.push(neighbor_ids[i]); } + } - var date = new Date(); - var timestamp = Math.round(date.getTime() / 1000); - query = query + "&ts=" + timestamp; - - query = query + "&cids=" + cids_to_request.toString(); - - if (!cached_article) { + debug("additional ids: " + cids_to_request.toString()); - notify_progress("Loading, please wait..."); + /* additional info for piggyback counters */ - debug(query); + if (tagsAreDisplayed()) { + query = query + "&omode=lt"; + } else { + query = query + "&omode=flc"; + } - xmlhttp.open("GET", query, true); - xmlhttp.onreadystatechange=article_callback; - xmlhttp.send(null); - } else if (cached_article && article_is_unread) { + var date = new Date(); + var timestamp = Math.round(date.getTime() / 1000); + query = query + "&ts=" + timestamp; - query = query + "&mode=prefetch"; + query = query + "&cids=" + cids_to_request.toString(); - debug(query); + var crow = document.getElementById("RROW-" + id); + var article_is_unread = crow.className.match("Unread"); - xmlhttp.open("GET", query, true); - xmlhttp.onreadystatechange=article_callback; - xmlhttp.send(null); + showArticleInHeadlines(id); - render_article(cached_article); + if (!cached_article) { - } else if (cached_article) { + notify_progress("Loading, please wait..."); - query = query + "&mode=prefetch_old"; + } else if (cached_article && article_is_unread) { - debug(query); + query = query + "&mode=prefetch"; - xmlhttp.open("GET", query, true); - xmlhttp.onreadystatechange=article_callback; - xmlhttp.send(null); + render_article(cached_article); - render_article(cached_article); + } else if (cached_article) { - } + query = query + "&mode=prefetch_old"; + render_article(cached_article); + } - cache_expire(); + cache_expire(); - } else { - debug("xmlhttp busy (@view)"); - printLockingError(); - } + new Ajax.Request(query, { + onComplete: function(transport) { + article_callback2(transport, id, feed_id); + } }); } catch (e) { exception_error("view", e); -- cgit v1.2.3