1 var _feed_cur_page = 0;
2 var _infscroll_disable = 0;
3 var _infscroll_request_sent = 0;
4 var feed_under_pointer = undefined;
6 var mouse_is_down = false;
10 var counter_timeout_id = false;
12 var resize_enabled = false;
13 var selection_disabled = false;
14 var counters_last_request = 0;
16 function toggle_sortable_feedlist(enabled) {
20 Sortable.create('feedList', {onChange: feedlist_dragsorted, only: "feedCat"});
22 Sortable.destroy('feedList');
26 exception_error("toggle_sortable_feedlist", e);
30 function viewCategory(cat) {
31 viewfeed(cat, '', true);
35 function render_feedlist(data) {
38 var f = $("feeds-frame");
40 // cache_invalidate("FEEDLIST");
41 // cache_inject("FEEDLIST", data, getInitParam("num_feeds"));
45 exception_error("render_feedlist", e);
49 function viewNextFeedPage() {
51 //if (!getActiveFeedId()) return;
53 console.log("viewNextFeedPage: calling viewfeed(), p: " + parseInt(_feed_cur_page+1));
55 viewfeed(getActiveFeedId(), undefined, activeFeedIsCat(), undefined,
56 undefined, parseInt(_feed_cur_page+1));
59 exception_error("viewNextFeedPage", e);
64 function viewfeed(feed, subop, is_cat, subop_param, skip_history, offset) {
67 if (offline_mode) return viewfeed_offline(feed, subop, is_cat, subop_param,
68 skip_history, offset);
70 // if (!offset) page_offset = 0;
72 last_requested_article = 0;
73 //counters_last_request = 0;
75 if (feed == getActiveFeedId()) {
76 cache_invalidate("F:" + feed);
79 /* if (getInitParam("theme") == "" || getInitParam("theme") == "compact") {
80 if (getInitParam("hide_feedlist") == 1) {
81 Element.hide("feeds-holder");
85 var force_nocache = false;
94 _infscroll_disable = 0;
97 if (getActiveFeedId() != feed) {
100 _infscroll_disable = 0;
103 if (page_offset != 0 && !subop) {
104 var date = new Date();
105 var timestamp = Math.round(date.getTime() / 1000);
107 console.log(_infscroll_request_sent + " : " + timestamp);
109 if (_infscroll_request_sent && _infscroll_request_sent + 30 > timestamp) {
110 console.log("infscroll request in progress, aborting");
114 _infscroll_request_sent = timestamp;
121 Form.enable("main_toolbar_form");
123 var toolbar_form = document.forms["main_toolbar_form"];
124 var toolbar_query = Form.serialize("main_toolbar_form");
126 if (toolbar_form.query) {
127 if (toolbar_form.query.value != "") {
128 force_nocache = true;
130 toolbar_form.query.value = "";
133 var query = "?op=viewfeed&feed=" + feed + "&" +
134 toolbar_query + "&subop=" + param_escape(subop);
136 if ($("search_form")) {
137 var search_query = Form.serialize("search_form");
138 query = query + "&" + search_query;
139 $("search_form").query.value = "";
141 force_nocache = true;
144 // console.log("IS_CAT_STORED: " + activeFeedIsCat() + ", IS_CAT: " + is_cat);
146 if (subop == "MarkAllRead") {
148 catchup_local_feed(feed, is_cat);
150 var show_next_feed = getInitParam("on_catchup_show_next_feed") == "1";
152 if (show_next_feed) {
154 if (!activeFeedIsCat()) {
156 var feedlist = $('feedList');
158 var next_unread_feed = getRelativeFeedId2(feed, false,
161 /* gRFI2 also returns categories which we don't really
162 * need here, so we skip them */
164 while (next_unread_feed && next_unread_feed.match("CAT:"))
165 next_unread_feed = getRelativeFeedId2(
166 next_unread_feed.replace("CAT:", ""),
169 if (!next_unread_feed) {
170 next_unread_feed = getRelativeFeedId2(-3, true,
174 if (next_unread_feed) {
175 query = query + "&nuf=" + param_escape(next_unread_feed);
176 //setActiveFeedId(next_unread_feed);
177 feed = next_unread_feed;
181 var next_unread_feed = getNextUnreadCat(feed);
183 /* we don't need to specify that our next feed is actually
184 a category, because we're in the is_cat mode by definition
187 if (next_unread_feed && show_next_feed) {
188 query = query + "&nuf=" + param_escape(next_unread_feed);
189 feed = next_unread_feed;
197 query = query + "&cat=1";
200 if (page_offset != 0) {
201 query = query + "&skip=" + page_offset;
203 // to prevent duplicate feed titles when showing grouped vfeeds
204 if (vgroup_last_feed) {
205 query = query + "&vgrlf=" + param_escape(vgroup_last_feed);
209 Form.enable("main_toolbar_form");
211 // for piggybacked counters
213 if (tagsAreDisplayed()) {
214 query = query + "&omode=lt";
216 query = query + "&omode=flc";
221 var container = $("headlinesInnerContainer");
223 /* if (container && page_offset == 0 && !isCdmMode()) {
224 new Effect.Fade(container, {duration: 1, to: 0.01,
225 queue: { position:'end', scope: 'FEEDL-' + feed, limit: 1 } } );
230 if (!is_cat) unread_ctr = get_feed_unread(feed);
232 var cache_check = false;
234 if (unread_ctr != -1 && !page_offset && !force_nocache && !subop) {
236 var cache_prefix = "";
244 cache_check = cache_check_param(cache_prefix + feed, unread_ctr);
245 console.log("headline cache check: " + cache_check);
249 var f = $("headlines-frame");
251 clean_feed_selections();
253 setActiveFeedId(feed, is_cat);
256 var feedr = $("FEEDR-" + feed);
257 if (feedr && !feedr.className.match("Selected")) {
258 feedr.className = feedr.className + "Selected";
261 var feedr = $("FCAT-" + feed_id);
262 if (feedr && !feedr.className.match("Selected")) {
263 feedr.className = feedr.className + "Selected";
267 f.innerHTML = cache_find_param(cache_prefix + feed, unread_ctr);
278 feedr = $('FCAP-' + feed);
280 feedr = $('FEEDR-' + feed);
283 if (feedr && !$('FLL-' + feed)) {
285 var img = $('FIMG-' + feed);
287 if (!is_cat && img) {
289 if (!img.src.match("indicator_white")) {
291 img.src = getInitParam("sign_progress");
296 if (!$('FLL-' + feed)) {
297 var ll = document.createElement('img');
299 ll.src = getInitParam("sign_progress_tiny");
300 ll.className = 'hlLoading';
301 ll.id = 'FLL-' + feed;
303 feedr.appendChild(ll);
309 new Ajax.Request("backend.php", {
311 onComplete: function(transport) {
312 headlines_callback2(transport, page_offset);
317 exception_error("viewfeed", e);
321 function toggleCollapseCat_af(effect) {
322 //var caption = elem.id.replace("FCATLIST-", "");
326 var elem = effect.element;
327 var cat = elem.id.replace("FCATLIST-", "");
328 var cap = $("FCAP-" + cat);
330 if (Element.visible(elem)) {
331 cap.innerHTML = cap.innerHTML.replace("…", "");
333 if (cap.innerHTML.lastIndexOf("…") != cap.innerHTML.length-3) {
334 cap.innerHTML = cap.innerHTML + "…";
339 exception_error("toggleCollapseCat_af", e);
343 function toggleCollapseCat(cat) {
346 var cat_elem = $("FCAT-" + cat);
347 var cat_list = $("FCATLIST-" + cat).parentNode;
348 var caption = $("FCAP-" + cat);
350 Effect.toggle('FCATLIST-' + cat, 'blind', { duration: 0.5,
351 afterFinish: toggleCollapseCat_af });
353 new Ajax.Request("backend.php",
354 { parameters: "backend.php?op=feeds&subop=collapse&cid=" +
355 param_escape(cat) } );
357 local_collapse_cat(cat);
360 exception_error("toggleCollapseCat", e);
364 function feedlist_dragsorted(ctr) {
366 var elem = $("feedList");
368 var cats = elem.getElementsByTagName("LI");
369 var ordered_cats = new Array();
371 for (var i = 0; i < cats.length; i++) {
372 if (cats[i].id && cats[i].id.match("FCAT-")) {
373 ordered_cats.push(cats[i].id.replace("FCAT-", ""));
377 if (ordered_cats.length > 0) {
379 var query = "?op=feeds&subop=catsort&corder=" +
380 param_escape(ordered_cats.toString());
382 //console.log(query);
384 new Ajax.Request("backend.php", { parameters: query });
388 exception_error("feedlist_dragsorted", e);
392 function feedlist_init() {
394 loading_set_progress(90);
396 //console.log("in feedlist init");
398 hideOrShowFeeds(getInitParam("hide_read_feeds") == 1);
399 document.onkeydown = hotkey_handler;
400 document.onmousemove = mouse_move_handler;
401 document.onmousedown = mouse_down_handler;
402 document.onmouseup = mouse_up_handler;
404 if (!offline_mode) setTimeout("timeout()", 1);
406 setTimeout("hotkey_prefix_timeout()", 5*1000);
408 if (getActiveFeedId()) {
409 //console.log("some feed is open on feedlist refresh, reloading");
410 //setTimeout("viewCurrentFeed()", 100);
412 if (getInitParam("cdm_auto_catchup") != 1 && get_feed_unread(-3) > 0) {
413 notify_silent_next();
414 setTimeout("viewfeed(-3)", 100);
416 setTimeout("viewfeed(-5)", 100);
421 if (getInitParam("theme") == "" ||
422 getInitParam("theme_options").match("hide_footer")) {
423 setTimeout("hide_footer()", 5000);
426 init_collapsable_feedlist(getInitParam("theme"));
428 toggle_sortable_feedlist(isFeedlistSortable());
431 exception_error("feedlist/init", e);
435 function hide_footer_af(effect) {
437 var c = $("content-frame");
440 c.style.bottom = "0px";
442 var ioa = $("inline_orig_article");
445 ioa.height = c.offsetHeight;
449 var h = $("headlines-frame");
452 h.style.bottom = "0px";
457 exception_error("hide_footer_af", e);
461 function hide_footer() {
463 if (Element.visible("footer")) {
464 new Effect.Fade("footer", { afterFinish: hide_footer_af });
467 exception_error("hide_footer", e);
471 function init_collapsable_feedlist() {
473 //console.log("init_collapsable_feedlist");
475 var theme = getInitParam("theme");
476 var options = getInitParam("theme_options");
478 if (theme != "" && !options.match("collapse_feedlist")) return;
480 var fbtn = $("collapse_feeds_btn");
482 if (fbtn) Element.show(fbtn);
484 if (getInitParam("collapsed_feedlist") == 1) {
489 exception_error("init_hidden_feedlist", e);
494 function mouse_move_handler(e) {
500 client_y = window.event.clientY;
501 client_x = window.event.clientX;
503 client_x = e.screenX;
504 client_y = e.screenY;
509 if (mouse_y == 0) mouse_y = client_y;
510 if (mouse_x == 0) mouse_x = client_x;
512 resize_headlines(mouse_x - client_x, mouse_y - client_y);
521 exception_error("mouse_move_handler", e);
525 function enable_selection(b) {
526 selection_disabled = !b;
529 function enable_resize(b) {
533 function mouse_down_handler(e) {
536 /* do not prevent right click */
537 if (e && e.button && e.button == 2) return;
539 if (resize_enabled) {
540 mouse_is_down = true;
543 document.onselectstart = function() { return false; };
547 if (selection_disabled) {
548 document.onselectstart = function() { return false; };
553 exception_error("mouse_down_handler", e);
557 function mouse_up_handler(e) {
559 mouse_is_down = false;
561 if (!selection_disabled) {
562 document.onselectstart = null;
563 var e = $("headlineActionsBody");
564 if (e) Element.hide(e);
566 var e = $("offlineModeDrop");
567 if (e) Element.hide(e);
572 exception_error("mouse_up_handler", e);
576 function request_counters_real() {
580 if (offline_mode) return;
582 console.log("requesting counters...");
584 var query = "?op=rpc&subop=getAllCounters";
586 if (tagsAreDisplayed()) {
587 query = query + "&omode=tl";
589 query = query + "&omode=flc";
592 new Ajax.Request("backend.php", {
594 onComplete: function(transport) {
596 handle_rpc_reply(transport);
598 exception_error("viewfeed/getcounters", e);
603 exception_error("request_counters_real", e);
608 function request_counters() {
612 if (getInitParam("bw_limit") == "1") return;
614 var date = new Date();
615 var timestamp = Math.round(date.getTime() / 1000);
617 if (timestamp - counters_last_request > 5) {
618 console.log("scheduling request of counters...");
620 window.clearTimeout(counter_timeout_id);
621 counter_timeout_id = window.setTimeout("request_counters_real()", 1000);
623 counters_last_request = timestamp;
625 console.log("request_counters: rate limit reached: " + (timestamp - counters_last_request));
629 exception_error("request_counters", e);