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