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