]>
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 | ||
e4f4b46f AD |
337 | function tPub(id) { |
338 | return togglePub(id); | |
339 | } | |
340 | ||
6b0f49f9 AD |
341 | function tMark_afh_off(effect) { |
342 | try { | |
343 | var elem = effect.effects[0].element; | |
344 | ||
345 | debug("tMark_afh_off : " + elem.id); | |
346 | ||
347 | if (elem) { | |
f5e0338d AD |
348 | elem.src = elem.src.replace("mark_set", "mark_unset"); |
349 | elem.alt = __("Star article"); | |
6b0f49f9 AD |
350 | Element.show(elem); |
351 | } | |
352 | ||
353 | } catch (e) { | |
354 | exception_error("tMark_afh_off", e); | |
355 | } | |
356 | } | |
357 | ||
358 | function tPub_afh_off(effect) { | |
359 | try { | |
360 | var elem = effect.effects[0].element; | |
361 | ||
362 | debug("tPub_afh_off : " + elem.id); | |
363 | ||
364 | if (elem) { | |
f5e0338d AD |
365 | elem.src = elem.src.replace("pub_set", "pub_unset"); |
366 | elem.alt = __("Publish article"); | |
6b0f49f9 AD |
367 | Element.show(elem); |
368 | } | |
369 | ||
370 | } catch (e) { | |
371 | exception_error("tPub_afh_off", e); | |
372 | } | |
373 | } | |
e4f4b46f | 374 | |
f5e0338d | 375 | function toggleMark(id, client_only, no_effects) { |
f0601b87 | 376 | |
b685ba25 | 377 | try { |
254e0e4b | 378 | |
b685ba25 AD |
379 | if (!xmlhttp_ready(xmlhttp_rpc)) { |
380 | printLockingError(); | |
381 | return; | |
7ba176d2 | 382 | } |
b685ba25 AD |
383 | |
384 | var query = "backend.php?op=rpc&id=" + id + "&subop=mark"; | |
385 | ||
386 | query = query + "&afid=" + getActiveFeedId(); | |
387 | ||
388 | if (tagsAreDisplayed()) { | |
389 | query = query + "&omode=tl"; | |
390 | } else { | |
391 | query = query + "&omode=flc"; | |
7ba176d2 | 392 | } |
b685ba25 AD |
393 | |
394 | var mark_img = document.getElementById("FMPIC-" + id); | |
395 | var vfeedu = document.getElementById("FEEDU--1"); | |
396 | var crow = document.getElementById("RROW-" + id); | |
397 | ||
f5e0338d AD |
398 | if (mark_img.src.match("mark_unset")) { |
399 | mark_img.src = mark_img.src.replace("mark_unset", "mark_set"); | |
400 | mark_img.alt = __("Unstar article"); | |
b685ba25 AD |
401 | query = query + "&mark=1"; |
402 | ||
403 | /* if (vfeedu && crow.className.match("Unread")) { | |
404 | vfeedu.innerHTML = (+vfeedu.innerHTML) + 1; | |
405 | } */ | |
406 | ||
407 | } else { | |
408 | //mark_img.src = "images/mark_unset.png"; | |
f5e0338d | 409 | mark_img.alt = __("Please wait..."); |
b685ba25 AD |
410 | query = query + "&mark=0"; |
411 | ||
412 | /* if (vfeedu && crow.className.match("Unread")) { | |
413 | vfeedu.innerHTML = (+vfeedu.innerHTML) - 1; | |
414 | } */ | |
415 | ||
f5e0338d | 416 | if (document.getElementById("headlinesList") && !no_effects) { |
b685ba25 AD |
417 | Effect.Puff(mark_img, {duration : 0.25, afterFinish: tMark_afh_off}); |
418 | } else { | |
f5e0338d AD |
419 | mark_img.src = mark_img.src.replace("mark_set", "mark_unset"); |
420 | mark_img.alt = __("Star article"); | |
b685ba25 | 421 | } |
ace1a6da | 422 | } |
b685ba25 AD |
423 | |
424 | /* var vfeedctr = document.getElementById("FEEDCTR--1"); | |
425 | var vfeedr = document.getElementById("FEEDR--1"); | |
426 | ||
427 | if (vfeedu && vfeedctr) { | |
428 | if ((+vfeedu.innerHTML) > 0) { | |
429 | if (crow.className.match("Unread") && !vfeedr.className.match("Unread")) { | |
430 | vfeedr.className = vfeedr.className + "Unread"; | |
431 | vfeedctr.className = "odd"; | |
432 | } | |
433 | } else { | |
434 | vfeedctr.className = "invisible"; | |
435 | vfeedr.className = vfeedr.className.replace("Unread", ""); | |
8add756a | 436 | } |
254e0e4b | 437 | } |
b685ba25 AD |
438 | |
439 | debug("toggle starred for aid " + id); | |
440 | ||
441 | //new Ajax.Request(query); */ | |
772bc83b | 442 | |
f5e0338d AD |
443 | if (!client_only) { |
444 | debug(query); | |
36e05046 | 445 | |
f5e0338d AD |
446 | xmlhttp_rpc.open("GET", query, true); |
447 | xmlhttp_rpc.onreadystatechange=all_counters_callback; | |
448 | xmlhttp_rpc.send(null); | |
449 | } | |
f0601b87 | 450 | |
b685ba25 AD |
451 | } catch (e) { |
452 | exception_error("toggleMark", e); | |
453 | } | |
f0601b87 AD |
454 | } |
455 | ||
f5e0338d | 456 | function togglePub(id, client_only, no_effects) { |
e4f4b46f | 457 | |
2bc2147f | 458 | try { |
e4f4b46f | 459 | |
2bc2147f AD |
460 | if (!xmlhttp_ready(xmlhttp_rpc)) { |
461 | printLockingError(); | |
462 | return; | |
e4f4b46f | 463 | } |
2bc2147f AD |
464 | |
465 | var query = "backend.php?op=rpc&id=" + id + "&subop=publ"; | |
466 | ||
467 | query = query + "&afid=" + getActiveFeedId(); | |
468 | ||
469 | if (tagsAreDisplayed()) { | |
470 | query = query + "&omode=tl"; | |
471 | } else { | |
472 | query = query + "&omode=flc"; | |
e4f4b46f | 473 | } |
2bc2147f AD |
474 | |
475 | var mark_img = document.getElementById("FPPIC-" + id); | |
476 | var vfeedu = document.getElementById("FEEDU--2"); | |
477 | var crow = document.getElementById("RROW-" + id); | |
478 | ||
f5e0338d AD |
479 | if (mark_img.src.match("pub_unset")) { |
480 | mark_img.src = mark_img.src.replace("pub_unset", "pub_set"); | |
481 | mark_img.alt = __("Unpublish article"); | |
2bc2147f AD |
482 | query = query + "&pub=1"; |
483 | ||
b685ba25 | 484 | /* if (vfeedu && crow.className.match("Unread")) { |
2bc2147f | 485 | vfeedu.innerHTML = (+vfeedu.innerHTML) + 1; |
b685ba25 | 486 | } */ |
2bc2147f | 487 | |
e4f4b46f | 488 | } else { |
6b0f49f9 | 489 | //mark_img.src = "images/pub_unset.png"; |
f5e0338d | 490 | mark_img.alt = __("Please wait..."); |
2bc2147f AD |
491 | query = query + "&pub=0"; |
492 | ||
b685ba25 | 493 | /* if (vfeedu && crow.className.match("Unread")) { |
2bc2147f | 494 | vfeedu.innerHTML = (+vfeedu.innerHTML) - 1; |
b685ba25 | 495 | } */ |
6b0f49f9 | 496 | |
f5e0338d | 497 | if (document.getElementById("headlinesList") && !no_effects) { |
ace1a6da AD |
498 | Effect.Puff(mark_img, {duration : 0.25, afterFinish: tPub_afh_off}); |
499 | } else { | |
f5e0338d AD |
500 | mark_img.src = mark_img.src.replace("pub_set", "pub_unset"); |
501 | mark_img.alt = __("Publish article"); | |
ace1a6da | 502 | } |
e4f4b46f | 503 | } |
2bc2147f | 504 | |
b685ba25 | 505 | /* var vfeedctr = document.getElementById("FEEDCTR--2"); |
2bc2147f AD |
506 | var vfeedr = document.getElementById("FEEDR--2"); |
507 | ||
508 | if (vfeedu && vfeedctr) { | |
509 | if ((+vfeedu.innerHTML) > 0) { | |
510 | if (crow.className.match("Unread") && !vfeedr.className.match("Unread")) { | |
511 | vfeedr.className = vfeedr.className + "Unread"; | |
512 | vfeedctr.className = "odd"; | |
513 | } | |
514 | } else { | |
515 | vfeedctr.className = "invisible"; | |
516 | vfeedr.className = vfeedr.className.replace("Unread", ""); | |
517 | } | |
518 | } | |
519 | ||
520 | debug("toggle published for aid " + id); | |
521 | ||
b685ba25 AD |
522 | new Ajax.Request(query); */ |
523 | ||
f5e0338d AD |
524 | if (!client_only) { |
525 | xmlhttp_rpc.open("GET", query, true); | |
526 | xmlhttp_rpc.onreadystatechange=all_counters_callback; | |
527 | xmlhttp_rpc.send(null); | |
528 | } | |
b685ba25 | 529 | |
2bc2147f | 530 | } catch (e) { |
e4f4b46f | 531 | |
2bc2147f AD |
532 | exception_error("togglePub", e); |
533 | } | |
e4f4b46f AD |
534 | } |
535 | ||
ac162cbe AD |
536 | function correctHeadlinesOffset(id) { |
537 | ||
538 | try { | |
539 | ||
540 | var hlist = document.getElementById("headlinesList"); | |
541 | var container = document.getElementById("headlinesInnerContainer"); | |
542 | var row = document.getElementById("RROW-" + id); | |
543 | ||
544 | var viewport = container.offsetHeight; | |
545 | ||
546 | var rel_offset_top = row.offsetTop - container.scrollTop; | |
547 | var rel_offset_bottom = row.offsetTop + row.offsetHeight - container.scrollTop; | |
548 | ||
549 | debug("Rtop: " + rel_offset_top + " Rbtm: " + rel_offset_bottom); | |
550 | debug("Vport: " + viewport); | |
a5e46e0f | 551 | |
ac162cbe AD |
552 | if (rel_offset_top <= 0 || rel_offset_top > viewport) { |
553 | container.scrollTop = row.offsetTop; | |
554 | } else if (rel_offset_bottom > viewport) { | |
a5e46e0f AD |
555 | |
556 | /* doesn't properly work with Opera in some cases because | |
557 | Opera fucks up element scrolling */ | |
558 | ||
ac162cbe AD |
559 | container.scrollTop = row.offsetTop + row.offsetHeight - viewport; |
560 | } | |
561 | ||
562 | } catch (e) { | |
563 | exception_error("correctHeadlinesOffset", e); | |
564 | } | |
565 | ||
566 | } | |
567 | ||
bb7cface | 568 | function moveToPost(mode) { |
f0601b87 | 569 | |
4e51dd2b AD |
570 | // check for combined mode |
571 | if (!document.getElementById("headlinesList")) | |
572 | return; | |
573 | ||
bb7cface AD |
574 | var rows = getVisibleHeadlineIds(); |
575 | ||
ac162cbe AD |
576 | var prev_id = false; |
577 | var next_id = false; | |
bb7cface | 578 | |
d4eec882 AD |
579 | if (!document.getElementById('RROW-' + active_post_id)) { |
580 | active_post_id = false; | |
581 | } | |
582 | ||
bb7cface AD |
583 | if (active_post_id == false) { |
584 | next_id = getFirstVisibleHeadlineId(); | |
585 | prev_id = getLastVisibleHeadlineId(); | |
586 | } else { | |
587 | for (var i = 0; i < rows.length; i++) { | |
588 | if (rows[i] == active_post_id) { | |
589 | prev_id = rows[i-1]; | |
590 | next_id = rows[i+1]; | |
591 | } | |
592 | } | |
593 | } | |
594 | ||
595 | if (mode == "next") { | |
ac162cbe AD |
596 | if (next_id) { |
597 | correctHeadlinesOffset(next_id); | |
86741347 | 598 | view(next_id, getActiveFeedId()); |
bb7cface AD |
599 | } |
600 | } | |
601 | ||
602 | if (mode == "prev") { | |
ac162cbe AD |
603 | if (prev_id) { |
604 | correctHeadlinesOffset(prev_id); | |
86741347 | 605 | view(prev_id, getActiveFeedId()); |
bb7cface AD |
606 | } |
607 | } | |
608 | } | |
609 | ||
5f51022a AD |
610 | function toggleUnread(id, cmode) { |
611 | try { | |
612 | if (!xmlhttp_ready(xmlhttp_rpc)) { | |
613 | printLockingError(); | |
614 | return; | |
615 | } | |
616 | ||
617 | var row = document.getElementById("RROW-" + id); | |
618 | if (row) { | |
619 | var nc = row.className; | |
620 | nc = nc.replace("Unread", ""); | |
621 | nc = nc.replace("Selected", ""); | |
622 | ||
623 | if (row.className.match("Unread")) { | |
624 | row.className = nc; | |
625 | } else { | |
626 | row.className = nc + "Unread"; | |
627 | } | |
628 | ||
629 | if (!cmode) cmode = 2; | |
630 | ||
631 | var query = "backend.php?op=rpc&subop=catchupSelected&ids=" + | |
632 | param_escape(id) + "&cmode=" + param_escape(cmode); | |
633 | ||
9ec58704 AD |
634 | notify_progress("Loading, please wait..."); |
635 | ||
5f51022a AD |
636 | xmlhttp_rpc.open("GET", query, true); |
637 | xmlhttp_rpc.onreadystatechange=all_counters_callback; | |
638 | xmlhttp_rpc.send(null); | |
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 AD |
649 | try { |
650 | if (!xmlhttp_ready(xmlhttp_rpc)) { | |
651 | printLockingError(); | |
652 | return; | |
653 | } | |
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 | |
e08443c1 AD |
708 | _catchup_callback_func = callback_func; |
709 | ||
9ec58704 AD |
710 | notify_progress("Loading, please wait..."); |
711 | ||
1572afe5 | 712 | xmlhttp_rpc.open("GET", query, true); |
e08443c1 | 713 | xmlhttp_rpc.onreadystatechange=catchup_callback; |
1572afe5 AD |
714 | xmlhttp_rpc.send(null); |
715 | ||
716 | } | |
717 | ||
718 | } catch (e) { | |
83f043bb | 719 | exception_error("selectionToggleUnread", e); |
1572afe5 AD |
720 | } |
721 | } | |
722 | ||
386cbf27 | 723 | function selectionToggleMarked(cdm_mode) { |
1572afe5 AD |
724 | try { |
725 | if (!xmlhttp_ready(xmlhttp_rpc)) { | |
726 | printLockingError(); | |
727 | return; | |
728 | } | |
729 | ||
386cbf27 AD |
730 | var rows; |
731 | ||
732 | if (cdm_mode) { | |
733 | rows = cdmGetSelectedArticles(); | |
734 | } else { | |
735 | rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK"); | |
736 | } | |
1572afe5 | 737 | |
9cc600d1 AD |
738 | if (rows.length == 0) { |
739 | alert(__("No articles are selected.")); | |
740 | return; | |
741 | } | |
742 | ||
1572afe5 | 743 | for (i = 0; i < rows.length; i++) { |
f5e0338d | 744 | toggleMark(rows[i], true, true); |
1572afe5 AD |
745 | } |
746 | ||
747 | if (rows.length > 0) { | |
748 | ||
749 | var query = "backend.php?op=rpc&subop=markSelected&ids=" + | |
750 | param_escape(rows.toString()) + "&cmode=2"; | |
751 | ||
2bc2147f AD |
752 | query = query + "&afid=" + getActiveFeedId(); |
753 | ||
754 | if (tagsAreDisplayed()) { | |
755 | query = query + "&omode=tl"; | |
756 | } else { | |
757 | query = query + "&omode=flc"; | |
758 | } | |
759 | ||
1572afe5 AD |
760 | xmlhttp_rpc.open("GET", query, true); |
761 | xmlhttp_rpc.onreadystatechange=all_counters_callback; | |
762 | xmlhttp_rpc.send(null); | |
763 | ||
764 | } | |
765 | ||
766 | } catch (e) { | |
83f043bb | 767 | exception_error("selectionToggleMarked", e); |
1572afe5 AD |
768 | } |
769 | } | |
770 | ||
e4f4b46f AD |
771 | function selectionTogglePublished(cdm_mode) { |
772 | try { | |
773 | if (!xmlhttp_ready(xmlhttp_rpc)) { | |
774 | printLockingError(); | |
775 | return; | |
776 | } | |
777 | ||
778 | var rows; | |
779 | ||
780 | if (cdm_mode) { | |
781 | rows = cdmGetSelectedArticles(); | |
782 | } else { | |
783 | rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK"); | |
784 | } | |
785 | ||
786 | if (rows.length == 0) { | |
787 | alert(__("No articles are selected.")); | |
788 | return; | |
789 | } | |
790 | ||
791 | for (i = 0; i < rows.length; i++) { | |
f5e0338d | 792 | togglePub(rows[i], true, true); |
e4f4b46f AD |
793 | } |
794 | ||
795 | if (rows.length > 0) { | |
796 | ||
797 | var query = "backend.php?op=rpc&subop=publishSelected&ids=" + | |
798 | param_escape(rows.toString()) + "&cmode=2"; | |
799 | ||
2bc2147f AD |
800 | query = query + "&afid=" + getActiveFeedId(); |
801 | ||
802 | if (tagsAreDisplayed()) { | |
803 | query = query + "&omode=tl"; | |
804 | } else { | |
805 | query = query + "&omode=flc"; | |
806 | } | |
807 | ||
e4f4b46f AD |
808 | xmlhttp_rpc.open("GET", query, true); |
809 | xmlhttp_rpc.onreadystatechange=all_counters_callback; | |
810 | xmlhttp_rpc.send(null); | |
811 | ||
812 | } | |
813 | ||
814 | } catch (e) { | |
815 | exception_error("selectionToggleMarked", e); | |
816 | } | |
817 | } | |
818 | ||
386cbf27 AD |
819 | function cdmGetSelectedArticles() { |
820 | var sel_articles = new Array(); | |
b2128f01 | 821 | var container = document.getElementById("headlinesInnerContainer"); |
386cbf27 AD |
822 | |
823 | for (i = 0; i < container.childNodes.length; i++) { | |
824 | var child = container.childNodes[i]; | |
825 | ||
826 | if (child.id.match("RROW-") && child.className.match("Selected")) { | |
827 | var c_id = child.id.replace("RROW-", ""); | |
828 | sel_articles.push(c_id); | |
829 | } | |
830 | } | |
831 | ||
832 | return sel_articles; | |
833 | } | |
834 | ||
8be83f42 AD |
835 | function cdmGetVisibleArticles() { |
836 | var sel_articles = new Array(); | |
837 | var container = document.getElementById("headlinesInnerContainer"); | |
838 | ||
839 | for (i = 0; i < container.childNodes.length; i++) { | |
840 | var child = container.childNodes[i]; | |
841 | ||
842 | if (child.id.match("RROW-")) { | |
843 | var c_id = child.id.replace("RROW-", ""); | |
844 | sel_articles.push(c_id); | |
845 | } | |
846 | } | |
847 | ||
848 | return sel_articles; | |
849 | } | |
850 | ||
851 | function cdmGetUnreadArticles() { | |
852 | var sel_articles = new Array(); | |
853 | var container = document.getElementById("headlinesInnerContainer"); | |
854 | ||
855 | for (i = 0; i < container.childNodes.length; i++) { | |
856 | var child = container.childNodes[i]; | |
857 | ||
858 | if (child.id.match("RROW-") && child.className.match("Unread")) { | |
859 | var c_id = child.id.replace("RROW-", ""); | |
860 | sel_articles.push(c_id); | |
861 | } | |
862 | } | |
863 | ||
864 | return sel_articles; | |
865 | } | |
866 | ||
867 | ||
386cbf27 AD |
868 | // mode = all,none,unread |
869 | function cdmSelectArticles(mode) { | |
b2128f01 | 870 | var container = document.getElementById("headlinesInnerContainer"); |
386cbf27 AD |
871 | |
872 | for (i = 0; i < container.childNodes.length; i++) { | |
873 | var child = container.childNodes[i]; | |
874 | ||
875 | if (child.id.match("RROW-")) { | |
06d1a1c1 AD |
876 | var aid = child.id.replace("RROW-", ""); |
877 | ||
878 | var cb = document.getElementById("RCHK-" + aid); | |
879 | ||
386cbf27 AD |
880 | if (mode == "all") { |
881 | if (!child.className.match("Selected")) { | |
882 | child.className = child.className + "Selected"; | |
06d1a1c1 | 883 | cb.checked = true; |
386cbf27 AD |
884 | } |
885 | } else if (mode == "unread") { | |
886 | if (child.className.match("Unread") && !child.className.match("Selected")) { | |
887 | child.className = child.className + "Selected"; | |
06d1a1c1 | 888 | cb.checked = true; |
386cbf27 AD |
889 | } |
890 | } else { | |
891 | child.className = child.className.replace("Selected", ""); | |
06d1a1c1 | 892 | cb.checked = false; |
386cbf27 AD |
893 | } |
894 | } | |
895 | } | |
896 | } | |
897 | ||
98bea1b1 | 898 | function catchupPage() { |
b47b5af7 | 899 | |
8a5b4579 AD |
900 | var fn = getFeedName(getActiveFeedId(), active_feed_is_cat); |
901 | ||
a5ae125a AD |
902 | var str = __("Mark all visible articles in %s as read?"); |
903 | ||
904 | str = str.replace("%s", fn); | |
8a5b4579 AD |
905 | |
906 | if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) { | |
907 | return; | |
908 | } | |
909 | ||
b47b5af7 AD |
910 | if (document.getElementById("headlinesList")) { |
911 | selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, 'Unread', true); | |
2228d0e4 | 912 | selectionToggleUnread(false, false, 'viewCurrentFeed()', true); |
b47b5af7 AD |
913 | selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false); |
914 | } else { | |
915 | cdmSelectArticles('all'); | |
2228d0e4 | 916 | selectionToggleUnread(true, false, 'viewCurrentFeed()', true) |
b47b5af7 AD |
917 | cdmSelectArticles('none'); |
918 | } | |
98bea1b1 AD |
919 | } |
920 | ||
a5ae125a AD |
921 | function catchupSelection() { |
922 | ||
923 | try { | |
924 | ||
925 | var rows; | |
926 | ||
927 | if (document.getElementById("headlinesList")) { | |
928 | rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK"); | |
929 | } else { | |
930 | rows = cdmGetSelectedArticles(); | |
931 | } | |
932 | ||
933 | if (rows.length == 0) { | |
934 | alert(__("No articles are selected.")); | |
935 | return; | |
936 | } | |
937 | ||
938 | ||
939 | var fn = getFeedName(getActiveFeedId(), active_feed_is_cat); | |
940 | ||
941 | var str = __("Mark all selected articles in %s as read?"); | |
942 | ||
943 | str = str.replace("%s", fn); | |
944 | ||
945 | if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) { | |
946 | return; | |
947 | } | |
948 | ||
949 | if (document.getElementById("headlinesList")) { | |
950 | selectionToggleUnread(false, false, 'viewCurrentFeed()', true); | |
951 | // selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false); | |
952 | } else { | |
953 | selectionToggleUnread(true, false, 'viewCurrentFeed()', true) | |
954 | // cdmSelectArticles('none'); | |
955 | } | |
956 | ||
957 | } catch (e) { | |
958 | exception_error("catchupSelection", e); | |
959 | } | |
960 | } | |
961 | ||
962 | ||
88040f57 AD |
963 | function labelFromSearch(search, search_mode, match_on, feed_id, is_cat) { |
964 | ||
965 | if (!xmlhttp_ready(xmlhttp_rpc)) { | |
966 | printLockingError(); | |
967 | } | |
968 | ||
a5ae125a | 969 | var title = prompt(__("Please enter label title:"), ""); |
88040f57 AD |
970 | |
971 | if (title) { | |
972 | ||
973 | var query = "backend.php?op=labelFromSearch&search=" + param_escape(search) + | |
974 | "&smode=" + param_escape(search_mode) + "&match=" + param_escape(match_on) + | |
975 | "&feed=" + param_escape(feed_id) + "&is_cat=" + param_escape(is_cat) + | |
976 | "&title=" + param_escape(title); | |
977 | ||
978 | debug("LFS: " + query); | |
979 | ||
980 | xmlhttp_rpc.open("GET", query, true); | |
0feab655 | 981 | xmlhttp_rpc.onreadystatechange=dlg_frefresh_callback; |
88040f57 AD |
982 | xmlhttp_rpc.send(null); |
983 | } | |
984 | ||
985 | } | |
986 | ||
13f08f75 | 987 | function editArticleTags(id, feed_id, cdm_enabled) { |
0b126ac2 AD |
988 | _tag_active_post_id = id; |
989 | _tag_active_feed_id = feed_id; | |
13f08f75 | 990 | _tag_active_cdm = cdm_enabled; |
b07b61da AD |
991 | |
992 | cache_invalidate(id); | |
993 | ||
13f08f75 AD |
994 | try { |
995 | _tag_cdm_scroll = document.getElementById("headlinesInnerContainer").scrollTop; | |
996 | } catch (e) { } | |
0b126ac2 AD |
997 | displayDlg('editArticleTags', id); |
998 | } | |
999 | ||
1000 | ||
1001 | function tag_saved_callback() { | |
1002 | if (xmlhttp_rpc.readyState == 4) { | |
1003 | try { | |
1004 | debug("in tag_saved_callback"); | |
1005 | ||
1006 | closeInfoBox(); | |
1007 | notify(""); | |
1008 | ||
1009 | if (tagsAreDisplayed()) { | |
1010 | _reload_feedlist_after_view = true; | |
1011 | } | |
1012 | ||
13f08f75 AD |
1013 | if (!_tag_active_cdm) { |
1014 | if (active_post_id == _tag_active_post_id) { | |
1015 | debug("reloading current article"); | |
1016 | view(_tag_active_post_id, _tag_active_feed_id); | |
1017 | } | |
1018 | } else { | |
1019 | debug("reloading current feed"); | |
1020 | viewCurrentFeed(); | |
1021 | } | |
0b126ac2 AD |
1022 | |
1023 | } catch (e) { | |
1024 | exception_error("catchup_callback", e); | |
1025 | } | |
1026 | } | |
1027 | } | |
1028 | ||
1029 | function editTagsSave() { | |
1030 | ||
1031 | if (!xmlhttp_ready(xmlhttp_rpc)) { | |
1032 | printLockingError(); | |
1033 | } | |
1034 | ||
42c32916 | 1035 | notify_progress("Saving article tags..."); |
88040f57 | 1036 | |
0b126ac2 AD |
1037 | var form = document.forms["tag_edit_form"]; |
1038 | ||
1039 | var query = Form.serialize("tag_edit_form"); | |
1040 | ||
14b6c54b AD |
1041 | query = "backend.php?op=rpc&subop=setArticleTags&" + query; |
1042 | ||
1043 | debug(query); | |
1044 | ||
1045 | xmlhttp_rpc.open("GET", query, true); | |
0b126ac2 AD |
1046 | xmlhttp_rpc.onreadystatechange=tag_saved_callback; |
1047 | xmlhttp_rpc.send(null); | |
1048 | ||
1049 | } | |
d62a3b63 AD |
1050 | |
1051 | function editTagsInsert() { | |
1052 | try { | |
1053 | ||
1054 | var form = document.forms["tag_edit_form"]; | |
1055 | ||
1056 | var found_tags = form.found_tags; | |
1057 | var tags_str = form.tags_str; | |
1058 | ||
1059 | var tag = found_tags[found_tags.selectedIndex].value; | |
1060 | ||
1061 | if (tags_str.value.length > 0 && | |
1062 | tags_str.value.lastIndexOf(", ") != tags_str.value.length - 2) { | |
1063 | ||
1064 | tags_str.value = tags_str.value + ", "; | |
1065 | } | |
1066 | ||
1067 | tags_str.value = tags_str.value + tag + ", "; | |
1068 | ||
1069 | found_tags.selectedIndex = 0; | |
1070 | ||
1071 | } catch (e) { | |
1072 | exception_error(e, "editTagsInsert"); | |
1073 | } | |
1074 | } | |
ba0978c8 AD |
1075 | |
1076 | function cdmWatchdog() { | |
1077 | ||
1078 | try { | |
1079 | ||
1080 | var ctr = document.getElementById("headlinesInnerContainer"); | |
1081 | ||
9acd22e8 AD |
1082 | if (!ctr) return; |
1083 | ||
ba0978c8 AD |
1084 | var ids = new Array(); |
1085 | ||
1086 | var e = ctr.firstChild; | |
1087 | ||
1088 | while (e) { | |
1089 | if (e.className && e.className == "cdmArticleUnread" && e.id && | |
1090 | e.id.match("RROW-")) { | |
1091 | ||
1092 | // article fits in viewport OR article is longer than viewport and | |
1093 | // its bottom is visible | |
1094 | ||
1095 | if (ctr.scrollTop <= e.offsetTop && e.offsetTop + e.offsetHeight <= | |
1096 | ctr.scrollTop + ctr.offsetHeight) { | |
1097 | ||
1098 | // debug(e.id + " is visible " + e.offsetTop + "." + | |
1099 | // (e.offsetTop + e.offsetHeight) + " vs " + ctr.scrollTop + "." + | |
1100 | // (ctr.scrollTop + ctr.offsetHeight)); | |
1101 | ||
1102 | ids.push(e.id.replace("RROW-", "")); | |
1103 | ||
1104 | } else if (e.offsetHeight > ctr.offsetHeight && | |
1105 | e.offsetTop + e.offsetHeight >= ctr.scrollTop && | |
1106 | e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight) { | |
1107 | ||
1108 | ids.push(e.id.replace("RROW-", "")); | |
1109 | ||
1110 | } | |
1111 | ||
c50e2b30 AD |
1112 | // method 2: article bottom is visible and is in upper 1/2 of the viewport |
1113 | ||
1114 | /* if (e.offsetTop + e.offsetHeight >= ctr.scrollTop && | |
1115 | e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight/2) { | |
1116 | ||
1117 | ids.push(e.id.replace("RROW-", "")); | |
1118 | ||
1119 | } */ | |
1120 | ||
ba0978c8 AD |
1121 | } |
1122 | ||
1123 | e = e.nextSibling; | |
1124 | } | |
1125 | ||
1126 | debug("cdmWatchdog, ids= " + ids.toString()); | |
1127 | ||
1128 | if (ids.length > 0 && xmlhttp_ready(xmlhttp_rpc)) { | |
1129 | ||
1130 | for (var i = 0; i < ids.length; i++) { | |
1131 | var e = document.getElementById("RROW-" + ids[i]); | |
1132 | if (e) { | |
1133 | e.className = e.className.replace("Unread", ""); | |
1134 | } | |
1135 | } | |
1136 | ||
1137 | var query = "backend.php?op=rpc&subop=catchupSelected&ids=" + | |
1138 | param_escape(ids.toString()) + "&cmode=0"; | |
1139 | ||
f8e47112 | 1140 | xmlhttp_rpc.open("GET", query, true); |
ba0978c8 | 1141 | xmlhttp_rpc.onreadystatechange=all_counters_callback; |
c50e2b30 | 1142 | xmlhttp_rpc.send(null); |
ba0978c8 AD |
1143 | |
1144 | } | |
1145 | ||
c50e2b30 | 1146 | _cdm_wd_timeout = window.setTimeout("cdmWatchdog()", 4000); |
ba0978c8 AD |
1147 | |
1148 | } catch (e) { | |
1149 | exception_error(e, "cdmWatchdog"); | |
1150 | } | |
1151 | ||
1152 | } | |
e097e8be AD |
1153 | |
1154 | ||
1155 | function cache_inject(id, article) { | |
fed4387d | 1156 | if (!cache_check(id)) { |
e097e8be AD |
1157 | debug("cache_article: miss: " + id); |
1158 | ||
1159 | var cache_obj = new Array(); | |
1160 | ||
fed4387d | 1161 | cache_obj["id"] = id; |
e097e8be AD |
1162 | cache_obj["data"] = article; |
1163 | ||
fed4387d | 1164 | article_cache.push(cache_obj); |
e097e8be AD |
1165 | |
1166 | } else { | |
1167 | debug("cache_article: hit: " + id); | |
1168 | } | |
1169 | } | |
1170 | ||
1171 | function cache_find(id) { | |
fed4387d AD |
1172 | for (var i = 0; i < article_cache.length; i++) { |
1173 | if (article_cache[i]["id"] == id) { | |
fed4387d AD |
1174 | return article_cache[i]["data"]; |
1175 | } | |
e097e8be | 1176 | } |
fed4387d | 1177 | return false; |
e097e8be AD |
1178 | } |
1179 | ||
1180 | function cache_check(id) { | |
fed4387d AD |
1181 | for (var i = 0; i < article_cache.length; i++) { |
1182 | if (article_cache[i]["id"] == id) { | |
1183 | return true; | |
1184 | } | |
1185 | } | |
1186 | return false; | |
e097e8be AD |
1187 | } |
1188 | ||
1189 | function cache_expire() { | |
7289eacf | 1190 | while (article_cache.length > 20) { |
fed4387d AD |
1191 | article_cache.shift(); |
1192 | } | |
e097e8be | 1193 | } |
b07b61da AD |
1194 | |
1195 | function cache_invalidate(id) { | |
1196 | var i = 0 | |
c1b18749 AD |
1197 | |
1198 | try { | |
1199 | ||
1200 | while (i < article_cache.length) { | |
1201 | if (article_cache[i]["id"] == id) { | |
1202 | debug("cache_invalidate: removed id " + id); | |
1203 | article_cache.splice(i, 1); | |
1204 | return true; | |
1205 | } | |
1206 | i++; | |
b07b61da | 1207 | } |
c1b18749 AD |
1208 | debug("cache_invalidate: id not found: " + id); |
1209 | return false; | |
1210 | } catch (e) { | |
1211 | exception_error("cache_invalidate", e); | |
b07b61da | 1212 | } |
b07b61da | 1213 | } |
298f3f78 AD |
1214 | |
1215 | function getActiveArticleId() { | |
1216 | return active_post_id; | |
1217 | } | |
e4914b62 AD |
1218 | |
1219 | function cdmMouseIn(elem) { | |
1220 | try { | |
1221 | if (elem.id && elem.id.match("RROW-")) { | |
1222 | var id = elem.id.replace("RROW-", ""); | |
1223 | active_post_id = id; | |
1224 | } | |
1225 | } catch (e) { | |
1226 | exception_error("cdmMouseIn", e); | |
1227 | } | |
1228 | ||
1229 | } | |
1230 | ||
1231 | function cdmMouseOut(elem) { | |
1232 | active_post_id = false; | |
1233 | } | |
ac541432 AD |
1234 | |
1235 | function headlines_scroll_handler() { | |
1236 | try { | |
1237 | ||
1238 | var e = document.getElementById("headlinesInnerContainer"); | |
1239 | ||
a219fec5 | 1240 | if (e.scrollTop + e.offsetHeight > e.scrollHeight - 300) { |
ac541432 AD |
1241 | debug("more cowbell!"); |
1242 | ||
1243 | viewNextFeedPage(); | |
1244 | } | |
1245 | ||
1246 | } catch (e) { | |
1247 | exception_error("headlines_scroll_handler", e); | |
1248 | } | |
1249 | } | |
8be83f42 AD |
1250 | |
1251 | function catchupRelativeToArticle(below) { | |
1252 | ||
1253 | try { | |
1254 | ||
1255 | if (!xmlhttp_ready(xmlhttp_rpc)) { | |
1256 | printLockingError(); | |
1257 | } | |
1258 | ||
1259 | if (!getActiveArticleId()) { | |
1260 | alert(__("No article is selected.")); | |
1261 | return; | |
1262 | } | |
1263 | ||
1264 | var visible_ids; | |
1265 | ||
1266 | if (document.getElementById("headlinesList")) { | |
1267 | visible_ids = getVisibleHeadlineIds(); | |
1268 | } else { | |
1269 | visible_ids = cdmGetVisibleArticles(); | |
1270 | } | |
1271 | ||
1272 | var ids_to_mark = new Array(); | |
1273 | ||
1274 | if (!below) { | |
1275 | for (var i = 0; i < visible_ids.length; i++) { | |
1276 | if (visible_ids[i] != getActiveArticleId()) { | |
1277 | var e = document.getElementById("RROW-" + visible_ids[i]); | |
1278 | ||
1279 | if (e && e.className.match("Unread")) { | |
1280 | ids_to_mark.push(visible_ids[i]); | |
1281 | } | |
1282 | } else { | |
1283 | break; | |
1284 | } | |
1285 | } | |
1286 | } else { | |
1287 | for (var i = visible_ids.length-1; i >= 0; i--) { | |
1288 | if (visible_ids[i] != getActiveArticleId()) { | |
1289 | var e = document.getElementById("RROW-" + visible_ids[i]); | |
1290 | ||
1291 | if (e && e.className.match("Unread")) { | |
1292 | ids_to_mark.push(visible_ids[i]); | |
1293 | } | |
1294 | } else { | |
1295 | break; | |
1296 | } | |
1297 | } | |
1298 | } | |
1299 | ||
1300 | if (ids_to_mark.length == 0) { | |
1301 | alert(__("No articles found to mark")); | |
1302 | } else { | |
1303 | var msg = __("Mark %d article(s) as read?").replace("%d", ids_to_mark.length); | |
1304 | ||
1305 | if (confirm(msg)) { | |
1306 | ||
1307 | for (var i = 0; i < ids_to_mark.length; i++) { | |
1308 | var e = document.getElementById("RROW-" + ids_to_mark[i]); | |
1309 | e.className = e.className.replace("Unread", ""); | |
1310 | } | |
1311 | ||
1312 | var query = "backend.php?op=rpc&subop=catchupSelected&ids=" + | |
1313 | param_escape(ids_to_mark.toString()) + "&cmode=0"; | |
1314 | ||
1315 | xmlhttp_rpc.open("GET", query, true); | |
1316 | xmlhttp_rpc.onreadystatechange=catchup_callback; | |
1317 | xmlhttp_rpc.send(null); | |
1318 | ||
1319 | } | |
1320 | } | |
1321 | ||
1322 | } catch (e) { | |
1323 | exception_error("catchupRelativeToArticle", e); | |
1324 | } | |
1325 | } |