]>
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 | ||
67343d9f AD |
291 | function tMark(id) { |
292 | return toggleMark(id); | |
293 | } | |
294 | ||
9932fb06 | 295 | function toggleMark(id) { |
f0601b87 AD |
296 | |
297 | if (!xmlhttp_ready(xmlhttp_rpc)) { | |
298 | printLockingError(); | |
299 | return; | |
300 | } | |
301 | ||
f0601b87 AD |
302 | var query = "backend.php?op=rpc&id=" + id + "&subop=mark"; |
303 | ||
67343d9f | 304 | var mark_img = document.getElementById("FMPIC-" + id); |
0feab655 | 305 | var vfeedu = document.getElementById("FEEDU--1"); |
7ba176d2 | 306 | var crow = document.getElementById("RROW-" + id); |
254e0e4b | 307 | |
9932fb06 | 308 | if (mark_img.alt != "Reset mark") { |
f0601b87 AD |
309 | mark_img.src = "images/mark_set.png"; |
310 | mark_img.alt = "Reset mark"; | |
f0601b87 | 311 | query = query + "&mark=1"; |
254e0e4b | 312 | |
7ba176d2 AD |
313 | if (vfeedu && crow.className.match("Unread")) { |
314 | vfeedu.innerHTML = (+vfeedu.innerHTML) + 1; | |
315 | } | |
316 | ||
f0601b87 AD |
317 | } else { |
318 | mark_img.src = "images/mark_unset.png"; | |
319 | mark_img.alt = "Set mark"; | |
f0601b87 | 320 | query = query + "&mark=0"; |
254e0e4b | 321 | |
7ba176d2 AD |
322 | if (vfeedu && crow.className.match("Unread")) { |
323 | vfeedu.innerHTML = (+vfeedu.innerHTML) - 1; | |
324 | } | |
254e0e4b AD |
325 | |
326 | } | |
327 | ||
0feab655 AD |
328 | var vfeedctr = document.getElementById("FEEDCTR--1"); |
329 | var vfeedr = document.getElementById("FEEDR--1"); | |
254e0e4b AD |
330 | |
331 | if (vfeedu && vfeedctr) { | |
332 | if ((+vfeedu.innerHTML) > 0) { | |
7ba176d2 | 333 | if (crow.className.match("Unread") && !vfeedr.className.match("Unread")) { |
8add756a | 334 | vfeedr.className = vfeedr.className + "Unread"; |
7ba176d2 | 335 | vfeedctr.className = "odd"; |
8add756a | 336 | } |
254e0e4b AD |
337 | } else { |
338 | vfeedctr.className = "invisible"; | |
8add756a | 339 | vfeedr.className = vfeedr.className.replace("Unread", ""); |
254e0e4b | 340 | } |
f0601b87 AD |
341 | } |
342 | ||
772bc83b AD |
343 | debug("toggle starred for aid " + id); |
344 | ||
345 | new Ajax.Request(query); | |
f0601b87 AD |
346 | |
347 | } | |
348 | ||
bb7cface | 349 | function moveToPost(mode) { |
f0601b87 | 350 | |
4e51dd2b AD |
351 | // check for combined mode |
352 | if (!document.getElementById("headlinesList")) | |
353 | return; | |
354 | ||
bb7cface AD |
355 | var rows = getVisibleHeadlineIds(); |
356 | ||
357 | var prev_id; | |
358 | var next_id; | |
359 | ||
d4eec882 AD |
360 | if (!document.getElementById('RROW-' + active_post_id)) { |
361 | active_post_id = false; | |
362 | } | |
363 | ||
bb7cface AD |
364 | if (active_post_id == false) { |
365 | next_id = getFirstVisibleHeadlineId(); | |
366 | prev_id = getLastVisibleHeadlineId(); | |
367 | } else { | |
368 | for (var i = 0; i < rows.length; i++) { | |
369 | if (rows[i] == active_post_id) { | |
370 | prev_id = rows[i-1]; | |
371 | next_id = rows[i+1]; | |
372 | } | |
373 | } | |
374 | } | |
375 | ||
376 | if (mode == "next") { | |
377 | if (next_id != undefined) { | |
86741347 | 378 | view(next_id, getActiveFeedId()); |
bb7cface AD |
379 | } |
380 | } | |
381 | ||
382 | if (mode == "prev") { | |
383 | if ( prev_id != undefined) { | |
86741347 | 384 | view(prev_id, getActiveFeedId()); |
bb7cface AD |
385 | } |
386 | } | |
387 | } | |
388 | ||
5f51022a AD |
389 | function toggleUnread(id, cmode) { |
390 | try { | |
391 | if (!xmlhttp_ready(xmlhttp_rpc)) { | |
392 | printLockingError(); | |
393 | return; | |
394 | } | |
395 | ||
396 | var row = document.getElementById("RROW-" + id); | |
397 | if (row) { | |
398 | var nc = row.className; | |
399 | nc = nc.replace("Unread", ""); | |
400 | nc = nc.replace("Selected", ""); | |
401 | ||
402 | if (row.className.match("Unread")) { | |
403 | row.className = nc; | |
404 | } else { | |
405 | row.className = nc + "Unread"; | |
406 | } | |
407 | ||
408 | if (!cmode) cmode = 2; | |
409 | ||
410 | var query = "backend.php?op=rpc&subop=catchupSelected&ids=" + | |
411 | param_escape(id) + "&cmode=" + param_escape(cmode); | |
412 | ||
9ec58704 AD |
413 | notify_progress("Loading, please wait..."); |
414 | ||
5f51022a AD |
415 | xmlhttp_rpc.open("GET", query, true); |
416 | xmlhttp_rpc.onreadystatechange=all_counters_callback; | |
417 | xmlhttp_rpc.send(null); | |
418 | ||
419 | } | |
420 | ||
421 | ||
422 | } catch (e) { | |
423 | exception_error("toggleUnread", e); | |
424 | } | |
425 | } | |
426 | ||
2228d0e4 | 427 | function selectionToggleUnread(cdm_mode, set_state, callback_func, no_error) { |
1572afe5 AD |
428 | try { |
429 | if (!xmlhttp_ready(xmlhttp_rpc)) { | |
430 | printLockingError(); | |
431 | return; | |
432 | } | |
433 | ||
386cbf27 AD |
434 | var rows; |
435 | ||
436 | if (cdm_mode) { | |
437 | rows = cdmGetSelectedArticles(); | |
438 | } else { | |
439 | rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK"); | |
440 | } | |
1572afe5 | 441 | |
2228d0e4 | 442 | if (rows.length == 0 && !no_error) { |
9cc600d1 AD |
443 | alert(__("No articles are selected.")); |
444 | return; | |
445 | } | |
446 | ||
1572afe5 | 447 | for (i = 0; i < rows.length; i++) { |
f1f2db64 AD |
448 | var row = document.getElementById("RROW-" + rows[i]); |
449 | if (row) { | |
450 | var nc = row.className; | |
451 | nc = nc.replace("Unread", ""); | |
452 | nc = nc.replace("Selected", ""); | |
453 | ||
454 | if (row.className.match("Unread")) { | |
455 | row.className = nc + "Selected"; | |
456 | } else { | |
457 | row.className = nc + "UnreadSelected"; | |
458 | } | |
459 | } | |
1572afe5 AD |
460 | } |
461 | ||
462 | if (rows.length > 0) { | |
463 | ||
b47b5af7 AD |
464 | var cmode = ""; |
465 | ||
466 | if (set_state == undefined) { | |
467 | cmode = "2"; | |
468 | } else if (set_state == true) { | |
469 | cmode = "1"; | |
470 | } else if (set_state == false) { | |
471 | cmode = "0"; | |
472 | } | |
473 | ||
1572afe5 | 474 | var query = "backend.php?op=rpc&subop=catchupSelected&ids=" + |
b47b5af7 | 475 | param_escape(rows.toString()) + "&cmode=" + cmode; |
1572afe5 | 476 | |
e08443c1 AD |
477 | _catchup_callback_func = callback_func; |
478 | ||
9ec58704 AD |
479 | notify_progress("Loading, please wait..."); |
480 | ||
1572afe5 | 481 | xmlhttp_rpc.open("GET", query, true); |
e08443c1 | 482 | xmlhttp_rpc.onreadystatechange=catchup_callback; |
1572afe5 AD |
483 | xmlhttp_rpc.send(null); |
484 | ||
485 | } | |
486 | ||
487 | } catch (e) { | |
83f043bb | 488 | exception_error("selectionToggleUnread", e); |
1572afe5 AD |
489 | } |
490 | } | |
491 | ||
386cbf27 | 492 | function selectionToggleMarked(cdm_mode) { |
1572afe5 AD |
493 | try { |
494 | if (!xmlhttp_ready(xmlhttp_rpc)) { | |
495 | printLockingError(); | |
496 | return; | |
497 | } | |
498 | ||
386cbf27 AD |
499 | var rows; |
500 | ||
501 | if (cdm_mode) { | |
502 | rows = cdmGetSelectedArticles(); | |
503 | } else { | |
504 | rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK"); | |
505 | } | |
1572afe5 | 506 | |
9cc600d1 AD |
507 | if (rows.length == 0) { |
508 | alert(__("No articles are selected.")); | |
509 | return; | |
510 | } | |
511 | ||
1572afe5 AD |
512 | for (i = 0; i < rows.length; i++) { |
513 | var row = document.getElementById("RROW-" + rows[i]); | |
514 | var mark_img = document.getElementById("FMARKPIC-" + rows[i]); | |
515 | ||
516 | if (row && mark_img) { | |
517 | ||
518 | if (mark_img.alt == "Set mark") { | |
519 | mark_img.src = "images/mark_set.png"; | |
520 | mark_img.alt = "Reset mark"; | |
521 | mark_img.setAttribute('onclick', | |
522 | 'javascript:toggleMark('+rows[i]+', false)'); | |
523 | ||
524 | } else { | |
525 | mark_img.src = "images/mark_unset.png"; | |
526 | mark_img.alt = "Set mark"; | |
527 | mark_img.setAttribute('onclick', | |
528 | 'javascript:toggleMark('+rows[i]+', true)'); | |
529 | } | |
530 | } | |
531 | } | |
532 | ||
533 | if (rows.length > 0) { | |
534 | ||
535 | var query = "backend.php?op=rpc&subop=markSelected&ids=" + | |
536 | param_escape(rows.toString()) + "&cmode=2"; | |
537 | ||
538 | xmlhttp_rpc.open("GET", query, true); | |
539 | xmlhttp_rpc.onreadystatechange=all_counters_callback; | |
540 | xmlhttp_rpc.send(null); | |
541 | ||
542 | } | |
543 | ||
544 | } catch (e) { | |
83f043bb | 545 | exception_error("selectionToggleMarked", e); |
1572afe5 AD |
546 | } |
547 | } | |
548 | ||
386cbf27 AD |
549 | function cdmGetSelectedArticles() { |
550 | var sel_articles = new Array(); | |
b2128f01 | 551 | var container = document.getElementById("headlinesInnerContainer"); |
386cbf27 AD |
552 | |
553 | for (i = 0; i < container.childNodes.length; i++) { | |
554 | var child = container.childNodes[i]; | |
555 | ||
556 | if (child.id.match("RROW-") && child.className.match("Selected")) { | |
557 | var c_id = child.id.replace("RROW-", ""); | |
558 | sel_articles.push(c_id); | |
559 | } | |
560 | } | |
561 | ||
562 | return sel_articles; | |
563 | } | |
564 | ||
565 | // mode = all,none,unread | |
566 | function cdmSelectArticles(mode) { | |
b2128f01 | 567 | var container = document.getElementById("headlinesInnerContainer"); |
386cbf27 AD |
568 | |
569 | for (i = 0; i < container.childNodes.length; i++) { | |
570 | var child = container.childNodes[i]; | |
571 | ||
572 | if (child.id.match("RROW-")) { | |
06d1a1c1 AD |
573 | var aid = child.id.replace("RROW-", ""); |
574 | ||
575 | var cb = document.getElementById("RCHK-" + aid); | |
576 | ||
386cbf27 AD |
577 | if (mode == "all") { |
578 | if (!child.className.match("Selected")) { | |
579 | child.className = child.className + "Selected"; | |
06d1a1c1 | 580 | cb.checked = true; |
386cbf27 AD |
581 | } |
582 | } else if (mode == "unread") { | |
583 | if (child.className.match("Unread") && !child.className.match("Selected")) { | |
584 | child.className = child.className + "Selected"; | |
06d1a1c1 | 585 | cb.checked = true; |
386cbf27 AD |
586 | } |
587 | } else { | |
588 | child.className = child.className.replace("Selected", ""); | |
06d1a1c1 | 589 | cb.checked = false; |
386cbf27 AD |
590 | } |
591 | } | |
592 | } | |
593 | } | |
594 | ||
98bea1b1 | 595 | function catchupPage() { |
b47b5af7 AD |
596 | |
597 | if (document.getElementById("headlinesList")) { | |
598 | selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, 'Unread', true); | |
2228d0e4 | 599 | selectionToggleUnread(false, false, 'viewCurrentFeed()', true); |
b47b5af7 AD |
600 | selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false); |
601 | } else { | |
602 | cdmSelectArticles('all'); | |
2228d0e4 | 603 | selectionToggleUnread(true, false, 'viewCurrentFeed()', true) |
b47b5af7 AD |
604 | cdmSelectArticles('none'); |
605 | } | |
98bea1b1 AD |
606 | } |
607 | ||
88040f57 AD |
608 | function labelFromSearch(search, search_mode, match_on, feed_id, is_cat) { |
609 | ||
610 | if (!xmlhttp_ready(xmlhttp_rpc)) { | |
611 | printLockingError(); | |
612 | } | |
613 | ||
614 | var title = prompt("Please enter label title:", ""); | |
615 | ||
616 | if (title) { | |
617 | ||
618 | var query = "backend.php?op=labelFromSearch&search=" + param_escape(search) + | |
619 | "&smode=" + param_escape(search_mode) + "&match=" + param_escape(match_on) + | |
620 | "&feed=" + param_escape(feed_id) + "&is_cat=" + param_escape(is_cat) + | |
621 | "&title=" + param_escape(title); | |
622 | ||
623 | debug("LFS: " + query); | |
624 | ||
625 | xmlhttp_rpc.open("GET", query, true); | |
0feab655 | 626 | xmlhttp_rpc.onreadystatechange=dlg_frefresh_callback; |
88040f57 AD |
627 | xmlhttp_rpc.send(null); |
628 | } | |
629 | ||
630 | } | |
631 | ||
13f08f75 | 632 | function editArticleTags(id, feed_id, cdm_enabled) { |
0b126ac2 AD |
633 | _tag_active_post_id = id; |
634 | _tag_active_feed_id = feed_id; | |
13f08f75 AD |
635 | _tag_active_cdm = cdm_enabled; |
636 | try { | |
637 | _tag_cdm_scroll = document.getElementById("headlinesInnerContainer").scrollTop; | |
638 | } catch (e) { } | |
0b126ac2 AD |
639 | displayDlg('editArticleTags', id); |
640 | } | |
641 | ||
642 | ||
643 | function tag_saved_callback() { | |
644 | if (xmlhttp_rpc.readyState == 4) { | |
645 | try { | |
646 | debug("in tag_saved_callback"); | |
647 | ||
648 | closeInfoBox(); | |
649 | notify(""); | |
650 | ||
651 | if (tagsAreDisplayed()) { | |
652 | _reload_feedlist_after_view = true; | |
653 | } | |
654 | ||
13f08f75 AD |
655 | if (!_tag_active_cdm) { |
656 | if (active_post_id == _tag_active_post_id) { | |
657 | debug("reloading current article"); | |
658 | view(_tag_active_post_id, _tag_active_feed_id); | |
659 | } | |
660 | } else { | |
661 | debug("reloading current feed"); | |
662 | viewCurrentFeed(); | |
663 | } | |
0b126ac2 AD |
664 | |
665 | } catch (e) { | |
666 | exception_error("catchup_callback", e); | |
667 | } | |
668 | } | |
669 | } | |
670 | ||
671 | function editTagsSave() { | |
672 | ||
673 | if (!xmlhttp_ready(xmlhttp_rpc)) { | |
674 | printLockingError(); | |
675 | } | |
676 | ||
42c32916 | 677 | notify_progress("Saving article tags..."); |
88040f57 | 678 | |
0b126ac2 AD |
679 | var form = document.forms["tag_edit_form"]; |
680 | ||
681 | var query = Form.serialize("tag_edit_form"); | |
682 | ||
683 | xmlhttp_rpc.open("GET", "backend.php?op=rpc&subop=setArticleTags&" + query, true); | |
684 | xmlhttp_rpc.onreadystatechange=tag_saved_callback; | |
685 | xmlhttp_rpc.send(null); | |
686 | ||
687 | } | |
d62a3b63 AD |
688 | |
689 | function editTagsInsert() { | |
690 | try { | |
691 | ||
692 | var form = document.forms["tag_edit_form"]; | |
693 | ||
694 | var found_tags = form.found_tags; | |
695 | var tags_str = form.tags_str; | |
696 | ||
697 | var tag = found_tags[found_tags.selectedIndex].value; | |
698 | ||
699 | if (tags_str.value.length > 0 && | |
700 | tags_str.value.lastIndexOf(", ") != tags_str.value.length - 2) { | |
701 | ||
702 | tags_str.value = tags_str.value + ", "; | |
703 | } | |
704 | ||
705 | tags_str.value = tags_str.value + tag + ", "; | |
706 | ||
707 | found_tags.selectedIndex = 0; | |
708 | ||
709 | } catch (e) { | |
710 | exception_error(e, "editTagsInsert"); | |
711 | } | |
712 | } | |
ba0978c8 AD |
713 | |
714 | function cdmWatchdog() { | |
715 | ||
716 | try { | |
717 | ||
718 | var ctr = document.getElementById("headlinesInnerContainer"); | |
719 | ||
9acd22e8 AD |
720 | if (!ctr) return; |
721 | ||
ba0978c8 AD |
722 | var ids = new Array(); |
723 | ||
724 | var e = ctr.firstChild; | |
725 | ||
726 | while (e) { | |
727 | if (e.className && e.className == "cdmArticleUnread" && e.id && | |
728 | e.id.match("RROW-")) { | |
729 | ||
730 | // article fits in viewport OR article is longer than viewport and | |
731 | // its bottom is visible | |
732 | ||
733 | if (ctr.scrollTop <= e.offsetTop && e.offsetTop + e.offsetHeight <= | |
734 | ctr.scrollTop + ctr.offsetHeight) { | |
735 | ||
736 | // debug(e.id + " is visible " + e.offsetTop + "." + | |
737 | // (e.offsetTop + e.offsetHeight) + " vs " + ctr.scrollTop + "." + | |
738 | // (ctr.scrollTop + ctr.offsetHeight)); | |
739 | ||
740 | ids.push(e.id.replace("RROW-", "")); | |
741 | ||
742 | } else if (e.offsetHeight > ctr.offsetHeight && | |
743 | e.offsetTop + e.offsetHeight >= ctr.scrollTop && | |
744 | e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight) { | |
745 | ||
746 | ids.push(e.id.replace("RROW-", "")); | |
747 | ||
748 | } | |
749 | ||
c50e2b30 AD |
750 | // method 2: article bottom is visible and is in upper 1/2 of the viewport |
751 | ||
752 | /* if (e.offsetTop + e.offsetHeight >= ctr.scrollTop && | |
753 | e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight/2) { | |
754 | ||
755 | ids.push(e.id.replace("RROW-", "")); | |
756 | ||
757 | } */ | |
758 | ||
ba0978c8 AD |
759 | } |
760 | ||
761 | e = e.nextSibling; | |
762 | } | |
763 | ||
764 | debug("cdmWatchdog, ids= " + ids.toString()); | |
765 | ||
766 | if (ids.length > 0 && xmlhttp_ready(xmlhttp_rpc)) { | |
767 | ||
768 | for (var i = 0; i < ids.length; i++) { | |
769 | var e = document.getElementById("RROW-" + ids[i]); | |
770 | if (e) { | |
771 | e.className = e.className.replace("Unread", ""); | |
772 | } | |
773 | } | |
774 | ||
775 | var query = "backend.php?op=rpc&subop=catchupSelected&ids=" + | |
776 | param_escape(ids.toString()) + "&cmode=0"; | |
777 | ||
f8e47112 | 778 | xmlhttp_rpc.open("GET", query, true); |
ba0978c8 | 779 | xmlhttp_rpc.onreadystatechange=all_counters_callback; |
c50e2b30 | 780 | xmlhttp_rpc.send(null); |
ba0978c8 AD |
781 | |
782 | } | |
783 | ||
c50e2b30 | 784 | _cdm_wd_timeout = window.setTimeout("cdmWatchdog()", 4000); |
ba0978c8 AD |
785 | |
786 | } catch (e) { | |
787 | exception_error(e, "cdmWatchdog"); | |
788 | } | |
789 | ||
790 | } | |
e097e8be AD |
791 | |
792 | ||
793 | function cache_inject(id, article) { | |
fed4387d | 794 | if (!cache_check(id)) { |
e097e8be AD |
795 | debug("cache_article: miss: " + id); |
796 | ||
797 | var cache_obj = new Array(); | |
798 | ||
fed4387d | 799 | cache_obj["id"] = id; |
e097e8be AD |
800 | cache_obj["data"] = article; |
801 | ||
fed4387d | 802 | article_cache.push(cache_obj); |
e097e8be AD |
803 | |
804 | } else { | |
805 | debug("cache_article: hit: " + id); | |
806 | } | |
807 | } | |
808 | ||
809 | function cache_find(id) { | |
fed4387d AD |
810 | for (var i = 0; i < article_cache.length; i++) { |
811 | if (article_cache[i]["id"] == id) { | |
fed4387d AD |
812 | return article_cache[i]["data"]; |
813 | } | |
e097e8be | 814 | } |
fed4387d | 815 | return false; |
e097e8be AD |
816 | } |
817 | ||
818 | function cache_check(id) { | |
fed4387d AD |
819 | for (var i = 0; i < article_cache.length; i++) { |
820 | if (article_cache[i]["id"] == id) { | |
821 | return true; | |
822 | } | |
823 | } | |
824 | return false; | |
e097e8be AD |
825 | } |
826 | ||
827 | function cache_expire() { | |
7289eacf | 828 | while (article_cache.length > 20) { |
fed4387d AD |
829 | article_cache.shift(); |
830 | } | |
e097e8be | 831 | } |