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