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