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