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