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