]> git.wh0rd.org - tt-rss.git/blob - viewfeed.js
fix preference tree elements not being properly clickable in Firefox
[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, feed_id, cdm_enabled) {
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
1086 function editTagsSave() {
1087
1088 notify_progress("Saving article tags...");
1089
1090 var form = document.forms["tag_edit_form"];
1091
1092 var query = Form.serialize("tag_edit_form");
1093
1094 query = "?op=rpc&subop=setArticleTags&" + query;
1095
1096 console.log(query);
1097
1098 new Ajax.Request("backend.php", {
1099 parameters: query,
1100 onComplete: function(transport) {
1101 try {
1102 //console.log("tags saved...");
1103
1104 closeInfoBox();
1105 notify("");
1106
1107 if (transport.responseXML) {
1108 var tags_str = transport.responseXML.getElementsByTagName("tags-str")[0];
1109
1110 if (tags_str) {
1111 var id = tags_str.getAttribute("id");
1112
1113 if (id) {
1114 var tags = $("ATSTR-" + id);
1115 if (tags) {
1116 tags.innerHTML = tags_str.firstChild.nodeValue;
1117 }
1118
1119 cache_invalidate(id);
1120 }
1121 }
1122 }
1123
1124 } catch (e) {
1125 exception_error("editTagsSave", e);
1126 }
1127 } });
1128 }
1129
1130 function editTagsInsert() {
1131 try {
1132
1133 var form = document.forms["tag_edit_form"];
1134
1135 var found_tags = form.found_tags;
1136 var tags_str = form.tags_str;
1137
1138 var tag = found_tags[found_tags.selectedIndex].value;
1139
1140 if (tags_str.value.length > 0 &&
1141 tags_str.value.lastIndexOf(", ") != tags_str.value.length - 2) {
1142
1143 tags_str.value = tags_str.value + ", ";
1144 }
1145
1146 tags_str.value = tags_str.value + tag + ", ";
1147
1148 found_tags.selectedIndex = 0;
1149
1150 } catch (e) {
1151 exception_error("editTagsInsert", e);
1152 }
1153 }
1154
1155 function cdmScrollToArticleId(id) {
1156 try {
1157 var ctr = $("headlines-frame");
1158 var e = $("RROW-" + id);
1159
1160 if (!e || !ctr) return;
1161
1162 ctr.scrollTop = e.offsetTop;
1163
1164 } catch (e) {
1165 exception_error("cdmScrollToArticleId", e);
1166 }
1167 }
1168
1169 function cdmWatchdog() {
1170
1171 try {
1172
1173 var ctr = $("headlines-frame");
1174
1175 if (!ctr) return;
1176
1177 var ids = new Array();
1178
1179 var e = ctr.firstChild;
1180
1181 while (e) {
1182 if (e.className && e.hasClassName("Unread") && e.id &&
1183 e.id.match("RROW-")) {
1184
1185 // article fits in viewport OR article is longer than viewport and
1186 // its bottom is visible
1187
1188 if (ctr.scrollTop <= e.offsetTop && e.offsetTop + e.offsetHeight <=
1189 ctr.scrollTop + ctr.offsetHeight) {
1190
1191 // console.log(e.id + " is visible " + e.offsetTop + "." +
1192 // (e.offsetTop + e.offsetHeight) + " vs " + ctr.scrollTop + "." +
1193 // (ctr.scrollTop + ctr.offsetHeight));
1194
1195 ids.push(e.id.replace("RROW-", ""));
1196
1197 } else if (e.offsetHeight > ctr.offsetHeight &&
1198 e.offsetTop + e.offsetHeight >= ctr.scrollTop &&
1199 e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight) {
1200
1201 ids.push(e.id.replace("RROW-", ""));
1202
1203 }
1204
1205 // method 2: article bottom is visible and is in upper 1/2 of the viewport
1206
1207 /* if (e.offsetTop + e.offsetHeight >= ctr.scrollTop &&
1208 e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight/2) {
1209
1210 ids.push(e.id.replace("RROW-", ""));
1211
1212 } */
1213
1214 }
1215
1216 e = e.nextSibling;
1217 }
1218
1219 console.log("cdmWatchdog, ids= " + ids.toString());
1220
1221 if (ids.length > 0) {
1222
1223 for (var i = 0; i < ids.length; i++) {
1224 var e = $("RROW-" + ids[i]);
1225 if (e) {
1226 e.removeClassName("Unread");
1227 }
1228 }
1229
1230 var query = "?op=rpc&subop=catchupSelected" +
1231 "&cmode=0" + "&ids=" + param_escape(ids.toString());
1232
1233 new Ajax.Request("backend.php", {
1234 parameters: query,
1235 onComplete: function(transport) {
1236 handle_rpc_reply(transport);
1237 } });
1238
1239 }
1240
1241 _cdm_wd_timeout = window.setTimeout("cdmWatchdog()", 4000);
1242
1243 } catch (e) {
1244 exception_error("cdmWatchdog", e);
1245 }
1246
1247 }
1248
1249
1250 function cache_inject(id, article, param) {
1251
1252 try {
1253 if (!cache_check_param(id, param)) {
1254 //console.log("cache_article: miss: " + id + " [p=" + param + "]");
1255
1256 var date = new Date();
1257 var ts = Math.round(date.getTime() / 1000);
1258
1259 var cache_obj = {};
1260
1261 cache_obj["id"] = id;
1262 cache_obj["data"] = article;
1263 cache_obj["param"] = param;
1264
1265 if (param) id = id + ":" + param;
1266
1267 cache_added["TS:" + id] = ts;
1268
1269 if (has_local_storage())
1270 sessionStorage.setItem(id, JSON.stringify(cache_obj));
1271 else
1272 article_cache.push(cache_obj);
1273
1274 } else {
1275 //console.log("cache_article: hit: " + id + " [p=" + param + "]");
1276 }
1277 } catch (e) {
1278 exception_error("cache_inject", e);
1279 }
1280 }
1281
1282 function cache_find(id) {
1283
1284 if (has_local_storage()) {
1285 var cache_obj = sessionStorage.getItem(id);
1286
1287 if (cache_obj) {
1288 cache_obj = JSON.parse(cache_obj);
1289
1290 if (cache_obj)
1291 return cache_obj['data'];
1292 }
1293
1294 } else {
1295 for (var i = 0; i < article_cache.length; i++) {
1296 if (article_cache[i]["id"] == id) {
1297 return article_cache[i]["data"];
1298 }
1299 }
1300 }
1301 return false;
1302 }
1303
1304 function cache_find_param(id, param) {
1305
1306 if (has_local_storage()) {
1307
1308 if (param) id = id + ":" + param;
1309
1310 var cache_obj = sessionStorage.getItem(id);
1311
1312 if (cache_obj) {
1313 cache_obj = JSON.parse(cache_obj);
1314
1315 if (cache_obj)
1316 return cache_obj['data'];
1317 }
1318
1319 } else {
1320 for (var i = 0; i < article_cache.length; i++) {
1321 if (article_cache[i]["id"] == id && article_cache[i]["param"] == param) {
1322 return article_cache[i]["data"];
1323 }
1324 }
1325 }
1326
1327 return false;
1328 }
1329
1330 function cache_check(id) {
1331 if (has_local_storage()) {
1332 if (sessionStorage.getItem(id))
1333 return true;
1334 } else {
1335 for (var i = 0; i < article_cache.length; i++) {
1336 if (article_cache[i]["id"] == id) {
1337 return true;
1338 }
1339 }
1340 }
1341 return false;
1342 }
1343
1344 function cache_check_param(id, param) {
1345 if (has_local_storage()) {
1346
1347 if (param) id = id + ":" + param;
1348
1349 if (sessionStorage.getItem(id))
1350 return true;
1351
1352 } else {
1353 for (var i = 0; i < article_cache.length; i++) {
1354 if (article_cache[i]["id"] == id && article_cache[i]["param"] == param) {
1355 return true;
1356 }
1357 }
1358 }
1359 return false;
1360 }
1361
1362 function cache_expire() {
1363 if (has_local_storage()) {
1364
1365 var date = new Date();
1366 var timestamp = Math.round(date.getTime() / 1000);
1367
1368 for (var i = 0; i < sessionStorage.length; i++) {
1369
1370 var id = sessionStorage.key(i);
1371
1372 if (timestamp - cache_added["TS:" + id] > 180) {
1373 sessionStorage.removeItem(id);
1374 }
1375 }
1376
1377 } else {
1378 while (article_cache.length > 25) {
1379 article_cache.shift();
1380 }
1381 }
1382 }
1383
1384 function cache_flush() {
1385 if (has_local_storage()) {
1386 sessionStorage.clear();
1387 } else {
1388 article_cache = new Array();
1389 }
1390 }
1391
1392 function cache_invalidate(id) {
1393 try {
1394 if (has_local_storage()) {
1395
1396 var found = false;
1397
1398 for (var i = 0; i < sessionStorage.length; i++) {
1399 var key = sessionStorage.key(i);
1400
1401 // console.warn("cache_invalidate: " + key_id + " cmp " + id);
1402
1403 if (key == id || key.indexOf(id + ":") == 0) {
1404 sessionStorage.removeItem(key);
1405 found = true;
1406 break;
1407 }
1408 }
1409
1410 return found;
1411
1412 } else {
1413 var i = 0
1414
1415 while (i < article_cache.length) {
1416 if (article_cache[i]["id"] == id) {
1417 //console.log("cache_invalidate: removed id " + id);
1418 article_cache.splice(i, 1);
1419 return true;
1420 }
1421 i++;
1422 }
1423 }
1424
1425 //console.log("cache_invalidate: id not found: " + id);
1426 return false;
1427 } catch (e) {
1428 exception_error("cache_invalidate", e);
1429 }
1430 }
1431
1432 function getActiveArticleId() {
1433 return active_post_id;
1434 }
1435
1436 function preloadBatchedArticles() {
1437 try {
1438
1439 var query = "?op=rpc&subop=getArticles&ids=" +
1440 preload_id_batch.toString();
1441
1442 new Ajax.Request("backend.php", {
1443 parameters: query,
1444 onComplete: function(transport) {
1445
1446 preload_id_batch = [];
1447
1448 var articles = transport.responseXML.getElementsByTagName("article");
1449
1450 for (var i = 0; i < articles.length; i++) {
1451 var id = articles[i].getAttribute("id");
1452 if (!cache_check(id)) {
1453 cache_inject(id, articles[i].firstChild.nodeValue);
1454 console.log("preloaded article: " + id);
1455 }
1456 }
1457 } });
1458
1459 } catch (e) {
1460 exception_error("preloadBatchedArticles", e);
1461 }
1462 }
1463
1464 function preloadArticleUnderPointer(id) {
1465 try {
1466 if (getInitParam("bw_limit") == "1") return;
1467
1468 if (post_under_pointer == id && !cache_check(id)) {
1469
1470 console.log("trying to preload article " + id);
1471
1472 var neighbor_ids = getRelativePostIds(id, 1);
1473
1474 /* only request uncached articles */
1475
1476 if (preload_id_batch.indexOf(id) == -1) {
1477 for (var i = 0; i < neighbor_ids.length; i++) {
1478 if (!cache_check(neighbor_ids[i])) {
1479 preload_id_batch.push(neighbor_ids[i]);
1480 }
1481 }
1482 }
1483
1484 if (preload_id_batch.indexOf(id) == -1)
1485 preload_id_batch.push(id);
1486
1487 //console.log("preload ids batch: " + preload_id_batch.toString());
1488
1489 window.clearTimeout(preload_timeout_id);
1490 preload_batch_timeout_id = window.setTimeout('preloadBatchedArticles()', 1000);
1491
1492 }
1493 } catch (e) {
1494 exception_error("preloadArticleUnderPointer", e);
1495 }
1496 }
1497
1498 function postMouseIn(id) {
1499 try {
1500 if (post_under_pointer != id) {
1501 post_under_pointer = id;
1502 if (!isCdmMode()) {
1503 window.setTimeout("preloadArticleUnderPointer(" + id + ")", 250);
1504 }
1505 }
1506
1507 } catch (e) {
1508 exception_error("postMouseIn", e);
1509 }
1510 }
1511
1512 function postMouseOut(id) {
1513 try {
1514 post_under_pointer = false;
1515 } catch (e) {
1516 exception_error("postMouseOut", e);
1517 }
1518 }
1519
1520 function headlines_scroll_handler(e) {
1521 try {
1522
1523 if (e.scrollTop + e.offsetHeight > e.scrollHeight - 100) {
1524 if (!_infscroll_disable) {
1525 viewNextFeedPage();
1526 }
1527 }
1528
1529 } catch (e) {
1530 exception_error("headlines_scroll_handler", e);
1531 }
1532 }
1533
1534 function catchupRelativeToArticle(below) {
1535
1536 try {
1537
1538
1539 if (!getActiveArticleId()) {
1540 alert(__("No article is selected."));
1541 return;
1542 }
1543
1544 var visible_ids = getVisibleArticleIds();
1545
1546 var ids_to_mark = new Array();
1547
1548 if (!below) {
1549 for (var i = 0; i < visible_ids.length; i++) {
1550 if (visible_ids[i] != getActiveArticleId()) {
1551 var e = $("RROW-" + visible_ids[i]);
1552
1553 if (e && e.hasClassName("Unread")) {
1554 ids_to_mark.push(visible_ids[i]);
1555 }
1556 } else {
1557 break;
1558 }
1559 }
1560 } else {
1561 for (var i = visible_ids.length-1; i >= 0; i--) {
1562 if (visible_ids[i] != getActiveArticleId()) {
1563 var e = $("RROW-" + visible_ids[i]);
1564
1565 if (e && e.hasClassName("Unread")) {
1566 ids_to_mark.push(visible_ids[i]);
1567 }
1568 } else {
1569 break;
1570 }
1571 }
1572 }
1573
1574 if (ids_to_mark.length == 0) {
1575 alert(__("No articles found to mark"));
1576 } else {
1577 var msg = __("Mark %d article(s) as read?").replace("%d", ids_to_mark.length);
1578
1579 if (getInitParam("confirm_feed_catchup") != 1 || confirm(msg)) {
1580
1581 for (var i = 0; i < ids_to_mark.length; i++) {
1582 var e = $("RROW-" + ids_to_mark[i]);
1583 e.removeClassName("Unread");
1584 }
1585
1586 var query = "?op=rpc&subop=catchupSelected" +
1587 "&cmode=0" + "&ids=" + param_escape(ids_to_mark.toString());
1588
1589 new Ajax.Request("backend.php", {
1590 parameters: query,
1591 onComplete: function(transport) {
1592 catchup_callback2(transport);
1593 } });
1594
1595 }
1596 }
1597
1598 } catch (e) {
1599 exception_error("catchupRelativeToArticle", e);
1600 }
1601 }
1602
1603 function cdmExpandArticle(id) {
1604 try {
1605
1606 hideAuxDlg();
1607
1608 var elem = $("CICD-" + active_post_id);
1609
1610 var upd_img_pic = $("FUPDPIC-" + id);
1611
1612 if (upd_img_pic && (upd_img_pic.src.match("updated.png") ||
1613 upd_img_pic.src.match("fresh_sign.png"))) {
1614
1615 upd_img_pic.src = "images/blank_icon.gif";
1616 }
1617
1618 if (id == active_post_id && Element.visible(elem))
1619 return true;
1620
1621 selectArticles("none");
1622
1623 var old_offset = $("RROW-" + id).offsetTop;
1624
1625 if (active_post_id && elem && !getInitParam("cdm_expanded")) {
1626 Element.hide(elem);
1627 Element.show("CEXC-" + active_post_id);
1628 }
1629
1630 active_post_id = id;
1631
1632 elem = $("CICD-" + id);
1633
1634 if (!Element.visible(elem)) {
1635 Element.show(elem);
1636 Element.hide("CEXC-" + id);
1637
1638 if ($("CWRAP-" + id).innerHTML == "") {
1639
1640 $("FUPDPIC-" + id).src = "images/indicator_tiny.gif";
1641
1642 $("CWRAP-" + id).innerHTML = "<div class=\"insensitive\">" +
1643 __("Loading, please wait...") + "</div>";
1644
1645 var query = "?op=rpc&subop=cdmGetArticle&id=" + param_escape(id);
1646
1647 //console.log(query);
1648
1649 new Ajax.Request("backend.php", {
1650 parameters: query,
1651 onComplete: function(transport) {
1652 $("FUPDPIC-" + id).src = 'images/blank_icon.gif';
1653
1654 if (transport.responseXML) {
1655 var article = transport.responseXML.getElementsByTagName("article")[0];
1656 var recv_id = article.getAttribute("id");
1657
1658 if (recv_id == id)
1659 $("CWRAP-" + id).innerHTML = article.firstChild.nodeValue;
1660
1661 } else {
1662 $("CWRAP-" + id).innerHTML = __("Unable to load article.");
1663
1664 }
1665 }});
1666
1667 }
1668 }
1669
1670 var new_offset = $("RROW-" + id).offsetTop;
1671
1672 $("headlines-frame").scrollTop += (new_offset-old_offset);
1673
1674 if ($("RROW-" + id).offsetTop != old_offset)
1675 $("headlines-frame").scrollTop = new_offset;
1676
1677 toggleUnread(id, 0, true);
1678 toggleSelected(id);
1679
1680 } catch (e) {
1681 exception_error("cdmExpandArticle", e);
1682 }
1683
1684 return false;
1685 }
1686
1687 function fixHeadlinesOrder(ids) {
1688 try {
1689 for (var i = 0; i < ids.length; i++) {
1690 var e = $("RROW-" + ids[i]);
1691
1692 if (e) {
1693 if (i % 2 == 0) {
1694 e.removeClassName("even");
1695 e.addClassName("odd");
1696 } else {
1697 e.removeClassName("odd");
1698 e.addClassName("even");
1699 }
1700 }
1701 }
1702 } catch (e) {
1703 exception_error("fixHeadlinesOrder", e);
1704 }
1705 }
1706
1707 function getArticleUnderPointer() {
1708 return post_under_pointer;
1709 }
1710
1711 function zoomToArticle(event, id) {
1712 try {
1713 var cached_article = cache_find(id);
1714
1715 if (dijit.byId("ATAB-" + id))
1716 if (!event || !event.shiftKey)
1717 return dijit.byId("content-tabs").selectChild(dijit.byId("ATAB-" + id));
1718
1719 if (cached_article) {
1720 //closeArticlePanel();
1721
1722 var article_pane = new dijit.layout.ContentPane({
1723 title: __("Loading...") , content: cached_article,
1724 style: 'padding : 0px;',
1725 id: 'ATAB-' + id,
1726 closable: true });
1727
1728 dijit.byId("content-tabs").addChild(article_pane);
1729
1730 if (!event || !event.shiftKey)
1731 dijit.byId("content-tabs").selectChild(article_pane);
1732
1733 if ($("PTITLE-" + id))
1734 article_pane.attr('title', $("PTITLE-" + id).innerHTML);
1735
1736 } else {
1737
1738 var query = "?op=rpc&subop=getArticles&ids=" + param_escape(id);
1739
1740 notify_progress("Loading, please wait...", true);
1741
1742 new Ajax.Request("backend.php", {
1743 parameters: query,
1744 onComplete: function(transport) {
1745 notify('');
1746
1747 if (transport.responseXML) {
1748 //closeArticlePanel();
1749
1750 var article = transport.responseXML.getElementsByTagName("article")[0];
1751 var content = article.firstChild.nodeValue;
1752
1753 var article_pane = new dijit.layout.ContentPane({
1754 title: "article-" + id , content: content,
1755 style: 'padding : 0px;',
1756 id: 'ATAB-' + id,
1757 closable: true });
1758
1759 dijit.byId("content-tabs").addChild(article_pane);
1760
1761 if (!event || !event.shiftKey)
1762 dijit.byId("content-tabs").selectChild(article_pane);
1763
1764 if ($("PTITLE-" + id))
1765 article_pane.attr('title', $("PTITLE-" + id).innerHTML);
1766 }
1767
1768 } });
1769 }
1770
1771 } catch (e) {
1772 exception_error("zoomToArticle", e);
1773 }
1774 }
1775
1776 function scrollArticle(offset) {
1777 try {
1778 if (!isCdmMode()) {
1779 var ci = $("content-insert");
1780 if (ci) {
1781 ci.scrollTop += offset;
1782 }
1783 } else {
1784 var hi = $("headlines-frame");
1785 if (hi) {
1786 hi.scrollTop += offset;
1787 }
1788
1789 }
1790 } catch (e) {
1791 exception_error("scrollArticle", e);
1792 }
1793 }
1794
1795 function show_labels_in_headlines(transport) {
1796 try {
1797 if (transport.responseXML) {
1798 var info = transport.responseXML.getElementsByTagName("info-for-headlines")[0];
1799
1800 var elems = info.getElementsByTagName("entry");
1801
1802 for (var l = 0; l < elems.length; l++) {
1803 var e_id = elems[l].getAttribute("id");
1804
1805 if (e_id) {
1806
1807 var ctr = $("HLLCTR-" + e_id);
1808
1809 if (ctr) {
1810 ctr.innerHTML = elems[l].firstChild.nodeValue;
1811 }
1812 }
1813
1814 }
1815
1816 }
1817 } catch (e) {
1818 exception_error("show_labels_in_headlines", e);
1819
1820 }
1821 }
1822
1823 function toggleHeadlineActions() {
1824 try {
1825 var e = $("headlineActionsBody");
1826 var p = $("headlineActionsDrop");
1827
1828 if (!Element.visible(e)) {
1829 Element.show(e);
1830 } else {
1831 Element.hide(e);
1832 }
1833
1834 e.scrollTop = 0;
1835 e.style.left = (p.offsetLeft + 1) + "px";
1836 e.style.top = (p.offsetTop + p.offsetHeight + 2) + "px";
1837
1838 } catch (e) {
1839 exception_error("toggleHeadlineActions", e);
1840 }
1841 }
1842
1843 function publishWithNote(id, def_note) {
1844 try {
1845 if (!def_note) def_note = '';
1846
1847 var note = prompt(__("Please enter a note for this article:"), def_note);
1848
1849 if (note != undefined) {
1850 togglePub(id, false, false, note);
1851 }
1852
1853 } catch (e) {
1854 exception_error("publishWithNote", e);
1855 }
1856 }
1857
1858 function emailArticle(id) {
1859 try {
1860 if (!id) {
1861 var ids = getSelectedArticleIds2();
1862
1863 if (ids.length == 0) {
1864 alert(__("No articles are selected."));
1865 return;
1866 }
1867
1868 id = ids.toString();
1869 }
1870
1871 if (dijit.byId("emailArticleDlg"))
1872 dijit.byId("emailArticleDlg").destroyRecursive();
1873
1874 var query = "backend.php?op=dlg&id=emailArticle&param=" + param_escape(id);
1875
1876 dialog = new dijit.Dialog({
1877 id: "emailArticleDlg",
1878 title: __("Forward article by email"),
1879 style: "width: 600px",
1880 execute: function() {
1881 if (this.validate()) {
1882
1883 new Ajax.Request("backend.php", {
1884 parameters: dojo.objectToQuery(this.attr('value')),
1885 onComplete: function(transport) {
1886
1887 var error = transport.responseXML.getElementsByTagName('error')[0];
1888
1889 if (error) {
1890 alert(__('Error sending email:') + ' ' + error.firstChild.nodeValue);
1891 } else {
1892 notify_info('Your message has been sent.');
1893 dialog.hide();
1894 }
1895
1896 } });
1897 }
1898 },
1899 href: query});
1900
1901 var tmph = dojo.connect(dialog, 'onLoad', function() {
1902 dojo.disconnect(tmph);
1903
1904 new Ajax.Autocompleter('emailArticleDlg_destination', 'emailArticleDlg_dst_choices',
1905 "backend.php?op=rpc&subop=completeEmails",
1906 { tokens: '', paramName: "search" });
1907 });
1908
1909 dialog.show();
1910
1911 /* displayDlg('emailArticle', id,
1912 function () {
1913 document.forms['article_email_form'].destination.focus();
1914
1915 new Ajax.Autocompleter('destination', 'destination_choices',
1916 "backend.php?op=rpc&subop=completeEmails",
1917 { tokens: '', paramName: "search" });
1918
1919 }); */
1920
1921 } catch (e) {
1922 exception_error("emailArticle", e);
1923 }
1924 }
1925
1926 function dismissArticle(id) {
1927 try {
1928 var elem = $("RROW-" + id);
1929
1930 toggleUnread(id, 0, true);
1931
1932 new Effect.Fade(elem, {duration : 0.5});
1933
1934 active_post_id = false;
1935
1936 } catch (e) {
1937 exception_error("dismissArticle", e);
1938 }
1939 }
1940
1941 function dismissSelectedArticles() {
1942 try {
1943
1944 var ids = getVisibleArticleIds();
1945 var tmp = [];
1946 var sel = [];
1947
1948 for (var i = 0; i < ids.length; i++) {
1949 var elem = $("RROW-" + ids[i]);
1950
1951 if (elem.className && elem.hasClassName("Selected") &&
1952 ids[i] != active_post_id) {
1953 new Effect.Fade(elem, {duration : 0.5});
1954 sel.push(ids[i]);
1955 } else {
1956 tmp.push(ids[i]);
1957 }
1958 }
1959
1960 if (sel.length > 0)
1961 selectionToggleUnread(false);
1962
1963 fixHeadlinesOrder(tmp);
1964
1965 } catch (e) {
1966 exception_error("dismissSelectedArticles", e);
1967 }
1968 }
1969
1970 function dismissReadArticles() {
1971 try {
1972
1973 var ids = getVisibleArticleIds();
1974 var tmp = [];
1975
1976 for (var i = 0; i < ids.length; i++) {
1977 var elem = $("RROW-" + ids[i]);
1978
1979 if (elem.className && !elem.hasClassName("Unread") &&
1980 !elem.hasClassName("Selected")) {
1981
1982 new Effect.Fade(elem, {duration : 0.5});
1983 } else {
1984 tmp.push(ids[i]);
1985 }
1986 }
1987
1988 fixHeadlinesOrder(tmp);
1989
1990 } catch (e) {
1991 exception_error("dismissSelectedArticles", e);
1992 }
1993 }
1994
1995 function getVisibleArticleIds() {
1996 var ids = [];
1997
1998 try {
1999
2000 getLoadedArticleIds().each(function(id) {
2001 var elem = $("RROW-" + id);
2002 if (elem && Element.visible(elem))
2003 ids.push(id);
2004 });
2005
2006 } catch (e) {
2007 exception_error("getVisibleArticleIds", e);
2008 }
2009
2010 return ids;
2011 }
2012
2013 function cdmClicked(event, id) {
2014 try {
2015 var shift_key = event.shiftKey;
2016
2017 hideAuxDlg();
2018
2019 if (!event.ctrlKey) {
2020
2021 if (!getInitParam("cdm_expanded")) {
2022 return cdmExpandArticle(id);
2023 } else {
2024
2025 selectArticles("none");
2026 toggleSelected(id);
2027
2028 var elem = $("RROW-" + id);
2029
2030 if (elem)
2031 elem.removeClassName("Unread");
2032
2033 var upd_img_pic = $("FUPDPIC-" + id);
2034
2035 if (upd_img_pic && (upd_img_pic.src.match("updated.png") ||
2036 upd_img_pic.src.match("fresh_sign.png"))) {
2037
2038 upd_img_pic.src = "images/blank_icon.gif";
2039 }
2040
2041 active_post_id = id;
2042
2043 var query = "?op=rpc&subop=catchupSelected" +
2044 "&cmode=0&ids=" + param_escape(id);
2045
2046 new Ajax.Request("backend.php", {
2047 parameters: query,
2048 onComplete: function(transport) {
2049 handle_rpc_reply(transport);
2050 } });
2051 }
2052
2053 } else {
2054 toggleSelected(id, true);
2055 toggleUnread(id, 0, false);
2056 zoomToArticle(event, id);
2057 }
2058
2059 } catch (e) {
2060 exception_error("cdmClicked");
2061 }
2062
2063 return false;
2064 }
2065
2066 function postClicked(event, id) {
2067 try {
2068
2069 if (!event.ctrlKey) {
2070 return true;
2071 } else {
2072 postOpenInNewTab(event, id);
2073 return false;
2074 }
2075
2076 } catch (e) {
2077 exception_error("postClicked");
2078 }
2079 }
2080
2081 function hlOpenInNewTab(event, id) {
2082 toggleUnread(id, 0, false);
2083 zoomToArticle(event, id);
2084 }
2085
2086 function postOpenInNewTab(event, id) {
2087 closeArticlePanel(id);
2088 zoomToArticle(event, id);
2089 }
2090
2091 function hlClicked(event, id) {
2092 try {
2093 if (event.altKey) {
2094 openArticleInNewWindow(id);
2095 } else if (!event.ctrlKey) {
2096 view(id);
2097 return true;
2098 } else {
2099 toggleSelected(id);
2100 toggleUnread(id, 0, false);
2101 zoomToArticle(event, id);
2102 return false;
2103 }
2104
2105 } catch (e) {
2106 exception_error("hlClicked");
2107 }
2108 }
2109
2110 function getFirstVisibleHeadlineId() {
2111 var rows = getVisibleArticleIds();
2112 return rows[0];
2113
2114 }
2115
2116 function getLastVisibleHeadlineId() {
2117 var rows = getVisibleArticleIds();
2118 return rows[rows.length-1];
2119 }
2120
2121 function openArticleInNewWindow(id) {
2122 toggleUnread(id, 0, false);
2123 window.open("backend.php?op=la&id=" + id);
2124 }
2125
2126 function isCdmMode() {
2127 return getInitParam("combined_display_mode");
2128 }
2129
2130 function markHeadline(id) {
2131 var row = $("RROW-" + id);
2132 if (row) {
2133 var check = $("RCHK-" + id);
2134
2135 if (check) {
2136 check.checked = true;
2137 }
2138
2139 row.addClassName("Selected");
2140 }
2141 }
2142
2143 function getRelativePostIds(id, limit) {
2144
2145 var tmp = [];
2146
2147 try {
2148
2149 if (!limit) limit = 3;
2150
2151 var ids = getVisibleArticleIds();
2152
2153 for (var i = 0; i < ids.length; i++) {
2154 if (ids[i] == id) {
2155 for (var k = 1; k <= limit; k++) {
2156 if (i > k-1) tmp.push(ids[i-k]);
2157 if (i < ids.length-k) tmp.push(ids[i+k]);
2158 }
2159 break;
2160 }
2161 }
2162
2163 } catch (e) {
2164 exception_error("getRelativePostIds", e);
2165 }
2166
2167 return tmp;
2168 }
2169
2170 function correctHeadlinesOffset(id) {
2171
2172 try {
2173
2174 var container = $("headlines-frame");
2175 var row = $("RROW-" + id);
2176
2177 var viewport = container.offsetHeight;
2178
2179 var rel_offset_top = row.offsetTop - container.scrollTop;
2180 var rel_offset_bottom = row.offsetTop + row.offsetHeight - container.scrollTop;
2181
2182 //console.log("Rtop: " + rel_offset_top + " Rbtm: " + rel_offset_bottom);
2183 //console.log("Vport: " + viewport);
2184
2185 if (rel_offset_top <= 0 || rel_offset_top > viewport) {
2186 container.scrollTop = row.offsetTop;
2187 } else if (rel_offset_bottom > viewport) {
2188
2189 /* doesn't properly work with Opera in some cases because
2190 Opera fucks up element scrolling */
2191
2192 container.scrollTop = row.offsetTop + row.offsetHeight - viewport;
2193 }
2194
2195 } catch (e) {
2196 exception_error("correctHeadlinesOffset", e);
2197 }
2198
2199 }
2200
2201 function headlineActionsChange(elem) {
2202 try {
2203 eval(elem.value);
2204 elem.attr('value', 'false');
2205 } catch (e) {
2206 exception_error("headlineActionsChange", e);
2207 }
2208 }
2209
2210 function closeArticlePanel() {
2211
2212 var tabs = dijit.byId("content-tabs");
2213 var child = tabs.selectedChildWidget;
2214
2215 if (child && tabs.getIndexOfChild(child) > 0) {
2216 tabs.removeChild(child);
2217 child.destroy();
2218 } else {
2219 if (dijit.byId("content-insert"))
2220 dijit.byId("headlines-wrap-inner").removeChild(
2221 dijit.byId("content-insert"));
2222 }
2223 }
2224
2225 function initHeadlinesMenu() {
2226 try {
2227 if (dijit.byId("headlinesMenu"))
2228 dijit.byId("headlinesMenu").destroyRecursive();
2229
2230 var ids = [];
2231
2232 if (!isCdmMode()) {
2233 nodes = $$("#headlines-frame > div[id*=RROW]");
2234 } else {
2235 nodes = $$("#headlines-frame span[id*=RTITLE]");
2236 }
2237
2238 nodes.each(function(node) {
2239 ids.push(node.id);
2240 });
2241
2242 var menu = new dijit.Menu({
2243 id: "headlinesMenu",
2244 targetNodeIds: ids,
2245 });
2246
2247 var tmph = dojo.connect(menu, '_openMyself', function (event) {
2248 var callerNode = event.target, match = null, tries = 0;
2249
2250 while (match == null && callerNode && tries <= 3) {
2251 match = callerNode.id.match("^[A-Z]+[-]([0-9]+)$");
2252 callerNode = callerNode.parentNode;
2253 ++tries;
2254 }
2255
2256 if (match) this.callerRowId = parseInt(match[1]);
2257
2258 });
2259
2260 if (!isCdmMode())
2261 menu.addChild(new dijit.MenuItem({
2262 label: __("View article"),
2263 onClick: function(event) {
2264 view(this.getParent().callerRowId);
2265 }}));
2266
2267 menu.addChild(new dijit.MenuItem({
2268 label: __("View in a new tab"),
2269 onClick: function(event) {
2270 hlOpenInNewTab(event, this.getParent().callerRowId);
2271 }}));
2272
2273 menu.addChild(new dijit.MenuSeparator());
2274
2275 menu.addChild(new dijit.MenuItem({
2276 label: __("Open original article"),
2277 onClick: function(event) {
2278 openArticleInNewWindow(this.getParent().callerRowId);
2279 }}));
2280
2281 var labels = dijit.byId("feedTree").model.getItemsInCategory(-2);
2282
2283 if (labels) {
2284
2285 menu.addChild(new dijit.MenuSeparator());
2286
2287 var labelsMenu = new dijit.Menu({ownerMenu: menu});
2288
2289 labels.each(function(label) {
2290 var id = label.id[0];
2291 var bare_id = id.substr(id.indexOf(":")+1);
2292 var name = label.name[0];
2293
2294 bare_id = -11-bare_id;
2295
2296 labelsMenu.addChild(new dijit.MenuItem({
2297 label: name,
2298 labelId: bare_id,
2299 onClick: function(event) {
2300 //console.log(this.labelId);
2301 //console.log(this.getParent().ownerMenu.callerRowId);
2302 selectionAssignLabel(this.labelId,
2303 [this.getParent().ownerMenu.callerRowId]);
2304 }}));
2305 });
2306
2307 menu.addChild(new dijit.PopupMenuItem({
2308 label: __("Labels"),
2309 popup: labelsMenu,
2310 }));
2311 }
2312
2313 menu.startup();
2314
2315 } catch (e) {
2316 exception_error("initHeadlinesMenu", e);
2317 }
2318 }