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