]> git.wh0rd.org - tt-rss.git/blob - viewfeed.js
view: update offline feedlist counters
[tt-rss.git] / viewfeed.js
1 var active_post_id = false;
2 var last_article_view = false;
3 var active_real_feed_id = false;
4
5 // FIXME: kludges, needs proper implementation
6 var _reload_feedlist_after_view = false;
7
8 var _cdm_wd_timeout = false;
9 var _cdm_wd_vishist = new Array();
10
11 var article_cache = new Array();
12
13 var vgroup_last_feed = false;
14 var post_under_pointer = false;
15
16 var last_requested_article = false;
17
18 function catchup_callback2(transport, callback) {
19 try {
20 debug("catchup_callback2 " + transport + ", " + callback);
21 notify("");
22 all_counters_callback2(transport);
23 if (callback) {
24 setTimeout(callback, 10);
25 }
26 } catch (e) {
27 exception_error("catchup_callback2", e, transport);
28 }
29 }
30
31 function clean_feed_selections() {
32 try {
33 var feeds = document.getElementById("feedList").getElementsByTagName("LI");
34
35 for (var i = 0; i < feeds.length; i++) {
36 if (feeds[i].id && feeds[i].id.match("FEEDR-")) {
37 feeds[i].className = feeds[i].className.replace("Selected", "");
38 }
39 if (feeds[i].id && feeds[i].id.match("FCAT-")) {
40 feeds[i].className = feeds[i].className.replace("Selected", "");
41 }
42 }
43 } catch (e) {
44 exception_error("clean_feed_selections", e);
45 }
46 }
47
48 function headlines_callback2(transport, feed_cur_page) {
49 try {
50
51 loading_set_progress(100);
52
53 debug("headlines_callback2 [page=" + feed_cur_page + "]");
54
55 if (!transport_error_check(transport)) return;
56
57 clean_feed_selections();
58
59 var is_cat = false;
60 var feed_id = false;
61
62 if (transport.responseXML) {
63 var headlines = transport.responseXML.getElementsByTagName("headlines")[0];
64 if (headlines) {
65 is_cat = headlines.getAttribute("is_cat");
66 feed_id = headlines.getAttribute("id");
67 setActiveFeedId(feed_id, is_cat);
68 }
69 }
70
71 if (!is_cat) {
72 var feedr = document.getElementById("FEEDR-" + feed_id);
73 if (feedr && !feedr.className.match("Selected")) {
74 feedr.className = feedr.className + "Selected";
75 }
76 } else {
77 var feedr = document.getElementById("FCAT-" + feed_id);
78 if (feedr && !feedr.className.match("Selected")) {
79 feedr.className = feedr.className + "Selected";
80 }
81 }
82
83 var f = document.getElementById("headlines-frame");
84 try {
85 if (feed_cur_page == 0) {
86 debug("resetting headlines scrollTop");
87 f.scrollTop = 0;
88 }
89 } catch (e) { };
90
91 if (transport.responseXML) {
92 var headlines = transport.responseXML.getElementsByTagName("headlines")[0];
93 var headlines_count_obj = transport.responseXML.getElementsByTagName("headlines-count")[0];
94 var headlines_unread_obj = transport.responseXML.getElementsByTagName("headlines-unread")[0];
95 var disable_cache_obj = transport.responseXML.getElementsByTagName("disable-cache")[0];
96
97 var vgroup_last_feed_obj = transport.responseXML.getElementsByTagName("vgroup-last-feed")[0];
98
99 var headlines_count = headlines_count_obj.getAttribute("value");
100 var headlines_unread = headlines_unread_obj.getAttribute("value");
101 var disable_cache = disable_cache_obj.getAttribute("value") != "0";
102
103 vgroup_last_feed = vgroup_last_feed_obj.getAttribute("value");
104
105 if (headlines_count == 0) {
106 _infscroll_disable = 1;
107 } else {
108 _infscroll_disable = 0;
109 }
110
111 var counters = transport.responseXML.getElementsByTagName("counters")[0];
112 var articles = transport.responseXML.getElementsByTagName("article");
113 var runtime_info = transport.responseXML.getElementsByTagName("runtime-info");
114
115 if (feed_cur_page == 0) {
116 if (headlines) {
117 f.innerHTML = headlines.firstChild.nodeValue;
118
119 var cache_prefix = "";
120
121 if (is_cat) {
122 cache_prefix = "C:";
123 } else {
124 cache_prefix = "F:";
125 }
126
127 cache_invalidate(cache_prefix + feed_id);
128
129 if (!disable_cache) {
130 cache_inject(cache_prefix + feed_id,
131 headlines.firstChild.nodeValue, headlines_unread);
132 }
133
134 } else {
135 debug("headlines_callback: returned no data");
136 f.innerHTML = "<div class='whiteBox'>" + __('Could not update headlines (missing XML data)') + "</div>";
137
138 }
139 } else {
140 if (headlines) {
141 if (headlines_count > 0) {
142 debug("adding some more headlines...");
143
144 var c = document.getElementById("headlinesList");
145
146 if (!c) {
147 c = document.getElementById("headlinesInnerContainer");
148 }
149
150 var ids = getSelectedArticleIds2();
151
152 c.innerHTML = c.innerHTML + headlines.firstChild.nodeValue;
153
154 debug("restore selected ids: " + ids);
155
156 for (var i = 0; i < ids.length; i++) {
157 markHeadline(ids[i]);
158 }
159
160 } else {
161 debug("no new headlines received");
162 }
163 } else {
164 debug("headlines_callback: returned no data");
165 notify_error("Error while trying to load more headlines");
166 }
167
168 }
169
170 if (articles) {
171 for (var i = 0; i < articles.length; i++) {
172 var a_id = articles[i].getAttribute("id");
173 debug("found id: " + a_id);
174 cache_inject(a_id, articles[i].firstChild.nodeValue);
175 }
176 } else {
177 debug("no cached articles received");
178 }
179
180 if (counters) {
181 debug("parsing piggybacked counters: " + counters);
182 parse_counters(counters, false);
183 } else {
184 debug("counters container not found in reply, requesting...");
185 request_counters();
186 }
187
188 if (runtime_info) {
189 debug("parsing runtime info: " + runtime_info[0]);
190 parse_runtime_info(runtime_info[0]);
191 } else {
192 debug("counters container not found in reply");
193 }
194
195 } else {
196 debug("headlines_callback: returned no XML object");
197 f.innerHTML = "<div class='whiteBox'>" + __('Could not update headlines (missing XML object)') + "</div>";
198 }
199
200 if (typeof correctPNG != 'undefined') {
201 correctPNG();
202 }
203
204 if (_cdm_wd_timeout) window.clearTimeout(_cdm_wd_timeout);
205
206 if (!document.getElementById("headlinesList") &&
207 getActiveFeedId() != -3 &&
208 getInitParam("cdm_auto_catchup") == 1) {
209 debug("starting CDM watchdog");
210 _cdm_wd_timeout = window.setTimeout("cdmWatchdog()", 5000);
211 _cdm_wd_vishist = new Array();
212 } else {
213 debug("not in CDM mode or watchdog disabled");
214 }
215
216 _feed_cur_page = feed_cur_page;
217 _infscroll_request_sent = 0;
218
219 notify("");
220
221 remove_splash();
222
223 } catch (e) {
224 exception_error("headlines_callback2", e, transport);
225 }
226 }
227
228 function render_article(article) {
229 try {
230 var f = document.getElementById("content-frame");
231 try {
232 f.scrollTop = 0;
233 } catch (e) { };
234
235 var fi = document.getElementById("content-insert");
236
237 try {
238 fi.scrollTop = 0;
239 } catch (e) { };
240
241 fi.innerHTML = article;
242
243 } catch (e) {
244 exception_error("render_article", e);
245 }
246 }
247
248 function showArticleInHeadlines(id) {
249
250 try {
251
252 cleanSelected("headlinesList");
253
254 var crow = document.getElementById("RROW-" + id);
255
256 if (!crow) return;
257
258 var article_is_unread = crow.className.match("Unread");
259
260 crow.className = crow.className.replace("Unread", "");
261
262 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
263
264 var upd_img_pic = document.getElementById("FUPDPIC-" + id);
265
266 var cache_prefix = "";
267
268 if (activeFeedIsCat()) {
269 cache_prefix = "C:";
270 } else {
271 cache_prefix = "F:";
272 }
273
274 var view_mode = false;
275
276 try {
277 view_mode = document.forms['main_toolbar_form'].view_mode;
278 view_mode = view_mode[view_mode.selectedIndex].value;
279 } catch (e) {
280 //
281 }
282
283 if (upd_img_pic && upd_img_pic.src.match("updated.png")) {
284 upd_img_pic.src = "images/blank_icon.gif";
285
286 cache_invalidate(cache_prefix + getActiveFeedId());
287
288 cache_inject(cache_prefix + getActiveFeedId(),
289 document.getElementById("headlines-frame").innerHTML,
290 get_feed_unread(getActiveFeedId()));
291
292 } else if (article_is_unread && view_mode == "all_articles") {
293
294 cache_invalidate(cache_prefix + getActiveFeedId());
295
296 cache_inject(cache_prefix + getActiveFeedId(),
297 document.getElementById("headlines-frame").innerHTML,
298 get_feed_unread(getActiveFeedId())-1);
299
300 } else if (article_is_unread) {
301 cache_invalidate(cache_prefix + getActiveFeedId());
302 }
303
304 markHeadline(id);
305
306 } catch (e) {
307 exception_error("showArticleInHeadlines", e);
308 }
309 }
310
311 function article_callback2(transport, id, feed_id) {
312 try {
313 debug("article_callback2 " + id);
314
315 if (transport.responseXML) {
316
317 if (!transport_error_check(transport)) return;
318
319 debug("looking for articles to cache...");
320
321 var articles = transport.responseXML.getElementsByTagName("article");
322
323 for (var i = 0; i < articles.length; i++) {
324 var a_id = articles[i].getAttribute("id");
325
326 debug("found id: " + a_id);
327
328 if (a_id == active_post_id) {
329 debug("active article, rendering...");
330 render_article(articles[i].firstChild.nodeValue);
331 }
332
333 cache_inject(a_id, articles[i].firstChild.nodeValue);
334 }
335
336 if (id != last_requested_article) {
337 debug("requested article id is out of sequence, aborting");
338 return;
339 }
340
341 active_real_feed_id = feed_id;
342 active_post_id = id;
343
344 showArticleInHeadlines(id);
345
346 if (db) {
347 db.execute("UPDATE articles SET unread = 0 WHERE id = ?", [id]);
348 }
349
350 var reply = transport.responseXML.firstChild.firstChild;
351
352 } else {
353 debug("article_callback: returned no XML object");
354 //var f = document.getElementById("content-frame");
355 //f.innerHTML = "<div class='whiteBox'>" + __('Could not display article (missing XML object)') + "</div>";
356 }
357
358 var date = new Date();
359 last_article_view = date.getTime() / 1000;
360
361 if (typeof correctPNG != 'undefined') {
362 correctPNG();
363 }
364
365 if (_reload_feedlist_after_view) {
366 setTimeout('updateFeedList(false, false)', 50);
367 _reload_feedlist_after_view = false;
368 } else {
369 if (transport.responseXML) {
370 var counters = transport.responseXML.getElementsByTagName("counters")[0];
371
372 if (counters) {
373 debug("parsing piggybacked counters: " + counters);
374 parse_counters(counters, false);
375 } else {
376 debug("counters container not found in reply, requesting...");
377 request_counters();
378 }
379 }
380 }
381
382 notify("");
383 } catch (e) {
384 exception_error("article_callback2", e, transport);
385 }
386 }
387
388 function view_offline(id, feed_id) {
389 try {
390
391 enableHotkeys();
392 showArticleInHeadlines(id);
393
394 if (db) {
395 db.execute("UPDATE articles SET unread = 0 WHERE id = ?", [id]);
396 }
397
398 render_article("FIXME");
399 update_feedlist_counters();
400
401 return false;
402
403 } catch (e) {
404 exception_error("view_offline", e);
405 }
406 }
407
408 function view(id, feed_id, skip_history) {
409
410 try {
411 debug("loading article: " + id + "/" + feed_id);
412
413 if (offline_mode) return view_offline(id, feed_id);
414
415 var cached_article = cache_find(id);
416
417 debug("cache check result: " + (cached_article != false));
418
419 enableHotkeys();
420
421 //setActiveFeedId(feed_id);
422
423 var query = "backend.php?op=view&id=" + param_escape(id) +
424 "&feed=" + param_escape(feed_id);
425
426 var date = new Date();
427
428 var neighbor_ids = getRelativePostIds(active_post_id);
429
430 /* only request uncached articles */
431
432 var cids_to_request = Array();
433
434 for (var i = 0; i < neighbor_ids.length; i++) {
435 if (!cache_check(neighbor_ids[i])) {
436 cids_to_request.push(neighbor_ids[i]);
437 }
438 }
439
440 debug("additional ids: " + cids_to_request.toString());
441
442 /* additional info for piggyback counters */
443
444 if (tagsAreDisplayed()) {
445 query = query + "&omode=lt";
446 } else {
447 query = query + "&omode=flc";
448 }
449
450 var date = new Date();
451 var timestamp = Math.round(date.getTime() / 1000);
452 query = query + "&ts=" + timestamp;
453
454 query = query + "&cids=" + cids_to_request.toString();
455
456 var crow = document.getElementById("RROW-" + id);
457 var article_is_unread = crow.className.match("Unread");
458
459 if (!async_counters_work) {
460 query = query + "&csync=true";
461 }
462
463 showArticleInHeadlines(id);
464
465 if (!cached_article) {
466
467 notify_progress("Loading, please wait...", true);
468
469 } else if (cached_article && article_is_unread) {
470
471 query = query + "&mode=prefetch";
472
473 render_article(cached_article);
474
475 } else if (cached_article) {
476
477 query = query + "&mode=prefetch_old";
478 render_article(cached_article);
479
480 }
481
482 cache_expire();
483
484 last_requested_article = id;
485
486 new Ajax.Request(query, {
487 onComplete: function(transport) {
488 article_callback2(transport, id, feed_id);
489 } });
490
491 return false;
492
493 } catch (e) {
494 exception_error("view", e);
495 }
496 }
497
498 function tMark(id) {
499 return toggleMark(id);
500 }
501
502 function tPub(id) {
503 return togglePub(id);
504 }
505
506 function tMark_afh_off(effect) {
507 try {
508 var elem = effect.effects[0].element;
509
510 debug("tMark_afh_off : " + elem.id);
511
512 if (elem) {
513 elem.src = elem.src.replace("mark_set", "mark_unset");
514 elem.alt = __("Star article");
515 Element.show(elem);
516 }
517
518 } catch (e) {
519 exception_error("tMark_afh_off", e);
520 }
521 }
522
523 function tPub_afh_off(effect) {
524 try {
525 var elem = effect.effects[0].element;
526
527 debug("tPub_afh_off : " + elem.id);
528
529 if (elem) {
530 elem.src = elem.src.replace("pub_set", "pub_unset");
531 elem.alt = __("Publish article");
532 Element.show(elem);
533 }
534
535 } catch (e) {
536 exception_error("tPub_afh_off", e);
537 }
538 }
539
540 function toggleMark(id, client_only, no_effects) {
541
542 try {
543
544 var query = "backend.php?op=rpc&id=" + id + "&subop=mark";
545
546 query = query + "&afid=" + getActiveFeedId();
547
548 if (tagsAreDisplayed()) {
549 query = query + "&omode=tl";
550 } else {
551 query = query + "&omode=flc";
552 }
553
554 var mark_img = document.getElementById("FMPIC-" + id);
555
556 if (!mark_img) return;
557
558 var vfeedu = document.getElementById("FEEDU--1");
559 var crow = document.getElementById("RROW-" + id);
560
561 if (mark_img.src.match("mark_unset")) {
562 mark_img.src = mark_img.src.replace("mark_unset", "mark_set");
563 mark_img.alt = __("Unstar article");
564 query = query + "&mark=1";
565
566 if (db) {
567 db.execute("UPDATE articles SET marked = 1 WHERE id = ?", [id]);
568 }
569
570 } else {
571 //mark_img.src = "images/mark_unset.png";
572 mark_img.alt = __("Please wait...");
573 query = query + "&mark=0";
574
575 if (document.getElementById("headlinesList") && !no_effects) {
576 Effect.Puff(mark_img, {duration : 0.25, afterFinish: tMark_afh_off});
577 } else {
578 mark_img.src = mark_img.src.replace("mark_set", "mark_unset");
579 mark_img.alt = __("Star article");
580 }
581
582 if (db) {
583 db.execute("UPDATE articles SET marked = 0 WHERE id = ?", [id]);
584 }
585
586 }
587
588 if (!client_only) {
589 debug(query);
590
591 new Ajax.Request(query, {
592 onComplete: function(transport) {
593 all_counters_callback2(transport);
594 } });
595
596 }
597
598 } catch (e) {
599 exception_error("toggleMark", e);
600 }
601 }
602
603 function togglePub(id, client_only, no_effects) {
604
605 try {
606
607 var query = "backend.php?op=rpc&id=" + id + "&subop=publ";
608
609 query = query + "&afid=" + getActiveFeedId();
610
611 if (tagsAreDisplayed()) {
612 query = query + "&omode=tl";
613 } else {
614 query = query + "&omode=flc";
615 }
616
617 var mark_img = document.getElementById("FPPIC-" + id);
618
619 if (!mark_img) return;
620
621 var vfeedu = document.getElementById("FEEDU--2");
622 var crow = document.getElementById("RROW-" + id);
623
624 if (mark_img.src.match("pub_unset")) {
625 mark_img.src = mark_img.src.replace("pub_unset", "pub_set");
626 mark_img.alt = __("Unpublish article");
627 query = query + "&pub=1";
628
629
630 } else {
631 //mark_img.src = "images/pub_unset.png";
632 mark_img.alt = __("Please wait...");
633 query = query + "&pub=0";
634
635 if (document.getElementById("headlinesList") && !no_effects) {
636 Effect.Puff(mark_img, {duration : 0.25, afterFinish: tPub_afh_off});
637 } else {
638 mark_img.src = mark_img.src.replace("pub_set", "pub_unset");
639 mark_img.alt = __("Publish article");
640 }
641 }
642
643 if (!client_only) {
644 new Ajax.Request(query, {
645 onComplete: function(transport) {
646 all_counters_callback2(transport);
647 } });
648 }
649
650 } catch (e) {
651
652 exception_error("togglePub", e);
653 }
654 }
655
656 function correctHeadlinesOffset(id) {
657
658 try {
659
660 var hlist = document.getElementById("headlinesList");
661 var container = document.getElementById("headlinesInnerContainer");
662 var row = document.getElementById("RROW-" + id);
663
664 var viewport = container.offsetHeight;
665
666 var rel_offset_top = row.offsetTop - container.scrollTop;
667 var rel_offset_bottom = row.offsetTop + row.offsetHeight - container.scrollTop;
668
669 debug("Rtop: " + rel_offset_top + " Rbtm: " + rel_offset_bottom);
670 debug("Vport: " + viewport);
671
672 if (rel_offset_top <= 0 || rel_offset_top > viewport) {
673 container.scrollTop = row.offsetTop;
674 } else if (rel_offset_bottom > viewport) {
675
676 /* doesn't properly work with Opera in some cases because
677 Opera fucks up element scrolling */
678
679 container.scrollTop = row.offsetTop + row.offsetHeight - viewport;
680 }
681
682 } catch (e) {
683 exception_error("correctHeadlinesOffset", e);
684 }
685
686 }
687
688 function moveToPost(mode) {
689
690 try {
691
692 var rows;
693
694 if (isCdmMode()) {
695 rows = cdmGetVisibleArticles();
696 } else {
697 rows = getVisibleHeadlineIds();
698 }
699
700 var prev_id = false;
701 var next_id = false;
702
703 if (!document.getElementById('RROW-' + active_post_id)) {
704 active_post_id = false;
705 }
706
707 if (active_post_id == false) {
708 next_id = getFirstVisibleHeadlineId();
709 prev_id = getLastVisibleHeadlineId();
710 } else {
711 for (var i = 0; i < rows.length; i++) {
712 if (rows[i] == active_post_id) {
713 prev_id = rows[i-1];
714 next_id = rows[i+1];
715 }
716 }
717 }
718
719 if (mode == "next") {
720 if (next_id) {
721 if (isCdmMode()) {
722
723 if (!cdmArticleIsActuallyVisible(next_id)) {
724 cdmScrollToArticleId(next_id);
725 }
726 cdmSelectArticles("none");
727 toggleUnread(next_id, 0, true);
728 toggleSelected(next_id);
729
730 } else {
731 correctHeadlinesOffset(next_id);
732 view(next_id, getActiveFeedId());
733 }
734 }
735 }
736
737 if (mode == "prev") {
738 if (prev_id) {
739 if (isCdmMode()) {
740 cdmScrollToArticleId(prev_id);
741 cdmSelectArticles("none");
742 toggleUnread(prev_id, 0, true);
743 toggleSelected(prev_id);
744 } else {
745 correctHeadlinesOffset(prev_id);
746 view(prev_id, getActiveFeedId());
747 }
748 }
749 }
750
751 } catch (e) {
752 exception_error("moveToPost", e);
753 }
754 }
755
756 function toggleSelected(id) {
757 try {
758
759 var cb = document.getElementById("RCHK-" + id);
760
761 var row = document.getElementById("RROW-" + id);
762 if (row) {
763 var nc = row.className;
764
765 if (!nc.match("Selected")) {
766 nc = nc + "Selected";
767 if (cb) {
768 cb.checked = true;
769 }
770
771 // In CDM basically last selected article == active article
772 if (isCdmMode()) active_post_id = id;
773 } else {
774 nc = nc.replace("Selected", "");
775 if (cb) {
776 cb.checked = false;
777 }
778
779 }
780
781 row.className = nc;
782 }
783 } catch (e) {
784 exception_error("toggleSelected", e);
785 }
786 }
787
788 function toggleUnread_afh(effect) {
789 try {
790
791 var elem = effect.element;
792 elem.style.backgroundColor = "";
793
794 } catch (e) {
795 exception_error("toggleUnread_afh", e);
796 }
797 }
798
799 function toggleUnread(id, cmode, effect) {
800 try {
801
802 var row = document.getElementById("RROW-" + id);
803 if (row) {
804 var nc = row.className;
805 var is_selected = row.className.match("Selected");
806 nc = nc.replace("Unread", "");
807 nc = nc.replace("Selected", "");
808
809 // since we are removing selection from the object, uncheck
810 // corresponding checkbox
811
812 var cb = document.getElementById("RCHK-" + id);
813 if (cb) {
814 cb.checked = false;
815 }
816
817 // NOTE: I'm not sure that resetting selection here is a feature -fox
818
819 if (cmode == undefined || cmode == 2) {
820 if (row.className.match("Unread")) {
821 row.className = nc;
822
823 if (effect) {
824 new Effect.Highlight(row, {duration: 1, startcolor: "#fff7d5",
825 afterFinish: toggleUnread_afh,
826 queue: { position:'end', scope: 'TMRQ-' + id, limit: 1 } } );
827 }
828
829 } else {
830 row.className = nc + "Unread";
831 }
832 } else if (cmode == 0) {
833 row.className = nc;
834
835 if (effect) {
836 new Effect.Highlight(row, {duration: 1, startcolor: "#fff7d5",
837 afterFinish: toggleUnread_afh,
838 queue: { position:'end', scope: 'TMRQ-' + id, limit: 1 } } );
839 }
840 } else if (cmode == 1) {
841 row.className = nc + "Unread";
842 }
843
844 // Disable unmarking as selected for the time being (16.05.08) -fox
845 if (is_selected) row.className = row.className + "Selected";
846
847 if (cmode == undefined) cmode = 2;
848
849 var query = "backend.php?op=rpc&subop=catchupSelected&ids=" +
850 param_escape(id) + "&cmode=" + param_escape(cmode);
851
852 // notify_progress("Loading, please wait...");
853
854 new Ajax.Request(query, {
855 onComplete: function(transport) {
856 all_counters_callback2(transport);
857 } });
858
859 }
860
861
862 } catch (e) {
863 exception_error("toggleUnread", e);
864 }
865 }
866
867 function selectionRemoveLabel(id) {
868 try {
869
870 var ids = getSelectedArticleIds2();
871
872 if (ids.length == 0) {
873 alert(__("No articles are selected."));
874 return;
875 }
876
877 // var ok = confirm(__("Remove selected articles from label?"));
878
879 // if (ok) {
880
881 var query = "backend.php?op=rpc&subop=removeFromLabel&ids=" +
882 param_escape(ids.toString()) + "&lid=" + param_escape(id);
883
884 // notify_progress("Loading, please wait...");
885
886 cache_invalidate("F:" + (-11 - id));
887
888 new Ajax.Request(query, {
889 onComplete: function(transport) {
890 show_labels_in_headlines(transport);
891 all_counters_callback2(transport);
892 } });
893
894 // }
895
896 } catch (e) {
897 exception_error("selectionAssignLabel", e);
898
899 }
900 }
901
902 function selectionAssignLabel(id) {
903 try {
904
905 var ids = getSelectedArticleIds2();
906
907 if (ids.length == 0) {
908 alert(__("No articles are selected."));
909 return;
910 }
911
912 // var ok = confirm(__("Assign selected articles to label?"));
913
914 // if (ok) {
915
916 cache_invalidate("F:" + (-11 - id));
917
918 var query = "backend.php?op=rpc&subop=assignToLabel&ids=" +
919 param_escape(ids.toString()) + "&lid=" + param_escape(id);
920
921 // notify_progress("Loading, please wait...");
922
923 new Ajax.Request(query, {
924 onComplete: function(transport) {
925 show_labels_in_headlines(transport);
926 all_counters_callback2(transport);
927 } });
928
929 // }
930
931 } catch (e) {
932 exception_error("selectionAssignLabel", e);
933
934 }
935 }
936
937 function selectionToggleUnread(cdm_mode, set_state, callback_func, no_error) {
938 try {
939 var rows;
940
941 if (cdm_mode) {
942 rows = cdmGetSelectedArticles();
943 } else {
944 rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
945 }
946
947 if (rows.length == 0 && !no_error) {
948 alert(__("No articles are selected."));
949 return;
950 }
951
952 for (i = 0; i < rows.length; i++) {
953 var row = document.getElementById("RROW-" + rows[i]);
954 if (row) {
955 var nc = row.className;
956 nc = nc.replace("Unread", "");
957 nc = nc.replace("Selected", "");
958
959 if (set_state == undefined) {
960 if (row.className.match("Unread")) {
961 row.className = nc + "Selected";
962 } else {
963 row.className = nc + "UnreadSelected";
964 }
965 }
966
967 if (set_state == false) {
968 row.className = nc + "Selected";
969 }
970
971 if (set_state == true) {
972 row.className = nc + "UnreadSelected";
973 }
974 }
975 }
976
977 if (rows.length > 0) {
978
979 var cmode = "";
980
981 if (set_state == undefined) {
982 cmode = "2";
983 } else if (set_state == true) {
984 cmode = "1";
985 } else if (set_state == false) {
986 cmode = "0";
987 }
988
989 var query = "backend.php?op=rpc&subop=catchupSelected&ids=" +
990 param_escape(rows.toString()) + "&cmode=" + cmode;
991
992 notify_progress("Loading, please wait...");
993
994 new Ajax.Request(query, {
995 onComplete: function(transport) {
996 catchup_callback2(transport, callback_func);
997 } });
998
999 }
1000
1001 } catch (e) {
1002 exception_error("selectionToggleUnread", e);
1003 }
1004 }
1005
1006 function selectionToggleMarked(cdm_mode) {
1007 try {
1008
1009 var rows;
1010
1011 if (cdm_mode) {
1012 rows = cdmGetSelectedArticles();
1013 } else {
1014 rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
1015 }
1016
1017 if (rows.length == 0) {
1018 alert(__("No articles are selected."));
1019 return;
1020 }
1021
1022 for (i = 0; i < rows.length; i++) {
1023 toggleMark(rows[i], true, true);
1024 }
1025
1026 if (rows.length > 0) {
1027
1028 var query = "backend.php?op=rpc&subop=markSelected&ids=" +
1029 param_escape(rows.toString()) + "&cmode=2";
1030
1031 query = query + "&afid=" + getActiveFeedId();
1032
1033 /* if (tagsAreDisplayed()) {
1034 query = query + "&omode=tl";
1035 } else {
1036 query = query + "&omode=flc";
1037 } */
1038
1039 query = query + "&omode=lc";
1040
1041 new Ajax.Request(query, {
1042 onComplete: function(transport) {
1043 all_counters_callback2(transport);
1044 } });
1045
1046 }
1047
1048 } catch (e) {
1049 exception_error("selectionToggleMarked", e);
1050 }
1051 }
1052
1053 function selectionTogglePublished(cdm_mode) {
1054 try {
1055
1056 var rows;
1057
1058 if (cdm_mode) {
1059 rows = cdmGetSelectedArticles();
1060 } else {
1061 rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
1062 }
1063
1064 if (rows.length == 0) {
1065 alert(__("No articles are selected."));
1066 return;
1067 }
1068
1069 for (i = 0; i < rows.length; i++) {
1070 togglePub(rows[i], true, true);
1071 }
1072
1073 if (rows.length > 0) {
1074
1075 var query = "backend.php?op=rpc&subop=publishSelected&ids=" +
1076 param_escape(rows.toString()) + "&cmode=2";
1077
1078 query = query + "&afid=" + getActiveFeedId();
1079
1080 /* if (tagsAreDisplayed()) {
1081 query = query + "&omode=tl";
1082 } else {
1083 query = query + "&omode=flc";
1084 } */
1085
1086 query = query + "&omode=lc";
1087
1088 new Ajax.Request(query, {
1089 onComplete: function(transport) {
1090 all_counters_callback2(transport);
1091 } });
1092
1093 }
1094
1095 } catch (e) {
1096 exception_error("selectionToggleMarked", e);
1097 }
1098 }
1099
1100 function cdmGetSelectedArticles() {
1101 var sel_articles = new Array();
1102 var container = document.getElementById("headlinesInnerContainer");
1103
1104 for (i = 0; i < container.childNodes.length; i++) {
1105 var child = container.childNodes[i];
1106
1107 if (child.id && child.id.match("RROW-") && child.className.match("Selected")) {
1108 var c_id = child.id.replace("RROW-", "");
1109 sel_articles.push(c_id);
1110 }
1111 }
1112
1113 return sel_articles;
1114 }
1115
1116 function cdmGetVisibleArticles() {
1117 var sel_articles = new Array();
1118 var container = document.getElementById("headlinesInnerContainer");
1119
1120 if (!container) return sel_articles;
1121
1122 for (i = 0; i < container.childNodes.length; i++) {
1123 var child = container.childNodes[i];
1124
1125 if (child.id && child.id.match("RROW-")) {
1126 var c_id = child.id.replace("RROW-", "");
1127 sel_articles.push(c_id);
1128 }
1129 }
1130
1131 return sel_articles;
1132 }
1133
1134 function cdmGetUnreadArticles() {
1135 var sel_articles = new Array();
1136 var container = document.getElementById("headlinesInnerContainer");
1137
1138 for (i = 0; i < container.childNodes.length; i++) {
1139 var child = container.childNodes[i];
1140
1141 if (child.id && child.id.match("RROW-") && child.className.match("Unread")) {
1142 var c_id = child.id.replace("RROW-", "");
1143 sel_articles.push(c_id);
1144 }
1145 }
1146
1147 return sel_articles;
1148 }
1149
1150
1151 // mode = all,none,unread
1152 function cdmSelectArticles(mode) {
1153 var container = document.getElementById("headlinesInnerContainer");
1154
1155 for (i = 0; i < container.childNodes.length; i++) {
1156 var child = container.childNodes[i];
1157
1158 if (child.id && child.id.match("RROW-")) {
1159 var aid = child.id.replace("RROW-", "");
1160
1161 var cb = document.getElementById("RCHK-" + aid);
1162
1163 if (mode == "all") {
1164 if (!child.className.match("Selected")) {
1165 child.className = child.className + "Selected";
1166 cb.checked = true;
1167 }
1168 } else if (mode == "unread") {
1169 if (child.className.match("Unread") && !child.className.match("Selected")) {
1170 child.className = child.className + "Selected";
1171 cb.checked = true;
1172 }
1173 } else {
1174 child.className = child.className.replace("Selected", "");
1175 cb.checked = false;
1176 }
1177 }
1178 }
1179 }
1180
1181 function catchupPage() {
1182
1183 var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
1184
1185 var str = __("Mark all visible articles in %s as read?");
1186
1187 str = str.replace("%s", fn);
1188
1189 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
1190 return;
1191 }
1192
1193 if (document.getElementById("headlinesList")) {
1194 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, 'Unread', true);
1195 selectionToggleUnread(false, false, 'viewCurrentFeed()', true);
1196 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
1197 } else {
1198 cdmSelectArticles('all');
1199 selectionToggleUnread(true, false, 'viewCurrentFeed()', true)
1200 cdmSelectArticles('none');
1201 }
1202 }
1203
1204 function catchupSelection() {
1205
1206 try {
1207
1208 var rows;
1209
1210 if (document.getElementById("headlinesList")) {
1211 rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
1212 } else {
1213 rows = cdmGetSelectedArticles();
1214 }
1215
1216 if (rows.length == 0) {
1217 alert(__("No articles are selected."));
1218 return;
1219 }
1220
1221
1222 var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
1223
1224 var str = __("Mark %d selected articles in %s as read?");
1225
1226 str = str.replace("%d", rows.length);
1227 str = str.replace("%s", fn);
1228
1229 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
1230 return;
1231 }
1232
1233 if (document.getElementById("headlinesList")) {
1234 selectionToggleUnread(false, false, 'viewCurrentFeed()', true);
1235 // selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
1236 } else {
1237 selectionToggleUnread(true, false, 'viewCurrentFeed()', true)
1238 // cdmSelectArticles('none');
1239 }
1240
1241 } catch (e) {
1242 exception_error("catchupSelection", e);
1243 }
1244 }
1245
1246 function editArticleTags(id, feed_id, cdm_enabled) {
1247 displayDlg('editArticleTags', id);
1248 }
1249
1250
1251 function tag_saved_callback(transport) {
1252 try {
1253 debug("in tag_saved_callback");
1254
1255 closeInfoBox();
1256 notify("");
1257
1258 if (tagsAreDisplayed()) {
1259 _reload_feedlist_after_view = true;
1260 }
1261
1262
1263 if (transport.responseXML) {
1264 var tags_str = transport.responseXML.getElementsByTagName("tags-str")[0];
1265
1266 if (tags_str) {
1267 var id = tags_str.getAttribute("id");
1268
1269 if (id) {
1270 var tags = document.getElementById("ATSTR-" + id);
1271 if (tags) {
1272 tags.innerHTML = tags_str.firstChild.nodeValue;
1273 }
1274 }
1275 }
1276 }
1277
1278 } catch (e) {
1279 exception_error("tag_saved_callback", e);
1280 }
1281 }
1282
1283 function editTagsSave() {
1284
1285 notify_progress("Saving article tags...");
1286
1287 var form = document.forms["tag_edit_form"];
1288
1289 var query = Form.serialize("tag_edit_form");
1290
1291 query = "backend.php?op=rpc&subop=setArticleTags&" + query;
1292
1293 debug(query);
1294
1295 new Ajax.Request(query, {
1296 onComplete: function(transport) {
1297 tag_saved_callback(transport);
1298 } });
1299
1300 }
1301
1302 function editTagsInsert() {
1303 try {
1304
1305 var form = document.forms["tag_edit_form"];
1306
1307 var found_tags = form.found_tags;
1308 var tags_str = form.tags_str;
1309
1310 var tag = found_tags[found_tags.selectedIndex].value;
1311
1312 if (tags_str.value.length > 0 &&
1313 tags_str.value.lastIndexOf(", ") != tags_str.value.length - 2) {
1314
1315 tags_str.value = tags_str.value + ", ";
1316 }
1317
1318 tags_str.value = tags_str.value + tag + ", ";
1319
1320 found_tags.selectedIndex = 0;
1321
1322 } catch (e) {
1323 exception_error("editTagsInsert", e);
1324 }
1325 }
1326
1327 function cdmScrollViewport(where) {
1328 debug("cdmScrollViewport: " + where);
1329
1330 var ctr = document.getElementById("headlinesInnerContainer");
1331
1332 if (!ctr) return;
1333
1334 if (where == "bottom") {
1335 ctr.scrollTop = ctr.scrollHeight;
1336 } else {
1337 ctr.scrollTop = where;
1338 }
1339 }
1340
1341 function cdmArticleIsBelowViewport(id) {
1342 try {
1343 var ctr = document.getElementById("headlinesInnerContainer");
1344 var e = document.getElementById("RROW-" + id);
1345
1346 if (!e || !ctr) return;
1347
1348 // article starts below viewport
1349
1350 if (ctr.scrollTop < e.offsetTop) {
1351 return true;
1352 } else {
1353 return false;
1354 }
1355
1356 } catch (e) {
1357 exception_error("cdmArticleIsVisible", e);
1358 }
1359 }
1360
1361 function cdmArticleIsAboveViewport(id) {
1362 try {
1363 var ctr = document.getElementById("headlinesInnerContainer");
1364 var e = document.getElementById("RROW-" + id);
1365
1366 if (!e || !ctr) return;
1367
1368 // article starts above viewport
1369
1370 if (ctr.scrollTop > e.offsetTop + e.offsetHeight) {
1371 return true;
1372 } else {
1373 return false;
1374 }
1375
1376 } catch (e) {
1377 exception_error("cdmArticleIsVisible", e);
1378 }
1379 }
1380
1381 function cdmScrollToArticleId(id) {
1382 try {
1383 var ctr = document.getElementById("headlinesInnerContainer");
1384 var e = document.getElementById("RROW-" + id);
1385
1386 if (!e || !ctr) return;
1387
1388 ctr.scrollTop = e.offsetTop;
1389
1390 } catch (e) {
1391 exception_error("cdmScrollToArticleId", e);
1392 }
1393 }
1394
1395 function cdmArticleIsActuallyVisible(id) {
1396 try {
1397 var ctr = document.getElementById("headlinesInnerContainer");
1398 var e = document.getElementById("RROW-" + id);
1399
1400 if (!e || !ctr) return;
1401
1402 // article fits in viewport OR article is longer than viewport and
1403 // its bottom is visible
1404
1405 if (ctr.scrollTop <= e.offsetTop && e.offsetTop + e.offsetHeight <=
1406 ctr.scrollTop + ctr.offsetHeight) {
1407
1408 return true;
1409
1410 } else if (e.offsetHeight > ctr.offsetHeight &&
1411 e.offsetTop + e.offsetHeight >= ctr.scrollTop &&
1412 e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight) {
1413
1414 return true;
1415
1416 }
1417
1418 return false;
1419
1420 } catch (e) {
1421 exception_error("cdmArticleIsVisible", e);
1422 }
1423 }
1424
1425 function cdmWatchdog() {
1426
1427 try {
1428
1429 var ctr = document.getElementById("headlinesInnerContainer");
1430
1431 if (!ctr) return;
1432
1433 var ids = new Array();
1434
1435 var e = ctr.firstChild;
1436
1437 while (e) {
1438 if (e.className && e.className == "cdmArticleUnread" && e.id &&
1439 e.id.match("RROW-")) {
1440
1441 // article fits in viewport OR article is longer than viewport and
1442 // its bottom is visible
1443
1444 if (ctr.scrollTop <= e.offsetTop && e.offsetTop + e.offsetHeight <=
1445 ctr.scrollTop + ctr.offsetHeight) {
1446
1447 // debug(e.id + " is visible " + e.offsetTop + "." +
1448 // (e.offsetTop + e.offsetHeight) + " vs " + ctr.scrollTop + "." +
1449 // (ctr.scrollTop + ctr.offsetHeight));
1450
1451 ids.push(e.id.replace("RROW-", ""));
1452
1453 } else if (e.offsetHeight > ctr.offsetHeight &&
1454 e.offsetTop + e.offsetHeight >= ctr.scrollTop &&
1455 e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight) {
1456
1457 ids.push(e.id.replace("RROW-", ""));
1458
1459 }
1460
1461 // method 2: article bottom is visible and is in upper 1/2 of the viewport
1462
1463 /* if (e.offsetTop + e.offsetHeight >= ctr.scrollTop &&
1464 e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight/2) {
1465
1466 ids.push(e.id.replace("RROW-", ""));
1467
1468 } */
1469
1470 }
1471
1472 e = e.nextSibling;
1473 }
1474
1475 debug("cdmWatchdog, ids= " + ids.toString());
1476
1477 if (ids.length > 0) {
1478
1479 for (var i = 0; i < ids.length; i++) {
1480 var e = document.getElementById("RROW-" + ids[i]);
1481 if (e) {
1482 e.className = e.className.replace("Unread", "");
1483 }
1484 }
1485
1486 var query = "backend.php?op=rpc&subop=catchupSelected&ids=" +
1487 param_escape(ids.toString()) + "&cmode=0";
1488
1489 new Ajax.Request(query, {
1490 onComplete: function(transport) {
1491 all_counters_callback2(transport);
1492 } });
1493
1494 }
1495
1496 _cdm_wd_timeout = window.setTimeout("cdmWatchdog()", 4000);
1497
1498 } catch (e) {
1499 exception_error("cdmWatchdog", e);
1500 }
1501
1502 }
1503
1504
1505 function cache_inject(id, article, param) {
1506 try {
1507 if (!cache_check_param(id, param)) {
1508 debug("cache_article: miss: " + id + " [p=" + param + "]");
1509
1510
1511 if (db) {
1512
1513 var date = new Date();
1514 var ts = Math.round(date.getTime() / 1000);
1515
1516 db.execute("INSERT INTO cache (id, article, param, added) VALUES (?, ?, ?, ?)",
1517 [id, article, param, ts]);
1518 } else {
1519
1520 var cache_obj = new Array();
1521
1522 cache_obj["id"] = id;
1523 cache_obj["data"] = article;
1524 cache_obj["param"] = param;
1525
1526 article_cache.push(cache_obj);
1527 }
1528
1529 } else {
1530 debug("cache_article: hit: " + id + " [p=" + param + "]");
1531 }
1532 } catch (e) {
1533 exception_error("cache_inject", e);
1534 }
1535 }
1536
1537 function cache_find(id) {
1538
1539 if (db) {
1540 var rs = db.execute("SELECT article FROM cache WHERE id = ?", [id]);
1541
1542 if (rs.isValidRow()) {
1543 return rs.field(0);
1544 }
1545
1546 } else {
1547 for (var i = 0; i < article_cache.length; i++) {
1548 if (article_cache[i]["id"] == id) {
1549 return article_cache[i]["data"];
1550 }
1551 }
1552 }
1553 return false;
1554 }
1555
1556 function cache_find_param(id, param) {
1557
1558 if (db) {
1559 var rs = db.execute("SELECT article FROM cache WHERE id = ? AND param = ?",
1560 [id, param]);
1561
1562 if (rs.isValidRow()) {
1563 return rs.field(0);
1564 }
1565
1566 } else {
1567 for (var i = 0; i < article_cache.length; i++) {
1568 if (article_cache[i]["id"] == id && article_cache[i]["param"] == param) {
1569 return article_cache[i]["data"];
1570 }
1571 }
1572 }
1573 return false;
1574 }
1575
1576 function cache_check(id) {
1577
1578 if (db) {
1579 var rs = db.execute("SELECT COUNT(*) AS c FROM cache WHERE id = ?",
1580 [id]);
1581
1582 if (rs.isValidRow()) {
1583 return rs.field(0) != "0";
1584 }
1585
1586 } else {
1587 for (var i = 0; i < article_cache.length; i++) {
1588 if (article_cache[i]["id"] == id) {
1589 return true;
1590 }
1591 }
1592 }
1593 return false;
1594 }
1595
1596 function cache_check_param(id, param) {
1597
1598 if (db) {
1599 var rs = db.execute("SELECT COUNT(*) AS c FROM cache WHERE id = ? AND param = ?",
1600 [id, param]);
1601
1602 if (rs.isValidRow()) {
1603 return rs.field(0) != "0";
1604 }
1605
1606 } else {
1607 for (var i = 0; i < article_cache.length; i++) {
1608 if (article_cache[i]["id"] == id && article_cache[i]["param"] == param) {
1609 return true;
1610 }
1611 }
1612 }
1613 return false;
1614 }
1615
1616 function cache_expire() {
1617 if (db) {
1618 var date = new Date();
1619 var ts = Math.round(date.getTime() / 1000);
1620
1621 db.execute("DELETE FROM cache WHERE added < ? - 1800 AND id LIKE 'FEEDLIST'", [ts]);
1622 db.execute("DELETE FROM cache WHERE added < ? - 600 AND (id LIKE 'F:%' OR id LIKE 'C:%')", [ts]);
1623 db.execute("DELETE FROM cache WHERE added < ? - 86400", [ts]);
1624
1625
1626 } else {
1627 while (article_cache.length > 25) {
1628 article_cache.shift();
1629 }
1630 }
1631 }
1632
1633 function cache_empty() {
1634 article_cache = new Array();
1635 }
1636
1637 function cache_invalidate(id) {
1638 try {
1639
1640 if (db) {
1641 rs = db.execute("DELETE FROM cache WHERE id = ?", [id]);
1642 return rs.rowsAffected != 0;
1643 } else {
1644
1645 var i = 0
1646
1647 while (i < article_cache.length) {
1648 if (article_cache[i]["id"] == id) {
1649 debug("cache_invalidate: removed id " + id);
1650 article_cache.splice(i, 1);
1651 return true;
1652 }
1653 i++;
1654 }
1655 }
1656
1657 debug("cache_invalidate: id not found: " + id);
1658 return false;
1659 } catch (e) {
1660 exception_error("cache_invalidate", e);
1661 }
1662 }
1663
1664 function getActiveArticleId() {
1665 return active_post_id;
1666 }
1667
1668 function cdmClicked(id) {
1669 try {
1670 var elem = document.getElementById("RROW-" + id);
1671
1672 if (elem) {
1673 var id = elem.id.replace("RROW-", "");
1674 active_post_id = id;
1675
1676 cdmSelectArticles("none");
1677 toggleUnread(id, 0, true);
1678 toggleSelected(id);
1679
1680 }
1681 } catch (e) {
1682 exception_error("cdmClicked", e);
1683 }
1684 }
1685
1686 function preload_article_callback(transport) {
1687 try {
1688 if (transport.responseXML) {
1689 var articles = transport.responseXML.getElementsByTagName("article");
1690
1691 for (var i = 0; i < articles.length; i++) {
1692 var id = articles[i].getAttribute("id");
1693 if (!cache_check(id)) {
1694 cache_inject(id, articles[i].firstChild.nodeValue);
1695 debug("preloaded article: " + id);
1696 }
1697 }
1698 }
1699 } catch (e) {
1700 exception_error("preload_article_callback", e);
1701 }
1702 }
1703
1704 function preloadArticleUnderPointer(id) {
1705 try {
1706 if (getInitParam("bw_limit") == "1") return;
1707
1708 if (post_under_pointer == id && !cache_check(id)) {
1709
1710 debug("trying to preload article " + id);
1711
1712 var neighbor_ids = getRelativePostIds(id, 1);
1713
1714 /* only request uncached articles */
1715
1716 var cids_to_request = Array();
1717
1718 for (var i = 0; i < neighbor_ids.length; i++) {
1719 if (!cache_check(neighbor_ids[i])) {
1720 cids_to_request.push(neighbor_ids[i]);
1721 }
1722 }
1723 debug("additional ids: " + cids_to_request.toString());
1724
1725 cids_to_request.push(id);
1726
1727 var query = "backend.php?op=rpc&subop=getArticles&ids=" +
1728 cids_to_request.toString();
1729 new Ajax.Request(query, {
1730 onComplete: function(transport) {
1731 preload_article_callback(transport);
1732 } });
1733 }
1734 } catch (e) {
1735 exception_error("preloadArticleUnderPointer", e);
1736 }
1737 }
1738
1739 function postMouseIn(id) {
1740 try {
1741 if (post_under_pointer != id) {
1742 post_under_pointer = id;
1743 if (!isCdmMode()) {
1744 window.setTimeout("preloadArticleUnderPointer(" + id + ")", 250);
1745 }
1746 }
1747
1748 } catch (e) {
1749 exception_error("postMouseIn", e);
1750 }
1751 }
1752
1753 function postMouseOut(id) {
1754 try {
1755 post_under_pointer = false;
1756 } catch (e) {
1757 exception_error("postMouseOut", e);
1758 }
1759 }
1760
1761 function headlines_scroll_handler() {
1762 try {
1763
1764 var e = document.getElementById("headlinesInnerContainer");
1765
1766 // don't do infinite scrolling when Limit == All
1767
1768 var toolbar_form = document.forms["main_toolbar_form"];
1769
1770 var limit = toolbar_form.limit[toolbar_form.limit.selectedIndex];
1771 if (limit.value != 0) {
1772
1773 debug((e.scrollTop + e.offsetHeight) + " vs " + e.scrollHeight + " dis? " +
1774 _infscroll_disable);
1775
1776 if (e.scrollTop + e.offsetHeight > e.scrollHeight - 100) {
1777 if (!_infscroll_disable) {
1778 debug("more cowbell!");
1779 viewNextFeedPage();
1780 }
1781 }
1782 }
1783
1784 } catch (e) {
1785 exception_error("headlines_scroll_handler", e);
1786 }
1787 }
1788
1789 function catchupRelativeToArticle(below) {
1790
1791 try {
1792
1793
1794 if (!getActiveArticleId()) {
1795 alert(__("No article is selected."));
1796 return;
1797 }
1798
1799 var visible_ids;
1800
1801 if (document.getElementById("headlinesList")) {
1802 visible_ids = getVisibleHeadlineIds();
1803 } else {
1804 visible_ids = cdmGetVisibleArticles();
1805 }
1806
1807 var ids_to_mark = new Array();
1808
1809 if (!below) {
1810 for (var i = 0; i < visible_ids.length; i++) {
1811 if (visible_ids[i] != getActiveArticleId()) {
1812 var e = document.getElementById("RROW-" + visible_ids[i]);
1813
1814 if (e && e.className.match("Unread")) {
1815 ids_to_mark.push(visible_ids[i]);
1816 }
1817 } else {
1818 break;
1819 }
1820 }
1821 } else {
1822 for (var i = visible_ids.length-1; i >= 0; i--) {
1823 if (visible_ids[i] != getActiveArticleId()) {
1824 var e = document.getElementById("RROW-" + visible_ids[i]);
1825
1826 if (e && e.className.match("Unread")) {
1827 ids_to_mark.push(visible_ids[i]);
1828 }
1829 } else {
1830 break;
1831 }
1832 }
1833 }
1834
1835 if (ids_to_mark.length == 0) {
1836 alert(__("No articles found to mark"));
1837 } else {
1838 var msg = __("Mark %d article(s) as read?").replace("%d", ids_to_mark.length);
1839
1840 if (confirm(msg)) {
1841
1842 for (var i = 0; i < ids_to_mark.length; i++) {
1843 var e = document.getElementById("RROW-" + ids_to_mark[i]);
1844 e.className = e.className.replace("Unread", "");
1845 }
1846
1847 var query = "backend.php?op=rpc&subop=catchupSelected&ids=" +
1848 param_escape(ids_to_mark.toString()) + "&cmode=0";
1849
1850 new Ajax.Request(query, {
1851 onComplete: function(transport) {
1852 catchup_callback2(transport);
1853 } });
1854
1855 }
1856 }
1857
1858 } catch (e) {
1859 exception_error("catchupRelativeToArticle", e);
1860 }
1861 }
1862
1863 function cdmExpandArticle(a_id) {
1864 try {
1865 var id = 'CICD-' + a_id;
1866
1867 try {
1868 Element.hide("CEXC-" + a_id);
1869 } catch (e) { }
1870
1871 Effect.Appear(id, {duration : 0.5,
1872 beforeStart: function(effect) {
1873 var h_id = 'CICH-' + a_id;
1874 var h_elem = document.getElementById(h_id);
1875 if (h_elem) { h_elem.style.display = "none"; }
1876
1877 toggleUnread(a_id, 0);
1878 }});
1879
1880
1881 } catch (e) {
1882 exception_error("appearBlockElementF", e);
1883 }
1884
1885 }
1886
1887 function fixHeadlinesOrder(ids) {
1888 try {
1889 for (var i = 0; i < ids.length; i++) {
1890 var e = document.getElementById("RROW-" + ids[i]);
1891
1892 if (e) {
1893 if (i % 2 == 0) {
1894 e.className = e.className.replace("even", "odd");
1895 } else {
1896 e.className = e.className.replace("odd", "even");
1897 }
1898 }
1899 }
1900 } catch (e) {
1901 exception_error("fixHeadlinesOrder", e);
1902 }
1903 }
1904
1905 function hideReadHeadlines() {
1906 try {
1907
1908 var ids = false;
1909 var vis_ids = new Array();
1910
1911 if (document.getElementById("headlinesList")) {
1912 ids = getVisibleHeadlineIds();
1913 } else {
1914 ids = cdmGetVisibleArticles();
1915 }
1916
1917 var read_headlines_visible = true;
1918
1919 for (var i = 0; i < ids.length; i++) {
1920 var row = document.getElementById("RROW-" + ids[i]);
1921
1922 if (row && row.className) {
1923 if (read_headlines_visible) {
1924 if (row.className.match("Unread") || row.className.match("Selected")) {
1925 Element.show(row);
1926 vis_ids.push(ids[i]);
1927 } else {
1928 //Effect.Fade(row, {duration : 0.3});
1929 Element.hide(row);
1930 }
1931 } else {
1932 Element.show(row);
1933 vis_ids.push(ids[i]);
1934 }
1935 }
1936 }
1937
1938 fixHeadlinesOrder(vis_ids);
1939
1940 read_headlines_visible = !read_headlines_visible;
1941
1942 } catch (e) {
1943 exception_error("hideReadHeadlines", e);
1944 }
1945 }
1946
1947 function invertHeadlineSelection() {
1948 try {
1949 var rows = new Array();
1950 var r = false;
1951
1952 if (!isCdmMode()) {
1953 r = document.getElementsByTagName("TR");
1954 } else {
1955 r = document.getElementsByTagName("DIV");
1956 }
1957
1958 for (var i = 0; i < r.length; i++) {
1959 if (r[i].id && r[i].id.match("RROW-")) {
1960 rows.push(r[i]);
1961 }
1962 }
1963
1964 for (var i = 0; i < rows.length; i++) {
1965 var nc = rows[i].className;
1966 var id = rows[i].id.replace("RROW-", "");
1967 var cb = document.getElementById("RCHK-" + id);
1968
1969 if (!rows[i].className.match("Selected")) {
1970 nc = nc + "Selected";
1971 cb.checked = true;
1972 } else {
1973 nc = nc.replace("Selected", "");
1974 cb.checked = false;
1975 }
1976
1977 rows[i].className = nc;
1978
1979 }
1980
1981 } catch (e) {
1982 exception_error("invertHeadlineSelection", e);
1983 }
1984 }
1985
1986 function getArticleUnderPointer() {
1987 return post_under_pointer;
1988 }
1989
1990 function zoomToArticle(id) {
1991 try {
1992 var w = window.open("backend.php?op=view&mode=zoom&id=" + param_escape(id),
1993 "ttrss_zoom_" + id,
1994 "status=0,toolbar=0,location=0,width=450,height=300,scrollbars=1,menubar=0");
1995
1996 } catch (e) {
1997 exception_error("zoomToArticle", e);
1998 }
1999 }
2000
2001 function showOriginalArticleInline(id) {
2002 try {
2003
2004 var query = "backend.php?op=rpc&subop=getArticleLink&id=" + id;
2005
2006 notify_progress("Loading, please wait...", true);
2007
2008 new Ajax.Request(query, {
2009 onComplete: function(transport) {
2010
2011 if (transport.responseXML) {
2012
2013 var link = transport.responseXML.getElementsByTagName("link")[0];
2014 var id = transport.responseXML.getElementsByTagName("id")[0];
2015
2016 notify("");
2017
2018 if (link && id) {
2019 link = link.firstChild.nodeValue;
2020
2021 var ci = document.getElementById("content-insert");
2022
2023 var tmp = "<iframe id=\"inline_orig_article\" width=\""+ci.offsetWidth+"\" height=\""+ci.offsetHeight+"\" style=\"border-width : 0px;\" src=\""+link+"\"></iframe>";
2024
2025 render_article(tmp);
2026
2027 }
2028 }
2029 } });
2030
2031 } catch (e) {
2032 exception_error("showOriginalArticleInline", e);
2033 }
2034 }
2035
2036
2037 function scrollArticle(offset) {
2038 try {
2039 if (!isCdmMode()) {
2040 var ci = document.getElementById("content-insert");
2041 if (ci) {
2042 ci.scrollTop += offset;
2043 }
2044 } else {
2045 var hi = document.getElementById("headlinesInnerContainer");
2046 if (hi) {
2047 hi.scrollTop += offset;
2048 }
2049
2050 }
2051 } catch (e) {
2052 exception_error("scrollArticle", e);
2053 }
2054 }
2055
2056 function show_labels_in_headlines(transport) {
2057 try {
2058 if (transport.responseXML) {
2059 var info = transport.responseXML.getElementsByTagName("info-for-headlines")[0];
2060
2061 var elems = info.getElementsByTagName("entry");
2062
2063 for (var l = 0; l < elems.length; l++) {
2064 var e_id = elems[l].getAttribute("id");
2065
2066 if (e_id) {
2067
2068 var ctr = document.getElementById("HLLCTR-" + e_id);
2069
2070 if (ctr) {
2071 ctr.innerHTML = elems[l].firstChild.nodeValue;
2072 }
2073 }
2074
2075 }
2076
2077 }
2078 } catch (e) {
2079 exception_error("show_labels_in_headlines", e);
2080
2081 }
2082 }
2083
2084 function toggleHeadlineActions() {
2085 try {
2086 var e = document.getElementById("headlineActionsBody");
2087 var p = document.getElementById("headlineActionsDrop");
2088
2089 if (!Element.visible(e)) {
2090 Element.show(e);
2091 } else {
2092 Element.hide(e);
2093 }
2094
2095 e.scrollTop = 0;
2096 e.style.left = (p.offsetLeft + 1) + "px";
2097 // e.style.top = (p.offsetTop + p.offsetHeight - 1) + "px";
2098
2099 } catch (e) {
2100 exception_error("toggleHeadlineActions", e);
2101 }
2102 }