1 var _infscroll_disable = 0;
2 var _infscroll_request_sent = 0;
3 var _search_query = false;
4 var _viewfeed_last = 0;
5 var _viewfeed_timeout = 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 unread_in_buffer = $$("#headlines-frame > div[id*=RROW][class*=Unread]").length;
22 var num_all = $$("#headlines-frame > div[id*=RROW]").length;
23 var num_unread = getFeedUnread(getActiveFeedId(), activeFeedIsCat());
25 // TODO implement marked & published
27 if (view_mode == "marked") {
28 console.warn("loadMoreHeadlines: marked is not implemented, falling back.");
30 } else if (view_mode == "published") {
31 console.warn("loadMoreHeadlines: published is not implemented, falling back.");
33 } else if (view_mode == "unread") {
34 offset = unread_in_buffer;
35 } else if (_search_query) {
37 } else if (view_mode == "adaptive") {
38 offset = num_unread > 0 ? unread_in_buffer : num_all;
43 console.log("offset: " + offset);
45 viewfeed(getActiveFeedId(), '', activeFeedIsCat(), offset, false, true);
48 exception_error("viewNextFeedPage", e);
53 function viewfeed(feed, method, is_cat, offset, background, infscroll_req, can_wait) {
55 if (is_cat == undefined)
60 if (method == undefined) method = '';
61 if (offset == undefined) offset = 0;
62 if (background == undefined) background = false;
63 if (infscroll_req == undefined) infscroll_req = false;
65 last_requested_article = 0;
67 if (feed != getActiveFeedId() || activeFeedIsCat() != is_cat) {
68 if (!background && _search_query) _search_query = false;
72 _viewfeed_last = get_timestamp();
74 if (getActiveFeedId() != feed || offset == 0) {
75 setActiveArticleId(0);
76 _infscroll_disable = 0;
79 if (offset != 0 && !method) {
80 var timestamp = get_timestamp();
82 if (_infscroll_request_sent && _infscroll_request_sent + 30 > timestamp) {
83 //console.log("infscroll request in progress, aborting");
87 _infscroll_request_sent = timestamp;
91 Form.enable("main_toolbar_form");
93 var toolbar_query = Form.serialize("main_toolbar_form");
95 var query = "?op=feeds&method=view&feed=" + param_escape(feed) + "&" +
99 query = query + "&m=" + param_escape(method);
104 force_nocache = true;
105 query = query + "&" + _search_query;
106 //_search_query = false;
110 query = query + "&skip=" + offset;
112 // to prevent duplicate feed titles when showing grouped vfeeds
113 if (vgroup_last_feed) {
114 query = query + "&vgrlf=" + param_escape(vgroup_last_feed);
117 if (!method && !is_cat && feed == getActiveFeedId()) {
118 query = query + "&m=ForceUpdate";
122 Form.enable("main_toolbar_form");
124 if (!setFeedExpandoIcon(feed, is_cat,
125 (is_cat) ? 'images/indicator_tiny.gif' : 'images/indicator_white.gif'))
126 notify_progress("Loading, please wait...", true);
129 query += "&cat=" + is_cat;
133 if (can_wait && _viewfeed_timeout) {
134 setFeedExpandoIcon(getActiveFeedId(), activeFeedIsCat(), 'images/blank_icon.gif');
135 clearTimeout(_viewfeed_timeout);
138 setActiveFeedId(feed, is_cat);
140 timeout_ms = can_wait ? 250 : 0;
141 _viewfeed_timeout = setTimeout(function() {
143 new Ajax.Request("backend.php", {
145 onComplete: function(transport) {
146 setFeedExpandoIcon(feed, is_cat, 'images/blank_icon.gif');
147 headlines_callback2(transport, offset, background, infscroll_req);
148 PluginHost.run(PluginHost.HOOK_FEED_LOADED, [feed, is_cat]);
150 }, timeout_ms); // Wait 250ms
153 exception_error("viewfeed", e);
157 function feedlist_init() {
159 console.log("in feedlist init");
161 loading_set_progress(50);
163 document.onkeydown = hotkey_handler;
164 setTimeout("hotkey_prefix_timeout()", 5*1000);
166 if (!getActiveFeedId()) {
169 viewfeed(getActiveFeedId(), '', activeFeedIsCat());
172 hideOrShowFeeds(getInitParam("hide_read_feeds") == 1);
174 request_counters(true);
178 exception_error("feedlist/init", e);
183 function request_counters(force) {
185 var date = new Date();
186 var timestamp = Math.round(date.getTime() / 1000);
188 if (force || timestamp - counters_last_request > 5) {
189 console.log("scheduling request of counters...");
191 counters_last_request = timestamp;
193 var query = "?op=rpc&method=getAllCounters&seq=" + next_seq();
196 query = query + "&last_article_id=" + getInitParam("last_article_id");
200 new Ajax.Request("backend.php", {
202 onComplete: function(transport) {
204 handle_rpc_json(transport);
206 exception_error("request_counters", e);
211 console.log("request_counters: rate limit reached: " + (timestamp - counters_last_request));
215 exception_error("request_counters", e);
219 function parse_counters(elems, scheduled_call) {
221 for (var l = 0; l < elems.length; l++) {
223 var id = elems[l].id;
224 var kind = elems[l].kind;
225 var ctr = parseInt(elems[l].counter);
226 var error = elems[l].error;
227 var has_img = elems[l].has_img;
228 var updated = elems[l].updated;
229 var auxctr = parseInt(elems[l].auxcounter);
231 if (id == "global-unread") {
237 if (id == "subscribed-feeds") {
242 if (getFeedUnread(id, (kind == "cat")) != ctr ||
246 setFeedUnread(id, (kind == "cat"), ctr);
247 setFeedValue(id, (kind == "cat"), 'auxcounter', auxctr);
250 setFeedValue(id, false, 'error', error);
251 setFeedValue(id, false, 'updated', updated);
255 setFeedIcon(id, false,
256 getInitParam("icons_url") + "/" + id + ".ico");
258 setFeedIcon(id, false, 'images/blank_icon.gif');
264 hideOrShowFeeds(getInitParam("hide_read_feeds") == 1);
267 exception_error("parse_counters", e);
271 function getFeedUnread(feed, is_cat) {
273 var tree = dijit.byId("feedTree");
275 if (tree && tree.model)
276 return tree.model.getFeedUnread(feed, is_cat);
285 function getFeedCategory(feed) {
287 var tree = dijit.byId("feedTree");
289 if (tree && tree.model)
290 return tree.getFeedCategory(feed);
299 function hideOrShowFeeds(hide) {
300 var tree = dijit.byId("feedTree");
303 return tree.hideRead(hide, getInitParam("hide_read_shows_special"));
306 function getFeedName(feed, is_cat) {
307 var tree = dijit.byId("feedTree");
309 if (tree && tree.model)
310 return tree.model.getFeedValue(feed, is_cat, 'name');
313 function getFeedValue(feed, is_cat, key) {
315 var tree = dijit.byId("feedTree");
317 if (tree && tree.model)
318 return tree.model.getFeedValue(feed, is_cat, key);
326 function setFeedUnread(feed, is_cat, unread) {
328 var tree = dijit.byId("feedTree");
330 if (tree && tree.model)
331 return tree.model.setFeedUnread(feed, is_cat, unread);
334 exception_error("setFeedUnread", e);
338 function setFeedValue(feed, is_cat, key, value) {
340 var tree = dijit.byId("feedTree");
342 if (tree && tree.model)
343 return tree.model.setFeedValue(feed, is_cat, key, value);
350 function selectFeed(feed, is_cat) {
352 var tree = dijit.byId("feedTree");
354 if (tree) return tree.selectFeed(feed, is_cat);
357 exception_error("selectFeed", e);
361 function setFeedIcon(feed, is_cat, src) {
363 var tree = dijit.byId("feedTree");
365 if (tree) return tree.setFeedIcon(feed, is_cat, src);
368 exception_error("setFeedIcon", e);
372 function setFeedExpandoIcon(feed, is_cat, src) {
374 var tree = dijit.byId("feedTree");
376 if (tree) return tree.setFeedExpandoIcon(feed, is_cat, src);
379 exception_error("setFeedIcon", e);
384 function getNextUnreadFeed(feed, is_cat) {
386 var tree = dijit.byId("feedTree");
387 var nuf = tree.model.getNextUnreadFeed(feed, is_cat);
390 return tree.model.store.getValue(nuf, 'bare_id');
393 exception_error("getNextUnreadFeed", e);
397 function catchupCurrentFeed(mode) {
398 catchupFeed(getActiveFeedId(), activeFeedIsCat(), mode);
401 function catchupFeedInGroup(id) {
404 var title = getFeedName(id);
406 var str = __("Mark all articles in %s as read?").replace("%s", title);
408 if (getInitParam("confirm_feed_catchup") != 1 || confirm(str)) {
409 return viewCurrentFeed('MarkAllReadGR:' + id);
413 exception_error("catchupFeedInGroup", e);
417 function catchupFeed(feed, is_cat, mode) {
419 if (is_cat == undefined) is_cat = false;
425 str = __("Mark all articles in %s older than 1 day as read?");
428 str = __("Mark all articles in %s older than 1 week as read?");
431 str = __("Mark all articles in %s older than 2 weeks as read?");
434 str = __("Mark all articles in %s as read?");
437 var fn = getFeedName(feed, is_cat);
439 str = str.replace("%s", fn);
441 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
445 var catchup_query = "?op=rpc&method=catchupFeed&feed_id=" +
446 feed + "&is_cat=" + is_cat + "&mode=" + mode;
448 console.log(catchup_query);
450 notify_progress("Loading, please wait...", true);
452 new Ajax.Request("backend.php", {
453 parameters: catchup_query,
454 onComplete: function(transport) {
455 handle_rpc_json(transport);
457 var show_next_feed = getInitParam("on_catchup_show_next_feed") == "1";
459 if (show_next_feed) {
460 var nuf = getNextUnreadFeed(feed, is_cat);
463 viewfeed(nuf, '', is_cat);
466 if (feed == getActiveFeedId() && is_cat == activeFeedIsCat()) {
475 exception_error("catchupFeed", e);
479 function decrementFeedCounter(feed, is_cat) {
481 var ctr = getFeedUnread(feed, is_cat);
484 setFeedUnread(feed, is_cat, ctr - 1);
485 global_unread = global_unread - 1;
489 var cat = parseInt(getFeedCategory(feed));
492 ctr = getFeedUnread(cat, true);
495 setFeedUnread(cat, true, ctr - 1);
502 exception_error("decrement_feed_counter", e);