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