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