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