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