]> git.wh0rd.org - tt-rss.git/blob - viewfeed.js
do not reset alt attribute when changing back feedlist icon from progressbar
[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
473 //setActiveFeedId(feed_id);
474
475 var query = "backend.php?op=view&id=" + param_escape(id) +
476 "&feed=" + param_escape(feed_id);
477
478 var date = new Date();
479
480 var neighbor_ids = getRelativePostIds(active_post_id);
481
482 /* only request uncached articles */
483
484 var cids_to_request = Array();
485
486 for (var i = 0; i < neighbor_ids.length; i++) {
487 if (!cache_check(neighbor_ids[i])) {
488 cids_to_request.push(neighbor_ids[i]);
489 }
490 }
491
492 debug("additional ids: " + cids_to_request.toString());
493
494 /* additional info for piggyback counters */
495
496 if (tagsAreDisplayed()) {
497 query = query + "&omode=lt";
498 } else {
499 query = query + "&omode=flc";
500 }
501
502 var date = new Date();
503 var timestamp = Math.round(date.getTime() / 1000);
504 query = query + "&ts=" + timestamp;
505
506 query = query + "&cids=" + cids_to_request.toString();
507
508 var crow = $("RROW-" + id);
509 var article_is_unread = crow.className.match("Unread");
510
511 if (!async_counters_work) {
512 query = query + "&csync=true";
513 }
514
515 showArticleInHeadlines(id);
516
517 if (!cached_article) {
518
519 // notify_progress("Loading, please wait...", true);
520
521 /* var content = $('HLC-' + id);
522
523 if (content && !$('LL-' + id)) {
524 var ll = document.createElement('img');
525
526 ll.src = 'images/indicator_tiny.gif';
527 ll.className = 'hlLoading';
528 ll.id = 'LL-' + id;
529
530 content.appendChild(ll);
531
532 } */
533
534 var upic = $('FUPDPIC-' + id);
535
536 if (upic) {
537 upic.src = 'images/indicator_white.gif';
538 }
539
540 } else if (cached_article && article_is_unread) {
541
542 query = query + "&mode=prefetch";
543
544 render_article(cached_article);
545
546 } else if (cached_article) {
547
548 query = query + "&mode=prefetch_old";
549 render_article(cached_article);
550
551 }
552
553 cache_expire();
554
555 last_requested_article = id;
556
557 new Ajax.Request(query, {
558 onComplete: function(transport) {
559 article_callback2(transport, id, feed_id);
560 } });
561
562 return false;
563
564 } catch (e) {
565 exception_error("view", e);
566 }
567 }
568
569 function tMark(id) {
570 return toggleMark(id);
571 }
572
573 function tPub(id) {
574 return togglePub(id);
575 }
576
577 function tMark_afh_off(effect) {
578 try {
579 var elem = effect.effects[0].element;
580
581 debug("tMark_afh_off : " + elem.id);
582
583 if (elem) {
584 elem.src = elem.src.replace("mark_set", "mark_unset");
585 elem.alt = __("Star article");
586 Element.show(elem);
587 }
588
589 } catch (e) {
590 exception_error("tMark_afh_off", e);
591 }
592 }
593
594 function tPub_afh_off(effect) {
595 try {
596 var elem = effect.effects[0].element;
597
598 debug("tPub_afh_off : " + elem.id);
599
600 if (elem) {
601 elem.src = elem.src.replace("pub_set", "pub_unset");
602 elem.alt = __("Publish article");
603 Element.show(elem);
604 }
605
606 } catch (e) {
607 exception_error("tPub_afh_off", e);
608 }
609 }
610
611 function toggleMark(id, client_only, no_effects) {
612
613 try {
614
615 var query = "backend.php?op=rpc&id=" + id + "&subop=mark";
616
617 query = query + "&afid=" + getActiveFeedId();
618
619 if (tagsAreDisplayed()) {
620 query = query + "&omode=tl";
621 } else {
622 query = query + "&omode=flc";
623 }
624
625 var mark_img = $("FMPIC-" + id);
626
627 if (!mark_img) return;
628
629 var vfeedu = $("FEEDU--1");
630 var crow = $("RROW-" + id);
631
632 if (mark_img.src.match("mark_unset")) {
633 mark_img.src = mark_img.src.replace("mark_unset", "mark_set");
634 mark_img.alt = __("Unstar article");
635 query = query + "&mark=1";
636
637 if (db) {
638 db.execute("UPDATE articles SET marked = 1 WHERE id = ?", [id]);
639 }
640
641 } else {
642 //mark_img.src = "images/mark_unset.png";
643 mark_img.alt = __("Please wait...");
644 query = query + "&mark=0";
645
646 if ($("headlinesList") && !no_effects) {
647 Effect.Puff(mark_img, {duration : 0.25, afterFinish: tMark_afh_off});
648 } else {
649 mark_img.src = mark_img.src.replace("mark_set", "mark_unset");
650 mark_img.alt = __("Star article");
651 }
652
653 if (db) {
654 db.execute("UPDATE articles SET marked = 0 WHERE id = ?", [id]);
655 }
656
657 }
658
659 if (!no_effects) update_local_feedlist_counters();
660
661 if (!client_only) {
662 debug(query);
663
664 new Ajax.Request(query, {
665 onComplete: function(transport) {
666 all_counters_callback2(transport);
667 } });
668
669 }
670
671 } catch (e) {
672 exception_error("toggleMark", e);
673 }
674 }
675
676 function togglePub(id, client_only, no_effects, note) {
677
678 try {
679
680 var query = "backend.php?op=rpc&id=" + id + "&subop=publ";
681
682 query = query + "&afid=" + getActiveFeedId();
683
684 if (note != undefined) {
685 query = query + "&note=" + param_escape(note);
686 } else {
687 query = query + "&note=undefined";
688 }
689
690 if (tagsAreDisplayed()) {
691 query = query + "&omode=tl";
692 } else {
693 query = query + "&omode=flc";
694 }
695
696 var mark_img = $("FPPIC-" + id);
697
698 if (!mark_img) return;
699
700 var vfeedu = $("FEEDU--2");
701 var crow = $("RROW-" + id);
702
703 if (mark_img.src.match("pub_unset") || note != undefined) {
704 mark_img.src = mark_img.src.replace("pub_unset", "pub_set");
705 mark_img.alt = __("Unpublish article");
706 query = query + "&pub=1";
707
708 } else {
709 //mark_img.src = "images/pub_unset.png";
710 mark_img.alt = __("Please wait...");
711 query = query + "&pub=0";
712
713 if ($("headlinesList") && !no_effects) {
714 Effect.Puff(mark_img, {duration : 0.25, afterFinish: tPub_afh_off});
715 } else {
716 mark_img.src = mark_img.src.replace("pub_set", "pub_unset");
717 mark_img.alt = __("Publish article");
718 }
719 }
720
721 if (!client_only) {
722 new Ajax.Request(query, {
723 onComplete: function(transport) {
724 toggle_published_callback(transport);
725 } });
726 }
727
728 } catch (e) {
729
730 exception_error("togglePub", e);
731 }
732 }
733
734 function correctHeadlinesOffset(id) {
735
736 try {
737
738 var hlist = $("headlinesList");
739 var container = $("headlinesInnerContainer");
740 var row = $("RROW-" + id);
741
742 var viewport = container.offsetHeight;
743
744 var rel_offset_top = row.offsetTop - container.scrollTop;
745 var rel_offset_bottom = row.offsetTop + row.offsetHeight - container.scrollTop;
746
747 debug("Rtop: " + rel_offset_top + " Rbtm: " + rel_offset_bottom);
748 debug("Vport: " + viewport);
749
750 if (rel_offset_top <= 0 || rel_offset_top > viewport) {
751 container.scrollTop = row.offsetTop;
752 } else if (rel_offset_bottom > viewport) {
753
754 /* doesn't properly work with Opera in some cases because
755 Opera fucks up element scrolling */
756
757 container.scrollTop = row.offsetTop + row.offsetHeight - viewport;
758 }
759
760 } catch (e) {
761 exception_error("correctHeadlinesOffset", e);
762 }
763
764 }
765
766 function moveToPost(mode) {
767
768 try {
769
770 var rows;
771
772 if (isCdmMode()) {
773 rows = cdmGetVisibleArticles();
774 } else {
775 rows = getVisibleHeadlineIds();
776 }
777
778 var prev_id = false;
779 var next_id = false;
780
781 if (!$('RROW-' + active_post_id)) {
782 active_post_id = false;
783 }
784
785 if (active_post_id == false) {
786 next_id = getFirstVisibleHeadlineId();
787 prev_id = getLastVisibleHeadlineId();
788 } else {
789 for (var i = 0; i < rows.length; i++) {
790 if (rows[i] == active_post_id) {
791 prev_id = rows[i-1];
792 next_id = rows[i+1];
793 }
794 }
795 }
796
797 if (mode == "next") {
798 if (next_id) {
799 if (isCdmMode()) {
800
801 if (!cdmArticleIsActuallyVisible(next_id)) {
802 cdmScrollToArticleId(next_id);
803 }
804 cdmSelectArticles("none");
805 toggleUnread(next_id, 0, true);
806 toggleSelected(next_id);
807
808 } else {
809 correctHeadlinesOffset(next_id);
810 view(next_id, getActiveFeedId());
811 }
812 }
813 }
814
815 if (mode == "prev") {
816 if (prev_id) {
817 if (isCdmMode()) {
818 cdmScrollToArticleId(prev_id);
819 cdmSelectArticles("none");
820 toggleUnread(prev_id, 0, true);
821 toggleSelected(prev_id);
822 } else {
823 correctHeadlinesOffset(prev_id);
824 view(prev_id, getActiveFeedId());
825 }
826 }
827 }
828
829 } catch (e) {
830 exception_error("moveToPost", e);
831 }
832 }
833
834 function toggleSelected(id) {
835 try {
836
837 var cb = $("RCHK-" + id);
838
839 var row = $("RROW-" + id);
840 if (row) {
841 var nc = row.className;
842
843 if (!nc.match("Selected")) {
844 nc = nc + "Selected";
845 if (cb) {
846 cb.checked = true;
847 }
848
849 // In CDM basically last selected article == active article
850 if (isCdmMode()) active_post_id = id;
851 } else {
852 nc = nc.replace("Selected", "");
853 if (cb) {
854 cb.checked = false;
855 }
856
857 }
858
859 row.className = nc;
860 }
861 } catch (e) {
862 exception_error("toggleSelected", e);
863 }
864 }
865
866 function toggleUnread_afh(effect) {
867 try {
868
869 var elem = effect.element;
870 elem.style.backgroundColor = "";
871
872 } catch (e) {
873 exception_error("toggleUnread_afh", e);
874 }
875 }
876
877 function toggleUnread(id, cmode, effect) {
878 try {
879
880 var row = $("RROW-" + id);
881 if (row) {
882 var nc = row.className;
883 var is_selected = row.className.match("Selected");
884 nc = nc.replace("Unread", "");
885 nc = nc.replace("Selected", "");
886
887 // since we are removing selection from the object, uncheck
888 // corresponding checkbox
889
890 var cb = $("RCHK-" + id);
891 if (cb) {
892 cb.checked = false;
893 }
894
895 // NOTE: I'm not sure that resetting selection here is a feature -fox
896
897 if (cmode == undefined || cmode == 2) {
898 if (row.className.match("Unread")) {
899 row.className = nc;
900
901 if (effect) {
902 new Effect.Highlight(row, {duration: 1, startcolor: "#fff7d5",
903 afterFinish: toggleUnread_afh,
904 queue: { position:'end', scope: 'TMRQ-' + id, limit: 1 } } );
905 }
906
907 } else {
908 row.className = nc + "Unread";
909 }
910
911 if (db) {
912 db.execute("UPDATE articles SET unread = not unread "+
913 "WHERE id = ?", [id]);
914 }
915
916 } else if (cmode == 0) {
917 row.className = nc;
918
919 if (effect) {
920 new Effect.Highlight(row, {duration: 1, startcolor: "#fff7d5",
921 afterFinish: toggleUnread_afh,
922 queue: { position:'end', scope: 'TMRQ-' + id, limit: 1 } } );
923 }
924
925 if (db) {
926 db.execute("UPDATE articles SET unread = 0 "+
927 "WHERE id = ?", [id]);
928 }
929
930 } else if (cmode == 1) {
931 row.className = nc + "Unread";
932
933 if (db) {
934 db.execute("UPDATE articles SET unread = 1 "+
935 "WHERE id = ?", [id]);
936 }
937
938 }
939
940 update_local_feedlist_counters();
941
942 // Disable unmarking as selected for the time being (16.05.08) -fox
943 if (is_selected) row.className = row.className + "Selected";
944
945 if (cmode == undefined) cmode = 2;
946
947 var query = "backend.php?op=rpc&subop=catchupSelected" +
948 "&cmode=" + param_escape(cmode);
949
950 var ids = "?ids=" + param_escape(id);
951
952 // notify_progress("Loading, please wait...");
953
954 new Ajax.Request(query, {
955 parameters: ids,
956 onComplete: function(transport) {
957 all_counters_callback2(transport);
958 } });
959
960 }
961
962 } catch (e) {
963 exception_error("toggleUnread", e);
964 }
965 }
966
967 function selectionRemoveLabel(id) {
968 try {
969
970 var ids = getSelectedArticleIds2();
971
972 if (ids.length == 0) {
973 alert(__("No articles are selected."));
974 return;
975 }
976
977 // var ok = confirm(__("Remove selected articles from label?"));
978
979 // if (ok) {
980
981 var query = "backend.php?op=rpc&subop=removeFromLabel&ids=" +
982 param_escape(ids.toString()) + "&lid=" + param_escape(id);
983
984 // notify_progress("Loading, please wait...");
985
986 cache_invalidate("F:" + (-11 - id));
987
988 new Ajax.Request(query, {
989 onComplete: function(transport) {
990 show_labels_in_headlines(transport);
991 all_counters_callback2(transport);
992 } });
993
994 // }
995
996 } catch (e) {
997 exception_error("selectionAssignLabel", e);
998
999 }
1000 }
1001
1002 function selectionAssignLabel(id) {
1003 try {
1004
1005 var ids = getSelectedArticleIds2();
1006
1007 if (ids.length == 0) {
1008 alert(__("No articles are selected."));
1009 return;
1010 }
1011
1012 // var ok = confirm(__("Assign selected articles to label?"));
1013
1014 // if (ok) {
1015
1016 cache_invalidate("F:" + (-11 - id));
1017
1018 var query = "backend.php?op=rpc&subop=assignToLabel&ids=" +
1019 param_escape(ids.toString()) + "&lid=" + param_escape(id);
1020
1021 // notify_progress("Loading, please wait...");
1022
1023 new Ajax.Request(query, {
1024 onComplete: function(transport) {
1025 show_labels_in_headlines(transport);
1026 all_counters_callback2(transport);
1027 } });
1028
1029 // }
1030
1031 } catch (e) {
1032 exception_error("selectionAssignLabel", e);
1033
1034 }
1035 }
1036
1037 function selectionToggleUnread(cdm_mode, set_state, callback_func, no_error) {
1038 try {
1039 var rows;
1040
1041 if (cdm_mode) {
1042 rows = cdmGetSelectedArticles();
1043 } else {
1044 rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
1045 }
1046
1047 if (rows.length == 0 && !no_error) {
1048 alert(__("No articles are selected."));
1049 return;
1050 }
1051
1052 for (i = 0; i < rows.length; i++) {
1053 var row = $("RROW-" + rows[i]);
1054 if (row) {
1055 var nc = row.className;
1056 nc = nc.replace("Unread", "");
1057 nc = nc.replace("Selected", "");
1058
1059 if (set_state == undefined) {
1060 if (row.className.match("Unread")) {
1061 row.className = nc + "Selected";
1062 } else {
1063 row.className = nc + "UnreadSelected";
1064 }
1065 if (db) {
1066 db.execute("UPDATE articles SET unread = NOT unread WHERE id = ?",
1067 [rows[i]]);
1068 }
1069 }
1070
1071 if (set_state == false) {
1072 row.className = nc + "Selected";
1073 if (db) {
1074 db.execute("UPDATE articles SET unread = 0 WHERE id = ?",
1075 [rows[i]]);
1076 }
1077 }
1078
1079 if (set_state == true) {
1080 row.className = nc + "UnreadSelected";
1081 if (db) {
1082 db.execute("UPDATE articles SET unread = 1 WHERE id = ?",
1083 [rows[i]]);
1084 }
1085 }
1086 }
1087 }
1088
1089 if (rows.length > 0) {
1090
1091 update_local_feedlist_counters();
1092
1093 var cmode = "";
1094
1095 if (set_state == undefined) {
1096 cmode = "2";
1097 } else if (set_state == true) {
1098 cmode = "1";
1099 } else if (set_state == false) {
1100 cmode = "0";
1101 }
1102
1103 var query = "backend.php?op=rpc&subop=catchupSelected" +
1104 "&cmode=" + cmode;
1105
1106 var ids = "?ids=" + param_escape(rows.toString());
1107
1108 notify_progress("Loading, please wait...");
1109
1110 new Ajax.Request(query, {
1111 parameters: ids,
1112 onComplete: function(transport) {
1113 catchup_callback2(transport, callback_func);
1114 } });
1115
1116 }
1117
1118 } catch (e) {
1119 exception_error("selectionToggleUnread", e);
1120 }
1121 }
1122
1123 function selectionToggleMarked(cdm_mode) {
1124 try {
1125
1126 var rows;
1127
1128 if (cdm_mode) {
1129 rows = cdmGetSelectedArticles();
1130 } else {
1131 rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
1132 }
1133
1134 if (rows.length == 0) {
1135 alert(__("No articles are selected."));
1136 return;
1137 }
1138
1139 for (i = 0; i < rows.length; i++) {
1140 toggleMark(rows[i], true, true);
1141 }
1142
1143 update_local_feedlist_counters();
1144
1145 if (rows.length > 0) {
1146
1147 var query = "backend.php?op=rpc&subop=markSelected&ids=" +
1148 param_escape(rows.toString()) + "&cmode=2";
1149
1150 query = query + "&afid=" + getActiveFeedId();
1151
1152 /* if (tagsAreDisplayed()) {
1153 query = query + "&omode=tl";
1154 } else {
1155 query = query + "&omode=flc";
1156 } */
1157
1158 query = query + "&omode=lc";
1159
1160 new Ajax.Request(query, {
1161 onComplete: function(transport) {
1162 all_counters_callback2(transport);
1163 } });
1164
1165 }
1166
1167 } catch (e) {
1168 exception_error("selectionToggleMarked", e);
1169 }
1170 }
1171
1172 function selectionTogglePublished(cdm_mode) {
1173 try {
1174
1175 var rows;
1176
1177 if (cdm_mode) {
1178 rows = cdmGetSelectedArticles();
1179 } else {
1180 rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
1181 }
1182
1183 if (rows.length == 0) {
1184 alert(__("No articles are selected."));
1185 return;
1186 }
1187
1188 for (i = 0; i < rows.length; i++) {
1189 togglePub(rows[i], true, true);
1190 }
1191
1192 if (rows.length > 0) {
1193
1194 var query = "backend.php?op=rpc&subop=publishSelected&ids=" +
1195 param_escape(rows.toString()) + "&cmode=2";
1196
1197 query = query + "&afid=" + getActiveFeedId();
1198
1199 /* if (tagsAreDisplayed()) {
1200 query = query + "&omode=tl";
1201 } else {
1202 query = query + "&omode=flc";
1203 } */
1204
1205 query = query + "&omode=lc";
1206
1207 new Ajax.Request(query, {
1208 onComplete: function(transport) {
1209 all_counters_callback2(transport);
1210 } });
1211
1212 }
1213
1214 } catch (e) {
1215 exception_error("selectionToggleMarked", e);
1216 }
1217 }
1218
1219 function cdmGetSelectedArticles() {
1220 var sel_articles = new Array();
1221 var container = $("headlinesInnerContainer");
1222
1223 for (i = 0; i < container.childNodes.length; i++) {
1224 var child = container.childNodes[i];
1225
1226 if (child.id && child.id.match("RROW-") && child.className.match("Selected")) {
1227 var c_id = child.id.replace("RROW-", "");
1228 sel_articles.push(c_id);
1229 }
1230 }
1231
1232 return sel_articles;
1233 }
1234
1235 function cdmGetVisibleArticles() {
1236 var sel_articles = new Array();
1237 var container = $("headlinesInnerContainer");
1238
1239 if (!container) return sel_articles;
1240
1241 for (i = 0; i < container.childNodes.length; i++) {
1242 var child = container.childNodes[i];
1243
1244 if (child.id && child.id.match("RROW-")) {
1245 var c_id = child.id.replace("RROW-", "");
1246 sel_articles.push(c_id);
1247 }
1248 }
1249
1250 return sel_articles;
1251 }
1252
1253 function cdmGetUnreadArticles() {
1254 var sel_articles = new Array();
1255 var container = $("headlinesInnerContainer");
1256
1257 for (i = 0; i < container.childNodes.length; i++) {
1258 var child = container.childNodes[i];
1259
1260 if (child.id && child.id.match("RROW-") && child.className.match("Unread")) {
1261 var c_id = child.id.replace("RROW-", "");
1262 sel_articles.push(c_id);
1263 }
1264 }
1265
1266 return sel_articles;
1267 }
1268
1269
1270 // mode = all,none,unread
1271 function cdmSelectArticles(mode) {
1272 var container = $("headlinesInnerContainer");
1273
1274 for (i = 0; i < container.childNodes.length; i++) {
1275 var child = container.childNodes[i];
1276
1277 if (child.id && child.id.match("RROW-")) {
1278 var aid = child.id.replace("RROW-", "");
1279
1280 var cb = $("RCHK-" + aid);
1281
1282 if (mode == "all") {
1283 if (!child.className.match("Selected")) {
1284 child.className = child.className + "Selected";
1285 cb.checked = true;
1286 }
1287 } else if (mode == "unread") {
1288 if (child.className.match("Unread") && !child.className.match("Selected")) {
1289 child.className = child.className + "Selected";
1290 cb.checked = true;
1291 }
1292 } else {
1293 child.className = child.className.replace("Selected", "");
1294 cb.checked = false;
1295 }
1296 }
1297 }
1298 }
1299
1300 function catchupPage() {
1301
1302 var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
1303
1304 var str = __("Mark all visible articles in %s as read?");
1305
1306 str = str.replace("%s", fn);
1307
1308 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
1309 return;
1310 }
1311
1312 if ($("headlinesList")) {
1313 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, 'Unread', true);
1314 selectionToggleUnread(false, false, 'viewCurrentFeed()', true);
1315 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
1316 } else {
1317 cdmSelectArticles('all');
1318 selectionToggleUnread(true, false, 'viewCurrentFeed()', true)
1319 cdmSelectArticles('none');
1320 }
1321 }
1322
1323 function catchupSelection() {
1324
1325 try {
1326
1327 var rows;
1328
1329 if ($("headlinesList")) {
1330 rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
1331 } else {
1332 rows = cdmGetSelectedArticles();
1333 }
1334
1335 if (rows.length == 0) {
1336 alert(__("No articles are selected."));
1337 return;
1338 }
1339
1340
1341 var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
1342
1343 var str = __("Mark %d selected articles in %s as read?");
1344
1345 str = str.replace("%d", rows.length);
1346 str = str.replace("%s", fn);
1347
1348 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
1349 return;
1350 }
1351
1352 if ($("headlinesList")) {
1353 selectionToggleUnread(false, false, 'viewCurrentFeed()', true);
1354 // selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
1355 } else {
1356 selectionToggleUnread(true, false, 'viewCurrentFeed()', true)
1357 // cdmSelectArticles('none');
1358 }
1359
1360 } catch (e) {
1361 exception_error("catchupSelection", e);
1362 }
1363 }
1364
1365 function editArticleTags(id, feed_id, cdm_enabled) {
1366 displayDlg('editArticleTags', id);
1367 }
1368
1369
1370 function tag_saved_callback(transport) {
1371 try {
1372 debug("in tag_saved_callback");
1373
1374 closeInfoBox();
1375 notify("");
1376
1377 if (tagsAreDisplayed()) {
1378 _reload_feedlist_after_view = true;
1379 }
1380
1381
1382 if (transport.responseXML) {
1383 var tags_str = transport.responseXML.getElementsByTagName("tags-str")[0];
1384
1385 if (tags_str) {
1386 var id = tags_str.getAttribute("id");
1387
1388 if (id) {
1389 var tags = $("ATSTR-" + id);
1390 if (tags) {
1391 tags.innerHTML = tags_str.firstChild.nodeValue;
1392 }
1393 }
1394 }
1395 }
1396
1397 } catch (e) {
1398 exception_error("tag_saved_callback", e);
1399 }
1400 }
1401
1402 function editTagsSave() {
1403
1404 notify_progress("Saving article tags...");
1405
1406 var form = document.forms["tag_edit_form"];
1407
1408 var query = Form.serialize("tag_edit_form");
1409
1410 query = "backend.php?op=rpc&subop=setArticleTags&" + query;
1411
1412 debug(query);
1413
1414 new Ajax.Request(query, {
1415 onComplete: function(transport) {
1416 tag_saved_callback(transport);
1417 } });
1418
1419 }
1420
1421 function editTagsInsert() {
1422 try {
1423
1424 var form = document.forms["tag_edit_form"];
1425
1426 var found_tags = form.found_tags;
1427 var tags_str = form.tags_str;
1428
1429 var tag = found_tags[found_tags.selectedIndex].value;
1430
1431 if (tags_str.value.length > 0 &&
1432 tags_str.value.lastIndexOf(", ") != tags_str.value.length - 2) {
1433
1434 tags_str.value = tags_str.value + ", ";
1435 }
1436
1437 tags_str.value = tags_str.value + tag + ", ";
1438
1439 found_tags.selectedIndex = 0;
1440
1441 } catch (e) {
1442 exception_error("editTagsInsert", e);
1443 }
1444 }
1445
1446 function cdmScrollViewport(where) {
1447 debug("cdmScrollViewport: " + where);
1448
1449 var ctr = $("headlinesInnerContainer");
1450
1451 if (!ctr) return;
1452
1453 if (where == "bottom") {
1454 ctr.scrollTop = ctr.scrollHeight;
1455 } else {
1456 ctr.scrollTop = where;
1457 }
1458 }
1459
1460 function cdmArticleIsBelowViewport(id) {
1461 try {
1462 var ctr = $("headlinesInnerContainer");
1463 var e = $("RROW-" + id);
1464
1465 if (!e || !ctr) return;
1466
1467 // article starts below viewport
1468
1469 if (ctr.scrollTop < e.offsetTop) {
1470 return true;
1471 } else {
1472 return false;
1473 }
1474
1475 } catch (e) {
1476 exception_error("cdmArticleIsVisible", e);
1477 }
1478 }
1479
1480 function cdmArticleIsAboveViewport(id) {
1481 try {
1482 var ctr = $("headlinesInnerContainer");
1483 var e = $("RROW-" + id);
1484
1485 if (!e || !ctr) return;
1486
1487 // article starts above viewport
1488
1489 if (ctr.scrollTop > e.offsetTop + e.offsetHeight) {
1490 return true;
1491 } else {
1492 return false;
1493 }
1494
1495 } catch (e) {
1496 exception_error("cdmArticleIsVisible", e);
1497 }
1498 }
1499
1500 function cdmScrollToArticleId(id) {
1501 try {
1502 var ctr = $("headlinesInnerContainer");
1503 var e = $("RROW-" + id);
1504
1505 if (!e || !ctr) return;
1506
1507 ctr.scrollTop = e.offsetTop;
1508
1509 } catch (e) {
1510 exception_error("cdmScrollToArticleId", e);
1511 }
1512 }
1513
1514 function cdmArticleIsActuallyVisible(id) {
1515 try {
1516 var ctr = $("headlinesInnerContainer");
1517 var e = $("RROW-" + id);
1518
1519 if (!e || !ctr) return;
1520
1521 // article fits in viewport OR article is longer than viewport and
1522 // its bottom is visible
1523
1524 if (ctr.scrollTop <= e.offsetTop && e.offsetTop + e.offsetHeight <=
1525 ctr.scrollTop + ctr.offsetHeight) {
1526
1527 return true;
1528
1529 } else if (e.offsetHeight > ctr.offsetHeight &&
1530 e.offsetTop + e.offsetHeight >= ctr.scrollTop &&
1531 e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight) {
1532
1533 return true;
1534
1535 }
1536
1537 return false;
1538
1539 } catch (e) {
1540 exception_error("cdmArticleIsVisible", e);
1541 }
1542 }
1543
1544 function cdmWatchdog() {
1545
1546 try {
1547
1548 var ctr = $("headlinesInnerContainer");
1549
1550 if (!ctr) return;
1551
1552 var ids = new Array();
1553
1554 var e = ctr.firstChild;
1555
1556 while (e) {
1557 if (e.className && e.className == "cdmArticleUnread" && e.id &&
1558 e.id.match("RROW-")) {
1559
1560 // article fits in viewport OR article is longer than viewport and
1561 // its bottom is visible
1562
1563 if (ctr.scrollTop <= e.offsetTop && e.offsetTop + e.offsetHeight <=
1564 ctr.scrollTop + ctr.offsetHeight) {
1565
1566 // debug(e.id + " is visible " + e.offsetTop + "." +
1567 // (e.offsetTop + e.offsetHeight) + " vs " + ctr.scrollTop + "." +
1568 // (ctr.scrollTop + ctr.offsetHeight));
1569
1570 ids.push(e.id.replace("RROW-", ""));
1571
1572 } else if (e.offsetHeight > ctr.offsetHeight &&
1573 e.offsetTop + e.offsetHeight >= ctr.scrollTop &&
1574 e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight) {
1575
1576 ids.push(e.id.replace("RROW-", ""));
1577
1578 }
1579
1580 // method 2: article bottom is visible and is in upper 1/2 of the viewport
1581
1582 /* if (e.offsetTop + e.offsetHeight >= ctr.scrollTop &&
1583 e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight/2) {
1584
1585 ids.push(e.id.replace("RROW-", ""));
1586
1587 } */
1588
1589 }
1590
1591 e = e.nextSibling;
1592 }
1593
1594 debug("cdmWatchdog, ids= " + ids.toString());
1595
1596 if (ids.length > 0) {
1597
1598 for (var i = 0; i < ids.length; i++) {
1599 var e = $("RROW-" + ids[i]);
1600 if (e) {
1601 e.className = e.className.replace("Unread", "");
1602 }
1603 }
1604
1605 var query = "backend.php?op=rpc&subop=catchupSelected" +
1606 "&cmode=0";
1607
1608 var ids = "?ids=" + param_escape(ids.toString());
1609
1610 new Ajax.Request(query, {
1611 parameters: ids,
1612 onComplete: function(transport) {
1613 all_counters_callback2(transport);
1614 } });
1615
1616 }
1617
1618 _cdm_wd_timeout = window.setTimeout("cdmWatchdog()", 4000);
1619
1620 } catch (e) {
1621 exception_error("cdmWatchdog", e);
1622 }
1623
1624 }
1625
1626
1627 function cache_inject(id, article, param) {
1628 try {
1629 if (!cache_check_param(id, param)) {
1630 debug("cache_article: miss: " + id + " [p=" + param + "]");
1631
1632
1633 if (db) {
1634
1635 var date = new Date();
1636 var ts = Math.round(date.getTime() / 1000);
1637
1638 db.execute("INSERT INTO cache (id, article, param, added) VALUES (?, ?, ?, ?)",
1639 [id, article, param, ts]);
1640 } else {
1641
1642 var cache_obj = new Array();
1643
1644 cache_obj["id"] = id;
1645 cache_obj["data"] = article;
1646 cache_obj["param"] = param;
1647
1648 article_cache.push(cache_obj);
1649 }
1650
1651 } else {
1652 debug("cache_article: hit: " + id + " [p=" + param + "]");
1653 }
1654 } catch (e) {
1655 exception_error("cache_inject", e);
1656 }
1657 }
1658
1659 function cache_find(id) {
1660
1661 if (db) {
1662 var rs = db.execute("SELECT article FROM cache WHERE id = ?", [id]);
1663 var a = false;
1664
1665 if (rs.isValidRow()) {
1666 var a = rs.field(0);
1667 }
1668
1669 rs.close();
1670
1671 return a;
1672
1673 } else {
1674 for (var i = 0; i < article_cache.length; i++) {
1675 if (article_cache[i]["id"] == id) {
1676 return article_cache[i]["data"];
1677 }
1678 }
1679 }
1680 return false;
1681 }
1682
1683 function cache_find_param(id, param) {
1684
1685 if (db) {
1686 var rs = db.execute("SELECT article FROM cache WHERE id = ? AND param = ?",
1687 [id, param]);
1688 var a = false;
1689
1690 if (rs.isValidRow()) {
1691 a = rs.field(0);
1692 }
1693
1694 rs.close();
1695
1696 return a;
1697
1698 } else {
1699 for (var i = 0; i < article_cache.length; i++) {
1700 if (article_cache[i]["id"] == id && article_cache[i]["param"] == param) {
1701 return article_cache[i]["data"];
1702 }
1703 }
1704 }
1705 return false;
1706 }
1707
1708 function cache_check(id) {
1709
1710 if (db) {
1711 var rs = db.execute("SELECT COUNT(*) AS c FROM cache WHERE id = ?",
1712 [id]);
1713 var a = false;
1714
1715 if (rs.isValidRow()) {
1716 a = rs.field(0) != "0";
1717 }
1718
1719 rs.close();
1720
1721 return a;
1722
1723 } else {
1724 for (var i = 0; i < article_cache.length; i++) {
1725 if (article_cache[i]["id"] == id) {
1726 return true;
1727 }
1728 }
1729 }
1730 return false;
1731 }
1732
1733 function cache_check_param(id, param) {
1734
1735 if (db) {
1736 var rs = db.execute("SELECT COUNT(*) AS c FROM cache WHERE id = ? AND param = ?",
1737 [id, param]);
1738 var a = false;
1739
1740 if (rs.isValidRow()) {
1741 a = rs.field(0) != "0";
1742 }
1743
1744 rs.close();
1745
1746 return a;
1747
1748 } else {
1749 for (var i = 0; i < article_cache.length; i++) {
1750 if (article_cache[i]["id"] == id && article_cache[i]["param"] == param) {
1751 return true;
1752 }
1753 }
1754 }
1755 return false;
1756 }
1757
1758 function cache_expire() {
1759 if (db) {
1760 var date = new Date();
1761 var ts = Math.round(date.getTime() / 1000);
1762
1763 db.execute("DELETE FROM cache WHERE added < ? - 1800 AND id LIKE 'FEEDLIST'", [ts]);
1764 db.execute("DELETE FROM cache WHERE added < ? - 600 AND (id LIKE 'F:%' OR id LIKE 'C:%')", [ts]);
1765 db.execute("DELETE FROM cache WHERE added < ? - 86400", [ts]);
1766
1767
1768 } else {
1769 while (article_cache.length > 25) {
1770 article_cache.shift();
1771 }
1772 }
1773 }
1774
1775 function cache_empty() {
1776 article_cache = new Array();
1777 }
1778
1779 function cache_invalidate(id) {
1780 try {
1781
1782 if (db) {
1783 rs = db.execute("DELETE FROM cache WHERE id = ?", [id]);
1784 return rs.rowsAffected != 0;
1785 } else {
1786
1787 var i = 0
1788
1789 while (i < article_cache.length) {
1790 if (article_cache[i]["id"] == id) {
1791 debug("cache_invalidate: removed id " + id);
1792 article_cache.splice(i, 1);
1793 return true;
1794 }
1795 i++;
1796 }
1797 }
1798
1799 debug("cache_invalidate: id not found: " + id);
1800 return false;
1801 } catch (e) {
1802 exception_error("cache_invalidate", e);
1803 }
1804 }
1805
1806 function getActiveArticleId() {
1807 return active_post_id;
1808 }
1809
1810 function cdmClicked(id) {
1811 try {
1812 var elem = $("RROW-" + id);
1813
1814 if (elem) {
1815 var id = elem.id.replace("RROW-", "");
1816 active_post_id = id;
1817
1818 // cdmSelectArticles("none");
1819 toggleUnread(id, 0, true);
1820 // toggleSelected(id);
1821
1822 }
1823 } catch (e) {
1824 exception_error("cdmClicked", e);
1825 }
1826 }
1827
1828 function preload_article_callback(transport) {
1829 try {
1830 if (transport.responseXML) {
1831 var articles = transport.responseXML.getElementsByTagName("article");
1832
1833 for (var i = 0; i < articles.length; i++) {
1834 var id = articles[i].getAttribute("id");
1835 if (!cache_check(id)) {
1836 cache_inject(id, articles[i].firstChild.nodeValue);
1837 debug("preloaded article: " + id);
1838 }
1839 }
1840 }
1841 } catch (e) {
1842 exception_error("preload_article_callback", e);
1843 }
1844 }
1845
1846 function preloadArticleUnderPointer(id) {
1847 try {
1848 if (getInitParam("bw_limit") == "1") return;
1849
1850 if (post_under_pointer == id && !cache_check(id)) {
1851
1852 debug("trying to preload article " + id);
1853
1854 var neighbor_ids = getRelativePostIds(id, 1);
1855
1856 /* only request uncached articles */
1857
1858 var cids_to_request = Array();
1859
1860 for (var i = 0; i < neighbor_ids.length; i++) {
1861 if (!cache_check(neighbor_ids[i])) {
1862 cids_to_request.push(neighbor_ids[i]);
1863 }
1864 }
1865 debug("additional ids: " + cids_to_request.toString());
1866
1867 cids_to_request.push(id);
1868
1869 var query = "backend.php?op=rpc&subop=getArticles&ids=" +
1870 cids_to_request.toString();
1871 new Ajax.Request(query, {
1872 onComplete: function(transport) {
1873 preload_article_callback(transport);
1874 } });
1875 }
1876 } catch (e) {
1877 exception_error("preloadArticleUnderPointer", e);
1878 }
1879 }
1880
1881 function postMouseIn(id) {
1882 try {
1883 if (post_under_pointer != id) {
1884 post_under_pointer = id;
1885 if (!isCdmMode()) {
1886 window.setTimeout("preloadArticleUnderPointer(" + id + ")", 250);
1887 }
1888 }
1889
1890 } catch (e) {
1891 exception_error("postMouseIn", e);
1892 }
1893 }
1894
1895 function postMouseOut(id) {
1896 try {
1897 post_under_pointer = false;
1898 } catch (e) {
1899 exception_error("postMouseOut", e);
1900 }
1901 }
1902
1903 function headlines_scroll_handler() {
1904 try {
1905
1906 var e = $("headlinesInnerContainer");
1907
1908 // don't do infinite scrolling when Limit == All
1909
1910 var toolbar_form = document.forms["main_toolbar_form"];
1911
1912 var limit = toolbar_form.limit[toolbar_form.limit.selectedIndex];
1913 if (limit.value != 0) {
1914
1915 debug((e.scrollTop + e.offsetHeight) + " vs " + e.scrollHeight + " dis? " +
1916 _infscroll_disable);
1917
1918 if (e.scrollTop + e.offsetHeight > e.scrollHeight - 100) {
1919 if (!_infscroll_disable) {
1920 debug("more cowbell!");
1921 viewNextFeedPage();
1922 }
1923 }
1924 }
1925
1926 } catch (e) {
1927 exception_error("headlines_scroll_handler", e);
1928 }
1929 }
1930
1931 function catchupRelativeToArticle(below) {
1932
1933 try {
1934
1935
1936 if (!getActiveArticleId()) {
1937 alert(__("No article is selected."));
1938 return;
1939 }
1940
1941 var visible_ids;
1942
1943 if ($("headlinesList")) {
1944 visible_ids = getVisibleHeadlineIds();
1945 } else {
1946 visible_ids = cdmGetVisibleArticles();
1947 }
1948
1949 var ids_to_mark = new Array();
1950
1951 if (!below) {
1952 for (var i = 0; i < visible_ids.length; i++) {
1953 if (visible_ids[i] != getActiveArticleId()) {
1954 var e = $("RROW-" + visible_ids[i]);
1955
1956 if (e && e.className.match("Unread")) {
1957 ids_to_mark.push(visible_ids[i]);
1958 }
1959 } else {
1960 break;
1961 }
1962 }
1963 } else {
1964 for (var i = visible_ids.length-1; i >= 0; i--) {
1965 if (visible_ids[i] != getActiveArticleId()) {
1966 var e = $("RROW-" + visible_ids[i]);
1967
1968 if (e && e.className.match("Unread")) {
1969 ids_to_mark.push(visible_ids[i]);
1970 }
1971 } else {
1972 break;
1973 }
1974 }
1975 }
1976
1977 if (ids_to_mark.length == 0) {
1978 alert(__("No articles found to mark"));
1979 } else {
1980 var msg = __("Mark %d article(s) as read?").replace("%d", ids_to_mark.length);
1981
1982 if (confirm(msg)) {
1983
1984 for (var i = 0; i < ids_to_mark.length; i++) {
1985 var e = $("RROW-" + ids_to_mark[i]);
1986 e.className = e.className.replace("Unread", "");
1987 }
1988
1989 var query = "backend.php?op=rpc&subop=catchupSelected" +
1990 "&cmode=0";
1991
1992 var ids = "?ids=" + param_escape(ids_to_mark.toString());
1993
1994 new Ajax.Request(query, {
1995 parameters: ids,
1996 onComplete: function(transport) {
1997 catchup_callback2(transport);
1998 } });
1999
2000 }
2001 }
2002
2003 } catch (e) {
2004 exception_error("catchupRelativeToArticle", e);
2005 }
2006 }
2007
2008 function cdmExpandArticle(a_id) {
2009 try {
2010 var id = 'CICD-' + a_id;
2011
2012 try {
2013 Element.hide("CEXC-" + a_id);
2014 } catch (e) { }
2015
2016 Effect.Appear(id, {duration : 0.5,
2017 beforeStart: function(effect) {
2018 var h_id = 'CICH-' + a_id;
2019 var h_elem = $(h_id);
2020 if (h_elem) { h_elem.style.display = "none"; }
2021
2022 toggleUnread(a_id, 0);
2023 }});
2024
2025
2026 } catch (e) {
2027 exception_error("appearBlockElementF", e);
2028 }
2029
2030 }
2031
2032 function fixHeadlinesOrder(ids) {
2033 try {
2034 for (var i = 0; i < ids.length; i++) {
2035 var e = $("RROW-" + ids[i]);
2036
2037 if (e) {
2038 if (i % 2 == 0) {
2039 e.className = e.className.replace("even", "odd");
2040 } else {
2041 e.className = e.className.replace("odd", "even");
2042 }
2043 }
2044 }
2045 } catch (e) {
2046 exception_error("fixHeadlinesOrder", e);
2047 }
2048 }
2049
2050 function hideReadHeadlines() {
2051 try {
2052
2053 var ids = false;
2054 var vis_ids = new Array();
2055
2056 if ($("headlinesList")) {
2057 ids = getVisibleHeadlineIds();
2058 } else {
2059 ids = cdmGetVisibleArticles();
2060 }
2061
2062 var read_headlines_visible = true;
2063
2064 for (var i = 0; i < ids.length; i++) {
2065 var row = $("RROW-" + ids[i]);
2066
2067 if (row && row.className) {
2068 if (read_headlines_visible) {
2069 if (row.className.match("Unread") || row.className.match("Selected")) {
2070 Element.show(row);
2071 vis_ids.push(ids[i]);
2072 } else {
2073 //Effect.Fade(row, {duration : 0.3});
2074 Element.hide(row);
2075 }
2076 } else {
2077 Element.show(row);
2078 vis_ids.push(ids[i]);
2079 }
2080 }
2081 }
2082
2083 fixHeadlinesOrder(vis_ids);
2084
2085 read_headlines_visible = !read_headlines_visible;
2086
2087 } catch (e) {
2088 exception_error("hideReadHeadlines", e);
2089 }
2090 }
2091
2092 function invertHeadlineSelection() {
2093 try {
2094 var rows = new Array();
2095 var r = false;
2096
2097 if (!isCdmMode()) {
2098 r = document.getElementsByTagName("TR");
2099 } else {
2100 r = document.getElementsByTagName("DIV");
2101 }
2102
2103 for (var i = 0; i < r.length; i++) {
2104 if (r[i].id && r[i].id.match("RROW-")) {
2105 rows.push(r[i]);
2106 }
2107 }
2108
2109 for (var i = 0; i < rows.length; i++) {
2110 var nc = rows[i].className;
2111 var id = rows[i].id.replace("RROW-", "");
2112 var cb = $("RCHK-" + id);
2113
2114 if (!rows[i].className.match("Selected")) {
2115 nc = nc + "Selected";
2116 cb.checked = true;
2117 } else {
2118 nc = nc.replace("Selected", "");
2119 cb.checked = false;
2120 }
2121
2122 rows[i].className = nc;
2123
2124 }
2125
2126 } catch (e) {
2127 exception_error("invertHeadlineSelection", e);
2128 }
2129 }
2130
2131 function getArticleUnderPointer() {
2132 return post_under_pointer;
2133 }
2134
2135 function zoomToArticle(id) {
2136 try {
2137 var w = window.open("backend.php?op=view&mode=zoom&id=" + param_escape(id),
2138 "ttrss_zoom_" + id,
2139 "status=0,toolbar=0,location=0,width=450,height=300,scrollbars=1,menubar=0");
2140
2141 } catch (e) {
2142 exception_error("zoomToArticle", e);
2143 }
2144 }
2145
2146 function showOriginalArticleInline(id) {
2147 try {
2148
2149 var query = "backend.php?op=rpc&subop=getArticleLink&id=" + id;
2150
2151 notify_progress("Loading, please wait...", true);
2152
2153 new Ajax.Request(query, {
2154 onComplete: function(transport) {
2155
2156 if (transport.responseXML) {
2157
2158 var link = transport.responseXML.getElementsByTagName("link")[0];
2159 var id = transport.responseXML.getElementsByTagName("id")[0];
2160
2161 notify("");
2162
2163 if (link && id) {
2164 link = link.firstChild.nodeValue;
2165
2166 var ci = $("content-insert");
2167
2168 var tmp = "<iframe id=\"inline_orig_article\" width=\""+ci.offsetWidth+"\" height=\""+ci.offsetHeight+"\" style=\"border-width : 0px;\" src=\""+link+"\"></iframe>";
2169
2170 render_article(tmp);
2171
2172 }
2173 }
2174 } });
2175
2176 } catch (e) {
2177 exception_error("showOriginalArticleInline", e);
2178 }
2179 }
2180
2181
2182 function scrollArticle(offset) {
2183 try {
2184 if (!isCdmMode()) {
2185 var ci = $("content-insert");
2186 if (ci) {
2187 ci.scrollTop += offset;
2188 }
2189 } else {
2190 var hi = $("headlinesInnerContainer");
2191 if (hi) {
2192 hi.scrollTop += offset;
2193 }
2194
2195 }
2196 } catch (e) {
2197 exception_error("scrollArticle", e);
2198 }
2199 }
2200
2201 function show_labels_in_headlines(transport) {
2202 try {
2203 if (transport.responseXML) {
2204 var info = transport.responseXML.getElementsByTagName("info-for-headlines")[0];
2205
2206 var elems = info.getElementsByTagName("entry");
2207
2208 for (var l = 0; l < elems.length; l++) {
2209 var e_id = elems[l].getAttribute("id");
2210
2211 if (e_id) {
2212
2213 var ctr = $("HLLCTR-" + e_id);
2214
2215 if (ctr) {
2216 ctr.innerHTML = elems[l].firstChild.nodeValue;
2217 }
2218 }
2219
2220 }
2221
2222 }
2223 } catch (e) {
2224 exception_error("show_labels_in_headlines", e);
2225
2226 }
2227 }
2228
2229 function toggleHeadlineActions() {
2230 try {
2231 var e = $("headlineActionsBody");
2232 var p = $("headlineActionsDrop");
2233
2234 if (!Element.visible(e)) {
2235 Element.show(e);
2236 } else {
2237 Element.hide(e);
2238 }
2239
2240 e.scrollTop = 0;
2241 e.style.left = (p.offsetLeft + 1) + "px";
2242 e.style.top = (p.offsetTop + p.offsetHeight + 2) + "px";
2243
2244 } catch (e) {
2245 exception_error("toggleHeadlineActions", e);
2246 }
2247 }
2248
2249 function publishWithNote(id, def_note) {
2250 try {
2251 if (!def_note) def_note = '';
2252
2253 var note = prompt(__("Please enter a note for this article:"), def_note);
2254
2255 if (note != undefined) {
2256 togglePub(id, false, false, note);
2257 }
2258
2259 } catch (e) {
2260 exception_error("publishWithNote", e);
2261 }
2262 }