]>
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"); | |
25 | if (_catchup_callback_func) { | |
26 | setTimeout(_catchup_callback_func, 100); | |
27 | } | |
9ec58704 | 28 | notify(""); |
8f3b99ba AD |
29 | all_counters_callback(); |
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 AD |
40 | try { |
41 | f.scrollTop = 0; | |
42 | } catch (e) { }; | |
6b4163cb | 43 | f.innerHTML = xmlhttp.responseText; |
30031575 | 44 | update_all_counters(); |
935f235d AD |
45 | if (typeof correctPNG != 'undefined') { |
46 | correctPNG(); | |
47 | } | |
ba0978c8 AD |
48 | |
49 | if (_cdm_wd_timeout) window.clearTimeout(_cdm_wd_timeout); | |
50 | ||
ac7bcd71 AD |
51 | if (!document.getElementById("headlinesList") && |
52 | getInitParam("cdm_auto_catchup") == 1) { | |
ba0978c8 AD |
53 | debug("starting CDM watchdog"); |
54 | _cdm_wd_timeout = window.setTimeout("cdmWatchdog()", 5000); | |
55 | _cdm_wd_vishist = new Array(); | |
ac7bcd71 AD |
56 | } else { |
57 | debug("not in CDM mode or watchdog disabled"); | |
ba0978c8 AD |
58 | } |
59 | ||
13f08f75 AD |
60 | if (_tag_cdm_scroll) { |
61 | try { | |
62 | document.getElementById("headlinesInnerContainer").scrollTop = _tag_cdm_scroll; | |
63 | _tag_cdm_scroll = false; | |
64 | } catch (e) { } | |
65 | } | |
66 | ||
33b8cab4 | 67 | notify(""); |
6b4163cb AD |
68 | } |
69 | } | |
70 | ||
e097e8be AD |
71 | function render_article(article) { |
72 | try { | |
6b4163cb | 73 | var f = document.getElementById("content-frame"); |
44cc6f20 AD |
74 | try { |
75 | f.scrollTop = 0; | |
76 | } catch (e) { }; | |
e097e8be AD |
77 | |
78 | f.innerHTML = article; | |
79 | ||
80 | } catch (e) { | |
81 | exception_error("render_article", e); | |
82 | } | |
83 | } | |
84 | ||
85 | function article_callback() { | |
86 | if (xmlhttp.readyState == 4) { | |
87 | debug("article_callback"); | |
88 | ||
89 | try { | |
90 | if (xmlhttp.responseXML) { | |
91 | var reply = xmlhttp.responseXML.firstChild.firstChild; | |
92 | ||
93 | var articles = xmlhttp.responseXML.getElementsByTagName("article"); | |
94 | ||
95 | for (var i = 0; i < articles.length; i++) { | |
96 | var a_id = articles[i].getAttribute("id"); | |
97 | ||
98 | debug("found id: " + a_id); | |
99 | ||
100 | if (a_id == active_post_id) { | |
101 | debug("active article, rendering..."); | |
102 | render_article(articles[i].firstChild.nodeValue); | |
103 | } | |
104 | ||
105 | cache_inject(a_id, articles[i].firstChild.nodeValue); | |
106 | } | |
107 | ||
108 | } else { | |
109 | debug("article_callback: returned no XML object"); | |
110 | } | |
111 | } catch (e) { | |
112 | exception_error("article_callback", e); | |
113 | } | |
4b6206fa AD |
114 | |
115 | var date = new Date(); | |
116 | last_article_view = date.getTime() / 1000; | |
117 | ||
935f235d AD |
118 | if (typeof correctPNG != 'undefined') { |
119 | correctPNG(); | |
120 | } | |
0b126ac2 AD |
121 | |
122 | if (_reload_feedlist_after_view) { | |
123 | setTimeout('updateFeedList(false, false)', 50); | |
124 | _reload_feedlist_after_view = false; | |
125 | } else { | |
5a94a953 AD |
126 | var counters = xmlhttp.responseXML.getElementsByTagName("counters")[0]; |
127 | ||
128 | if (counters) { | |
129 | debug("parsing piggybacked counters: " + counters); | |
130 | parse_counters(counters, false); | |
131 | } else { | |
132 | update_all_counters(); | |
133 | } | |
0b126ac2 | 134 | } |
9ec58704 AD |
135 | |
136 | notify(""); | |
6b4163cb AD |
137 | } |
138 | } | |
139 | ||
1dc8dba0 | 140 | function view(id, feed_id, skip_history) { |
ee1f45f4 AD |
141 | |
142 | try { | |
ee1f45f4 | 143 | debug("loading article: " + id + "/" + feed_id); |
1dc8dba0 | 144 | |
0b126ac2 AD |
145 | active_real_feed_id = feed_id; |
146 | ||
e097e8be AD |
147 | var cached_article = cache_find(id); |
148 | ||
149 | debug("cache check result: " + (cached_article != false)); | |
150 | ||
151 | /* if (!skip_history) { | |
1dc8dba0 | 152 | history_push("ARTICLE:" + id + ":" + feed_id); |
e097e8be | 153 | } */ |
ee1f45f4 | 154 | |
ee1f45f4 AD |
155 | enableHotkeys(); |
156 | ||
ee1f45f4 | 157 | active_post_id = id; |
1c2d7193 | 158 | //setActiveFeedId(feed_id); |
090e250b | 159 | |
6b4163cb AD |
160 | var query = "backend.php?op=view&id=" + param_escape(id) + |
161 | "&feed=" + param_escape(feed_id); | |
162 | ||
4b6206fa AD |
163 | var date = new Date(); |
164 | ||
165 | if (!xmlhttp_ready(xmlhttp) && last_article_view < date.getTime() / 1000 - 15) { | |
166 | debug("<b>xmlhttp seems to be stuck at view, aborting</b>"); | |
167 | xmlhttp.abort(); | |
168 | } | |
169 | ||
e097e8be | 170 | if (cached_article || xmlhttp_ready(xmlhttp)) { |
4b6206fa AD |
171 | |
172 | cleanSelected("headlinesList"); | |
173 | ||
174 | var crow = document.getElementById("RROW-" + active_post_id); | |
e097e8be AD |
175 | |
176 | var article_is_unread = crow.className.match("Unread"); | |
177 | debug("article is unread: " + article_is_unread); | |
178 | ||
4b6206fa AD |
179 | crow.className = crow.className.replace("Unread", ""); |
180 | ||
181 | var upd_img_pic = document.getElementById("FUPDPIC-" + active_post_id); | |
182 | ||
183 | if (upd_img_pic) { | |
184 | upd_img_pic.src = "images/blank_icon.gif"; | |
185 | } | |
186 | ||
187 | selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false); | |
188 | markHeadline(active_post_id); | |
189 | ||
e097e8be AD |
190 | var neighbor_ids = getRelativePostIds(active_post_id); |
191 | ||
192 | /* only request uncached articles */ | |
193 | ||
194 | var cids_to_request = Array(); | |
195 | ||
196 | for (var i = 0; i < neighbor_ids.length; i++) { | |
197 | if (!cache_check(neighbor_ids[i])) { | |
198 | cids_to_request.push(neighbor_ids[i]); | |
199 | } | |
200 | } | |
201 | ||
202 | debug("additional ids: " + cids_to_request.toString()); | |
203 | ||
5a94a953 AD |
204 | /* additional info for piggyback counters */ |
205 | ||
206 | if (tagsAreDisplayed()) { | |
207 | query = query + "&omode=lt"; | |
208 | } else { | |
209 | query = query + "&omode=flc"; | |
210 | } | |
211 | ||
86173d9a AD |
212 | var date = new Date(); |
213 | var timestamp = Math.round(date.getTime() / 1000); | |
9ec58704 AD |
214 | query = query + "&ts=" + timestamp; |
215 | ||
e097e8be AD |
216 | query = query + "&cids=" + cids_to_request.toString(); |
217 | ||
218 | if (!cached_article) { | |
219 | ||
220 | notify_progress("Loading, please wait..."); | |
221 | ||
222 | debug(query); | |
223 | ||
224 | xmlhttp.open("GET", query, true); | |
225 | xmlhttp.onreadystatechange=article_callback; | |
226 | xmlhttp.send(null); | |
227 | } else if (cached_article && article_is_unread) { | |
228 | ||
229 | query = query + "&mode=prefetch"; | |
230 | ||
231 | debug(query); | |
232 | ||
233 | xmlhttp.open("GET", query, true); | |
234 | xmlhttp.onreadystatechange=article_callback; | |
235 | xmlhttp.send(null); | |
236 | ||
237 | render_article(cached_article); | |
238 | ||
239 | } else if (cached_article) { | |
240 | ||
241 | render_article(cached_article); | |
242 | ||
243 | } | |
244 | ||
245 | cache_expire(); | |
86173d9a | 246 | |
6b4163cb AD |
247 | } else { |
248 | debug("xmlhttp busy (@view)"); | |
f88e0a5d | 249 | printLockingError(); |
6b4163cb AD |
250 | } |
251 | ||
ee1f45f4 AD |
252 | } catch (e) { |
253 | exception_error("view", e); | |
254 | } | |
f0601b87 AD |
255 | } |
256 | ||
9932fb06 | 257 | function toggleMark(id) { |
f0601b87 AD |
258 | |
259 | if (!xmlhttp_ready(xmlhttp_rpc)) { | |
260 | printLockingError(); | |
261 | return; | |
262 | } | |
263 | ||
f0601b87 AD |
264 | var query = "backend.php?op=rpc&id=" + id + "&subop=mark"; |
265 | ||
7ba176d2 | 266 | var mark_img = document.getElementById("FMARKPIC-" + id); |
0feab655 | 267 | var vfeedu = document.getElementById("FEEDU--1"); |
7ba176d2 | 268 | var crow = document.getElementById("RROW-" + id); |
254e0e4b | 269 | |
9932fb06 | 270 | if (mark_img.alt != "Reset mark") { |
f0601b87 AD |
271 | mark_img.src = "images/mark_set.png"; |
272 | mark_img.alt = "Reset mark"; | |
f0601b87 | 273 | query = query + "&mark=1"; |
254e0e4b | 274 | |
7ba176d2 AD |
275 | if (vfeedu && crow.className.match("Unread")) { |
276 | vfeedu.innerHTML = (+vfeedu.innerHTML) + 1; | |
277 | } | |
278 | ||
f0601b87 AD |
279 | } else { |
280 | mark_img.src = "images/mark_unset.png"; | |
281 | mark_img.alt = "Set mark"; | |
f0601b87 | 282 | query = query + "&mark=0"; |
254e0e4b | 283 | |
7ba176d2 AD |
284 | if (vfeedu && crow.className.match("Unread")) { |
285 | vfeedu.innerHTML = (+vfeedu.innerHTML) - 1; | |
286 | } | |
254e0e4b AD |
287 | |
288 | } | |
289 | ||
0feab655 AD |
290 | var vfeedctr = document.getElementById("FEEDCTR--1"); |
291 | var vfeedr = document.getElementById("FEEDR--1"); | |
254e0e4b AD |
292 | |
293 | if (vfeedu && vfeedctr) { | |
294 | if ((+vfeedu.innerHTML) > 0) { | |
7ba176d2 | 295 | if (crow.className.match("Unread") && !vfeedr.className.match("Unread")) { |
8add756a | 296 | vfeedr.className = vfeedr.className + "Unread"; |
7ba176d2 | 297 | vfeedctr.className = "odd"; |
8add756a | 298 | } |
254e0e4b AD |
299 | } else { |
300 | vfeedctr.className = "invisible"; | |
8add756a | 301 | vfeedr.className = vfeedr.className.replace("Unread", ""); |
254e0e4b | 302 | } |
f0601b87 AD |
303 | } |
304 | ||
772bc83b AD |
305 | debug("toggle starred for aid " + id); |
306 | ||
307 | new Ajax.Request(query); | |
f0601b87 AD |
308 | |
309 | } | |
310 | ||
bb7cface | 311 | function moveToPost(mode) { |
f0601b87 | 312 | |
4e51dd2b AD |
313 | // check for combined mode |
314 | if (!document.getElementById("headlinesList")) | |
315 | return; | |
316 | ||
bb7cface AD |
317 | var rows = getVisibleHeadlineIds(); |
318 | ||
319 | var prev_id; | |
320 | var next_id; | |
321 | ||
d4eec882 AD |
322 | if (!document.getElementById('RROW-' + active_post_id)) { |
323 | active_post_id = false; | |
324 | } | |
325 | ||
bb7cface AD |
326 | if (active_post_id == false) { |
327 | next_id = getFirstVisibleHeadlineId(); | |
328 | prev_id = getLastVisibleHeadlineId(); | |
329 | } else { | |
330 | for (var i = 0; i < rows.length; i++) { | |
331 | if (rows[i] == active_post_id) { | |
332 | prev_id = rows[i-1]; | |
333 | next_id = rows[i+1]; | |
334 | } | |
335 | } | |
336 | } | |
337 | ||
338 | if (mode == "next") { | |
339 | if (next_id != undefined) { | |
86741347 | 340 | view(next_id, getActiveFeedId()); |
bb7cface AD |
341 | } |
342 | } | |
343 | ||
344 | if (mode == "prev") { | |
345 | if ( prev_id != undefined) { | |
86741347 | 346 | view(prev_id, getActiveFeedId()); |
bb7cface AD |
347 | } |
348 | } | |
349 | } | |
350 | ||
5f51022a AD |
351 | function toggleUnread(id, cmode) { |
352 | try { | |
353 | if (!xmlhttp_ready(xmlhttp_rpc)) { | |
354 | printLockingError(); | |
355 | return; | |
356 | } | |
357 | ||
358 | var row = document.getElementById("RROW-" + id); | |
359 | if (row) { | |
360 | var nc = row.className; | |
361 | nc = nc.replace("Unread", ""); | |
362 | nc = nc.replace("Selected", ""); | |
363 | ||
364 | if (row.className.match("Unread")) { | |
365 | row.className = nc; | |
366 | } else { | |
367 | row.className = nc + "Unread"; | |
368 | } | |
369 | ||
370 | if (!cmode) cmode = 2; | |
371 | ||
372 | var query = "backend.php?op=rpc&subop=catchupSelected&ids=" + | |
373 | param_escape(id) + "&cmode=" + param_escape(cmode); | |
374 | ||
9ec58704 AD |
375 | notify_progress("Loading, please wait..."); |
376 | ||
5f51022a AD |
377 | xmlhttp_rpc.open("GET", query, true); |
378 | xmlhttp_rpc.onreadystatechange=all_counters_callback; | |
379 | xmlhttp_rpc.send(null); | |
380 | ||
381 | } | |
382 | ||
383 | ||
384 | } catch (e) { | |
385 | exception_error("toggleUnread", e); | |
386 | } | |
387 | } | |
388 | ||
2228d0e4 | 389 | function selectionToggleUnread(cdm_mode, set_state, callback_func, no_error) { |
1572afe5 AD |
390 | try { |
391 | if (!xmlhttp_ready(xmlhttp_rpc)) { | |
392 | printLockingError(); | |
393 | return; | |
394 | } | |
395 | ||
386cbf27 AD |
396 | var rows; |
397 | ||
398 | if (cdm_mode) { | |
399 | rows = cdmGetSelectedArticles(); | |
400 | } else { | |
401 | rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK"); | |
402 | } | |
1572afe5 | 403 | |
2228d0e4 | 404 | if (rows.length == 0 && !no_error) { |
9cc600d1 AD |
405 | alert(__("No articles are selected.")); |
406 | return; | |
407 | } | |
408 | ||
1572afe5 | 409 | for (i = 0; i < rows.length; i++) { |
f1f2db64 AD |
410 | var row = document.getElementById("RROW-" + rows[i]); |
411 | if (row) { | |
412 | var nc = row.className; | |
413 | nc = nc.replace("Unread", ""); | |
414 | nc = nc.replace("Selected", ""); | |
415 | ||
416 | if (row.className.match("Unread")) { | |
417 | row.className = nc + "Selected"; | |
418 | } else { | |
419 | row.className = nc + "UnreadSelected"; | |
420 | } | |
421 | } | |
1572afe5 AD |
422 | } |
423 | ||
424 | if (rows.length > 0) { | |
425 | ||
b47b5af7 AD |
426 | var cmode = ""; |
427 | ||
428 | if (set_state == undefined) { | |
429 | cmode = "2"; | |
430 | } else if (set_state == true) { | |
431 | cmode = "1"; | |
432 | } else if (set_state == false) { | |
433 | cmode = "0"; | |
434 | } | |
435 | ||
1572afe5 | 436 | var query = "backend.php?op=rpc&subop=catchupSelected&ids=" + |
b47b5af7 | 437 | param_escape(rows.toString()) + "&cmode=" + cmode; |
1572afe5 | 438 | |
e08443c1 AD |
439 | _catchup_callback_func = callback_func; |
440 | ||
9ec58704 AD |
441 | notify_progress("Loading, please wait..."); |
442 | ||
1572afe5 | 443 | xmlhttp_rpc.open("GET", query, true); |
e08443c1 | 444 | xmlhttp_rpc.onreadystatechange=catchup_callback; |
1572afe5 AD |
445 | xmlhttp_rpc.send(null); |
446 | ||
447 | } | |
448 | ||
449 | } catch (e) { | |
83f043bb | 450 | exception_error("selectionToggleUnread", e); |
1572afe5 AD |
451 | } |
452 | } | |
453 | ||
386cbf27 | 454 | function selectionToggleMarked(cdm_mode) { |
1572afe5 AD |
455 | try { |
456 | if (!xmlhttp_ready(xmlhttp_rpc)) { | |
457 | printLockingError(); | |
458 | return; | |
459 | } | |
460 | ||
386cbf27 AD |
461 | var rows; |
462 | ||
463 | if (cdm_mode) { | |
464 | rows = cdmGetSelectedArticles(); | |
465 | } else { | |
466 | rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK"); | |
467 | } | |
1572afe5 | 468 | |
9cc600d1 AD |
469 | if (rows.length == 0) { |
470 | alert(__("No articles are selected.")); | |
471 | return; | |
472 | } | |
473 | ||
1572afe5 AD |
474 | for (i = 0; i < rows.length; i++) { |
475 | var row = document.getElementById("RROW-" + rows[i]); | |
476 | var mark_img = document.getElementById("FMARKPIC-" + rows[i]); | |
477 | ||
478 | if (row && mark_img) { | |
479 | ||
480 | if (mark_img.alt == "Set mark") { | |
481 | mark_img.src = "images/mark_set.png"; | |
482 | mark_img.alt = "Reset mark"; | |
483 | mark_img.setAttribute('onclick', | |
484 | 'javascript:toggleMark('+rows[i]+', false)'); | |
485 | ||
486 | } else { | |
487 | mark_img.src = "images/mark_unset.png"; | |
488 | mark_img.alt = "Set mark"; | |
489 | mark_img.setAttribute('onclick', | |
490 | 'javascript:toggleMark('+rows[i]+', true)'); | |
491 | } | |
492 | } | |
493 | } | |
494 | ||
495 | if (rows.length > 0) { | |
496 | ||
497 | var query = "backend.php?op=rpc&subop=markSelected&ids=" + | |
498 | param_escape(rows.toString()) + "&cmode=2"; | |
499 | ||
500 | xmlhttp_rpc.open("GET", query, true); | |
501 | xmlhttp_rpc.onreadystatechange=all_counters_callback; | |
502 | xmlhttp_rpc.send(null); | |
503 | ||
504 | } | |
505 | ||
506 | } catch (e) { | |
83f043bb | 507 | exception_error("selectionToggleMarked", e); |
1572afe5 AD |
508 | } |
509 | } | |
510 | ||
386cbf27 AD |
511 | function cdmGetSelectedArticles() { |
512 | var sel_articles = new Array(); | |
b2128f01 | 513 | var container = document.getElementById("headlinesInnerContainer"); |
386cbf27 AD |
514 | |
515 | for (i = 0; i < container.childNodes.length; i++) { | |
516 | var child = container.childNodes[i]; | |
517 | ||
518 | if (child.id.match("RROW-") && child.className.match("Selected")) { | |
519 | var c_id = child.id.replace("RROW-", ""); | |
520 | sel_articles.push(c_id); | |
521 | } | |
522 | } | |
523 | ||
524 | return sel_articles; | |
525 | } | |
526 | ||
527 | // mode = all,none,unread | |
528 | function cdmSelectArticles(mode) { | |
b2128f01 | 529 | var container = document.getElementById("headlinesInnerContainer"); |
386cbf27 AD |
530 | |
531 | for (i = 0; i < container.childNodes.length; i++) { | |
532 | var child = container.childNodes[i]; | |
533 | ||
534 | if (child.id.match("RROW-")) { | |
06d1a1c1 AD |
535 | var aid = child.id.replace("RROW-", ""); |
536 | ||
537 | var cb = document.getElementById("RCHK-" + aid); | |
538 | ||
386cbf27 AD |
539 | if (mode == "all") { |
540 | if (!child.className.match("Selected")) { | |
541 | child.className = child.className + "Selected"; | |
06d1a1c1 | 542 | cb.checked = true; |
386cbf27 AD |
543 | } |
544 | } else if (mode == "unread") { | |
545 | if (child.className.match("Unread") && !child.className.match("Selected")) { | |
546 | child.className = child.className + "Selected"; | |
06d1a1c1 | 547 | cb.checked = true; |
386cbf27 AD |
548 | } |
549 | } else { | |
550 | child.className = child.className.replace("Selected", ""); | |
06d1a1c1 | 551 | cb.checked = false; |
386cbf27 AD |
552 | } |
553 | } | |
554 | } | |
555 | } | |
556 | ||
98bea1b1 | 557 | function catchupPage() { |
b47b5af7 AD |
558 | |
559 | if (document.getElementById("headlinesList")) { | |
560 | selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, 'Unread', true); | |
2228d0e4 | 561 | selectionToggleUnread(false, false, 'viewCurrentFeed()', true); |
b47b5af7 AD |
562 | selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false); |
563 | } else { | |
564 | cdmSelectArticles('all'); | |
2228d0e4 | 565 | selectionToggleUnread(true, false, 'viewCurrentFeed()', true) |
b47b5af7 AD |
566 | cdmSelectArticles('none'); |
567 | } | |
98bea1b1 AD |
568 | } |
569 | ||
88040f57 AD |
570 | function labelFromSearch(search, search_mode, match_on, feed_id, is_cat) { |
571 | ||
572 | if (!xmlhttp_ready(xmlhttp_rpc)) { | |
573 | printLockingError(); | |
574 | } | |
575 | ||
576 | var title = prompt("Please enter label title:", ""); | |
577 | ||
578 | if (title) { | |
579 | ||
580 | var query = "backend.php?op=labelFromSearch&search=" + param_escape(search) + | |
581 | "&smode=" + param_escape(search_mode) + "&match=" + param_escape(match_on) + | |
582 | "&feed=" + param_escape(feed_id) + "&is_cat=" + param_escape(is_cat) + | |
583 | "&title=" + param_escape(title); | |
584 | ||
585 | debug("LFS: " + query); | |
586 | ||
587 | xmlhttp_rpc.open("GET", query, true); | |
0feab655 | 588 | xmlhttp_rpc.onreadystatechange=dlg_frefresh_callback; |
88040f57 AD |
589 | xmlhttp_rpc.send(null); |
590 | } | |
591 | ||
592 | } | |
593 | ||
13f08f75 | 594 | function editArticleTags(id, feed_id, cdm_enabled) { |
0b126ac2 AD |
595 | _tag_active_post_id = id; |
596 | _tag_active_feed_id = feed_id; | |
13f08f75 AD |
597 | _tag_active_cdm = cdm_enabled; |
598 | try { | |
599 | _tag_cdm_scroll = document.getElementById("headlinesInnerContainer").scrollTop; | |
600 | } catch (e) { } | |
0b126ac2 AD |
601 | displayDlg('editArticleTags', id); |
602 | } | |
603 | ||
604 | ||
605 | function tag_saved_callback() { | |
606 | if (xmlhttp_rpc.readyState == 4) { | |
607 | try { | |
608 | debug("in tag_saved_callback"); | |
609 | ||
610 | closeInfoBox(); | |
611 | notify(""); | |
612 | ||
613 | if (tagsAreDisplayed()) { | |
614 | _reload_feedlist_after_view = true; | |
615 | } | |
616 | ||
13f08f75 AD |
617 | if (!_tag_active_cdm) { |
618 | if (active_post_id == _tag_active_post_id) { | |
619 | debug("reloading current article"); | |
620 | view(_tag_active_post_id, _tag_active_feed_id); | |
621 | } | |
622 | } else { | |
623 | debug("reloading current feed"); | |
624 | viewCurrentFeed(); | |
625 | } | |
0b126ac2 AD |
626 | |
627 | } catch (e) { | |
628 | exception_error("catchup_callback", e); | |
629 | } | |
630 | } | |
631 | } | |
632 | ||
633 | function editTagsSave() { | |
634 | ||
635 | if (!xmlhttp_ready(xmlhttp_rpc)) { | |
636 | printLockingError(); | |
637 | } | |
638 | ||
42c32916 | 639 | notify_progress("Saving article tags..."); |
88040f57 | 640 | |
0b126ac2 AD |
641 | var form = document.forms["tag_edit_form"]; |
642 | ||
643 | var query = Form.serialize("tag_edit_form"); | |
644 | ||
645 | xmlhttp_rpc.open("GET", "backend.php?op=rpc&subop=setArticleTags&" + query, true); | |
646 | xmlhttp_rpc.onreadystatechange=tag_saved_callback; | |
647 | xmlhttp_rpc.send(null); | |
648 | ||
649 | } | |
d62a3b63 AD |
650 | |
651 | function editTagsInsert() { | |
652 | try { | |
653 | ||
654 | var form = document.forms["tag_edit_form"]; | |
655 | ||
656 | var found_tags = form.found_tags; | |
657 | var tags_str = form.tags_str; | |
658 | ||
659 | var tag = found_tags[found_tags.selectedIndex].value; | |
660 | ||
661 | if (tags_str.value.length > 0 && | |
662 | tags_str.value.lastIndexOf(", ") != tags_str.value.length - 2) { | |
663 | ||
664 | tags_str.value = tags_str.value + ", "; | |
665 | } | |
666 | ||
667 | tags_str.value = tags_str.value + tag + ", "; | |
668 | ||
669 | found_tags.selectedIndex = 0; | |
670 | ||
671 | } catch (e) { | |
672 | exception_error(e, "editTagsInsert"); | |
673 | } | |
674 | } | |
ba0978c8 AD |
675 | |
676 | function cdmWatchdog() { | |
677 | ||
678 | try { | |
679 | ||
680 | var ctr = document.getElementById("headlinesInnerContainer"); | |
681 | ||
9acd22e8 AD |
682 | if (!ctr) return; |
683 | ||
ba0978c8 AD |
684 | var ids = new Array(); |
685 | ||
686 | var e = ctr.firstChild; | |
687 | ||
688 | while (e) { | |
689 | if (e.className && e.className == "cdmArticleUnread" && e.id && | |
690 | e.id.match("RROW-")) { | |
691 | ||
692 | // article fits in viewport OR article is longer than viewport and | |
693 | // its bottom is visible | |
694 | ||
695 | if (ctr.scrollTop <= e.offsetTop && e.offsetTop + e.offsetHeight <= | |
696 | ctr.scrollTop + ctr.offsetHeight) { | |
697 | ||
698 | // debug(e.id + " is visible " + e.offsetTop + "." + | |
699 | // (e.offsetTop + e.offsetHeight) + " vs " + ctr.scrollTop + "." + | |
700 | // (ctr.scrollTop + ctr.offsetHeight)); | |
701 | ||
702 | ids.push(e.id.replace("RROW-", "")); | |
703 | ||
704 | } else if (e.offsetHeight > ctr.offsetHeight && | |
705 | e.offsetTop + e.offsetHeight >= ctr.scrollTop && | |
706 | e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight) { | |
707 | ||
708 | ids.push(e.id.replace("RROW-", "")); | |
709 | ||
710 | } | |
711 | ||
c50e2b30 AD |
712 | // method 2: article bottom is visible and is in upper 1/2 of the viewport |
713 | ||
714 | /* if (e.offsetTop + e.offsetHeight >= ctr.scrollTop && | |
715 | e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight/2) { | |
716 | ||
717 | ids.push(e.id.replace("RROW-", "")); | |
718 | ||
719 | } */ | |
720 | ||
ba0978c8 AD |
721 | } |
722 | ||
723 | e = e.nextSibling; | |
724 | } | |
725 | ||
726 | debug("cdmWatchdog, ids= " + ids.toString()); | |
727 | ||
728 | if (ids.length > 0 && xmlhttp_ready(xmlhttp_rpc)) { | |
729 | ||
730 | for (var i = 0; i < ids.length; i++) { | |
731 | var e = document.getElementById("RROW-" + ids[i]); | |
732 | if (e) { | |
733 | e.className = e.className.replace("Unread", ""); | |
734 | } | |
735 | } | |
736 | ||
737 | var query = "backend.php?op=rpc&subop=catchupSelected&ids=" + | |
738 | param_escape(ids.toString()) + "&cmode=0"; | |
739 | ||
f8e47112 | 740 | xmlhttp_rpc.open("GET", query, true); |
ba0978c8 | 741 | xmlhttp_rpc.onreadystatechange=all_counters_callback; |
c50e2b30 | 742 | xmlhttp_rpc.send(null); |
ba0978c8 AD |
743 | |
744 | } | |
745 | ||
c50e2b30 | 746 | _cdm_wd_timeout = window.setTimeout("cdmWatchdog()", 4000); |
ba0978c8 AD |
747 | |
748 | } catch (e) { | |
749 | exception_error(e, "cdmWatchdog"); | |
750 | } | |
751 | ||
752 | } | |
e097e8be AD |
753 | |
754 | ||
755 | function cache_inject(id, article) { | |
fed4387d | 756 | if (!cache_check(id)) { |
e097e8be AD |
757 | debug("cache_article: miss: " + id); |
758 | ||
759 | var cache_obj = new Array(); | |
760 | ||
761 | var d = new Date(); | |
fed4387d AD |
762 | |
763 | cache_obj["id"] = id; | |
e097e8be AD |
764 | cache_obj["entered"] = d.getTime() / 1000; |
765 | cache_obj["data"] = article; | |
fed4387d AD |
766 | cache_obj["last_access"] = 0; |
767 | ||
768 | //article_cache[id] = cache_obj; | |
e097e8be | 769 | |
fed4387d | 770 | article_cache.push(cache_obj); |
e097e8be AD |
771 | |
772 | } else { | |
773 | debug("cache_article: hit: " + id); | |
774 | } | |
775 | } | |
776 | ||
777 | function cache_find(id) { | |
fed4387d AD |
778 | for (var i = 0; i < article_cache.length; i++) { |
779 | if (article_cache[i]["id"] == id) { | |
780 | var d = new Date(); | |
781 | article_cache[i]["last_access"] = d.getTime() / 1000; | |
782 | return article_cache[i]["data"]; | |
783 | } | |
e097e8be | 784 | } |
fed4387d | 785 | return false; |
e097e8be AD |
786 | } |
787 | ||
788 | function cache_check(id) { | |
fed4387d AD |
789 | for (var i = 0; i < article_cache.length; i++) { |
790 | if (article_cache[i]["id"] == id) { | |
791 | return true; | |
792 | } | |
793 | } | |
794 | return false; | |
e097e8be AD |
795 | } |
796 | ||
797 | function cache_expire() { | |
fed4387d AD |
798 | while (article_cache.length > 30) { |
799 | article_cache.shift(); | |
800 | } | |
e097e8be | 801 | } |