]> git.wh0rd.org - tt-rss.git/blame - viewfeed.js
new option: STRIP_UNSAFE_TAGS
[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
AD
48
49 f.innerHTML = headlines.firstChild.nodeValue;
50
961f4c73
AD
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
3de0261a
AD
59 if (counters) {
60 debug("parsing piggybacked counters: " + counters);
61 parse_counters(counters, false);
addb5836
AD
62 } else {
63 debug("counters container not found in reply");
3de0261a
AD
64 }
65 } else {
66 debug("headlines_callback: returned no XML object");
addb5836 67 f.innerHTML = "<div class='whiteBox'>" + __('Could not update headlines (missing XML object)') + "</div>";
3de0261a
AD
68 }
69
935f235d
AD
70 if (typeof correctPNG != 'undefined') {
71 correctPNG();
72 }
ba0978c8
AD
73
74 if (_cdm_wd_timeout) window.clearTimeout(_cdm_wd_timeout);
75
ac7bcd71
AD
76 if (!document.getElementById("headlinesList") &&
77 getInitParam("cdm_auto_catchup") == 1) {
ba0978c8
AD
78 debug("starting CDM watchdog");
79 _cdm_wd_timeout = window.setTimeout("cdmWatchdog()", 5000);
80 _cdm_wd_vishist = new Array();
ac7bcd71
AD
81 } else {
82 debug("not in CDM mode or watchdog disabled");
ba0978c8
AD
83 }
84
13f08f75
AD
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
33b8cab4 92 notify("");
6b4163cb
AD
93 }
94}
95
e097e8be
AD
96function render_article(article) {
97 try {
6b4163cb 98 var f = document.getElementById("content-frame");
44cc6f20
AD
99 try {
100 f.scrollTop = 0;
101 } catch (e) { };
e097e8be
AD
102
103 f.innerHTML = article;
104
105 } catch (e) {
106 exception_error("render_article", e);
107 }
108}
109
110function 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");
0d88fd97
AD
135 var f = document.getElementById("content-frame");
136 f.innerHTML = "<div class='whiteBox'>" + __('Could not display article (missing XML object)') + "</div>";
e097e8be
AD
137 }
138 } catch (e) {
139 exception_error("article_callback", e);
140 }
4b6206fa
AD
141
142 var date = new Date();
143 last_article_view = date.getTime() / 1000;
144
935f235d
AD
145 if (typeof correctPNG != 'undefined') {
146 correctPNG();
147 }
0b126ac2
AD
148
149 if (_reload_feedlist_after_view) {
150 setTimeout('updateFeedList(false, false)', 50);
151 _reload_feedlist_after_view = false;
152 } else {
5a94a953
AD
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 {
addb5836 159 debug("counters container not found in reply");
5a94a953 160 }
0b126ac2 161 }
9ec58704
AD
162
163 notify("");
6b4163cb
AD
164 }
165}
166
1dc8dba0 167function view(id, feed_id, skip_history) {
ee1f45f4
AD
168
169 try {
ee1f45f4 170 debug("loading article: " + id + "/" + feed_id);
1dc8dba0 171
0b126ac2
AD
172 active_real_feed_id = feed_id;
173
e097e8be
AD
174 var cached_article = cache_find(id);
175
176 debug("cache check result: " + (cached_article != false));
177
178/* if (!skip_history) {
1dc8dba0 179 history_push("ARTICLE:" + id + ":" + feed_id);
e097e8be 180 } */
ee1f45f4 181
ee1f45f4
AD
182 enableHotkeys();
183
1c2d7193 184 //setActiveFeedId(feed_id);
090e250b 185
6b4163cb
AD
186 var query = "backend.php?op=view&id=" + param_escape(id) +
187 "&feed=" + param_escape(feed_id);
188
4b6206fa
AD
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
ac162cbe
AD
196 if (xmlhttp_ready(xmlhttp)) {
197
198 active_post_id = id;
4b6206fa
AD
199
200 cleanSelected("headlinesList");
201
202 var crow = document.getElementById("RROW-" + active_post_id);
e097e8be
AD
203
204 var article_is_unread = crow.className.match("Unread");
205 debug("article is unread: " + article_is_unread);
206
4b6206fa
AD
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
e097e8be
AD
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
5a94a953
AD
232 /* additional info for piggyback counters */
233
234 if (tagsAreDisplayed()) {
235 query = query + "&omode=lt";
236 } else {
237 query = query + "&omode=flc";
238 }
239
86173d9a
AD
240 var date = new Date();
241 var timestamp = Math.round(date.getTime() / 1000);
9ec58704
AD
242 query = query + "&ts=" + timestamp;
243
e097e8be
AD
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
addb5836
AD
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
e097e8be
AD
277 render_article(cached_article);
278
279 }
280
281 cache_expire();
86173d9a 282
6b4163cb
AD
283 } else {
284 debug("xmlhttp busy (@view)");
f88e0a5d 285 printLockingError();
6b4163cb
AD
286 }
287
ee1f45f4
AD
288 } catch (e) {
289 exception_error("view", e);
290 }
f0601b87
AD
291}
292
67343d9f
AD
293function tMark(id) {
294 return toggleMark(id);
295}
296
9932fb06 297function toggleMark(id) {
f0601b87
AD
298
299 if (!xmlhttp_ready(xmlhttp_rpc)) {
300 printLockingError();
301 return;
302 }
303
f0601b87
AD
304 var query = "backend.php?op=rpc&id=" + id + "&subop=mark";
305
67343d9f 306 var mark_img = document.getElementById("FMPIC-" + id);
0feab655 307 var vfeedu = document.getElementById("FEEDU--1");
7ba176d2 308 var crow = document.getElementById("RROW-" + id);
254e0e4b 309
9932fb06 310 if (mark_img.alt != "Reset mark") {
f0601b87
AD
311 mark_img.src = "images/mark_set.png";
312 mark_img.alt = "Reset mark";
f0601b87 313 query = query + "&mark=1";
254e0e4b 314
7ba176d2
AD
315 if (vfeedu && crow.className.match("Unread")) {
316 vfeedu.innerHTML = (+vfeedu.innerHTML) + 1;
317 }
318
f0601b87
AD
319 } else {
320 mark_img.src = "images/mark_unset.png";
321 mark_img.alt = "Set mark";
f0601b87 322 query = query + "&mark=0";
254e0e4b 323
7ba176d2
AD
324 if (vfeedu && crow.className.match("Unread")) {
325 vfeedu.innerHTML = (+vfeedu.innerHTML) - 1;
326 }
254e0e4b
AD
327
328 }
329
0feab655
AD
330 var vfeedctr = document.getElementById("FEEDCTR--1");
331 var vfeedr = document.getElementById("FEEDR--1");
254e0e4b
AD
332
333 if (vfeedu && vfeedctr) {
334 if ((+vfeedu.innerHTML) > 0) {
7ba176d2 335 if (crow.className.match("Unread") && !vfeedr.className.match("Unread")) {
8add756a 336 vfeedr.className = vfeedr.className + "Unread";
7ba176d2 337 vfeedctr.className = "odd";
8add756a 338 }
254e0e4b
AD
339 } else {
340 vfeedctr.className = "invisible";
8add756a 341 vfeedr.className = vfeedr.className.replace("Unread", "");
254e0e4b 342 }
f0601b87
AD
343 }
344
772bc83b
AD
345 debug("toggle starred for aid " + id);
346
347 new Ajax.Request(query);
f0601b87
AD
348
349}
350
ac162cbe
AD
351function 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);
a5e46e0f 366
ac162cbe
AD
367 if (rel_offset_top <= 0 || rel_offset_top > viewport) {
368 container.scrollTop = row.offsetTop;
369 } else if (rel_offset_bottom > viewport) {
a5e46e0f
AD
370
371 /* doesn't properly work with Opera in some cases because
372 Opera fucks up element scrolling */
373
ac162cbe
AD
374 container.scrollTop = row.offsetTop + row.offsetHeight - viewport;
375 }
376
377 } catch (e) {
378 exception_error("correctHeadlinesOffset", e);
379 }
380
381}
382
bb7cface 383function moveToPost(mode) {
f0601b87 384
4e51dd2b
AD
385 // check for combined mode
386 if (!document.getElementById("headlinesList"))
387 return;
388
bb7cface
AD
389 var rows = getVisibleHeadlineIds();
390
ac162cbe
AD
391 var prev_id = false;
392 var next_id = false;
bb7cface 393
d4eec882
AD
394 if (!document.getElementById('RROW-' + active_post_id)) {
395 active_post_id = false;
396 }
397
bb7cface
AD
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") {
ac162cbe
AD
411 if (next_id) {
412 correctHeadlinesOffset(next_id);
86741347 413 view(next_id, getActiveFeedId());
bb7cface
AD
414 }
415 }
416
417 if (mode == "prev") {
ac162cbe
AD
418 if (prev_id) {
419 correctHeadlinesOffset(prev_id);
86741347 420 view(prev_id, getActiveFeedId());
bb7cface
AD
421 }
422 }
423}
424
5f51022a
AD
425function 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
9ec58704
AD
449 notify_progress("Loading, please wait...");
450
5f51022a
AD
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
2228d0e4 463function selectionToggleUnread(cdm_mode, set_state, callback_func, no_error) {
1572afe5
AD
464 try {
465 if (!xmlhttp_ready(xmlhttp_rpc)) {
466 printLockingError();
467 return;
468 }
469
386cbf27
AD
470 var rows;
471
472 if (cdm_mode) {
473 rows = cdmGetSelectedArticles();
474 } else {
475 rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
476 }
1572afe5 477
2228d0e4 478 if (rows.length == 0 && !no_error) {
9cc600d1
AD
479 alert(__("No articles are selected."));
480 return;
481 }
482
1572afe5 483 for (i = 0; i < rows.length; i++) {
f1f2db64
AD
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 }
1572afe5
AD
496 }
497
498 if (rows.length > 0) {
499
b47b5af7
AD
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
1572afe5 510 var query = "backend.php?op=rpc&subop=catchupSelected&ids=" +
b47b5af7 511 param_escape(rows.toString()) + "&cmode=" + cmode;
1572afe5 512
e08443c1
AD
513 _catchup_callback_func = callback_func;
514
9ec58704
AD
515 notify_progress("Loading, please wait...");
516
1572afe5 517 xmlhttp_rpc.open("GET", query, true);
e08443c1 518 xmlhttp_rpc.onreadystatechange=catchup_callback;
1572afe5
AD
519 xmlhttp_rpc.send(null);
520
521 }
522
523 } catch (e) {
83f043bb 524 exception_error("selectionToggleUnread", e);
1572afe5
AD
525 }
526}
527
386cbf27 528function selectionToggleMarked(cdm_mode) {
1572afe5
AD
529 try {
530 if (!xmlhttp_ready(xmlhttp_rpc)) {
531 printLockingError();
532 return;
533 }
534
386cbf27
AD
535 var rows;
536
537 if (cdm_mode) {
538 rows = cdmGetSelectedArticles();
539 } else {
540 rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
541 }
1572afe5 542
9cc600d1
AD
543 if (rows.length == 0) {
544 alert(__("No articles are selected."));
545 return;
546 }
547
1572afe5
AD
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) {
83f043bb 581 exception_error("selectionToggleMarked", e);
1572afe5
AD
582 }
583}
584
386cbf27
AD
585function cdmGetSelectedArticles() {
586 var sel_articles = new Array();
b2128f01 587 var container = document.getElementById("headlinesInnerContainer");
386cbf27
AD
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
602function cdmSelectArticles(mode) {
b2128f01 603 var container = document.getElementById("headlinesInnerContainer");
386cbf27
AD
604
605 for (i = 0; i < container.childNodes.length; i++) {
606 var child = container.childNodes[i];
607
608 if (child.id.match("RROW-")) {
06d1a1c1
AD
609 var aid = child.id.replace("RROW-", "");
610
611 var cb = document.getElementById("RCHK-" + aid);
612
386cbf27
AD
613 if (mode == "all") {
614 if (!child.className.match("Selected")) {
615 child.className = child.className + "Selected";
06d1a1c1 616 cb.checked = true;
386cbf27
AD
617 }
618 } else if (mode == "unread") {
619 if (child.className.match("Unread") && !child.className.match("Selected")) {
620 child.className = child.className + "Selected";
06d1a1c1 621 cb.checked = true;
386cbf27
AD
622 }
623 } else {
624 child.className = child.className.replace("Selected", "");
06d1a1c1 625 cb.checked = false;
386cbf27
AD
626 }
627 }
628 }
629}
630
98bea1b1 631function catchupPage() {
b47b5af7
AD
632
633 if (document.getElementById("headlinesList")) {
634 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, 'Unread', true);
2228d0e4 635 selectionToggleUnread(false, false, 'viewCurrentFeed()', true);
b47b5af7
AD
636 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
637 } else {
638 cdmSelectArticles('all');
2228d0e4 639 selectionToggleUnread(true, false, 'viewCurrentFeed()', true)
b47b5af7
AD
640 cdmSelectArticles('none');
641 }
98bea1b1
AD
642}
643
88040f57
AD
644function 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);
0feab655 662 xmlhttp_rpc.onreadystatechange=dlg_frefresh_callback;
88040f57
AD
663 xmlhttp_rpc.send(null);
664 }
665
666}
667
13f08f75 668function editArticleTags(id, feed_id, cdm_enabled) {
0b126ac2
AD
669 _tag_active_post_id = id;
670 _tag_active_feed_id = feed_id;
13f08f75 671 _tag_active_cdm = cdm_enabled;
b07b61da
AD
672
673 cache_invalidate(id);
674
13f08f75
AD
675 try {
676 _tag_cdm_scroll = document.getElementById("headlinesInnerContainer").scrollTop;
677 } catch (e) { }
0b126ac2
AD
678 displayDlg('editArticleTags', id);
679}
680
681
682function 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
13f08f75
AD
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 }
0b126ac2
AD
703
704 } catch (e) {
705 exception_error("catchup_callback", e);
706 }
707 }
708}
709
710function editTagsSave() {
711
712 if (!xmlhttp_ready(xmlhttp_rpc)) {
713 printLockingError();
714 }
715
42c32916 716 notify_progress("Saving article tags...");
88040f57 717
0b126ac2
AD
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}
d62a3b63
AD
727
728function 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}
ba0978c8
AD
752
753function cdmWatchdog() {
754
755 try {
756
757 var ctr = document.getElementById("headlinesInnerContainer");
758
9acd22e8
AD
759 if (!ctr) return;
760
ba0978c8
AD
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
c50e2b30
AD
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
ba0978c8
AD
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
f8e47112 817 xmlhttp_rpc.open("GET", query, true);
ba0978c8 818 xmlhttp_rpc.onreadystatechange=all_counters_callback;
c50e2b30 819 xmlhttp_rpc.send(null);
ba0978c8
AD
820
821 }
822
c50e2b30 823 _cdm_wd_timeout = window.setTimeout("cdmWatchdog()", 4000);
ba0978c8
AD
824
825 } catch (e) {
826 exception_error(e, "cdmWatchdog");
827 }
828
829}
e097e8be
AD
830
831
832function cache_inject(id, article) {
fed4387d 833 if (!cache_check(id)) {
e097e8be
AD
834 debug("cache_article: miss: " + id);
835
836 var cache_obj = new Array();
837
fed4387d 838 cache_obj["id"] = id;
e097e8be
AD
839 cache_obj["data"] = article;
840
fed4387d 841 article_cache.push(cache_obj);
e097e8be
AD
842
843 } else {
844 debug("cache_article: hit: " + id);
845 }
846}
847
848function cache_find(id) {
fed4387d
AD
849 for (var i = 0; i < article_cache.length; i++) {
850 if (article_cache[i]["id"] == id) {
fed4387d
AD
851 return article_cache[i]["data"];
852 }
e097e8be 853 }
fed4387d 854 return false;
e097e8be
AD
855}
856
857function cache_check(id) {
fed4387d
AD
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;
e097e8be
AD
864}
865
866function cache_expire() {
7289eacf 867 while (article_cache.length > 20) {
fed4387d
AD
868 article_cache.shift();
869 }
e097e8be 870}
b07b61da
AD
871
872function 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}