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