From 261b88b39c94a5c306dc909c3689fd0e047617ce Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Tue, 3 Feb 2009 19:09:59 +0300 Subject: [PATCH] offline: render headlines list using local data --- feedlist.js | 154 ++++++++++++++++++++++++++++++++++++++++++++++++++- functions.js | 10 ++++ 2 files changed, 163 insertions(+), 1 deletion(-) diff --git a/feedlist.js b/feedlist.js index fbf3d927..05867d7b 100644 --- a/feedlist.js +++ b/feedlist.js @@ -129,8 +129,160 @@ function viewNextFeedPage() { } } -function viewfeed_offline(feed, subop, is_cat, subop_param, skip_history, offset) { +function viewfeed_offline(feed_id, subop, is_cat, subop_param, skip_history, offset) { try { + notify(''); + + loading_set_progress(100); + + clean_feed_selections(); + + setActiveFeedId(feed_id, is_cat); + + if (!is_cat) { + var feedr = document.getElementById("FEEDR-" + feed_id); + if (feedr && !feedr.className.match("Selected")) { + feedr.className = feedr.className + "Selected"; + } + } else { + var feedr = document.getElementById("FCAT-" + feed_id); + if (feedr && !feedr.className.match("Selected")) { + feedr.className = feedr.className + "Selected"; + } + } + + var f = document.getElementById("headlines-frame"); + try { + if (reply.offset == 0) { + debug("resetting headlines scrollTop"); + f.scrollTop = 0; + } + } catch (e) { }; + + + var container = document.getElementById("headlines-frame"); + + var tmp = ""; + + rs = db.execute("SELECT title FROM feeds WHERE id = ?", [feed_id]); + + if (rs.isValidRow()) { + + var feed_title = rs.field(0); + + if (offset == 0) { + tmp += "
"; + + tmp += "
"; + tmp += "
"; + tmp += feed_title; + tmp += "
"; + + var sel_all_link = "javascript:selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, '', true)"; + var sel_unread_link = "javascript:selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, 'Unread', true)"; + var sel_none_link = "javascript:selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false)"; + var sel_inv_link = "javascript:invertHeadlineSelection()"; + + tmp += __('Select:')+ + " "+__('All')+", "+ + ""+__('Unread')+", "+ + ""+__('Invert')+", "+ + ""+__('None')+""; + + tmp += "  "; + + tmp += "
"; + + tmp += "
"; + + tmp += ""; + + } + + var rs = db.execute("SELECT * FROM articles WHERE feed_id = ?", [feed_id]); + + var line_num = 0; + + while (rs.isValidRow()) { + + var id = rs.fieldByName("id"); + var feed_id = rs.fieldByName("feed_id"); + + var marked_pic; + + var row_class = (line_num % 2) ? "even" : "odd"; + + if (rs.fieldByName("unread") == "1") { + row_class += "Unread"; + } + + if (rs.fieldByName("marked") == "1") { + marked_pic = ""; + } else { + marked_pic = ""; + } + + var mouseover_attrs = "onmouseover='postMouseIn($id)' "+ + "onmouseout='postMouseOut($id)'"; + + tmp += ""; + + tmp += ""; + + tmp += ""; + + tmp += ""; + + tmp += ""; + + tmp += ""; + + tmp += ""; + + rs.next(); + line_num++; + } + + if (offset == 0) { + tmp += "
"+ + ""+marked_pic+""; + + tmp += ""+ + rs.fieldByName("title"); + + var content_preview = truncate_string(strip_tags(rs.fieldByName("content")), + 100); + + tmp += " - "+content_preview+""; + + tmp += ""; + + tmp += ""+ + ""+rs.fieldByName("updated").substring(0,16)+"
"; + tmp += "
"; + } + + if (offset == 0) { + container.innerHTML = tmp; + } else { + var ids = getSelectedArticleIds2(); + + //container.innerHTML = container.innerHTML + tmp; + + for (var i = 0; i < ids.length; i++) { + markHeadline(ids[i]); + } + } + } + + remove_splash(); } catch (e) { diff --git a/functions.js b/functions.js index ecb41db2..2b0370d3 100644 --- a/functions.js +++ b/functions.js @@ -2109,3 +2109,13 @@ function transport_error_check(transport) { return true; } +function strip_tags(s) { + return s.replace(/<\/?[^>]+(>|$)/g, ""); +} + +function truncate_string(s, length) { + if (!length) length = 30; + var tmp = s.substring(0, length); + if (s.length > length) tmp += "…"; + return tmp; +} -- 2.39.5