1 var _infscroll_disable = 0;
2 var _infscroll_request_sent = 0;
3 var _search_query = false;
5 var counter_timeout_id = false;
7 var counters_last_request = 0;
9 function viewCategory(cat) {
10 viewfeed(cat, '', true);
14 function loadMoreHeadlines() {
16 console.log("loadMoreHeadlines");
20 var view_mode = document.forms["main_toolbar_form"].view_mode.value;
21 var num_unread = $$("#headlines-frame > div[id*=RROW][class*=Unread]").length;
22 var num_all = $$("#headlines-frame > div[id*=RROW]").length;
24 // TODO implement marked & published
26 if (view_mode == "marked") {
27 console.warn("loadMoreHeadlines: marked is not implemented, falling back.");
29 } else if (view_mode == "published") {
30 console.warn("loadMoreHeadlines: published is not implemented, falling back.");
32 } else if (view_mode == "unread") {
34 } else if (view_mode == "adaptive") {
43 viewfeed(getActiveFeedId(), '', activeFeedIsCat(), offset, false, true);
46 exception_error("viewNextFeedPage", e);
51 function viewfeed(feed, method, is_cat, offset, background, infscroll_req) {
53 if (is_cat == undefined)
58 if (method == undefined) method = '';
59 if (offset == undefined) offset = 0;
60 if (background == undefined) background = false;
61 if (infscroll_req == undefined) infscroll_req = false;
63 last_requested_article = 0;
65 var cached_headlines = false;
67 if (feed == getActiveFeedId()) {
68 cache_delete("feed:" + feed + ":" + is_cat);
70 cached_headlines = cache_get("feed:" + feed + ":" + is_cat);
72 // switching to a different feed, we might as well catchup stuff visible
73 // in headlines buffer (if any)
74 if (!background && isCdmMode() && getInitParam("cdm_auto_catchup") == 1 && parseInt(getActiveFeedId()) > 0) {
76 $$("#headlines-frame > div[id*=RROW][class*=Unread]").each(
78 var hf = $("headlines-frame");
80 if (hf.scrollTop + hf.offsetHeight >=
81 child.offsetTop + child.offsetHeight) {
83 var id = child.id.replace("RROW-", "");
85 if (catchup_id_batch.indexOf(id) == -1)
86 catchup_id_batch.push(id);
90 if (catchup_id_batch.length > 0) {
91 window.clearTimeout(catchup_timeout_id);
93 if (!_infscroll_request_sent) {
94 catchup_timeout_id = window.setTimeout('catchupBatchedArticles()',
103 if (offset == 0 && !background)
104 dijit.byId("content-tabs").selectChild(
105 dijit.byId("content-tabs").getChildren()[0]);
108 if (getActiveFeedId() != feed || offset == 0) {
110 _infscroll_disable = 0;
113 if (!offset && !method && cached_headlines && !background) {
115 render_local_headlines(feed, is_cat, JSON.parse(cached_headlines));
118 console.warn("render_local_headlines failed: " + e);
122 if (offset != 0 && !method) {
123 var date = new Date();
124 var timestamp = Math.round(date.getTime() / 1000);
126 if (_infscroll_request_sent && _infscroll_request_sent + 30 > timestamp) {
127 //console.log("infscroll request in progress, aborting");
131 _infscroll_request_sent = timestamp;
137 Form.enable("main_toolbar_form");
139 var toolbar_query = Form.serialize("main_toolbar_form");
141 var query = "?op=feeds&method=view&feed=" + feed + "&" +
142 toolbar_query + "&m=" + param_escape(method);
146 force_nocache = true;
147 query = query + "&" + _search_query;
148 _search_query = false;
152 query = query + "&skip=" + offset;
154 // to prevent duplicate feed titles when showing grouped vfeeds
155 if (vgroup_last_feed) {
156 query = query + "&vgrlf=" + param_escape(vgroup_last_feed);
160 Form.enable("main_toolbar_form");
164 if (!setFeedExpandoIcon(feed, is_cat, 'images/indicator_white.gif'))
165 notify_progress("Loading, please wait...", true);
167 notify_progress("Loading, please wait...", true);
171 query += "&cat=" + is_cat;
175 new Ajax.Request("backend.php", {
177 onComplete: function(transport) {
178 setFeedExpandoIcon(feed, is_cat, 'images/blank_icon.gif');
179 headlines_callback2(transport, offset, background, infscroll_req);
183 exception_error("viewfeed", e);
187 function feedlist_init() {
189 console.log("in feedlist init");
191 hideOrShowFeeds(getInitParam("hide_read_feeds") == 1);
192 document.onkeydown = hotkey_handler;
193 setTimeout("hotkey_prefix_timeout()", 5*1000);
195 if (!getActiveFeedId()) {
196 setTimeout("viewfeed(-3)", 100);
200 getInitParam("cdm_auto_catchup") + " " + getFeedUnread(-3));
202 hideOrShowFeeds(getInitParam("hide_read_feeds") == 1);
204 setTimeout("timeout()", 5000);
205 setTimeout("precache_headlines_idle()", 3000);
208 exception_error("feedlist/init", e);
212 function request_counters_real() {
214 console.log("requesting counters...");
216 var query = "?op=rpc&method=getAllCounters&seq=" + next_seq();
218 query = query + "&omode=flc";
220 new Ajax.Request("backend.php", {
222 onComplete: function(transport) {
224 handle_rpc_json(transport);
226 exception_error("viewfeed/getcounters", e);
231 exception_error("request_counters_real", e);
236 function request_counters() {
240 if (getInitParam("bw_limit") == "1") return;
242 var date = new Date();
243 var timestamp = Math.round(date.getTime() / 1000);
245 if (timestamp - counters_last_request > 5) {
246 console.log("scheduling request of counters...");
248 window.clearTimeout(counter_timeout_id);
249 counter_timeout_id = window.setTimeout("request_counters_real()", 1000);
251 counters_last_request = timestamp;
253 console.log("request_counters: rate limit reached: " + (timestamp - counters_last_request));
257 exception_error("request_counters", e);
261 function displayNewContentPrompt(id) {
264 var msg = "<a href='#' onclick='viewCurrentFeed()'>" +
265 __("New articles available in this feed (click to show)") + "</a>";
267 msg = msg.replace("%s", getFeedName(id));
269 $('auxDlg').innerHTML = msg;
271 new Effect.Appear('auxDlg', {duration : 0.5});
274 exception_error("displayNewContentPrompt", e);
278 function parse_counters(elems, scheduled_call) {
280 for (var l = 0; l < elems.length; l++) {
282 var id = elems[l].id;
283 var kind = elems[l].kind;
284 var ctr = parseInt(elems[l].counter);
285 var error = elems[l].error;
286 var has_img = elems[l].has_img;
287 var updated = elems[l].updated;
289 if (id == "global-unread") {
295 if (id == "subscribed-feeds") {
300 // TODO: enable new content notification for categories
302 if (!activeFeedIsCat() && id == getActiveFeedId()
303 && ctr > getFeedUnread(id) && scheduled_call) {
304 displayNewContentPrompt(id);
307 if (getFeedUnread(id, (kind == "cat")) != ctr)
308 cache_delete("feed:" + id + ":" + (kind == "cat"));
310 setFeedUnread(id, (kind == "cat"), ctr);
313 setFeedValue(id, false, 'error', error);
314 setFeedValue(id, false, 'updated', updated);
318 setFeedIcon(id, false,
319 getInitParam("icons_url") + "/" + id + ".ico");
321 setFeedIcon(id, false, 'images/blank_icon.gif');
327 hideOrShowFeeds(getInitParam("hide_read_feeds") == 1);
330 exception_error("parse_counters", e);
334 function getFeedUnread(feed, is_cat) {
336 var tree = dijit.byId("feedTree");
338 if (tree && tree.model)
339 return tree.model.getFeedUnread(feed, is_cat);
348 function getFeedCategory(feed) {
350 var tree = dijit.byId("feedTree");
352 if (tree && tree.model)
353 return tree.getFeedCategory(feed);
362 function hideOrShowFeeds(hide) {
363 var tree = dijit.byId("feedTree");
366 return tree.hideRead(hide, getInitParam("hide_read_shows_special"));
369 function getFeedName(feed, is_cat) {
370 var tree = dijit.byId("feedTree");
372 if (tree && tree.model)
373 return tree.model.getFeedValue(feed, is_cat, 'name');
376 function getFeedValue(feed, is_cat, key) {
378 var tree = dijit.byId("feedTree");
380 if (tree && tree.model)
381 return tree.model.getFeedValue(feed, is_cat, key);
389 function setFeedUnread(feed, is_cat, unread) {
391 var tree = dijit.byId("feedTree");
393 if (tree && tree.model)
394 return tree.model.setFeedUnread(feed, is_cat, unread);
397 exception_error("setFeedUnread", e);
401 function setFeedValue(feed, is_cat, key, value) {
403 var tree = dijit.byId("feedTree");
405 if (tree && tree.model)
406 return tree.model.setFeedValue(feed, is_cat, key, value);
413 function selectFeed(feed, is_cat) {
415 var tree = dijit.byId("feedTree");
417 if (tree) return tree.selectFeed(feed, is_cat);
420 exception_error("selectFeed", e);
424 function setFeedIcon(feed, is_cat, src) {
426 var tree = dijit.byId("feedTree");
428 if (tree) return tree.setFeedIcon(feed, is_cat, src);
431 exception_error("setFeedIcon", e);
435 function setFeedExpandoIcon(feed, is_cat, src) {
437 var tree = dijit.byId("feedTree");
439 if (tree) return tree.setFeedExpandoIcon(feed, is_cat, src);
442 exception_error("setFeedIcon", e);
447 function getNextUnreadFeed(feed, is_cat) {
449 var tree = dijit.byId("feedTree");
450 var nuf = tree.model.getNextUnreadFeed(feed, is_cat);
453 return tree.model.store.getValue(nuf, 'bare_id');
456 exception_error("getNextUnreadFeed", e);
460 function catchupCurrentFeed() {
461 return catchupFeed(getActiveFeedId(), activeFeedIsCat());
464 function catchupFeedInGroup(id) {
467 var title = getFeedName(id);
469 var str = __("Mark all articles in %s as read?").replace("%s", title);
471 if (getInitParam("confirm_feed_catchup") != 1 || confirm(str)) {
472 return viewCurrentFeed('MarkAllReadGR:' + id);
476 exception_error("catchupFeedInGroup", e);
480 function catchupFeed(feed, is_cat) {
482 var str = __("Mark all articles in %s as read?");
483 var fn = getFeedName(feed, is_cat);
485 str = str.replace("%s", fn);
487 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
491 var catchup_query = "?op=rpc&method=catchupFeed&feed_id=" +
492 feed + "&is_cat=" + is_cat;
494 notify_progress("Loading, please wait...", true);
496 new Ajax.Request("backend.php", {
497 parameters: catchup_query,
498 onComplete: function(transport) {
499 handle_rpc_json(transport);
501 if (feed == getActiveFeedId() && is_cat == activeFeedIsCat()) {
503 $$("#headlines-frame > div[id*=RROW][class*=Unread]").each(
505 child.removeClassName("Unread");
510 var show_next_feed = getInitParam("on_catchup_show_next_feed") == "1";
512 if (show_next_feed) {
513 var nuf = getNextUnreadFeed(feed, is_cat);
516 viewfeed(nuf, '', is_cat);
524 exception_error("catchupFeed", e);
528 function decrementFeedCounter(feed, is_cat) {
530 var ctr = getFeedUnread(feed, is_cat);
533 setFeedUnread(feed, is_cat, ctr - 1);
536 var cat = parseInt(getFeedCategory(feed));
539 ctr = getFeedUnread(cat, true);
542 setFeedUnread(cat, true, ctr - 1);
549 exception_error("decrement_feed_counter", e);