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