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