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