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