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