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