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