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