]>
Commit | Line | Data |
---|---|---|
1 | var _feed_cur_page = 0; | |
2 | var _infscroll_disable = 0; | |
3 | var _infscroll_request_sent = 0; | |
4 | var feed_under_pointer = undefined; | |
5 | ||
6 | var mouse_is_down = false; | |
7 | var mouse_y = 0; | |
8 | var mouse_x = 0; | |
9 | ||
10 | var counter_timeout_id = false; | |
11 | ||
12 | var resize_enabled = false; | |
13 | var selection_disabled = false; | |
14 | var counters_last_request = 0; | |
15 | ||
16 | var feeds_sort_by_unread = false; | |
17 | var feedlist_sortable_enabled = false; | |
18 | ||
19 | function toggle_sortable_feedlist(enabled) { | |
20 | try { | |
21 | ||
22 | if (enabled) { | |
23 | Sortable.create('feedList', {onChange: feedlist_dragsorted, only: "feedCat"}); | |
24 | } else { | |
25 | Sortable.destroy('feedList'); | |
26 | } | |
27 | ||
28 | } catch (e) { | |
29 | exception_error("toggle_sortable_feedlist", e); | |
30 | } | |
31 | } | |
32 | ||
33 | function viewCategory(cat) { | |
34 | viewfeed(cat, '', true); | |
35 | return false; | |
36 | } | |
37 | ||
38 | function render_feedlist(data) { | |
39 | try { | |
40 | ||
41 | var f = $("feeds-frame"); | |
42 | f.innerHTML = data; | |
43 | // cache_invalidate("FEEDLIST"); | |
44 | // cache_inject("FEEDLIST", data, getInitParam("num_feeds")); | |
45 | feedlist_init(); | |
46 | ||
47 | } catch (e) { | |
48 | exception_error("render_feedlist", e); | |
49 | } | |
50 | } | |
51 | ||
52 | function viewNextFeedPage() { | |
53 | try { | |
54 | //if (!getActiveFeedId()) return; | |
55 | ||
56 | console.log("viewNextFeedPage: calling viewfeed(), p: " + parseInt(_feed_cur_page+1)); | |
57 | ||
58 | viewfeed(getActiveFeedId(), '', activeFeedIsCat(), parseInt(_feed_cur_page+1)); | |
59 | ||
60 | } catch (e) { | |
61 | exception_error("viewNextFeedPage", e); | |
62 | } | |
63 | } | |
64 | ||
65 | ||
66 | function viewfeed(feed, subop, is_cat, offset) { | |
67 | try { | |
68 | if (is_cat == undefined) is_cat = false; | |
69 | ||
70 | if (offline_mode) return viewfeed_offline(feed, subop, is_cat, offset); | |
71 | ||
72 | // if (!offset) page_offset = 0; | |
73 | ||
74 | last_requested_article = 0; | |
75 | //counters_last_request = 0; | |
76 | ||
77 | if (feed == getActiveFeedId()) { | |
78 | cache_invalidate("F:" + feed); | |
79 | } | |
80 | ||
81 | /* if (getInitParam("theme") == "" || getInitParam("theme") == "compact") { | |
82 | if (getInitParam("hide_feedlist") == 1) { | |
83 | Element.hide("feeds-holder"); | |
84 | } | |
85 | } */ | |
86 | ||
87 | var force_nocache = false; | |
88 | ||
89 | var page_offset = 0; | |
90 | ||
91 | if (offset > 0) { | |
92 | page_offset = offset; | |
93 | } else { | |
94 | page_offset = 0; | |
95 | _feed_cur_page = 0; | |
96 | _infscroll_disable = 0; | |
97 | } | |
98 | ||
99 | if (getActiveFeedId() != feed) { | |
100 | _feed_cur_page = 0; | |
101 | active_post_id = 0; | |
102 | _infscroll_disable = 0; | |
103 | } | |
104 | ||
105 | if (page_offset != 0 && !subop) { | |
106 | var date = new Date(); | |
107 | var timestamp = Math.round(date.getTime() / 1000); | |
108 | ||
109 | console.log(_infscroll_request_sent + " : " + timestamp); | |
110 | ||
111 | if (_infscroll_request_sent && _infscroll_request_sent + 30 > timestamp) { | |
112 | console.log("infscroll request in progress, aborting"); | |
113 | return; | |
114 | } | |
115 | ||
116 | _infscroll_request_sent = timestamp; | |
117 | } | |
118 | ||
119 | enableHotkeys(); | |
120 | hideAuxDlg(); | |
121 | closeInfoBox(); | |
122 | ||
123 | Form.enable("main_toolbar_form"); | |
124 | ||
125 | var toolbar_form = document.forms["main_toolbar_form"]; | |
126 | var toolbar_query = Form.serialize("main_toolbar_form"); | |
127 | ||
128 | if (toolbar_form.query) { | |
129 | if (toolbar_form.query.value != "") { | |
130 | force_nocache = true; | |
131 | } | |
132 | toolbar_form.query.value = ""; | |
133 | } | |
134 | ||
135 | var query = "?op=viewfeed&feed=" + feed + "&" + | |
136 | toolbar_query + "&subop=" + param_escape(subop); | |
137 | ||
138 | if ($("search_form")) { | |
139 | var search_query = Form.serialize("search_form"); | |
140 | query = query + "&" + search_query; | |
141 | $("search_form").query.value = ""; | |
142 | closeInfoBox(true); | |
143 | force_nocache = true; | |
144 | } | |
145 | ||
146 | // console.log("IS_CAT_STORED: " + activeFeedIsCat() + ", IS_CAT: " + is_cat); | |
147 | ||
148 | if (subop == "MarkAllRead") { | |
149 | ||
150 | catchup_local_feed(feed, is_cat); | |
151 | ||
152 | var show_next_feed = getInitParam("on_catchup_show_next_feed") == "1"; | |
153 | ||
154 | if (show_next_feed) { | |
155 | ||
156 | if (!activeFeedIsCat()) { | |
157 | ||
158 | var feedlist = $('feedList'); | |
159 | ||
160 | var next_unread_feed = getRelativeFeedId2(feed, false, | |
161 | "next", true); | |
162 | ||
163 | /* gRFI2 also returns categories which we don't really | |
164 | * need here, so we skip them */ | |
165 | ||
166 | while (next_unread_feed && next_unread_feed.match("CAT:")) | |
167 | next_unread_feed = getRelativeFeedId2( | |
168 | next_unread_feed.replace("CAT:", ""), | |
169 | true, "next", true); | |
170 | ||
171 | if (!next_unread_feed) { | |
172 | next_unread_feed = getRelativeFeedId2(-3, true, | |
173 | "next", true); | |
174 | } | |
175 | ||
176 | if (next_unread_feed) { | |
177 | query = query + "&nuf=" + param_escape(next_unread_feed); | |
178 | //setActiveFeedId(next_unread_feed); | |
179 | feed = next_unread_feed; | |
180 | } | |
181 | } else { | |
182 | ||
183 | var next_unread_feed = getNextUnreadCat(feed); | |
184 | ||
185 | /* we don't need to specify that our next feed is actually | |
186 | a category, because we're in the is_cat mode by definition | |
187 | already */ | |
188 | ||
189 | if (next_unread_feed && show_next_feed) { | |
190 | query = query + "&nuf=" + param_escape(next_unread_feed); | |
191 | feed = next_unread_feed; | |
192 | } | |
193 | ||
194 | } | |
195 | } | |
196 | } | |
197 | ||
198 | if (is_cat) { | |
199 | query = query + "&cat=1"; | |
200 | } | |
201 | ||
202 | if (page_offset != 0) { | |
203 | query = query + "&skip=" + page_offset; | |
204 | ||
205 | // to prevent duplicate feed titles when showing grouped vfeeds | |
206 | if (vgroup_last_feed) { | |
207 | query = query + "&vgrlf=" + param_escape(vgroup_last_feed); | |
208 | } | |
209 | } | |
210 | ||
211 | Form.enable("main_toolbar_form"); | |
212 | ||
213 | console.log(query); | |
214 | ||
215 | var container = $("headlinesInnerContainer"); | |
216 | ||
217 | var unread_ctr = -1; | |
218 | ||
219 | if (!is_cat) unread_ctr = get_feed_unread(feed); | |
220 | ||
221 | var cache_check = false; | |
222 | ||
223 | if (unread_ctr != -1 && !page_offset && !force_nocache && !subop) { | |
224 | ||
225 | var cache_prefix = ""; | |
226 | ||
227 | if (is_cat) { | |
228 | cache_prefix = "C:"; | |
229 | } else { | |
230 | cache_prefix = "F:"; | |
231 | } | |
232 | ||
233 | cache_check = cache_check_param(cache_prefix + feed, unread_ctr); | |
234 | console.log("headline cache check: " + cache_check); | |
235 | } | |
236 | ||
237 | if (cache_check) { | |
238 | var f = $("headlines-frame"); | |
239 | ||
240 | clean_feed_selections(); | |
241 | ||
242 | setActiveFeedId(feed, is_cat); | |
243 | ||
244 | if (!is_cat) { | |
245 | var feedr = $("FEEDR-" + feed); | |
246 | if (feedr && !feedr.hasClassName("Selected")) { | |
247 | feedr.addClassName("Selected"); | |
248 | } | |
249 | } else { | |
250 | var feedr = $("FCAT-" + feed_id); | |
251 | if (feedr && !feedr.hasClassName("Selected")) { | |
252 | feedr.addClassName("Selected"); | |
253 | } | |
254 | } | |
255 | ||
256 | f.innerHTML = cache_find_param(cache_prefix + feed, unread_ctr); | |
257 | ||
258 | request_counters(); | |
259 | remove_splash(); | |
260 | ||
261 | } else { | |
262 | ||
263 | // if (!page_offset) { | |
264 | var feedr; | |
265 | ||
266 | if (is_cat) { | |
267 | feedr = $('FCAP-' + feed); | |
268 | } else { | |
269 | feedr = $('FEEDR-' + feed); | |
270 | } | |
271 | ||
272 | if (feedr && !$('FLL-' + feed)) { | |
273 | ||
274 | var img = $('FIMG-' + feed); | |
275 | ||
276 | if (!is_cat && img) { | |
277 | ||
278 | var cat_list = feedr.parentNode; | |
279 | ||
280 | if (!cat_list || Element.visible(cat_list)) { | |
281 | if (!img.src.match("indicator_white")) { | |
282 | img.alt = img.src; | |
283 | img.src = getInitParam("sign_progress"); | |
284 | } | |
285 | } else if (cat_list) { | |
286 | feed_cat_id = cat_list.id.replace("FCATLIST-", ""); | |
287 | ||
288 | if (!$('FLL-' + feed_cat_id)) { | |
289 | ||
290 | var ll = document.createElement('img'); | |
291 | ||
292 | ll.src = getInitParam("sign_progress_tiny"); | |
293 | ll.className = 'hlLoading'; | |
294 | ll.id = 'FLL-' + feed; | |
295 | ||
296 | $("FCAP-" + feed_cat_id).appendChild(ll); | |
297 | } | |
298 | } | |
299 | ||
300 | } else { | |
301 | ||
302 | if (!$('FLL-' + feed)) { | |
303 | var ll = document.createElement('img'); | |
304 | ||
305 | ll.src = getInitParam("sign_progress_tiny"); | |
306 | ll.className = 'hlLoading'; | |
307 | ll.id = 'FLL-' + feed; | |
308 | ||
309 | feedr.appendChild(ll); | |
310 | } | |
311 | } | |
312 | } | |
313 | // } | |
314 | ||
315 | new Ajax.Request("backend.php", { | |
316 | parameters: query, | |
317 | onComplete: function(transport) { | |
318 | headlines_callback2(transport, page_offset); | |
319 | } }); | |
320 | } | |
321 | ||
322 | } catch (e) { | |
323 | exception_error("viewfeed", e); | |
324 | } | |
325 | } | |
326 | ||
327 | function toggleCollapseCat_af(effect) { | |
328 | //var caption = elem.id.replace("FCATLIST-", ""); | |
329 | ||
330 | try { | |
331 | ||
332 | var elem = effect.element; | |
333 | var cat = elem.id.replace("FCATLIST-", ""); | |
334 | var cap = $("FCAP-" + cat); | |
335 | ||
336 | if (Element.visible(elem)) { | |
337 | cap.innerHTML = cap.innerHTML.replace("…", ""); | |
338 | } else { | |
339 | if (cap.innerHTML.lastIndexOf("…") != cap.innerHTML.length-3) { | |
340 | cap.innerHTML = cap.innerHTML + "…"; | |
341 | } | |
342 | } | |
343 | ||
344 | } catch (e) { | |
345 | exception_error("toggleCollapseCat_af", e); | |
346 | } | |
347 | } | |
348 | ||
349 | function toggleCollapseCat(cat) { | |
350 | try { | |
351 | ||
352 | var cat_elem = $("FCAT-" + cat); | |
353 | var cat_list = $("FCATLIST-" + cat).parentNode; | |
354 | var caption = $("FCAP-" + cat); | |
355 | ||
356 | Effect.toggle('FCATLIST-' + cat, 'blind', { duration: 0.5, | |
357 | afterFinish: toggleCollapseCat_af }); | |
358 | ||
359 | var img = cat_elem.getElementsByTagName("IMG")[0]; | |
360 | ||
361 | if (img.src.match("-collapse")) | |
362 | img.src = img.src.replace("-collapse", "-uncollapse") | |
363 | else | |
364 | img.src = img.src.replace("-uncollapse", "-collapse") | |
365 | ||
366 | new Ajax.Request("backend.php", | |
367 | { parameters: "backend.php?op=feeds&subop=collapse&cid=" + | |
368 | param_escape(cat) } ); | |
369 | ||
370 | local_collapse_cat(cat); | |
371 | ||
372 | } catch (e) { | |
373 | exception_error("toggleCollapseCat", e); | |
374 | } | |
375 | } | |
376 | ||
377 | function isCatCollapsed(cat) { | |
378 | try { | |
379 | return Element.visible("FCATLIST-" + cat); | |
380 | } catch (e) { | |
381 | exception_error("isCatCollapsed", e); | |
382 | } | |
383 | } | |
384 | ||
385 | function feedlist_dragsorted(ctr) { | |
386 | try { | |
387 | var cats = $$("#feedList > li[id*=FCAT-]"); | |
388 | var ordered_cats = []; | |
389 | ||
390 | cats.each(function(cat) { | |
391 | ordered_cats.push(cat.id.replace("FCAT-", "")); | |
392 | }); | |
393 | ||
394 | if (ordered_cats.length > 0) { | |
395 | ||
396 | var query = "?op=feeds&subop=catsort&corder=" + | |
397 | param_escape(ordered_cats.toString()); | |
398 | ||
399 | //console.log(query); | |
400 | ||
401 | new Ajax.Request("backend.php", { parameters: query }); | |
402 | } | |
403 | ||
404 | } catch (e) { | |
405 | exception_error("feedlist_dragsorted", e); | |
406 | } | |
407 | } | |
408 | ||
409 | function feedlist_init() { | |
410 | try { | |
411 | loading_set_progress(90); | |
412 | ||
413 | //console.log("in feedlist init"); | |
414 | ||
415 | hideOrShowFeeds(getInitParam("hide_read_feeds") == 1); | |
416 | document.onkeydown = hotkey_handler; | |
417 | document.onmousemove = mouse_move_handler; | |
418 | document.onmousedown = mouse_down_handler; | |
419 | document.onmouseup = mouse_up_handler; | |
420 | ||
421 | if (!offline_mode) setTimeout("timeout()", 1); | |
422 | ||
423 | setTimeout("hotkey_prefix_timeout()", 5*1000); | |
424 | ||
425 | if (getActiveFeedId()) { | |
426 | //console.log("some feed is open on feedlist refresh, reloading"); | |
427 | //setTimeout("viewCurrentFeed()", 100); | |
428 | } else { | |
429 | if (getInitParam("cdm_auto_catchup") != 1 && get_feed_unread(-3) > 0) { | |
430 | notify_silent_next(); | |
431 | setTimeout("viewfeed(-3)", 100); | |
432 | } else { | |
433 | setTimeout("viewfeed(-5)", 100); | |
434 | remove_splash(); | |
435 | } | |
436 | } | |
437 | ||
438 | if (getInitParam("theme") == "" || | |
439 | getInitParam("theme_options").match("hide_footer")) { | |
440 | setTimeout("hide_footer()", 5000); | |
441 | } | |
442 | ||
443 | init_collapsable_feedlist(getInitParam("theme")); | |
444 | ||
445 | toggle_sortable_feedlist(isFeedlistSortable()); | |
446 | ||
447 | } catch (e) { | |
448 | exception_error("feedlist/init", e); | |
449 | } | |
450 | } | |
451 | ||
452 | function hide_footer_af(effect) { | |
453 | try { | |
454 | var c = $("content-frame"); | |
455 | ||
456 | if (c) { | |
457 | c.style.bottom = "0px"; | |
458 | ||
459 | var ioa = $("inline_orig_article"); | |
460 | ||
461 | if (ioa) { | |
462 | ioa.height = c.offsetHeight; | |
463 | } | |
464 | ||
465 | } else { | |
466 | var h = $("headlines-frame"); | |
467 | ||
468 | if (h) { | |
469 | h.style.bottom = "0px"; | |
470 | } | |
471 | } | |
472 | ||
473 | } catch (e) { | |
474 | exception_error("hide_footer_af", e); | |
475 | } | |
476 | } | |
477 | ||
478 | function hide_footer() { | |
479 | try { | |
480 | if (Element.visible("footer")) { | |
481 | new Effect.Fade("footer", { afterFinish: hide_footer_af }); | |
482 | } | |
483 | } catch (e) { | |
484 | exception_error("hide_footer", e); | |
485 | } | |
486 | } | |
487 | ||
488 | function init_collapsable_feedlist() { | |
489 | try { | |
490 | //console.log("init_collapsable_feedlist"); | |
491 | ||
492 | var theme = getInitParam("theme"); | |
493 | var options = getInitParam("theme_options"); | |
494 | ||
495 | if (theme != "" && !options.match("collapse_feedlist")) return; | |
496 | ||
497 | var fbtn = $("collapse_feeds_btn"); | |
498 | ||
499 | if (fbtn) Element.show(fbtn); | |
500 | ||
501 | if (getInitParam("collapsed_feedlist") == 1) { | |
502 | collapse_feedlist(); | |
503 | } | |
504 | ||
505 | } catch (e) { | |
506 | exception_error("init_hidden_feedlist", e); | |
507 | } | |
508 | ||
509 | } | |
510 | ||
511 | function mouse_move_handler(e) { | |
512 | try { | |
513 | var client_y; | |
514 | var client_x; | |
515 | ||
516 | if (window.event) { | |
517 | client_y = window.event.clientY; | |
518 | client_x = window.event.clientX; | |
519 | } else if (e) { | |
520 | client_x = e.screenX; | |
521 | client_y = e.screenY; | |
522 | } | |
523 | ||
524 | if (mouse_is_down) { | |
525 | ||
526 | if (mouse_y == 0) mouse_y = client_y; | |
527 | if (mouse_x == 0) mouse_x = client_x; | |
528 | ||
529 | resize_headlines(mouse_x - client_x, mouse_y - client_y); | |
530 | ||
531 | mouse_y = client_y; | |
532 | mouse_x = client_x; | |
533 | ||
534 | return false; | |
535 | } | |
536 | ||
537 | } catch (e) { | |
538 | exception_error("mouse_move_handler", e); | |
539 | } | |
540 | } | |
541 | ||
542 | function enable_selection(b) { | |
543 | selection_disabled = !b; | |
544 | } | |
545 | ||
546 | function enable_resize(b) { | |
547 | resize_enabled = b; | |
548 | } | |
549 | ||
550 | function mouse_down_handler(e) { | |
551 | try { | |
552 | ||
553 | /* do not prevent right click */ | |
554 | if (e && e.button && e.button == 2) return; | |
555 | ||
556 | if (resize_enabled) { | |
557 | mouse_is_down = true; | |
558 | mouse_x = 0; | |
559 | mouse_y = 0; | |
560 | document.onselectstart = function() { return false; }; | |
561 | return false; | |
562 | } | |
563 | ||
564 | if (selection_disabled) { | |
565 | document.onselectstart = function() { return false; }; | |
566 | return false; | |
567 | } | |
568 | ||
569 | } catch (e) { | |
570 | exception_error("mouse_down_handler", e); | |
571 | } | |
572 | } | |
573 | ||
574 | function mouse_up_handler(e) { | |
575 | try { | |
576 | mouse_is_down = false; | |
577 | ||
578 | if (!selection_disabled) { | |
579 | document.onselectstart = null; | |
580 | var e = $("headlineActionsBody"); | |
581 | if (e) Element.hide(e); | |
582 | ||
583 | var e = $("offlineModeDrop"); | |
584 | if (e) Element.hide(e); | |
585 | ||
586 | } | |
587 | ||
588 | } catch (e) { | |
589 | exception_error("mouse_up_handler", e); | |
590 | } | |
591 | } | |
592 | ||
593 | function request_counters_real() { | |
594 | ||
595 | try { | |
596 | ||
597 | if (offline_mode) return; | |
598 | ||
599 | console.log("requesting counters..."); | |
600 | ||
601 | var query = "?op=rpc&subop=getAllCounters&seq=" + next_seq(); | |
602 | ||
603 | if (tagsAreDisplayed()) { | |
604 | query = query + "&omode=tl"; | |
605 | } else { | |
606 | query = query + "&omode=flc"; | |
607 | } | |
608 | ||
609 | new Ajax.Request("backend.php", { | |
610 | parameters: query, | |
611 | onComplete: function(transport) { | |
612 | try { | |
613 | handle_rpc_reply(transport); | |
614 | } catch (e) { | |
615 | exception_error("viewfeed/getcounters", e); | |
616 | } | |
617 | } }); | |
618 | ||
619 | } catch (e) { | |
620 | exception_error("request_counters_real", e); | |
621 | } | |
622 | } | |
623 | ||
624 | ||
625 | function request_counters() { | |
626 | ||
627 | try { | |
628 | ||
629 | if (getInitParam("bw_limit") == "1") return; | |
630 | ||
631 | var date = new Date(); | |
632 | var timestamp = Math.round(date.getTime() / 1000); | |
633 | ||
634 | if (timestamp - counters_last_request > 5) { | |
635 | console.log("scheduling request of counters..."); | |
636 | ||
637 | window.clearTimeout(counter_timeout_id); | |
638 | counter_timeout_id = window.setTimeout("request_counters_real()", 1000); | |
639 | ||
640 | counters_last_request = timestamp; | |
641 | } else { | |
642 | console.log("request_counters: rate limit reached: " + (timestamp - counters_last_request)); | |
643 | } | |
644 | ||
645 | } catch (e) { | |
646 | exception_error("request_counters", e); | |
647 | } | |
648 | } | |
649 | ||
650 | function displayNewContentPrompt(id) { | |
651 | try { | |
652 | ||
653 | var msg = "<a href='#' onclick='viewfeed("+id+")'>" + | |
654 | __("New articles available in this feed (click to show)") + "</a>"; | |
655 | ||
656 | msg = msg.replace("%s", getFeedName(id)); | |
657 | ||
658 | $('auxDlg').innerHTML = msg; | |
659 | ||
660 | new Effect.Appear('auxDlg', {duration : 0.5}); | |
661 | ||
662 | } catch (e) { | |
663 | exception_error("displayNewContentPrompt", e); | |
664 | } | |
665 | } | |
666 | ||
667 | function parse_counters(reply, scheduled_call) { | |
668 | try { | |
669 | ||
670 | var feeds_found = 0; | |
671 | ||
672 | var elems = JSON.parse(reply.firstChild.nodeValue); | |
673 | ||
674 | for (var l = 0; l < elems.length; l++) { | |
675 | ||
676 | var id = elems[l].id | |
677 | var kind = elems[l].kind; | |
678 | var ctr = parseInt(elems[l].counter) | |
679 | var error = elems[l].error; | |
680 | var has_img = elems[l].has_img; | |
681 | var updated = elems[l].updated; | |
682 | var title = elems[l].title; | |
683 | var xmsg = elems[l].xmsg; | |
684 | ||
685 | if (id == "global-unread") { | |
686 | ||
687 | if (ctr > global_unread) { | |
688 | offlineDownloadStart(1); | |
689 | } | |
690 | ||
691 | global_unread = ctr; | |
692 | updateTitle(); | |
693 | continue; | |
694 | } | |
695 | ||
696 | if (id == "subscribed-feeds") { | |
697 | feeds_found = ctr; | |
698 | continue; | |
699 | } | |
700 | ||
701 | if (kind && kind == "cat") { | |
702 | var catctr = $("FCATCTR-" + id); | |
703 | if (catctr) { | |
704 | catctr.innerHTML = "(" + ctr + ")"; | |
705 | if (ctr > 0) { | |
706 | catctr.addClassName("Unread"); | |
707 | } else { | |
708 | catctr.removeClassName("Unread"); | |
709 | } | |
710 | } | |
711 | continue; | |
712 | } | |
713 | ||
714 | var feedctr = $("FEEDCTR-" + id); | |
715 | var feedu = $("FEEDU-" + id); | |
716 | var feedr = $("FEEDR-" + id); | |
717 | var feed_img = $("FIMG-" + id); | |
718 | var feedlink = $("FEEDL-" + id); | |
719 | var feedupd = $("FLUPD-" + id); | |
720 | ||
721 | if (updated && feedlink) { | |
722 | if (error) { | |
723 | feedlink.title = __("Error:") + " " + error + " (" + updated + ")"; | |
724 | } else { | |
725 | feedlink.title = __("Updated:") + " " + updated; | |
726 | } | |
727 | } else if (!updated && feedlink) { | |
728 | feedlink.title = __("Updated:") + " " + __("Never"); | |
729 | } | |
730 | ||
731 | if (feedupd) { | |
732 | if (!updated) updated = ""; | |
733 | ||
734 | if (error) { | |
735 | if (xmsg) { | |
736 | feedupd.innerHTML = updated + " " + xmsg + " (Error)"; | |
737 | } else { | |
738 | feedupd.innerHTML = updated + " (Error)"; | |
739 | } | |
740 | } else { | |
741 | if (xmsg) { | |
742 | feedupd.innerHTML = updated + " (" + xmsg + ")"; | |
743 | } else { | |
744 | feedupd.innerHTML = updated; | |
745 | } | |
746 | } | |
747 | } | |
748 | ||
749 | if (has_img && feed_img) { | |
750 | if (!feed_img.src.match(id + ".ico")) { | |
751 | feed_img.src = getInitParam("icons_url") + "/" + id + ".ico"; | |
752 | } | |
753 | } | |
754 | ||
755 | if (feedlink && title) { | |
756 | feedlink.innerHTML = title; | |
757 | } | |
758 | ||
759 | if (feedctr && feedu && feedr) { | |
760 | ||
761 | // if (id == getActiveFeedId()) | |
762 | // console.log("HAS CTR: " + feedu.innerHTML + " GOT CTR: " + ctr + | |
763 | // " IS_SCHED: " + scheduled_call); | |
764 | ||
765 | if (parseInt(ctr) > 0 && | |
766 | parseInt(feedu.innerHTML) < parseInt(ctr) && | |
767 | id == getActiveFeedId() && scheduled_call) { | |
768 | ||
769 | displayNewContentPrompt(id); | |
770 | } | |
771 | ||
772 | var row_needs_hl = (ctr > 0 && ctr > parseInt(feedu.innerHTML)); | |
773 | ||
774 | feedu.innerHTML = ctr; | |
775 | ||
776 | if (error) { | |
777 | feedr.removeClassName("feed"); | |
778 | feedr.addClassName("error"); | |
779 | } else if (id > 0) { | |
780 | feedr.removeClassName("error"); | |
781 | feedr.addClassName("feed"); | |
782 | } | |
783 | ||
784 | if (ctr > 0) { | |
785 | feedctr.addClassName("Unread"); | |
786 | feedr.addClassName("Unread"); | |
787 | ||
788 | if (row_needs_hl && | |
789 | !getInitParam("theme_options").match('no_highlights')) { | |
790 | new Effect.Highlight(feedr, {duration: 1, startcolor: "#fff7d5", | |
791 | queue: { position:'end', scope: 'EFQ-' + id, limit: 1 } } ); | |
792 | ||
793 | cache_invalidate("F:" + id); | |
794 | } | |
795 | } else { | |
796 | feedctr.removeClassName("Unread"); | |
797 | feedr.removeClassName("Unread"); | |
798 | } | |
799 | } | |
800 | } | |
801 | ||
802 | hideOrShowFeeds(getInitParam("hide_read_feeds") == 1); | |
803 | ||
804 | var feeds_stored = number_of_feeds; | |
805 | ||
806 | //console.log("Feed counters, C: " + feeds_found + ", S:" + feeds_stored); | |
807 | ||
808 | if (feeds_stored != feeds_found) { | |
809 | number_of_feeds = feeds_found; | |
810 | ||
811 | if (feeds_stored != 0 && feeds_found != 0) { | |
812 | console.log("Subscribed feed number changed, refreshing feedlist"); | |
813 | setTimeout('updateFeedList(false, false)', 50); | |
814 | } | |
815 | } else { | |
816 | /* var fl = $("feeds-frame").innerHTML; | |
817 | if (fl) { | |
818 | cache_invalidate("FEEDLIST"); | |
819 | cache_inject("FEEDLIST", fl, getInitParam("num_feeds")); | |
820 | } */ | |
821 | } | |
822 | ||
823 | } catch (e) { | |
824 | exception_error("parse_counters", e); | |
825 | } | |
826 | } | |
827 | ||
828 | function get_feed_unread(id) { | |
829 | try { | |
830 | return parseInt($("FEEDU-" + id).innerHTML); | |
831 | } catch (e) { | |
832 | return -1; | |
833 | } | |
834 | } | |
835 | ||
836 | function get_cat_unread(id) { | |
837 | try { | |
838 | var ctr = $("FCATCTR-" + id).innerHTML; | |
839 | ctr = ctr.replace("(", ""); | |
840 | ctr = ctr.replace(")", ""); | |
841 | return parseInt(ctr); | |
842 | } catch (e) { | |
843 | return -1; | |
844 | } | |
845 | } | |
846 | ||
847 | function get_feed_entry_unread(elem) { | |
848 | ||
849 | var id = elem.id.replace("FEEDR-", ""); | |
850 | ||
851 | if (id <= 0) { | |
852 | return -1; | |
853 | } | |
854 | ||
855 | try { | |
856 | return parseInt($("FEEDU-" + id).innerHTML); | |
857 | } catch (e) { | |
858 | return -1; | |
859 | } | |
860 | } | |
861 | ||
862 | function get_feed_entry_name(elem) { | |
863 | var id = elem.id.replace("FEEDR-", ""); | |
864 | return getFeedName(id); | |
865 | } | |
866 | ||
867 | ||
868 | function resort_category(node, cat_mode) { | |
869 | ||
870 | try { | |
871 | ||
872 | //console.log("resort_category: " + node + " CM=" + cat_mode); | |
873 | ||
874 | var by_unread = feedsSortByUnread(); | |
875 | ||
876 | var list = node.getElementsByTagName("LI"); | |
877 | ||
878 | for (i = 0; i < list.length; i++) { | |
879 | ||
880 | for (j = i+1; j < list.length; j++) { | |
881 | ||
882 | var tmp_val = get_feed_entry_unread(list[i]); | |
883 | var cur_val = get_feed_entry_unread(list[j]); | |
884 | ||
885 | var tmp_name = get_feed_entry_name(list[i]).toLowerCase(); | |
886 | var cur_name = get_feed_entry_name(list[j]).toLowerCase(); | |
887 | ||
888 | /* we don't want to match FEEDR-0 - e.g. Archived articles */ | |
889 | ||
890 | var valid_pair = cat_mode || (list[i].id.match(/FEEDR-[1-9]/) && | |
891 | list[j].id.match(/FEEDR-[1-9]/)); | |
892 | ||
893 | if (valid_pair && ((by_unread && (cur_val > tmp_val)) || (!by_unread && (cur_name < tmp_name)))) { | |
894 | tempnode_i = list[i].cloneNode(true); | |
895 | tempnode_j = list[j].cloneNode(true); | |
896 | node.replaceChild(tempnode_i, list[j]); | |
897 | node.replaceChild(tempnode_j, list[i]); | |
898 | } | |
899 | } | |
900 | } | |
901 | ||
902 | } catch (e) { | |
903 | exception_error("resort_category", e); | |
904 | } | |
905 | ||
906 | } | |
907 | ||
908 | function resort_feedlist() { | |
909 | console.log("resort_feedlist"); | |
910 | ||
911 | if ($("FCATLIST--1")) { | |
912 | ||
913 | var lists = $$("#feedList ul[id*=FCATLIST]"); | |
914 | ||
915 | lists.each(function(list) { | |
916 | if (list.id != "FCATLIST--1") resort_category(list, true); | |
917 | }); | |
918 | ||
919 | } else { | |
920 | resort_category($("feedList"), false); | |
921 | } | |
922 | } | |
923 | ||
924 | function hideOrShowFeeds(hide) { | |
925 | ||
926 | try { | |
927 | ||
928 | if ($("FCATLIST--1")) { | |
929 | ||
930 | var lists = $$("#feedList ul[id*=FCATLIST]"); | |
931 | ||
932 | lists.each(function(list) { | |
933 | hideOrShowFeedsCategory(list.id.replace("FCATLIST-", ""), hide); | |
934 | }); | |
935 | ||
936 | } else { | |
937 | hideOrShowFeedsCategory(null, hide); | |
938 | } | |
939 | ||
940 | } catch (e) { | |
941 | exception_error("hideOrShowFeeds", e); | |
942 | } | |
943 | } | |
944 | ||
945 | function hideOrShowFeedsCategory(cat_id, hide) { | |
946 | try { | |
947 | ||
948 | var nodes; | |
949 | var cat_node; | |
950 | ||
951 | if (cat_id) { | |
952 | nodes = $$("#FCATLIST-" + cat_id + " > li"); | |
953 | cat_node = $("FCAT-" + cat_id); | |
954 | } else { | |
955 | nodes = $$("#feedList li"); | |
956 | } | |
957 | ||
958 | var cat_unread = 0; | |
959 | ||
960 | nodes.each(function(node) { | |
961 | ||
962 | var is_unread = node.hasClassName("Unread") || | |
963 | (node.hasClassName("virt") && | |
964 | getInitParam("hide_read_shows_special")) || | |
965 | node.hasClassName("error"); | |
966 | ||
967 | if (hide && !is_unread) { | |
968 | Effect.Fade(node, {duration : 0.3, | |
969 | queue: { position: 'end', scope: 'FFADE-' + node.id, limit: 1 }}); | |
970 | } else { | |
971 | Element.show(node); | |
972 | ++cat_unread; | |
973 | } | |
974 | ||
975 | }); | |
976 | ||
977 | if (cat_node) { | |
978 | if (hide && cat_unread == 0) { | |
979 | Effect.Fade(cat_node, {duration : 0.3, | |
980 | queue: { position: 'end', scope: 'CFADE-' + cat_node.id, limit: 1 }}); | |
981 | } else { | |
982 | Element.show(cat_node); | |
983 | } | |
984 | } | |
985 | ||
986 | } catch (e) { | |
987 | exception_error("hideOrShowFeedsCategory", e); | |
988 | } | |
989 | } | |
990 | ||
991 | function getFeedName(id, is_cat) { | |
992 | var e; | |
993 | ||
994 | if (is_cat) { | |
995 | e = $("FCATN-" + id); | |
996 | } else { | |
997 | e = $("FEEDN-" + id); | |
998 | } | |
999 | if (e) { | |
1000 | return e.innerHTML.stripTags(); | |
1001 | } else { | |
1002 | return null; | |
1003 | } | |
1004 | } | |
1005 | ||
1006 | function getNextUnreadCat(id) { | |
1007 | try { | |
1008 | var rows = $$("#feedList li[id*=FCAT]"); | |
1009 | var unread_cats = []; | |
1010 | ||
1011 | rows.each(function(row) { | |
1012 | var cat_id = row.id.replace("FCAT-", ""); | |
1013 | ||
1014 | if (Element.visible(row) && get_cat_unread(cat_id) > 0) | |
1015 | unread_cats.push(parseInt(cat_id)); | |
1016 | }); | |
1017 | ||
1018 | console.log(unread_cats); | |
1019 | ||
1020 | var idx = unread_cats.indexOf(id); | |
1021 | ||
1022 | if (idx != -1 && idx < unread_cats.length-1) { | |
1023 | return unread_cats[idx+1]; | |
1024 | } else { | |
1025 | return unread_cats[0]; | |
1026 | } | |
1027 | ||
1028 | } catch (e) { | |
1029 | exception_error("getNextUnreadCat", e); | |
1030 | } | |
1031 | } | |
1032 | ||
1033 | function getRelativeFeedId2(id, is_cat, direction, unread_only) { | |
1034 | try { | |
1035 | ||
1036 | // alert(id + " IC: " + is_cat + " D: " + direction + " U: " + unread_only); | |
1037 | ||
1038 | var rows = $$("#feedList li"); | |
1039 | var feeds = new Array(); | |
1040 | ||
1041 | for (var i = 0; i < rows.length; i++) { | |
1042 | if (rows[i].id.match("FEEDR-")) { | |
1043 | ||
1044 | if (rows[i].id == "FEEDR-" + id && !is_cat || (Element.visible(rows[i]) && Element.visible(rows[i].parentNode))) { | |
1045 | ||
1046 | if (!unread_only || | |
1047 | (rows[i].hasClassName("Unread") || rows[i].id == "FEEDR-" + id)) { | |
1048 | feeds.push(rows[i].id.replace("FEEDR-", "")); | |
1049 | } | |
1050 | } | |
1051 | } | |
1052 | ||
1053 | if (rows[i].id.match("FCAT-")) { | |
1054 | if (rows[i].id == "FCAT-" + id && is_cat || (Element.visible(rows[i]) && Element.visible(rows[i].parentNode))) { | |
1055 | ||
1056 | var cat_id = parseInt(rows[i].id.replace("FCAT-", "")); | |
1057 | ||
1058 | if (cat_id >= 0) { | |
1059 | if (!unread_only || get_cat_unread(cat_id) > 0) { | |
1060 | feeds.push("CAT:"+cat_id); | |
1061 | } | |
1062 | } | |
1063 | } | |
1064 | } | |
1065 | } | |
1066 | ||
1067 | // alert(feeds.toString()); | |
1068 | ||
1069 | if (!id) { | |
1070 | if (direction == "next") { | |
1071 | return feeds.shift(); | |
1072 | } else { | |
1073 | return feeds.pop(); | |
1074 | } | |
1075 | } else { | |
1076 | if (direction == "next") { | |
1077 | if (is_cat) id = "CAT:" + id; | |
1078 | var idx = feeds.indexOf(id); | |
1079 | if (idx != -1 && idx < feeds.length) { | |
1080 | return feeds[idx+1]; | |
1081 | } else { | |
1082 | return getRelativeFeedId2(false, is_cat, direction, unread_only); | |
1083 | } | |
1084 | } else { | |
1085 | if (is_cat) id = "CAT:" + id; | |
1086 | var idx = feeds.indexOf(id); | |
1087 | if (idx > 0) { | |
1088 | return feeds[idx-1]; | |
1089 | } else { | |
1090 | return getRelativeFeedId2(false, is_cat, direction, unread_only); | |
1091 | } | |
1092 | } | |
1093 | ||
1094 | } | |
1095 | ||
1096 | } catch (e) { | |
1097 | exception_error("getRelativeFeedId2", e); | |
1098 | } | |
1099 | } | |
1100 | ||
1101 | function clean_feed_selections() { | |
1102 | try { | |
1103 | $$("#feedList li").invoke('removeClassName', 'Selected'); | |
1104 | } catch (e) { | |
1105 | exception_error("clean_feed_selections", e); | |
1106 | } | |
1107 | } | |
1108 | ||
1109 | function feedsSortByUnread() { | |
1110 | return feeds_sort_by_unread; | |
1111 | } | |
1112 | ||
1113 |