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