]> git.wh0rd.org - tt-rss.git/blame - viewfeed.js
properly unmark updated articles when reading
[tt-rss.git] / viewfeed.js
CommitLineData
bb7cface 1var active_post_id = false;
e08443c1 2var _catchup_callback_func = false;
4b6206fa 3var last_article_view = false;
0b126ac2
AD
4var active_real_feed_id = false;
5
6var _tag_active_post_id = false;
7var _tag_active_feed_id = false;
13f08f75 8var _tag_active_cdm = false;
0b126ac2 9
13f08f75
AD
10// FIXME: kludge, to restore scrollTop after tag editor terminates
11var _tag_cdm_scroll = false;
12
13// FIXME: kludges, needs proper implementation
0b126ac2 14var _reload_feedlist_after_view = false;
e08443c1 15
ba0978c8
AD
16var _cdm_wd_timeout = false;
17var _cdm_wd_vishist = new Array();
18
e097e8be
AD
19var article_cache = new Array();
20
e08443c1
AD
21function catchup_callback() {
22 if (xmlhttp_rpc.readyState == 4) {
8f3b99ba
AD
23 try {
24 debug("catchup_callback");
25 if (_catchup_callback_func) {
26 setTimeout(_catchup_callback_func, 100);
27 }
9ec58704 28 notify("");
8f3b99ba
AD
29 all_counters_callback();
30 } catch (e) {
31 exception_error("catchup_callback", e);
32 }
e08443c1
AD
33 }
34}
f0601b87 35
6b4163cb
AD
36function headlines_callback() {
37 if (xmlhttp.readyState == 4) {
38 debug("headlines_callback");
39 var f = document.getElementById("headlines-frame");
44cc6f20
AD
40 try {
41 f.scrollTop = 0;
42 } catch (e) { };
3de0261a
AD
43
44 if (xmlhttp.responseXML) {
45 var headlines = xmlhttp.responseXML.getElementsByTagName("headlines")[0];
46 var counters = xmlhttp.responseXML.getElementsByTagName("counters")[0];
47
48 f.innerHTML = headlines.firstChild.nodeValue;
49
50 if (counters) {
51 debug("parsing piggybacked counters: " + counters);
52 parse_counters(counters, false);
addb5836
AD
53 } else {
54 debug("counters container not found in reply");
3de0261a
AD
55 }
56 } else {
57 debug("headlines_callback: returned no XML object");
addb5836 58 f.innerHTML = "<div class='whiteBox'>" + __('Could not update headlines (missing XML object)') + "</div>";
3de0261a
AD
59 }
60
935f235d
AD
61 if (typeof correctPNG != 'undefined') {
62 correctPNG();
63 }
ba0978c8
AD
64
65 if (_cdm_wd_timeout) window.clearTimeout(_cdm_wd_timeout);
66
ac7bcd71
AD
67 if (!document.getElementById("headlinesList") &&
68 getInitParam("cdm_auto_catchup") == 1) {
ba0978c8
AD
69 debug("starting CDM watchdog");
70 _cdm_wd_timeout = window.setTimeout("cdmWatchdog()", 5000);
71 _cdm_wd_vishist = new Array();
ac7bcd71
AD
72 } else {
73 debug("not in CDM mode or watchdog disabled");
ba0978c8
AD
74 }
75
13f08f75
AD
76 if (_tag_cdm_scroll) {
77 try {
78 document.getElementById("headlinesInnerContainer").scrollTop = _tag_cdm_scroll;
79 _tag_cdm_scroll = false;
80 } catch (e) { }
81 }
82
33b8cab4 83 notify("");
6b4163cb
AD
84 }
85}
86
e097e8be
AD
87function render_article(article) {
88 try {
6b4163cb 89 var f = document.getElementById("content-frame");
44cc6f20
AD
90 try {
91 f.scrollTop = 0;
92 } catch (e) { };
e097e8be
AD
93
94 f.innerHTML = article;
95
96 } catch (e) {
97 exception_error("render_article", e);
98 }
99}
100
101function article_callback() {
102 if (xmlhttp.readyState == 4) {
103 debug("article_callback");
104
105 try {
106 if (xmlhttp.responseXML) {
107 var reply = xmlhttp.responseXML.firstChild.firstChild;
108
109 var articles = xmlhttp.responseXML.getElementsByTagName("article");
110
111 for (var i = 0; i < articles.length; i++) {
112 var a_id = articles[i].getAttribute("id");
113
114 debug("found id: " + a_id);
115
116 if (a_id == active_post_id) {
117 debug("active article, rendering...");
118 render_article(articles[i].firstChild.nodeValue);
119 }
120
121 cache_inject(a_id, articles[i].firstChild.nodeValue);
122 }
123
124 } else {
125 debug("article_callback: returned no XML object");
addb5836 126 f.innerHTML = "<div class='whiteBox'>" + __('Could not display article (missing XML object)') + "</div>";
e097e8be
AD
127 }
128 } catch (e) {
129 exception_error("article_callback", e);
130 }
4b6206fa
AD
131
132 var date = new Date();
133 last_article_view = date.getTime() / 1000;
134
935f235d
AD
135 if (typeof correctPNG != 'undefined') {
136 correctPNG();
137 }
0b126ac2
AD
138
139 if (_reload_feedlist_after_view) {
140 setTimeout('updateFeedList(false, false)', 50);
141 _reload_feedlist_after_view = false;
142 } else {
5a94a953
AD
143 var counters = xmlhttp.responseXML.getElementsByTagName("counters")[0];
144
145 if (counters) {
146 debug("parsing piggybacked counters: " + counters);
147 parse_counters(counters, false);
148 } else {
addb5836 149 debug("counters container not found in reply");
5a94a953 150 }
0b126ac2 151 }
9ec58704
AD
152
153 notify("");
6b4163cb
AD
154 }
155}
156
1dc8dba0 157function view(id, feed_id, skip_history) {
ee1f45f4
AD
158
159 try {
ee1f45f4 160 debug("loading article: " + id + "/" + feed_id);
1dc8dba0 161
0b126ac2
AD
162 active_real_feed_id = feed_id;
163
e097e8be
AD
164 var cached_article = cache_find(id);
165
166 debug("cache check result: " + (cached_article != false));
167
168/* if (!skip_history) {
1dc8dba0 169 history_push("ARTICLE:" + id + ":" + feed_id);
e097e8be 170 } */
ee1f45f4 171
ee1f45f4
AD
172 enableHotkeys();
173
ee1f45f4 174 active_post_id = id;
1c2d7193 175 //setActiveFeedId(feed_id);
090e250b 176
6b4163cb
AD
177 var query = "backend.php?op=view&id=" + param_escape(id) +
178 "&feed=" + param_escape(feed_id);
179
4b6206fa
AD
180 var date = new Date();
181
182 if (!xmlhttp_ready(xmlhttp) && last_article_view < date.getTime() / 1000 - 15) {
183 debug("<b>xmlhttp seems to be stuck at view, aborting</b>");
184 xmlhttp.abort();
185 }
186
e097e8be 187 if (cached_article || xmlhttp_ready(xmlhttp)) {
4b6206fa
AD
188
189 cleanSelected("headlinesList");
190
191 var crow = document.getElementById("RROW-" + active_post_id);
e097e8be
AD
192
193 var article_is_unread = crow.className.match("Unread");
194 debug("article is unread: " + article_is_unread);
195
4b6206fa
AD
196 crow.className = crow.className.replace("Unread", "");
197
198 var upd_img_pic = document.getElementById("FUPDPIC-" + active_post_id);
199
200 if (upd_img_pic) {
201 upd_img_pic.src = "images/blank_icon.gif";
202 }
203
204 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
205 markHeadline(active_post_id);
206
e097e8be
AD
207 var neighbor_ids = getRelativePostIds(active_post_id);
208
209 /* only request uncached articles */
210
211 var cids_to_request = Array();
212
213 for (var i = 0; i < neighbor_ids.length; i++) {
214 if (!cache_check(neighbor_ids[i])) {
215 cids_to_request.push(neighbor_ids[i]);
216 }
217 }
218
219 debug("additional ids: " + cids_to_request.toString());
220
5a94a953
AD
221 /* additional info for piggyback counters */
222
223 if (tagsAreDisplayed()) {
224 query = query + "&omode=lt";
225 } else {
226 query = query + "&omode=flc";
227 }
228
86173d9a
AD
229 var date = new Date();
230 var timestamp = Math.round(date.getTime() / 1000);
9ec58704
AD
231 query = query + "&ts=" + timestamp;
232
e097e8be
AD
233 query = query + "&cids=" + cids_to_request.toString();
234
235 if (!cached_article) {
236
237 notify_progress("Loading, please wait...");
238
239 debug(query);
240
241 xmlhttp.open("GET", query, true);
242 xmlhttp.onreadystatechange=article_callback;
243 xmlhttp.send(null);
244 } else if (cached_article && article_is_unread) {
245
246 query = query + "&mode=prefetch";
247
248 debug(query);
249
250 xmlhttp.open("GET", query, true);
251 xmlhttp.onreadystatechange=article_callback;
252 xmlhttp.send(null);
253
254 render_article(cached_article);
255
256 } else if (cached_article) {
257
addb5836
AD
258 query = query + "&mode=prefetch_old";
259
260 debug(query);
261
262 xmlhttp.open("GET", query, true);
263 xmlhttp.onreadystatechange=article_callback;
264 xmlhttp.send(null);
265
e097e8be
AD
266 render_article(cached_article);
267
268 }
269
270 cache_expire();
86173d9a 271
6b4163cb
AD
272 } else {
273 debug("xmlhttp busy (@view)");
f88e0a5d 274 printLockingError();
6b4163cb
AD
275 }
276
ee1f45f4
AD
277 } catch (e) {
278 exception_error("view", e);
279 }
f0601b87
AD
280}
281
9932fb06 282function toggleMark(id) {
f0601b87
AD
283
284 if (!xmlhttp_ready(xmlhttp_rpc)) {
285 printLockingError();
286 return;
287 }
288
f0601b87
AD
289 var query = "backend.php?op=rpc&id=" + id + "&subop=mark";
290
7ba176d2 291 var mark_img = document.getElementById("FMARKPIC-" + id);
0feab655 292 var vfeedu = document.getElementById("FEEDU--1");
7ba176d2 293 var crow = document.getElementById("RROW-" + id);
254e0e4b 294
9932fb06 295 if (mark_img.alt != "Reset mark") {
f0601b87
AD
296 mark_img.src = "images/mark_set.png";
297 mark_img.alt = "Reset mark";
f0601b87 298 query = query + "&mark=1";
254e0e4b 299
7ba176d2
AD
300 if (vfeedu && crow.className.match("Unread")) {
301 vfeedu.innerHTML = (+vfeedu.innerHTML) + 1;
302 }
303
f0601b87
AD
304 } else {
305 mark_img.src = "images/mark_unset.png";
306 mark_img.alt = "Set mark";
f0601b87 307 query = query + "&mark=0";
254e0e4b 308
7ba176d2
AD
309 if (vfeedu && crow.className.match("Unread")) {
310 vfeedu.innerHTML = (+vfeedu.innerHTML) - 1;
311 }
254e0e4b
AD
312
313 }
314
0feab655
AD
315 var vfeedctr = document.getElementById("FEEDCTR--1");
316 var vfeedr = document.getElementById("FEEDR--1");
254e0e4b
AD
317
318 if (vfeedu && vfeedctr) {
319 if ((+vfeedu.innerHTML) > 0) {
7ba176d2 320 if (crow.className.match("Unread") && !vfeedr.className.match("Unread")) {
8add756a 321 vfeedr.className = vfeedr.className + "Unread";
7ba176d2 322 vfeedctr.className = "odd";
8add756a 323 }
254e0e4b
AD
324 } else {
325 vfeedctr.className = "invisible";
8add756a 326 vfeedr.className = vfeedr.className.replace("Unread", "");
254e0e4b 327 }
f0601b87
AD
328 }
329
772bc83b
AD
330 debug("toggle starred for aid " + id);
331
332 new Ajax.Request(query);
f0601b87
AD
333
334}
335
bb7cface 336function moveToPost(mode) {
f0601b87 337
4e51dd2b
AD
338 // check for combined mode
339 if (!document.getElementById("headlinesList"))
340 return;
341
bb7cface
AD
342 var rows = getVisibleHeadlineIds();
343
344 var prev_id;
345 var next_id;
346
d4eec882
AD
347 if (!document.getElementById('RROW-' + active_post_id)) {
348 active_post_id = false;
349 }
350
bb7cface
AD
351 if (active_post_id == false) {
352 next_id = getFirstVisibleHeadlineId();
353 prev_id = getLastVisibleHeadlineId();
354 } else {
355 for (var i = 0; i < rows.length; i++) {
356 if (rows[i] == active_post_id) {
357 prev_id = rows[i-1];
358 next_id = rows[i+1];
359 }
360 }
361 }
362
363 if (mode == "next") {
364 if (next_id != undefined) {
86741347 365 view(next_id, getActiveFeedId());
bb7cface
AD
366 }
367 }
368
369 if (mode == "prev") {
370 if ( prev_id != undefined) {
86741347 371 view(prev_id, getActiveFeedId());
bb7cface
AD
372 }
373 }
374}
375
5f51022a
AD
376function toggleUnread(id, cmode) {
377 try {
378 if (!xmlhttp_ready(xmlhttp_rpc)) {
379 printLockingError();
380 return;
381 }
382
383 var row = document.getElementById("RROW-" + id);
384 if (row) {
385 var nc = row.className;
386 nc = nc.replace("Unread", "");
387 nc = nc.replace("Selected", "");
388
389 if (row.className.match("Unread")) {
390 row.className = nc;
391 } else {
392 row.className = nc + "Unread";
393 }
394
395 if (!cmode) cmode = 2;
396
397 var query = "backend.php?op=rpc&subop=catchupSelected&ids=" +
398 param_escape(id) + "&cmode=" + param_escape(cmode);
399
9ec58704
AD
400 notify_progress("Loading, please wait...");
401
5f51022a
AD
402 xmlhttp_rpc.open("GET", query, true);
403 xmlhttp_rpc.onreadystatechange=all_counters_callback;
404 xmlhttp_rpc.send(null);
405
406 }
407
408
409 } catch (e) {
410 exception_error("toggleUnread", e);
411 }
412}
413
2228d0e4 414function selectionToggleUnread(cdm_mode, set_state, callback_func, no_error) {
1572afe5
AD
415 try {
416 if (!xmlhttp_ready(xmlhttp_rpc)) {
417 printLockingError();
418 return;
419 }
420
386cbf27
AD
421 var rows;
422
423 if (cdm_mode) {
424 rows = cdmGetSelectedArticles();
425 } else {
426 rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
427 }
1572afe5 428
2228d0e4 429 if (rows.length == 0 && !no_error) {
9cc600d1
AD
430 alert(__("No articles are selected."));
431 return;
432 }
433
1572afe5 434 for (i = 0; i < rows.length; i++) {
f1f2db64
AD
435 var row = document.getElementById("RROW-" + rows[i]);
436 if (row) {
437 var nc = row.className;
438 nc = nc.replace("Unread", "");
439 nc = nc.replace("Selected", "");
440
441 if (row.className.match("Unread")) {
442 row.className = nc + "Selected";
443 } else {
444 row.className = nc + "UnreadSelected";
445 }
446 }
1572afe5
AD
447 }
448
449 if (rows.length > 0) {
450
b47b5af7
AD
451 var cmode = "";
452
453 if (set_state == undefined) {
454 cmode = "2";
455 } else if (set_state == true) {
456 cmode = "1";
457 } else if (set_state == false) {
458 cmode = "0";
459 }
460
1572afe5 461 var query = "backend.php?op=rpc&subop=catchupSelected&ids=" +
b47b5af7 462 param_escape(rows.toString()) + "&cmode=" + cmode;
1572afe5 463
e08443c1
AD
464 _catchup_callback_func = callback_func;
465
9ec58704
AD
466 notify_progress("Loading, please wait...");
467
1572afe5 468 xmlhttp_rpc.open("GET", query, true);
e08443c1 469 xmlhttp_rpc.onreadystatechange=catchup_callback;
1572afe5
AD
470 xmlhttp_rpc.send(null);
471
472 }
473
474 } catch (e) {
83f043bb 475 exception_error("selectionToggleUnread", e);
1572afe5
AD
476 }
477}
478
386cbf27 479function selectionToggleMarked(cdm_mode) {
1572afe5
AD
480 try {
481 if (!xmlhttp_ready(xmlhttp_rpc)) {
482 printLockingError();
483 return;
484 }
485
386cbf27
AD
486 var rows;
487
488 if (cdm_mode) {
489 rows = cdmGetSelectedArticles();
490 } else {
491 rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
492 }
1572afe5 493
9cc600d1
AD
494 if (rows.length == 0) {
495 alert(__("No articles are selected."));
496 return;
497 }
498
1572afe5
AD
499 for (i = 0; i < rows.length; i++) {
500 var row = document.getElementById("RROW-" + rows[i]);
501 var mark_img = document.getElementById("FMARKPIC-" + rows[i]);
502
503 if (row && mark_img) {
504
505 if (mark_img.alt == "Set mark") {
506 mark_img.src = "images/mark_set.png";
507 mark_img.alt = "Reset mark";
508 mark_img.setAttribute('onclick',
509 'javascript:toggleMark('+rows[i]+', false)');
510
511 } else {
512 mark_img.src = "images/mark_unset.png";
513 mark_img.alt = "Set mark";
514 mark_img.setAttribute('onclick',
515 'javascript:toggleMark('+rows[i]+', true)');
516 }
517 }
518 }
519
520 if (rows.length > 0) {
521
522 var query = "backend.php?op=rpc&subop=markSelected&ids=" +
523 param_escape(rows.toString()) + "&cmode=2";
524
525 xmlhttp_rpc.open("GET", query, true);
526 xmlhttp_rpc.onreadystatechange=all_counters_callback;
527 xmlhttp_rpc.send(null);
528
529 }
530
531 } catch (e) {
83f043bb 532 exception_error("selectionToggleMarked", e);
1572afe5
AD
533 }
534}
535
386cbf27
AD
536function cdmGetSelectedArticles() {
537 var sel_articles = new Array();
b2128f01 538 var container = document.getElementById("headlinesInnerContainer");
386cbf27
AD
539
540 for (i = 0; i < container.childNodes.length; i++) {
541 var child = container.childNodes[i];
542
543 if (child.id.match("RROW-") && child.className.match("Selected")) {
544 var c_id = child.id.replace("RROW-", "");
545 sel_articles.push(c_id);
546 }
547 }
548
549 return sel_articles;
550}
551
552// mode = all,none,unread
553function cdmSelectArticles(mode) {
b2128f01 554 var container = document.getElementById("headlinesInnerContainer");
386cbf27
AD
555
556 for (i = 0; i < container.childNodes.length; i++) {
557 var child = container.childNodes[i];
558
559 if (child.id.match("RROW-")) {
06d1a1c1
AD
560 var aid = child.id.replace("RROW-", "");
561
562 var cb = document.getElementById("RCHK-" + aid);
563
386cbf27
AD
564 if (mode == "all") {
565 if (!child.className.match("Selected")) {
566 child.className = child.className + "Selected";
06d1a1c1 567 cb.checked = true;
386cbf27
AD
568 }
569 } else if (mode == "unread") {
570 if (child.className.match("Unread") && !child.className.match("Selected")) {
571 child.className = child.className + "Selected";
06d1a1c1 572 cb.checked = true;
386cbf27
AD
573 }
574 } else {
575 child.className = child.className.replace("Selected", "");
06d1a1c1 576 cb.checked = false;
386cbf27
AD
577 }
578 }
579 }
580}
581
98bea1b1 582function catchupPage() {
b47b5af7
AD
583
584 if (document.getElementById("headlinesList")) {
585 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, 'Unread', true);
2228d0e4 586 selectionToggleUnread(false, false, 'viewCurrentFeed()', true);
b47b5af7
AD
587 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
588 } else {
589 cdmSelectArticles('all');
2228d0e4 590 selectionToggleUnread(true, false, 'viewCurrentFeed()', true)
b47b5af7
AD
591 cdmSelectArticles('none');
592 }
98bea1b1
AD
593}
594
88040f57
AD
595function labelFromSearch(search, search_mode, match_on, feed_id, is_cat) {
596
597 if (!xmlhttp_ready(xmlhttp_rpc)) {
598 printLockingError();
599 }
600
601 var title = prompt("Please enter label title:", "");
602
603 if (title) {
604
605 var query = "backend.php?op=labelFromSearch&search=" + param_escape(search) +
606 "&smode=" + param_escape(search_mode) + "&match=" + param_escape(match_on) +
607 "&feed=" + param_escape(feed_id) + "&is_cat=" + param_escape(is_cat) +
608 "&title=" + param_escape(title);
609
610 debug("LFS: " + query);
611
612 xmlhttp_rpc.open("GET", query, true);
0feab655 613 xmlhttp_rpc.onreadystatechange=dlg_frefresh_callback;
88040f57
AD
614 xmlhttp_rpc.send(null);
615 }
616
617}
618
13f08f75 619function editArticleTags(id, feed_id, cdm_enabled) {
0b126ac2
AD
620 _tag_active_post_id = id;
621 _tag_active_feed_id = feed_id;
13f08f75
AD
622 _tag_active_cdm = cdm_enabled;
623 try {
624 _tag_cdm_scroll = document.getElementById("headlinesInnerContainer").scrollTop;
625 } catch (e) { }
0b126ac2
AD
626 displayDlg('editArticleTags', id);
627}
628
629
630function tag_saved_callback() {
631 if (xmlhttp_rpc.readyState == 4) {
632 try {
633 debug("in tag_saved_callback");
634
635 closeInfoBox();
636 notify("");
637
638 if (tagsAreDisplayed()) {
639 _reload_feedlist_after_view = true;
640 }
641
13f08f75
AD
642 if (!_tag_active_cdm) {
643 if (active_post_id == _tag_active_post_id) {
644 debug("reloading current article");
645 view(_tag_active_post_id, _tag_active_feed_id);
646 }
647 } else {
648 debug("reloading current feed");
649 viewCurrentFeed();
650 }
0b126ac2
AD
651
652 } catch (e) {
653 exception_error("catchup_callback", e);
654 }
655 }
656}
657
658function editTagsSave() {
659
660 if (!xmlhttp_ready(xmlhttp_rpc)) {
661 printLockingError();
662 }
663
42c32916 664 notify_progress("Saving article tags...");
88040f57 665
0b126ac2
AD
666 var form = document.forms["tag_edit_form"];
667
668 var query = Form.serialize("tag_edit_form");
669
670 xmlhttp_rpc.open("GET", "backend.php?op=rpc&subop=setArticleTags&" + query, true);
671 xmlhttp_rpc.onreadystatechange=tag_saved_callback;
672 xmlhttp_rpc.send(null);
673
674}
d62a3b63
AD
675
676function editTagsInsert() {
677 try {
678
679 var form = document.forms["tag_edit_form"];
680
681 var found_tags = form.found_tags;
682 var tags_str = form.tags_str;
683
684 var tag = found_tags[found_tags.selectedIndex].value;
685
686 if (tags_str.value.length > 0 &&
687 tags_str.value.lastIndexOf(", ") != tags_str.value.length - 2) {
688
689 tags_str.value = tags_str.value + ", ";
690 }
691
692 tags_str.value = tags_str.value + tag + ", ";
693
694 found_tags.selectedIndex = 0;
695
696 } catch (e) {
697 exception_error(e, "editTagsInsert");
698 }
699}
ba0978c8
AD
700
701function cdmWatchdog() {
702
703 try {
704
705 var ctr = document.getElementById("headlinesInnerContainer");
706
9acd22e8
AD
707 if (!ctr) return;
708
ba0978c8
AD
709 var ids = new Array();
710
711 var e = ctr.firstChild;
712
713 while (e) {
714 if (e.className && e.className == "cdmArticleUnread" && e.id &&
715 e.id.match("RROW-")) {
716
717 // article fits in viewport OR article is longer than viewport and
718 // its bottom is visible
719
720 if (ctr.scrollTop <= e.offsetTop && e.offsetTop + e.offsetHeight <=
721 ctr.scrollTop + ctr.offsetHeight) {
722
723// debug(e.id + " is visible " + e.offsetTop + "." +
724// (e.offsetTop + e.offsetHeight) + " vs " + ctr.scrollTop + "." +
725// (ctr.scrollTop + ctr.offsetHeight));
726
727 ids.push(e.id.replace("RROW-", ""));
728
729 } else if (e.offsetHeight > ctr.offsetHeight &&
730 e.offsetTop + e.offsetHeight >= ctr.scrollTop &&
731 e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight) {
732
733 ids.push(e.id.replace("RROW-", ""));
734
735 }
736
c50e2b30
AD
737 // method 2: article bottom is visible and is in upper 1/2 of the viewport
738
739/* if (e.offsetTop + e.offsetHeight >= ctr.scrollTop &&
740 e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight/2) {
741
742 ids.push(e.id.replace("RROW-", ""));
743
744 } */
745
ba0978c8
AD
746 }
747
748 e = e.nextSibling;
749 }
750
751 debug("cdmWatchdog, ids= " + ids.toString());
752
753 if (ids.length > 0 && xmlhttp_ready(xmlhttp_rpc)) {
754
755 for (var i = 0; i < ids.length; i++) {
756 var e = document.getElementById("RROW-" + ids[i]);
757 if (e) {
758 e.className = e.className.replace("Unread", "");
759 }
760 }
761
762 var query = "backend.php?op=rpc&subop=catchupSelected&ids=" +
763 param_escape(ids.toString()) + "&cmode=0";
764
f8e47112 765 xmlhttp_rpc.open("GET", query, true);
ba0978c8 766 xmlhttp_rpc.onreadystatechange=all_counters_callback;
c50e2b30 767 xmlhttp_rpc.send(null);
ba0978c8
AD
768
769 }
770
c50e2b30 771 _cdm_wd_timeout = window.setTimeout("cdmWatchdog()", 4000);
ba0978c8
AD
772
773 } catch (e) {
774 exception_error(e, "cdmWatchdog");
775 }
776
777}
e097e8be
AD
778
779
780function cache_inject(id, article) {
fed4387d 781 if (!cache_check(id)) {
e097e8be
AD
782 debug("cache_article: miss: " + id);
783
784 var cache_obj = new Array();
785
786 var d = new Date();
fed4387d
AD
787
788 cache_obj["id"] = id;
e097e8be
AD
789 cache_obj["entered"] = d.getTime() / 1000;
790 cache_obj["data"] = article;
fed4387d
AD
791 cache_obj["last_access"] = 0;
792
793 //article_cache[id] = cache_obj;
e097e8be 794
fed4387d 795 article_cache.push(cache_obj);
e097e8be
AD
796
797 } else {
798 debug("cache_article: hit: " + id);
799 }
800}
801
802function cache_find(id) {
fed4387d
AD
803 for (var i = 0; i < article_cache.length; i++) {
804 if (article_cache[i]["id"] == id) {
805 var d = new Date();
806 article_cache[i]["last_access"] = d.getTime() / 1000;
807 return article_cache[i]["data"];
808 }
e097e8be 809 }
fed4387d 810 return false;
e097e8be
AD
811}
812
813function cache_check(id) {
fed4387d
AD
814 for (var i = 0; i < article_cache.length; i++) {
815 if (article_cache[i]["id"] == id) {
816 return true;
817 }
818 }
819 return false;
e097e8be
AD
820}
821
822function cache_expire() {
7289eacf 823 while (article_cache.length > 20) {
fed4387d
AD
824 article_cache.shift();
825 }
e097e8be 826}