1 var _feed_cur_page = 0;
2 var _infscroll_disable = 0;
3 var _infscroll_request_sent = 0;
4 var _search_query = false;
6 var counter_timeout_id = false;
8 var resize_enabled = false;
9 var counters_last_request = 0;
11 function viewCategory(cat) {
12 viewfeed(cat, '', true);
16 function viewNextFeedPage() {
18 //if (!getActiveFeedId()) return;
20 console.log("viewNextFeedPage: calling viewfeed(), p: " + parseInt(_feed_cur_page+1));
22 viewfeed(getActiveFeedId(), '', activeFeedIsCat(), parseInt(_feed_cur_page+1));
25 exception_error("viewNextFeedPage", e);
30 function viewfeed(feed, subop, is_cat, offset) {
32 if (is_cat == undefined) is_cat = false;
33 if (subop == undefined) subop = '';
35 // if (!offset) page_offset = 0;
37 last_requested_article = 0;
38 //counters_last_request = 0;
40 if (feed == getActiveFeedId()) {
41 cache_invalidate("F:" + feed);
44 /* if (getInitParam("theme") == "" || getInitParam("theme") == "compact") {
45 if (getInitParam("hide_feedlist") == 1) {
46 Element.hide("feeds-holder");
50 dijit.byId("content-tabs").selectChild(
51 dijit.byId("content-tabs").getChildren()[0]);
53 var force_nocache = false;
62 _infscroll_disable = 0;
65 if (getActiveFeedId() != feed) {
68 _infscroll_disable = 0;
71 if (page_offset != 0 && !subop) {
72 var date = new Date();
73 var timestamp = Math.round(date.getTime() / 1000);
75 console.log(_infscroll_request_sent + " : " + timestamp);
77 if (_infscroll_request_sent && _infscroll_request_sent + 30 > timestamp) {
78 console.log("infscroll request in progress, aborting");
82 _infscroll_request_sent = timestamp;
87 Form.enable("main_toolbar_form");
89 var toolbar_form = document.forms["main_toolbar_form"];
90 var toolbar_query = Form.serialize("main_toolbar_form");
92 if (toolbar_form.query) {
93 if (toolbar_form.query.value != "") {
96 toolbar_form.query.value = "";
99 var query = "?op=viewfeed&feed=" + feed + "&" +
100 toolbar_query + "&subop=" + param_escape(subop);
103 force_nocache = true;
104 query = query + "&" + _search_query;
105 _search_query = false;
108 // console.log("IS_CAT_STORED: " + activeFeedIsCat() + ", IS_CAT: " + is_cat);
110 if (subop == "MarkAllRead") {
112 var show_next_feed = getInitParam("on_catchup_show_next_feed") == "1";
114 if (show_next_feed) {
115 var tree = dijit.byId("feedTree");
116 var nuf = tree.model.getNextUnreadFeed(feed, is_cat);
119 var nuf_id = tree.model.store.getValue(nuf, 'bare_id');
121 query = query + "&nuf=" + param_escape(nuf_id);
127 query = query + "&cat=1";
130 if (page_offset != 0) {
131 query = query + "&skip=" + page_offset;
133 // to prevent duplicate feed titles when showing grouped vfeeds
134 if (vgroup_last_feed) {
135 query = query + "&vgrlf=" + param_escape(vgroup_last_feed);
139 Form.enable("main_toolbar_form");
143 /* var unread_ctr = -1;
145 if (!is_cat) unread_ctr = getFeedUnread(feed);
147 var cache_check = false;
149 if (unread_ctr != -1 && !page_offset && !force_nocache && !subop) {
151 var cache_prefix = "";
159 cache_check = cache_check_param(cache_prefix + feed, unread_ctr);
160 console.log("headline cache check: " + cache_check);
165 setActiveFeedId(feed, is_cat);
167 $("headlines-frame").innerHTML = cache_find_param(cache_prefix + feed,
176 if (!setFeedExpandoIcon(feed, is_cat, 'images/indicator_white.gif'))
177 notify_progress("Loading, please wait...", true);
179 notify_progress("Loading, please wait...", true);
182 new Ajax.Request("backend.php", {
184 onComplete: function(transport) {
185 setFeedExpandoIcon(feed, is_cat, 'images/blank_icon.gif');
186 headlines_callback2(transport, page_offset);
191 exception_error("viewfeed", e);
195 function feedlist_init() {
197 console.log("in feedlist init");
199 hideOrShowFeeds(getInitParam("hide_read_feeds") == 1);
200 document.onkeydown = hotkey_handler;
201 setTimeout("hotkey_prefix_timeout()", 5*1000);
203 if (!getActiveFeedId()) {
204 setTimeout("viewfeed(-3)", 100);
208 getInitParam("cdm_auto_catchup") + " " + getFeedUnread(-3));
210 hideOrShowFeeds(getInitParam("hide_read_feeds") == 1);
212 setTimeout("timeout()", 5000);
215 exception_error("feedlist/init", e);
219 function request_counters_real() {
221 console.log("requesting counters...");
223 var query = "?op=rpc&subop=getAllCounters&seq=" + next_seq();
225 query = query + "&omode=flc";
227 new Ajax.Request("backend.php", {
229 onComplete: function(transport) {
231 handle_rpc_json(transport);
233 exception_error("viewfeed/getcounters", e);
238 exception_error("request_counters_real", e);
243 function request_counters() {
247 if (getInitParam("bw_limit") == "1") return;
249 var date = new Date();
250 var timestamp = Math.round(date.getTime() / 1000);
252 if (timestamp - counters_last_request > 5) {
253 console.log("scheduling request of counters...");
255 window.clearTimeout(counter_timeout_id);
256 counter_timeout_id = window.setTimeout("request_counters_real()", 1000);
258 counters_last_request = timestamp;
260 console.log("request_counters: rate limit reached: " + (timestamp - counters_last_request));
264 exception_error("request_counters", e);
268 function displayNewContentPrompt(id) {
271 var msg = "<a href='#' onclick='viewCurrentFeed()'>" +
272 __("New articles available in this feed (click to show)") + "</a>";
274 msg = msg.replace("%s", getFeedName(id));
276 $('auxDlg').innerHTML = msg;
278 new Effect.Appear('auxDlg', {duration : 0.5});
281 exception_error("displayNewContentPrompt", e);
285 function parse_counters(elems, scheduled_call) {
290 for (var l = 0; l < elems.length; l++) {
293 var kind = elems[l].kind;
294 var ctr = parseInt(elems[l].counter)
295 var error = elems[l].error;
296 var has_img = elems[l].has_img;
297 var updated = elems[l].updated;
298 var title = elems[l].title;
300 if (id == "global-unread") {
306 if (id == "subscribed-feeds") {
313 // TODO: enable new content notification for categories
315 if (!activeFeedIsCat() && id == getActiveFeedId()
316 && ctr > getFeedUnread(id) && scheduled_call) {
317 displayNewContentPrompt(id);
320 setFeedUnread(id, (kind == "cat"), ctr);
323 setFeedValue(id, false, 'error', error);
324 setFeedValue(id, false, 'updated', updated);
328 setFeedIcon(id, false,
329 getInitParam("icons_url") + "/" + id + ".ico");
331 setFeedIcon(id, false, 'images/blank_icon.gif');
337 hideOrShowFeeds(getInitParam("hide_read_feeds") == 1);
340 exception_error("parse_counters", e);
344 function getFeedUnread(feed, is_cat) {
346 var tree = dijit.byId("feedTree");
348 if (tree && tree.model)
349 return tree.model.getFeedUnread(feed, is_cat);
358 function resort_feedlist() {
359 console.warn("resort_feedlist: function not implemented");
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);