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