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