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