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