]>
Commit | Line | Data |
---|---|---|
bb7cface | 1 | var active_post_id = false; |
4b6206fa | 2 | var last_article_view = false; |
0b126ac2 AD |
3 | var active_real_feed_id = false; |
4 | ||
5 | var _tag_active_post_id = false; | |
6 | var _tag_active_feed_id = false; | |
13f08f75 | 7 | var _tag_active_cdm = false; |
0b126ac2 | 8 | |
13f08f75 AD |
9 | // FIXME: kludge, to restore scrollTop after tag editor terminates |
10 | var _tag_cdm_scroll = false; | |
11 | ||
12 | // FIXME: kludges, needs proper implementation | |
0b126ac2 | 13 | var _reload_feedlist_after_view = false; |
e08443c1 | 14 | |
ba0978c8 AD |
15 | var _cdm_wd_timeout = false; |
16 | var _cdm_wd_vishist = new Array(); | |
17 | ||
e097e8be AD |
18 | var article_cache = new Array(); |
19 | ||
e08443c1 AD |
20 | function catchup_callback() { |
21 | if (xmlhttp_rpc.readyState == 4) { | |
8f3b99ba AD |
22 | try { |
23 | debug("catchup_callback"); | |
9ec58704 | 24 | notify(""); |
d395a942 | 25 | all_counters_callback2(xmlhttp_rpc); |
af6f8bf2 AD |
26 | if (_catchup_callback_func) { |
27 | setTimeout(_catchup_callback_func, 10); | |
28 | } | |
8f3b99ba AD |
29 | } catch (e) { |
30 | exception_error("catchup_callback", e); | |
31 | } | |
e08443c1 AD |
32 | } |
33 | } | |
f0601b87 | 34 | |
1341ea0d AD |
35 | function catchup_callback2(transport, callback) { |
36 | try { | |
37 | debug("catchup_callback2 " + transport + ", " + callback); | |
38 | notify(""); | |
39 | all_counters_callback2(transport); | |
40 | if (callback) { | |
41 | setTimeout(callback, 10); | |
42 | } | |
43 | } catch (e) { | |
44 | exception_error("catchup_callback2", e); | |
45 | } | |
46 | } | |
47 | ||
a49f5e05 AD |
48 | function headlines_callback2(transport, active_feed_id, active_feed_is_cat, feed_cur_page) { |
49 | debug("headlines_callback2"); | |
50 | var f = document.getElementById("headlines-frame"); | |
51 | try { | |
52 | if (feed_cur_page == 0) { | |
53 | debug("resetting headlines scrollTop"); | |
54 | f.scrollTop = 0; | |
55 | } | |
56 | } catch (e) { }; | |
3de0261a | 57 | |
a49f5e05 AD |
58 | if (transport.responseXML) { |
59 | var headlines = transport.responseXML.getElementsByTagName("headlines")[0]; | |
60 | var counters = transport.responseXML.getElementsByTagName("counters")[0]; | |
61 | var articles = transport.responseXML.getElementsByTagName("article"); | |
62 | var runtime_info = transport.responseXML.getElementsByTagName("runtime-info"); | |
63 | ||
64 | if (feed_cur_page == 0) { | |
65 | if (headlines) { | |
66 | f.innerHTML = headlines.firstChild.nodeValue; | |
007a38d4 | 67 | } else { |
a49f5e05 AD |
68 | debug("headlines_callback: returned no data"); |
69 | f.innerHTML = "<div class='whiteBox'>" + __('Could not update headlines (missing XML data)') + "</div>"; | |
ac541432 | 70 | |
a49f5e05 AD |
71 | } |
72 | } else { | |
73 | if (headlines) { | |
74 | debug("adding some more headlines..."); | |
ac541432 | 75 | |
a49f5e05 | 76 | var c = document.getElementById("headlinesList"); |
ac541432 | 77 | |
a49f5e05 AD |
78 | if (!c) { |
79 | c = document.getElementById("headlinesInnerContainer"); | |
ac541432 | 80 | } |
007a38d4 | 81 | |
a49f5e05 | 82 | c.innerHTML = c.innerHTML + headlines.firstChild.nodeValue; |
007a38d4 | 83 | } else { |
a49f5e05 AD |
84 | debug("headlines_callback: returned no data"); |
85 | notify_error("Error while trying to load more headlines"); | |
961f4c73 AD |
86 | } |
87 | ||
a49f5e05 | 88 | } |
03c88bdd | 89 | |
a49f5e05 AD |
90 | if (articles) { |
91 | for (var i = 0; i < articles.length; i++) { | |
92 | var a_id = articles[i].getAttribute("id"); | |
93 | debug("found id: " + a_id); | |
94 | cache_inject(a_id, articles[i].firstChild.nodeValue); | |
03c88bdd | 95 | } |
3de0261a | 96 | } else { |
a49f5e05 | 97 | debug("no cached articles received"); |
3de0261a AD |
98 | } |
99 | ||
a49f5e05 AD |
100 | if (counters) { |
101 | debug("parsing piggybacked counters: " + counters); | |
102 | parse_counters(counters, false); | |
103 | } else { | |
104 | debug("counters container not found in reply"); | |
935f235d | 105 | } |
ba0978c8 | 106 | |
a49f5e05 AD |
107 | if (runtime_info) { |
108 | debug("parsing runtime info: " + runtime_info[0]); | |
109 | parse_runtime_info(runtime_info[0]); | |
ac7bcd71 | 110 | } else { |
a49f5e05 | 111 | debug("counters container not found in reply"); |
ba0978c8 AD |
112 | } |
113 | ||
a49f5e05 AD |
114 | } else { |
115 | debug("headlines_callback: returned no XML object"); | |
116 | f.innerHTML = "<div class='whiteBox'>" + __('Could not update headlines (missing XML object)') + "</div>"; | |
117 | } | |
ac541432 | 118 | |
a49f5e05 AD |
119 | if (typeof correctPNG != 'undefined') { |
120 | correctPNG(); | |
121 | } | |
122 | ||
123 | if (_cdm_wd_timeout) window.clearTimeout(_cdm_wd_timeout); | |
124 | ||
125 | if (!document.getElementById("headlinesList") && | |
126 | getInitParam("cdm_auto_catchup") == 1) { | |
127 | debug("starting CDM watchdog"); | |
128 | _cdm_wd_timeout = window.setTimeout("cdmWatchdog()", 5000); | |
129 | _cdm_wd_vishist = new Array(); | |
130 | } else { | |
131 | debug("not in CDM mode or watchdog disabled"); | |
132 | } | |
133 | ||
134 | if (_tag_cdm_scroll) { | |
135 | try { | |
136 | document.getElementById("headlinesInnerContainer").scrollTop = _tag_cdm_scroll; | |
137 | _tag_cdm_scroll = false; | |
138 | debug("resetting headlinesInner scrollTop"); | |
13f08f75 | 139 | |
a49f5e05 | 140 | } catch (e) { } |
6b4163cb | 141 | } |
a49f5e05 AD |
142 | |
143 | notify(""); | |
6b4163cb AD |
144 | } |
145 | ||
e097e8be AD |
146 | function render_article(article) { |
147 | try { | |
6b4163cb | 148 | var f = document.getElementById("content-frame"); |
44cc6f20 AD |
149 | try { |
150 | f.scrollTop = 0; | |
151 | } catch (e) { }; | |
e097e8be AD |
152 | |
153 | f.innerHTML = article; | |
154 | ||
155 | } catch (e) { | |
156 | exception_error("render_article", e); | |
157 | } | |
158 | } | |
159 | ||
160 | function article_callback() { | |
161 | if (xmlhttp.readyState == 4) { | |
162 | debug("article_callback"); | |
163 | ||
164 | try { | |
165 | if (xmlhttp.responseXML) { | |
166 | var reply = xmlhttp.responseXML.firstChild.firstChild; | |
167 | ||
168 | var articles = xmlhttp.responseXML.getElementsByTagName("article"); | |
169 | ||
170 | for (var i = 0; i < articles.length; i++) { | |
171 | var a_id = articles[i].getAttribute("id"); | |
172 | ||
173 | debug("found id: " + a_id); | |
174 | ||
175 | if (a_id == active_post_id) { | |
176 | debug("active article, rendering..."); | |
177 | render_article(articles[i].firstChild.nodeValue); | |
178 | } | |
179 | ||
180 | cache_inject(a_id, articles[i].firstChild.nodeValue); | |
181 | } | |
182 | ||
183 | } else { | |
184 | debug("article_callback: returned no XML object"); | |
0d88fd97 AD |
185 | var f = document.getElementById("content-frame"); |
186 | f.innerHTML = "<div class='whiteBox'>" + __('Could not display article (missing XML object)') + "</div>"; | |
e097e8be AD |
187 | } |
188 | } catch (e) { | |
189 | exception_error("article_callback", e); | |
190 | } | |
4b6206fa AD |
191 | |
192 | var date = new Date(); | |
193 | last_article_view = date.getTime() / 1000; | |
194 | ||
935f235d AD |
195 | if (typeof correctPNG != 'undefined') { |
196 | correctPNG(); | |
197 | } | |
0b126ac2 AD |
198 | |
199 | if (_reload_feedlist_after_view) { | |
200 | setTimeout('updateFeedList(false, false)', 50); | |
201 | _reload_feedlist_after_view = false; | |
202 | } else { | |
5a94a953 AD |
203 | var counters = xmlhttp.responseXML.getElementsByTagName("counters")[0]; |
204 | ||
205 | if (counters) { | |
206 | debug("parsing piggybacked counters: " + counters); | |
207 | parse_counters(counters, false); | |
208 | } else { | |
addb5836 | 209 | debug("counters container not found in reply"); |
5a94a953 | 210 | } |
0b126ac2 | 211 | } |
9ec58704 AD |
212 | |
213 | notify(""); | |
6b4163cb AD |
214 | } |
215 | } | |
216 | ||
1dc8dba0 | 217 | function view(id, feed_id, skip_history) { |
ee1f45f4 AD |
218 | |
219 | try { | |
ee1f45f4 | 220 | debug("loading article: " + id + "/" + feed_id); |
1dc8dba0 | 221 | |
0b126ac2 AD |
222 | active_real_feed_id = feed_id; |
223 | ||
e097e8be AD |
224 | var cached_article = cache_find(id); |
225 | ||
226 | debug("cache check result: " + (cached_article != false)); | |
ee1f45f4 | 227 | |
ee1f45f4 AD |
228 | enableHotkeys(); |
229 | ||
1c2d7193 | 230 | //setActiveFeedId(feed_id); |
090e250b | 231 | |
6b4163cb AD |
232 | var query = "backend.php?op=view&id=" + param_escape(id) + |
233 | "&feed=" + param_escape(feed_id); | |
234 | ||
4b6206fa AD |
235 | var date = new Date(); |
236 | ||
237 | if (!xmlhttp_ready(xmlhttp) && last_article_view < date.getTime() / 1000 - 15) { | |
238 | debug("<b>xmlhttp seems to be stuck at view, aborting</b>"); | |
239 | xmlhttp.abort(); | |
c5af7171 | 240 | if (is_safari()) { |
86227583 AD |
241 | debug("trying alternative reset method for Safari"); |
242 | xmlhttp = Ajax.getTransport(); | |
c5af7171 | 243 | } |
4b6206fa AD |
244 | } |
245 | ||
ac162cbe AD |
246 | if (xmlhttp_ready(xmlhttp)) { |
247 | ||
248 | active_post_id = id; | |
4b6206fa AD |
249 | |
250 | cleanSelected("headlinesList"); | |
251 | ||
252 | var crow = document.getElementById("RROW-" + active_post_id); | |
e097e8be AD |
253 | |
254 | var article_is_unread = crow.className.match("Unread"); | |
255 | debug("article is unread: " + article_is_unread); | |
256 | ||
4b6206fa AD |
257 | crow.className = crow.className.replace("Unread", ""); |
258 | ||
259 | var upd_img_pic = document.getElementById("FUPDPIC-" + active_post_id); | |
260 | ||
261 | if (upd_img_pic) { | |
262 | upd_img_pic.src = "images/blank_icon.gif"; | |
263 | } | |
264 | ||
265 | selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false); | |
266 | markHeadline(active_post_id); | |
267 | ||
e097e8be AD |
268 | var neighbor_ids = getRelativePostIds(active_post_id); |
269 | ||
270 | /* only request uncached articles */ | |
271 | ||
272 | var cids_to_request = Array(); | |
273 | ||
274 | for (var i = 0; i < neighbor_ids.length; i++) { | |
275 | if (!cache_check(neighbor_ids[i])) { | |
276 | cids_to_request.push(neighbor_ids[i]); | |
277 | } | |
278 | } | |
279 | ||
280 | debug("additional ids: " + cids_to_request.toString()); | |
281 | ||
5a94a953 AD |
282 | /* additional info for piggyback counters */ |
283 | ||
284 | if (tagsAreDisplayed()) { | |
285 | query = query + "&omode=lt"; | |
286 | } else { | |
287 | query = query + "&omode=flc"; | |
288 | } | |
289 | ||
86173d9a AD |
290 | var date = new Date(); |
291 | var timestamp = Math.round(date.getTime() / 1000); | |
9ec58704 AD |
292 | query = query + "&ts=" + timestamp; |
293 | ||
e097e8be AD |
294 | query = query + "&cids=" + cids_to_request.toString(); |
295 | ||
296 | if (!cached_article) { | |
297 | ||
298 | notify_progress("Loading, please wait..."); | |
299 | ||
300 | debug(query); | |
301 | ||
302 | xmlhttp.open("GET", query, true); | |
303 | xmlhttp.onreadystatechange=article_callback; | |
304 | xmlhttp.send(null); | |
305 | } else if (cached_article && article_is_unread) { | |
306 | ||
307 | query = query + "&mode=prefetch"; | |
308 | ||
309 | debug(query); | |
310 | ||
311 | xmlhttp.open("GET", query, true); | |
312 | xmlhttp.onreadystatechange=article_callback; | |
313 | xmlhttp.send(null); | |
314 | ||
315 | render_article(cached_article); | |
316 | ||
317 | } else if (cached_article) { | |
318 | ||
addb5836 AD |
319 | query = query + "&mode=prefetch_old"; |
320 | ||
321 | debug(query); | |
322 | ||
323 | xmlhttp.open("GET", query, true); | |
324 | xmlhttp.onreadystatechange=article_callback; | |
325 | xmlhttp.send(null); | |
326 | ||
e097e8be AD |
327 | render_article(cached_article); |
328 | ||
329 | } | |
330 | ||
331 | cache_expire(); | |
86173d9a | 332 | |
6b4163cb AD |
333 | } else { |
334 | debug("xmlhttp busy (@view)"); | |
f88e0a5d | 335 | printLockingError(); |
6b4163cb AD |
336 | } |
337 | ||
ee1f45f4 AD |
338 | } catch (e) { |
339 | exception_error("view", e); | |
340 | } | |
f0601b87 AD |
341 | } |
342 | ||
67343d9f AD |
343 | function tMark(id) { |
344 | return toggleMark(id); | |
345 | } | |
346 | ||
e4f4b46f AD |
347 | function tPub(id) { |
348 | return togglePub(id); | |
349 | } | |
350 | ||
6b0f49f9 AD |
351 | function tMark_afh_off(effect) { |
352 | try { | |
353 | var elem = effect.effects[0].element; | |
354 | ||
355 | debug("tMark_afh_off : " + elem.id); | |
356 | ||
357 | if (elem) { | |
f5e0338d AD |
358 | elem.src = elem.src.replace("mark_set", "mark_unset"); |
359 | elem.alt = __("Star article"); | |
6b0f49f9 AD |
360 | Element.show(elem); |
361 | } | |
362 | ||
363 | } catch (e) { | |
364 | exception_error("tMark_afh_off", e); | |
365 | } | |
366 | } | |
367 | ||
368 | function tPub_afh_off(effect) { | |
369 | try { | |
370 | var elem = effect.effects[0].element; | |
371 | ||
372 | debug("tPub_afh_off : " + elem.id); | |
373 | ||
374 | if (elem) { | |
f5e0338d AD |
375 | elem.src = elem.src.replace("pub_set", "pub_unset"); |
376 | elem.alt = __("Publish article"); | |
6b0f49f9 AD |
377 | Element.show(elem); |
378 | } | |
379 | ||
380 | } catch (e) { | |
381 | exception_error("tPub_afh_off", e); | |
382 | } | |
383 | } | |
e4f4b46f | 384 | |
f5e0338d | 385 | function toggleMark(id, client_only, no_effects) { |
f0601b87 | 386 | |
b685ba25 | 387 | try { |
254e0e4b | 388 | |
b685ba25 AD |
389 | var query = "backend.php?op=rpc&id=" + id + "&subop=mark"; |
390 | ||
391 | query = query + "&afid=" + getActiveFeedId(); | |
392 | ||
393 | if (tagsAreDisplayed()) { | |
394 | query = query + "&omode=tl"; | |
395 | } else { | |
396 | query = query + "&omode=flc"; | |
7ba176d2 | 397 | } |
b685ba25 AD |
398 | |
399 | var mark_img = document.getElementById("FMPIC-" + id); | |
400 | var vfeedu = document.getElementById("FEEDU--1"); | |
401 | var crow = document.getElementById("RROW-" + id); | |
402 | ||
f5e0338d AD |
403 | if (mark_img.src.match("mark_unset")) { |
404 | mark_img.src = mark_img.src.replace("mark_unset", "mark_set"); | |
405 | mark_img.alt = __("Unstar article"); | |
b685ba25 AD |
406 | query = query + "&mark=1"; |
407 | ||
408 | /* if (vfeedu && crow.className.match("Unread")) { | |
409 | vfeedu.innerHTML = (+vfeedu.innerHTML) + 1; | |
410 | } */ | |
411 | ||
412 | } else { | |
413 | //mark_img.src = "images/mark_unset.png"; | |
f5e0338d | 414 | mark_img.alt = __("Please wait..."); |
b685ba25 AD |
415 | query = query + "&mark=0"; |
416 | ||
417 | /* if (vfeedu && crow.className.match("Unread")) { | |
418 | vfeedu.innerHTML = (+vfeedu.innerHTML) - 1; | |
419 | } */ | |
420 | ||
f5e0338d | 421 | if (document.getElementById("headlinesList") && !no_effects) { |
b685ba25 AD |
422 | Effect.Puff(mark_img, {duration : 0.25, afterFinish: tMark_afh_off}); |
423 | } else { | |
f5e0338d AD |
424 | mark_img.src = mark_img.src.replace("mark_set", "mark_unset"); |
425 | mark_img.alt = __("Star article"); | |
b685ba25 | 426 | } |
ace1a6da | 427 | } |
b685ba25 AD |
428 | |
429 | /* var vfeedctr = document.getElementById("FEEDCTR--1"); | |
430 | var vfeedr = document.getElementById("FEEDR--1"); | |
431 | ||
432 | if (vfeedu && vfeedctr) { | |
433 | if ((+vfeedu.innerHTML) > 0) { | |
434 | if (crow.className.match("Unread") && !vfeedr.className.match("Unread")) { | |
435 | vfeedr.className = vfeedr.className + "Unread"; | |
436 | vfeedctr.className = "odd"; | |
437 | } | |
438 | } else { | |
439 | vfeedctr.className = "invisible"; | |
440 | vfeedr.className = vfeedr.className.replace("Unread", ""); | |
8add756a | 441 | } |
254e0e4b | 442 | } |
b685ba25 AD |
443 | |
444 | debug("toggle starred for aid " + id); | |
445 | ||
446 | //new Ajax.Request(query); */ | |
772bc83b | 447 | |
f5e0338d AD |
448 | if (!client_only) { |
449 | debug(query); | |
36e05046 | 450 | |
1341ea0d AD |
451 | new Ajax.Request(query, { |
452 | onComplete: function(transport) { | |
453 | all_counters_callback2(transport); | |
454 | } }); | |
455 | ||
f5e0338d | 456 | } |
f0601b87 | 457 | |
b685ba25 AD |
458 | } catch (e) { |
459 | exception_error("toggleMark", e); | |
460 | } | |
f0601b87 AD |
461 | } |
462 | ||
f5e0338d | 463 | function togglePub(id, client_only, no_effects) { |
e4f4b46f | 464 | |
2bc2147f | 465 | try { |
e4f4b46f | 466 | |
2bc2147f AD |
467 | var query = "backend.php?op=rpc&id=" + id + "&subop=publ"; |
468 | ||
469 | query = query + "&afid=" + getActiveFeedId(); | |
470 | ||
471 | if (tagsAreDisplayed()) { | |
472 | query = query + "&omode=tl"; | |
473 | } else { | |
474 | query = query + "&omode=flc"; | |
e4f4b46f | 475 | } |
2bc2147f AD |
476 | |
477 | var mark_img = document.getElementById("FPPIC-" + id); | |
478 | var vfeedu = document.getElementById("FEEDU--2"); | |
479 | var crow = document.getElementById("RROW-" + id); | |
480 | ||
f5e0338d AD |
481 | if (mark_img.src.match("pub_unset")) { |
482 | mark_img.src = mark_img.src.replace("pub_unset", "pub_set"); | |
483 | mark_img.alt = __("Unpublish article"); | |
2bc2147f AD |
484 | query = query + "&pub=1"; |
485 | ||
b685ba25 | 486 | /* if (vfeedu && crow.className.match("Unread")) { |
2bc2147f | 487 | vfeedu.innerHTML = (+vfeedu.innerHTML) + 1; |
b685ba25 | 488 | } */ |
2bc2147f | 489 | |
e4f4b46f | 490 | } else { |
6b0f49f9 | 491 | //mark_img.src = "images/pub_unset.png"; |
f5e0338d | 492 | mark_img.alt = __("Please wait..."); |
2bc2147f AD |
493 | query = query + "&pub=0"; |
494 | ||
b685ba25 | 495 | /* if (vfeedu && crow.className.match("Unread")) { |
2bc2147f | 496 | vfeedu.innerHTML = (+vfeedu.innerHTML) - 1; |
b685ba25 | 497 | } */ |
6b0f49f9 | 498 | |
f5e0338d | 499 | if (document.getElementById("headlinesList") && !no_effects) { |
ace1a6da AD |
500 | Effect.Puff(mark_img, {duration : 0.25, afterFinish: tPub_afh_off}); |
501 | } else { | |
f5e0338d AD |
502 | mark_img.src = mark_img.src.replace("pub_set", "pub_unset"); |
503 | mark_img.alt = __("Publish article"); | |
ace1a6da | 504 | } |
e4f4b46f | 505 | } |
2bc2147f | 506 | |
b685ba25 | 507 | /* var vfeedctr = document.getElementById("FEEDCTR--2"); |
2bc2147f AD |
508 | var vfeedr = document.getElementById("FEEDR--2"); |
509 | ||
510 | if (vfeedu && vfeedctr) { | |
511 | if ((+vfeedu.innerHTML) > 0) { | |
512 | if (crow.className.match("Unread") && !vfeedr.className.match("Unread")) { | |
513 | vfeedr.className = vfeedr.className + "Unread"; | |
514 | vfeedctr.className = "odd"; | |
515 | } | |
516 | } else { | |
517 | vfeedctr.className = "invisible"; | |
518 | vfeedr.className = vfeedr.className.replace("Unread", ""); | |
519 | } | |
520 | } | |
521 | ||
522 | debug("toggle published for aid " + id); | |
523 | ||
b685ba25 AD |
524 | new Ajax.Request(query); */ |
525 | ||
f5e0338d | 526 | if (!client_only) { |
1341ea0d AD |
527 | new Ajax.Request(query, { |
528 | onComplete: function(transport) { | |
529 | all_counters_callback2(transport); | |
530 | } }); | |
f5e0338d | 531 | } |
b685ba25 | 532 | |
2bc2147f | 533 | } catch (e) { |
e4f4b46f | 534 | |
2bc2147f AD |
535 | exception_error("togglePub", e); |
536 | } | |
e4f4b46f AD |
537 | } |
538 | ||
ac162cbe AD |
539 | function correctHeadlinesOffset(id) { |
540 | ||
541 | try { | |
542 | ||
543 | var hlist = document.getElementById("headlinesList"); | |
544 | var container = document.getElementById("headlinesInnerContainer"); | |
545 | var row = document.getElementById("RROW-" + id); | |
546 | ||
547 | var viewport = container.offsetHeight; | |
548 | ||
549 | var rel_offset_top = row.offsetTop - container.scrollTop; | |
550 | var rel_offset_bottom = row.offsetTop + row.offsetHeight - container.scrollTop; | |
551 | ||
552 | debug("Rtop: " + rel_offset_top + " Rbtm: " + rel_offset_bottom); | |
553 | debug("Vport: " + viewport); | |
a5e46e0f | 554 | |
ac162cbe AD |
555 | if (rel_offset_top <= 0 || rel_offset_top > viewport) { |
556 | container.scrollTop = row.offsetTop; | |
557 | } else if (rel_offset_bottom > viewport) { | |
a5e46e0f AD |
558 | |
559 | /* doesn't properly work with Opera in some cases because | |
560 | Opera fucks up element scrolling */ | |
561 | ||
ac162cbe AD |
562 | container.scrollTop = row.offsetTop + row.offsetHeight - viewport; |
563 | } | |
564 | ||
565 | } catch (e) { | |
566 | exception_error("correctHeadlinesOffset", e); | |
567 | } | |
568 | ||
569 | } | |
570 | ||
bb7cface | 571 | function moveToPost(mode) { |
f0601b87 | 572 | |
4e51dd2b AD |
573 | // check for combined mode |
574 | if (!document.getElementById("headlinesList")) | |
575 | return; | |
576 | ||
bb7cface AD |
577 | var rows = getVisibleHeadlineIds(); |
578 | ||
ac162cbe AD |
579 | var prev_id = false; |
580 | var next_id = false; | |
bb7cface | 581 | |
d4eec882 AD |
582 | if (!document.getElementById('RROW-' + active_post_id)) { |
583 | active_post_id = false; | |
584 | } | |
585 | ||
bb7cface AD |
586 | if (active_post_id == false) { |
587 | next_id = getFirstVisibleHeadlineId(); | |
588 | prev_id = getLastVisibleHeadlineId(); | |
589 | } else { | |
590 | for (var i = 0; i < rows.length; i++) { | |
591 | if (rows[i] == active_post_id) { | |
592 | prev_id = rows[i-1]; | |
593 | next_id = rows[i+1]; | |
594 | } | |
595 | } | |
596 | } | |
597 | ||
598 | if (mode == "next") { | |
ac162cbe AD |
599 | if (next_id) { |
600 | correctHeadlinesOffset(next_id); | |
86741347 | 601 | view(next_id, getActiveFeedId()); |
bb7cface AD |
602 | } |
603 | } | |
604 | ||
605 | if (mode == "prev") { | |
ac162cbe AD |
606 | if (prev_id) { |
607 | correctHeadlinesOffset(prev_id); | |
86741347 | 608 | view(prev_id, getActiveFeedId()); |
bb7cface AD |
609 | } |
610 | } | |
611 | } | |
612 | ||
5f51022a AD |
613 | function toggleUnread(id, cmode) { |
614 | try { | |
5f51022a AD |
615 | |
616 | var row = document.getElementById("RROW-" + id); | |
617 | if (row) { | |
618 | var nc = row.className; | |
619 | nc = nc.replace("Unread", ""); | |
620 | nc = nc.replace("Selected", ""); | |
621 | ||
622 | if (row.className.match("Unread")) { | |
623 | row.className = nc; | |
624 | } else { | |
625 | row.className = nc + "Unread"; | |
626 | } | |
627 | ||
628 | if (!cmode) cmode = 2; | |
629 | ||
630 | var query = "backend.php?op=rpc&subop=catchupSelected&ids=" + | |
631 | param_escape(id) + "&cmode=" + param_escape(cmode); | |
632 | ||
1341ea0d | 633 | // notify_progress("Loading, please wait..."); |
9ec58704 | 634 | |
1341ea0d AD |
635 | new Ajax.Request(query, { |
636 | onComplete: function(transport) { | |
637 | all_counters_callback2(transport); | |
638 | } }); | |
5f51022a AD |
639 | |
640 | } | |
641 | ||
642 | ||
643 | } catch (e) { | |
644 | exception_error("toggleUnread", e); | |
645 | } | |
646 | } | |
647 | ||
2228d0e4 | 648 | function selectionToggleUnread(cdm_mode, set_state, callback_func, no_error) { |
1572afe5 | 649 | try { |
1341ea0d | 650 | /* if (!xmlhttp_ready(xmlhttp_rpc)) { |
1572afe5 AD |
651 | printLockingError(); |
652 | return; | |
1341ea0d | 653 | } */ |
1572afe5 | 654 | |
386cbf27 AD |
655 | var rows; |
656 | ||
657 | if (cdm_mode) { | |
658 | rows = cdmGetSelectedArticles(); | |
659 | } else { | |
660 | rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK"); | |
661 | } | |
1572afe5 | 662 | |
2228d0e4 | 663 | if (rows.length == 0 && !no_error) { |
9cc600d1 AD |
664 | alert(__("No articles are selected.")); |
665 | return; | |
666 | } | |
667 | ||
1572afe5 | 668 | for (i = 0; i < rows.length; i++) { |
f1f2db64 AD |
669 | var row = document.getElementById("RROW-" + rows[i]); |
670 | if (row) { | |
671 | var nc = row.className; | |
672 | nc = nc.replace("Unread", ""); | |
673 | nc = nc.replace("Selected", ""); | |
674 | ||
a5ae125a AD |
675 | if (set_state == undefined) { |
676 | if (row.className.match("Unread")) { | |
677 | row.className = nc + "Selected"; | |
678 | } else { | |
679 | row.className = nc + "UnreadSelected"; | |
680 | } | |
681 | } | |
682 | ||
683 | if (set_state == false) { | |
f1f2db64 | 684 | row.className = nc + "Selected"; |
a5ae125a AD |
685 | } |
686 | ||
687 | if (set_state == true) { | |
f1f2db64 AD |
688 | row.className = nc + "UnreadSelected"; |
689 | } | |
690 | } | |
1572afe5 AD |
691 | } |
692 | ||
693 | if (rows.length > 0) { | |
694 | ||
b47b5af7 AD |
695 | var cmode = ""; |
696 | ||
697 | if (set_state == undefined) { | |
698 | cmode = "2"; | |
699 | } else if (set_state == true) { | |
700 | cmode = "1"; | |
701 | } else if (set_state == false) { | |
702 | cmode = "0"; | |
703 | } | |
704 | ||
1572afe5 | 705 | var query = "backend.php?op=rpc&subop=catchupSelected&ids=" + |
b47b5af7 | 706 | param_escape(rows.toString()) + "&cmode=" + cmode; |
1572afe5 | 707 | |
1341ea0d AD |
708 | // _catchup_callback_func = callback_func; |
709 | ||
710 | debug(callback_func); | |
e08443c1 | 711 | |
9ec58704 AD |
712 | notify_progress("Loading, please wait..."); |
713 | ||
1341ea0d | 714 | /* xmlhttp_rpc.open("GET", query, true); |
e08443c1 | 715 | xmlhttp_rpc.onreadystatechange=catchup_callback; |
1341ea0d AD |
716 | xmlhttp_rpc.send(null); */ |
717 | ||
718 | new Ajax.Request(query, { | |
719 | onComplete: function(transport) { | |
720 | catchup_callback2(transport, callback_func); | |
721 | } }); | |
1572afe5 AD |
722 | |
723 | } | |
724 | ||
725 | } catch (e) { | |
83f043bb | 726 | exception_error("selectionToggleUnread", e); |
1572afe5 AD |
727 | } |
728 | } | |
729 | ||
386cbf27 | 730 | function selectionToggleMarked(cdm_mode) { |
1572afe5 | 731 | try { |
1572afe5 | 732 | |
386cbf27 AD |
733 | var rows; |
734 | ||
735 | if (cdm_mode) { | |
736 | rows = cdmGetSelectedArticles(); | |
737 | } else { | |
738 | rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK"); | |
739 | } | |
1572afe5 | 740 | |
9cc600d1 AD |
741 | if (rows.length == 0) { |
742 | alert(__("No articles are selected.")); | |
743 | return; | |
744 | } | |
745 | ||
1572afe5 | 746 | for (i = 0; i < rows.length; i++) { |
f5e0338d | 747 | toggleMark(rows[i], true, true); |
1572afe5 AD |
748 | } |
749 | ||
750 | if (rows.length > 0) { | |
751 | ||
752 | var query = "backend.php?op=rpc&subop=markSelected&ids=" + | |
753 | param_escape(rows.toString()) + "&cmode=2"; | |
754 | ||
2bc2147f AD |
755 | query = query + "&afid=" + getActiveFeedId(); |
756 | ||
1341ea0d | 757 | /* if (tagsAreDisplayed()) { |
2bc2147f AD |
758 | query = query + "&omode=tl"; |
759 | } else { | |
760 | query = query + "&omode=flc"; | |
1341ea0d AD |
761 | } */ |
762 | ||
763 | query = query + "&omode=lc"; | |
2bc2147f | 764 | |
1341ea0d AD |
765 | new Ajax.Request(query, { |
766 | onComplete: function(transport) { | |
767 | all_counters_callback2(transport); | |
768 | } }); | |
1572afe5 AD |
769 | |
770 | } | |
771 | ||
772 | } catch (e) { | |
83f043bb | 773 | exception_error("selectionToggleMarked", e); |
1572afe5 AD |
774 | } |
775 | } | |
776 | ||
e4f4b46f AD |
777 | function selectionTogglePublished(cdm_mode) { |
778 | try { | |
e4f4b46f AD |
779 | |
780 | var rows; | |
781 | ||
782 | if (cdm_mode) { | |
783 | rows = cdmGetSelectedArticles(); | |
784 | } else { | |
785 | rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK"); | |
786 | } | |
787 | ||
788 | if (rows.length == 0) { | |
789 | alert(__("No articles are selected.")); | |
790 | return; | |
791 | } | |
792 | ||
793 | for (i = 0; i < rows.length; i++) { | |
f5e0338d | 794 | togglePub(rows[i], true, true); |
e4f4b46f AD |
795 | } |
796 | ||
797 | if (rows.length > 0) { | |
798 | ||
799 | var query = "backend.php?op=rpc&subop=publishSelected&ids=" + | |
800 | param_escape(rows.toString()) + "&cmode=2"; | |
801 | ||
2bc2147f AD |
802 | query = query + "&afid=" + getActiveFeedId(); |
803 | ||
1341ea0d | 804 | /* if (tagsAreDisplayed()) { |
2bc2147f AD |
805 | query = query + "&omode=tl"; |
806 | } else { | |
807 | query = query + "&omode=flc"; | |
1341ea0d AD |
808 | } */ |
809 | ||
810 | query = query + "&omode=lc"; | |
2bc2147f | 811 | |
1341ea0d AD |
812 | new Ajax.Request(query, { |
813 | onComplete: function(transport) { | |
814 | all_counters_callback2(transport); | |
815 | } }); | |
e4f4b46f AD |
816 | |
817 | } | |
818 | ||
819 | } catch (e) { | |
820 | exception_error("selectionToggleMarked", e); | |
821 | } | |
822 | } | |
823 | ||
386cbf27 AD |
824 | function cdmGetSelectedArticles() { |
825 | var sel_articles = new Array(); | |
b2128f01 | 826 | var container = document.getElementById("headlinesInnerContainer"); |
386cbf27 AD |
827 | |
828 | for (i = 0; i < container.childNodes.length; i++) { | |
829 | var child = container.childNodes[i]; | |
830 | ||
831 | if (child.id.match("RROW-") && child.className.match("Selected")) { | |
832 | var c_id = child.id.replace("RROW-", ""); | |
833 | sel_articles.push(c_id); | |
834 | } | |
835 | } | |
836 | ||
837 | return sel_articles; | |
838 | } | |
839 | ||
8be83f42 AD |
840 | function cdmGetVisibleArticles() { |
841 | var sel_articles = new Array(); | |
842 | var container = document.getElementById("headlinesInnerContainer"); | |
843 | ||
844 | for (i = 0; i < container.childNodes.length; i++) { | |
845 | var child = container.childNodes[i]; | |
846 | ||
847 | if (child.id.match("RROW-")) { | |
848 | var c_id = child.id.replace("RROW-", ""); | |
849 | sel_articles.push(c_id); | |
850 | } | |
851 | } | |
852 | ||
853 | return sel_articles; | |
854 | } | |
855 | ||
856 | function cdmGetUnreadArticles() { | |
857 | var sel_articles = new Array(); | |
858 | var container = document.getElementById("headlinesInnerContainer"); | |
859 | ||
860 | for (i = 0; i < container.childNodes.length; i++) { | |
861 | var child = container.childNodes[i]; | |
862 | ||
863 | if (child.id.match("RROW-") && child.className.match("Unread")) { | |
864 | var c_id = child.id.replace("RROW-", ""); | |
865 | sel_articles.push(c_id); | |
866 | } | |
867 | } | |
868 | ||
869 | return sel_articles; | |
870 | } | |
871 | ||
872 | ||
386cbf27 AD |
873 | // mode = all,none,unread |
874 | function cdmSelectArticles(mode) { | |
b2128f01 | 875 | var container = document.getElementById("headlinesInnerContainer"); |
386cbf27 AD |
876 | |
877 | for (i = 0; i < container.childNodes.length; i++) { | |
878 | var child = container.childNodes[i]; | |
879 | ||
880 | if (child.id.match("RROW-")) { | |
06d1a1c1 AD |
881 | var aid = child.id.replace("RROW-", ""); |
882 | ||
883 | var cb = document.getElementById("RCHK-" + aid); | |
884 | ||
386cbf27 AD |
885 | if (mode == "all") { |
886 | if (!child.className.match("Selected")) { | |
887 | child.className = child.className + "Selected"; | |
06d1a1c1 | 888 | cb.checked = true; |
386cbf27 AD |
889 | } |
890 | } else if (mode == "unread") { | |
891 | if (child.className.match("Unread") && !child.className.match("Selected")) { | |
892 | child.className = child.className + "Selected"; | |
06d1a1c1 | 893 | cb.checked = true; |
386cbf27 AD |
894 | } |
895 | } else { | |
896 | child.className = child.className.replace("Selected", ""); | |
06d1a1c1 | 897 | cb.checked = false; |
386cbf27 AD |
898 | } |
899 | } | |
900 | } | |
901 | } | |
902 | ||
98bea1b1 | 903 | function catchupPage() { |
b47b5af7 | 904 | |
8a5b4579 AD |
905 | var fn = getFeedName(getActiveFeedId(), active_feed_is_cat); |
906 | ||
a5ae125a AD |
907 | var str = __("Mark all visible articles in %s as read?"); |
908 | ||
909 | str = str.replace("%s", fn); | |
8a5b4579 AD |
910 | |
911 | if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) { | |
912 | return; | |
913 | } | |
914 | ||
b47b5af7 AD |
915 | if (document.getElementById("headlinesList")) { |
916 | selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, 'Unread', true); | |
2228d0e4 | 917 | selectionToggleUnread(false, false, 'viewCurrentFeed()', true); |
b47b5af7 AD |
918 | selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false); |
919 | } else { | |
920 | cdmSelectArticles('all'); | |
2228d0e4 | 921 | selectionToggleUnread(true, false, 'viewCurrentFeed()', true) |
b47b5af7 AD |
922 | cdmSelectArticles('none'); |
923 | } | |
98bea1b1 AD |
924 | } |
925 | ||
a5ae125a AD |
926 | function catchupSelection() { |
927 | ||
928 | try { | |
929 | ||
930 | var rows; | |
931 | ||
932 | if (document.getElementById("headlinesList")) { | |
933 | rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK"); | |
934 | } else { | |
935 | rows = cdmGetSelectedArticles(); | |
936 | } | |
937 | ||
938 | if (rows.length == 0) { | |
939 | alert(__("No articles are selected.")); | |
940 | return; | |
941 | } | |
942 | ||
943 | ||
944 | var fn = getFeedName(getActiveFeedId(), active_feed_is_cat); | |
945 | ||
946 | var str = __("Mark all selected articles in %s as read?"); | |
947 | ||
948 | str = str.replace("%s", fn); | |
949 | ||
950 | if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) { | |
951 | return; | |
952 | } | |
953 | ||
954 | if (document.getElementById("headlinesList")) { | |
955 | selectionToggleUnread(false, false, 'viewCurrentFeed()', true); | |
956 | // selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false); | |
957 | } else { | |
958 | selectionToggleUnread(true, false, 'viewCurrentFeed()', true) | |
959 | // cdmSelectArticles('none'); | |
960 | } | |
961 | ||
962 | } catch (e) { | |
963 | exception_error("catchupSelection", e); | |
964 | } | |
965 | } | |
966 | ||
967 | ||
88040f57 AD |
968 | function labelFromSearch(search, search_mode, match_on, feed_id, is_cat) { |
969 | ||
970 | if (!xmlhttp_ready(xmlhttp_rpc)) { | |
971 | printLockingError(); | |
972 | } | |
973 | ||
a5ae125a | 974 | var title = prompt(__("Please enter label title:"), ""); |
88040f57 AD |
975 | |
976 | if (title) { | |
977 | ||
978 | var query = "backend.php?op=labelFromSearch&search=" + param_escape(search) + | |
979 | "&smode=" + param_escape(search_mode) + "&match=" + param_escape(match_on) + | |
980 | "&feed=" + param_escape(feed_id) + "&is_cat=" + param_escape(is_cat) + | |
981 | "&title=" + param_escape(title); | |
982 | ||
983 | debug("LFS: " + query); | |
984 | ||
985 | xmlhttp_rpc.open("GET", query, true); | |
0feab655 | 986 | xmlhttp_rpc.onreadystatechange=dlg_frefresh_callback; |
88040f57 AD |
987 | xmlhttp_rpc.send(null); |
988 | } | |
989 | ||
990 | } | |
991 | ||
13f08f75 | 992 | function editArticleTags(id, feed_id, cdm_enabled) { |
0b126ac2 AD |
993 | _tag_active_post_id = id; |
994 | _tag_active_feed_id = feed_id; | |
13f08f75 | 995 | _tag_active_cdm = cdm_enabled; |
b07b61da AD |
996 | |
997 | cache_invalidate(id); | |
998 | ||
13f08f75 AD |
999 | try { |
1000 | _tag_cdm_scroll = document.getElementById("headlinesInnerContainer").scrollTop; | |
1001 | } catch (e) { } | |
0b126ac2 AD |
1002 | displayDlg('editArticleTags', id); |
1003 | } | |
1004 | ||
1005 | ||
1006 | function tag_saved_callback() { | |
1007 | if (xmlhttp_rpc.readyState == 4) { | |
1008 | try { | |
1009 | debug("in tag_saved_callback"); | |
1010 | ||
1011 | closeInfoBox(); | |
1012 | notify(""); | |
1013 | ||
1014 | if (tagsAreDisplayed()) { | |
1015 | _reload_feedlist_after_view = true; | |
1016 | } | |
1017 | ||
13f08f75 AD |
1018 | if (!_tag_active_cdm) { |
1019 | if (active_post_id == _tag_active_post_id) { | |
1020 | debug("reloading current article"); | |
1021 | view(_tag_active_post_id, _tag_active_feed_id); | |
1022 | } | |
1023 | } else { | |
1024 | debug("reloading current feed"); | |
1025 | viewCurrentFeed(); | |
1026 | } | |
0b126ac2 AD |
1027 | |
1028 | } catch (e) { | |
1029 | exception_error("catchup_callback", e); | |
1030 | } | |
1031 | } | |
1032 | } | |
1033 | ||
1034 | function editTagsSave() { | |
1035 | ||
1036 | if (!xmlhttp_ready(xmlhttp_rpc)) { | |
1037 | printLockingError(); | |
1038 | } | |
1039 | ||
42c32916 | 1040 | notify_progress("Saving article tags..."); |
88040f57 | 1041 | |
0b126ac2 AD |
1042 | var form = document.forms["tag_edit_form"]; |
1043 | ||
1044 | var query = Form.serialize("tag_edit_form"); | |
1045 | ||
14b6c54b AD |
1046 | query = "backend.php?op=rpc&subop=setArticleTags&" + query; |
1047 | ||
1048 | debug(query); | |
1049 | ||
1050 | xmlhttp_rpc.open("GET", query, true); | |
0b126ac2 AD |
1051 | xmlhttp_rpc.onreadystatechange=tag_saved_callback; |
1052 | xmlhttp_rpc.send(null); | |
1053 | ||
1054 | } | |
d62a3b63 AD |
1055 | |
1056 | function editTagsInsert() { | |
1057 | try { | |
1058 | ||
1059 | var form = document.forms["tag_edit_form"]; | |
1060 | ||
1061 | var found_tags = form.found_tags; | |
1062 | var tags_str = form.tags_str; | |
1063 | ||
1064 | var tag = found_tags[found_tags.selectedIndex].value; | |
1065 | ||
1066 | if (tags_str.value.length > 0 && | |
1067 | tags_str.value.lastIndexOf(", ") != tags_str.value.length - 2) { | |
1068 | ||
1069 | tags_str.value = tags_str.value + ", "; | |
1070 | } | |
1071 | ||
1072 | tags_str.value = tags_str.value + tag + ", "; | |
1073 | ||
1074 | found_tags.selectedIndex = 0; | |
1075 | ||
1076 | } catch (e) { | |
1077 | exception_error(e, "editTagsInsert"); | |
1078 | } | |
1079 | } | |
ba0978c8 AD |
1080 | |
1081 | function cdmWatchdog() { | |
1082 | ||
1083 | try { | |
1084 | ||
1085 | var ctr = document.getElementById("headlinesInnerContainer"); | |
1086 | ||
9acd22e8 AD |
1087 | if (!ctr) return; |
1088 | ||
ba0978c8 AD |
1089 | var ids = new Array(); |
1090 | ||
1091 | var e = ctr.firstChild; | |
1092 | ||
1093 | while (e) { | |
1094 | if (e.className && e.className == "cdmArticleUnread" && e.id && | |
1095 | e.id.match("RROW-")) { | |
1096 | ||
1097 | // article fits in viewport OR article is longer than viewport and | |
1098 | // its bottom is visible | |
1099 | ||
1100 | if (ctr.scrollTop <= e.offsetTop && e.offsetTop + e.offsetHeight <= | |
1101 | ctr.scrollTop + ctr.offsetHeight) { | |
1102 | ||
1103 | // debug(e.id + " is visible " + e.offsetTop + "." + | |
1104 | // (e.offsetTop + e.offsetHeight) + " vs " + ctr.scrollTop + "." + | |
1105 | // (ctr.scrollTop + ctr.offsetHeight)); | |
1106 | ||
1107 | ids.push(e.id.replace("RROW-", "")); | |
1108 | ||
1109 | } else if (e.offsetHeight > ctr.offsetHeight && | |
1110 | e.offsetTop + e.offsetHeight >= ctr.scrollTop && | |
1111 | e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight) { | |
1112 | ||
1113 | ids.push(e.id.replace("RROW-", "")); | |
1114 | ||
1115 | } | |
1116 | ||
c50e2b30 AD |
1117 | // method 2: article bottom is visible and is in upper 1/2 of the viewport |
1118 | ||
1119 | /* if (e.offsetTop + e.offsetHeight >= ctr.scrollTop && | |
1120 | e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight/2) { | |
1121 | ||
1122 | ids.push(e.id.replace("RROW-", "")); | |
1123 | ||
1124 | } */ | |
1125 | ||
ba0978c8 AD |
1126 | } |
1127 | ||
1128 | e = e.nextSibling; | |
1129 | } | |
1130 | ||
1131 | debug("cdmWatchdog, ids= " + ids.toString()); | |
1132 | ||
1341ea0d | 1133 | if (ids.length > 0) { |
ba0978c8 AD |
1134 | |
1135 | for (var i = 0; i < ids.length; i++) { | |
1136 | var e = document.getElementById("RROW-" + ids[i]); | |
1137 | if (e) { | |
1138 | e.className = e.className.replace("Unread", ""); | |
1139 | } | |
1140 | } | |
1141 | ||
1142 | var query = "backend.php?op=rpc&subop=catchupSelected&ids=" + | |
1143 | param_escape(ids.toString()) + "&cmode=0"; | |
1144 | ||
1341ea0d AD |
1145 | new Ajax.Request(query, { |
1146 | onComplete: function(transport) { | |
1147 | all_counters_callback2(transport); | |
1148 | } }); | |
ba0978c8 AD |
1149 | |
1150 | } | |
1151 | ||
c50e2b30 | 1152 | _cdm_wd_timeout = window.setTimeout("cdmWatchdog()", 4000); |
ba0978c8 AD |
1153 | |
1154 | } catch (e) { | |
1155 | exception_error(e, "cdmWatchdog"); | |
1156 | } | |
1157 | ||
1158 | } | |
e097e8be AD |
1159 | |
1160 | ||
1161 | function cache_inject(id, article) { | |
fed4387d | 1162 | if (!cache_check(id)) { |
e097e8be AD |
1163 | debug("cache_article: miss: " + id); |
1164 | ||
1165 | var cache_obj = new Array(); | |
1166 | ||
fed4387d | 1167 | cache_obj["id"] = id; |
e097e8be AD |
1168 | cache_obj["data"] = article; |
1169 | ||
fed4387d | 1170 | article_cache.push(cache_obj); |
e097e8be AD |
1171 | |
1172 | } else { | |
1173 | debug("cache_article: hit: " + id); | |
1174 | } | |
1175 | } | |
1176 | ||
1177 | function cache_find(id) { | |
fed4387d AD |
1178 | for (var i = 0; i < article_cache.length; i++) { |
1179 | if (article_cache[i]["id"] == id) { | |
fed4387d AD |
1180 | return article_cache[i]["data"]; |
1181 | } | |
e097e8be | 1182 | } |
fed4387d | 1183 | return false; |
e097e8be AD |
1184 | } |
1185 | ||
1186 | function cache_check(id) { | |
fed4387d AD |
1187 | for (var i = 0; i < article_cache.length; i++) { |
1188 | if (article_cache[i]["id"] == id) { | |
1189 | return true; | |
1190 | } | |
1191 | } | |
1192 | return false; | |
e097e8be AD |
1193 | } |
1194 | ||
1195 | function cache_expire() { | |
7289eacf | 1196 | while (article_cache.length > 20) { |
fed4387d AD |
1197 | article_cache.shift(); |
1198 | } | |
e097e8be | 1199 | } |
b07b61da AD |
1200 | |
1201 | function cache_invalidate(id) { | |
1202 | var i = 0 | |
c1b18749 AD |
1203 | |
1204 | try { | |
1205 | ||
1206 | while (i < article_cache.length) { | |
1207 | if (article_cache[i]["id"] == id) { | |
1208 | debug("cache_invalidate: removed id " + id); | |
1209 | article_cache.splice(i, 1); | |
1210 | return true; | |
1211 | } | |
1212 | i++; | |
b07b61da | 1213 | } |
c1b18749 AD |
1214 | debug("cache_invalidate: id not found: " + id); |
1215 | return false; | |
1216 | } catch (e) { | |
1217 | exception_error("cache_invalidate", e); | |
b07b61da | 1218 | } |
b07b61da | 1219 | } |
298f3f78 AD |
1220 | |
1221 | function getActiveArticleId() { | |
1222 | return active_post_id; | |
1223 | } | |
e4914b62 AD |
1224 | |
1225 | function cdmMouseIn(elem) { | |
1226 | try { | |
1227 | if (elem.id && elem.id.match("RROW-")) { | |
1228 | var id = elem.id.replace("RROW-", ""); | |
1229 | active_post_id = id; | |
1230 | } | |
1231 | } catch (e) { | |
1232 | exception_error("cdmMouseIn", e); | |
1233 | } | |
1234 | ||
1235 | } | |
1236 | ||
1237 | function cdmMouseOut(elem) { | |
1238 | active_post_id = false; | |
1239 | } | |
ac541432 AD |
1240 | |
1241 | function headlines_scroll_handler() { | |
1242 | try { | |
1243 | ||
1244 | var e = document.getElementById("headlinesInnerContainer"); | |
1245 | ||
a219fec5 | 1246 | if (e.scrollTop + e.offsetHeight > e.scrollHeight - 300) { |
ac541432 AD |
1247 | debug("more cowbell!"); |
1248 | ||
1249 | viewNextFeedPage(); | |
1250 | } | |
1251 | ||
1252 | } catch (e) { | |
1253 | exception_error("headlines_scroll_handler", e); | |
1254 | } | |
1255 | } | |
8be83f42 AD |
1256 | |
1257 | function catchupRelativeToArticle(below) { | |
1258 | ||
1259 | try { | |
1260 | ||
1261 | if (!xmlhttp_ready(xmlhttp_rpc)) { | |
1262 | printLockingError(); | |
1263 | } | |
1264 | ||
1265 | if (!getActiveArticleId()) { | |
1266 | alert(__("No article is selected.")); | |
1267 | return; | |
1268 | } | |
1269 | ||
1270 | var visible_ids; | |
1271 | ||
1272 | if (document.getElementById("headlinesList")) { | |
1273 | visible_ids = getVisibleHeadlineIds(); | |
1274 | } else { | |
1275 | visible_ids = cdmGetVisibleArticles(); | |
1276 | } | |
1277 | ||
1278 | var ids_to_mark = new Array(); | |
1279 | ||
1280 | if (!below) { | |
1281 | for (var i = 0; i < visible_ids.length; i++) { | |
1282 | if (visible_ids[i] != getActiveArticleId()) { | |
1283 | var e = document.getElementById("RROW-" + visible_ids[i]); | |
1284 | ||
1285 | if (e && e.className.match("Unread")) { | |
1286 | ids_to_mark.push(visible_ids[i]); | |
1287 | } | |
1288 | } else { | |
1289 | break; | |
1290 | } | |
1291 | } | |
1292 | } else { | |
1293 | for (var i = visible_ids.length-1; i >= 0; i--) { | |
1294 | if (visible_ids[i] != getActiveArticleId()) { | |
1295 | var e = document.getElementById("RROW-" + visible_ids[i]); | |
1296 | ||
1297 | if (e && e.className.match("Unread")) { | |
1298 | ids_to_mark.push(visible_ids[i]); | |
1299 | } | |
1300 | } else { | |
1301 | break; | |
1302 | } | |
1303 | } | |
1304 | } | |
1305 | ||
1306 | if (ids_to_mark.length == 0) { | |
1307 | alert(__("No articles found to mark")); | |
1308 | } else { | |
1309 | var msg = __("Mark %d article(s) as read?").replace("%d", ids_to_mark.length); | |
1310 | ||
1311 | if (confirm(msg)) { | |
1312 | ||
1313 | for (var i = 0; i < ids_to_mark.length; i++) { | |
1314 | var e = document.getElementById("RROW-" + ids_to_mark[i]); | |
1315 | e.className = e.className.replace("Unread", ""); | |
1316 | } | |
1317 | ||
1318 | var query = "backend.php?op=rpc&subop=catchupSelected&ids=" + | |
1319 | param_escape(ids_to_mark.toString()) + "&cmode=0"; | |
1320 | ||
1321 | xmlhttp_rpc.open("GET", query, true); | |
1322 | xmlhttp_rpc.onreadystatechange=catchup_callback; | |
1323 | xmlhttp_rpc.send(null); | |
1324 | ||
1325 | } | |
1326 | } | |
1327 | ||
1328 | } catch (e) { | |
1329 | exception_error("catchupRelativeToArticle", e); | |
1330 | } | |
1331 | } |