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