]>
Commit | Line | Data |
---|---|---|
1 | var active_post_id = false; | |
2 | var last_article_view = false; | |
3 | var active_real_feed_id = false; | |
4 | ||
5 | // FIXME: kludges, needs proper implementation | |
6 | var _reload_feedlist_after_view = false; | |
7 | ||
8 | var _cdm_wd_timeout = false; | |
9 | var _cdm_wd_vishist = new Array(); | |
10 | ||
11 | var article_cache = new Array(); | |
12 | ||
13 | var vgroup_last_feed = false; | |
14 | var post_under_pointer = false; | |
15 | ||
16 | var last_requested_article = false; | |
17 | ||
18 | function catchup_callback2(transport, callback) { | |
19 | try { | |
20 | console.log("catchup_callback2 " + transport + ", " + callback); | |
21 | notify(""); | |
22 | all_counters_callback2(transport); | |
23 | if (callback) { | |
24 | setTimeout(callback, 10); | |
25 | } | |
26 | } catch (e) { | |
27 | exception_error("catchup_callback2", e, transport); | |
28 | } | |
29 | } | |
30 | ||
31 | function clean_feed_selections() { | |
32 | try { | |
33 | var feeds = $("feedList").getElementsByTagName("LI"); | |
34 | ||
35 | for (var i = 0; i < feeds.length; i++) { | |
36 | if (feeds[i].id && feeds[i].id.match("FEEDR-")) { | |
37 | feeds[i].className = feeds[i].className.replace("Selected", ""); | |
38 | } | |
39 | if (feeds[i].id && feeds[i].id.match("FCAT-")) { | |
40 | feeds[i].className = feeds[i].className.replace("Selected", ""); | |
41 | } | |
42 | } | |
43 | } catch (e) { | |
44 | exception_error("clean_feed_selections", e); | |
45 | } | |
46 | } | |
47 | ||
48 | function headlines_callback2(transport, feed_cur_page) { | |
49 | try { | |
50 | ||
51 | if (!transport.responseText && db) { | |
52 | offlineConfirmModeChange(); | |
53 | return; | |
54 | } | |
55 | ||
56 | loading_set_progress(100); | |
57 | ||
58 | console.log("headlines_callback2 [page=" + feed_cur_page + "]"); | |
59 | ||
60 | if (!transport_error_check(transport)) return; | |
61 | ||
62 | clean_feed_selections(); | |
63 | ||
64 | var is_cat = false; | |
65 | var feed_id = false; | |
66 | ||
67 | if (transport.responseXML) { | |
68 | var headlines = transport.responseXML.getElementsByTagName("headlines")[0]; | |
69 | if (headlines) { | |
70 | is_cat = headlines.getAttribute("is_cat"); | |
71 | feed_id = headlines.getAttribute("id"); | |
72 | setActiveFeedId(feed_id, is_cat); | |
73 | } | |
74 | } | |
75 | ||
76 | var ll = $('FLL-' + feed_id); | |
77 | ||
78 | if (!is_cat) { | |
79 | var feedr = $("FEEDR-" + feed_id); | |
80 | if (feedr && !feedr.className.match("Selected")) { | |
81 | feedr.className = feedr.className + "Selected"; | |
82 | } | |
83 | if (feedr && ll) feedr.removeChild(ll); | |
84 | } else { | |
85 | var feedr = $("FCAT-" + feed_id); | |
86 | if (feedr && !feedr.className.match("Selected")) { | |
87 | feedr.className = feedr.className + "Selected"; | |
88 | } | |
89 | ||
90 | var fcap = $("FCAP-" + feed_id); | |
91 | if (fcap && ll) fcap.removeChild(ll); | |
92 | ||
93 | } | |
94 | ||
95 | var img = $('FIMG-' + feed_id); | |
96 | ||
97 | if (img && !is_cat) { | |
98 | img.src = img.alt; | |
99 | } | |
100 | ||
101 | var f = $("headlines-frame"); | |
102 | try { | |
103 | if (feed_cur_page == 0) { | |
104 | console.log("resetting headlines scrollTop"); | |
105 | f.scrollTop = 0; | |
106 | } | |
107 | } catch (e) { }; | |
108 | ||
109 | if (transport.responseXML) { | |
110 | var response = transport.responseXML; | |
111 | ||
112 | var headlines = response.getElementsByTagName("headlines")[0]; | |
113 | var headlines_info = response.getElementsByTagName("headlines-info")[0]; | |
114 | ||
115 | if (headlines_info) | |
116 | headlines_info = JSON.parse(headlines_info.firstChild.nodeValue); | |
117 | else | |
118 | console.log("didn't find headlines-info object in response"); | |
119 | ||
120 | var headlines_count = headlines_info.count; | |
121 | var headlines_unread = headlines_info.unread; | |
122 | var disable_cache = headlines_info.disable_cache; | |
123 | ||
124 | vgroup_last_feed = headlines_info.vgroup_last_feed; | |
125 | ||
126 | if (headlines_count == 0) { | |
127 | _infscroll_disable = 1; | |
128 | } else { | |
129 | _infscroll_disable = 0; | |
130 | } | |
131 | ||
132 | var counters = response.getElementsByTagName("counters")[0]; | |
133 | var articles = response.getElementsByTagName("article"); | |
134 | var runtime_info = response.getElementsByTagName("runtime-info"); | |
135 | ||
136 | if (feed_cur_page == 0) { | |
137 | if (headlines) { | |
138 | f.innerHTML = headlines.firstChild.nodeValue; | |
139 | ||
140 | var cache_prefix = ""; | |
141 | ||
142 | if (is_cat) { | |
143 | cache_prefix = "C:"; | |
144 | } else { | |
145 | cache_prefix = "F:"; | |
146 | } | |
147 | ||
148 | cache_invalidate(cache_prefix + feed_id); | |
149 | ||
150 | if (!disable_cache) { | |
151 | cache_inject(cache_prefix + feed_id, | |
152 | headlines.firstChild.nodeValue, headlines_unread); | |
153 | } | |
154 | ||
155 | } else { | |
156 | console.log("headlines_callback: returned no data"); | |
157 | f.innerHTML = "<div class='whiteBox'>" + __('Could not update headlines (missing XML data)') + "</div>"; | |
158 | ||
159 | } | |
160 | } else { | |
161 | if (headlines) { | |
162 | if (headlines_count > 0) { | |
163 | console.log("adding some more headlines..."); | |
164 | ||
165 | var c = $("headlinesList"); | |
166 | ||
167 | if (!c) { | |
168 | c = $("headlinesInnerContainer"); | |
169 | } | |
170 | ||
171 | var ids = getSelectedArticleIds2(); | |
172 | ||
173 | c.innerHTML = c.innerHTML + headlines.firstChild.nodeValue; | |
174 | ||
175 | console.log("restore selected ids: " + ids); | |
176 | ||
177 | for (var i = 0; i < ids.length; i++) { | |
178 | markHeadline(ids[i]); | |
179 | } | |
180 | ||
181 | } else { | |
182 | console.log("no new headlines received"); | |
183 | } | |
184 | } else { | |
185 | console.log("headlines_callback: returned no data"); | |
186 | notify_error("Error while trying to load more headlines"); | |
187 | } | |
188 | ||
189 | } | |
190 | ||
191 | if (articles) { | |
192 | for (var i = 0; i < articles.length; i++) { | |
193 | var a_id = articles[i].getAttribute("id"); | |
194 | console.log("found id: " + a_id); | |
195 | cache_inject(a_id, articles[i].firstChild.nodeValue); | |
196 | } | |
197 | } else { | |
198 | console.log("no cached articles received"); | |
199 | } | |
200 | ||
201 | if (counters) { | |
202 | console.log("parsing piggybacked counters: " + counters); | |
203 | parse_counters(counters, false); | |
204 | } else { | |
205 | console.log("counters container not found in reply, requesting..."); | |
206 | request_counters(); | |
207 | } | |
208 | ||
209 | if (runtime_info) { | |
210 | console.log("parsing runtime info: " + runtime_info[0]); | |
211 | parse_runtime_info(runtime_info[0]); | |
212 | } else { | |
213 | console.log("counters container not found in reply"); | |
214 | } | |
215 | ||
216 | } else { | |
217 | console.log("headlines_callback: returned no XML object"); | |
218 | f.innerHTML = "<div class='whiteBox'>" + __('Could not update headlines (missing XML object)') + "</div>"; | |
219 | } | |
220 | ||
221 | if (typeof correctPNG != 'undefined') { | |
222 | correctPNG(); | |
223 | } | |
224 | ||
225 | if (_cdm_wd_timeout) window.clearTimeout(_cdm_wd_timeout); | |
226 | ||
227 | if (!$("headlinesList") && | |
228 | getActiveFeedId() != -3 && | |
229 | getInitParam("cdm_auto_catchup") == 1) { | |
230 | console.log("starting CDM watchdog"); | |
231 | _cdm_wd_timeout = window.setTimeout("cdmWatchdog()", 5000); | |
232 | _cdm_wd_vishist = new Array(); | |
233 | } else { | |
234 | console.log("not in CDM mode or watchdog disabled"); | |
235 | } | |
236 | ||
237 | _feed_cur_page = feed_cur_page; | |
238 | _infscroll_request_sent = 0; | |
239 | ||
240 | notify(""); | |
241 | ||
242 | remove_splash(); | |
243 | ||
244 | } catch (e) { | |
245 | exception_error("headlines_callback2", e, transport); | |
246 | } | |
247 | } | |
248 | ||
249 | function render_article(article) { | |
250 | try { | |
251 | var f = $("content-frame"); | |
252 | try { | |
253 | f.scrollTop = 0; | |
254 | } catch (e) { }; | |
255 | ||
256 | var fi = $("content-insert"); | |
257 | ||
258 | try { | |
259 | fi.scrollTop = 0; | |
260 | } catch (e) { }; | |
261 | ||
262 | fi.innerHTML = article; | |
263 | ||
264 | // article.evalScripts(); | |
265 | ||
266 | } catch (e) { | |
267 | exception_error("render_article", e); | |
268 | } | |
269 | } | |
270 | ||
271 | function showArticleInHeadlines(id) { | |
272 | ||
273 | try { | |
274 | ||
275 | cleanSelected("headlinesList"); | |
276 | ||
277 | var crow = $("RROW-" + id); | |
278 | ||
279 | if (!crow) return; | |
280 | ||
281 | var article_is_unread = crow.className.match("Unread"); | |
282 | ||
283 | crow.className = crow.className.replace("Unread", ""); | |
284 | ||
285 | selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false); | |
286 | ||
287 | var upd_img_pic = $("FUPDPIC-" + id); | |
288 | ||
289 | var cache_prefix = ""; | |
290 | ||
291 | if (activeFeedIsCat()) { | |
292 | cache_prefix = "C:"; | |
293 | } else { | |
294 | cache_prefix = "F:"; | |
295 | } | |
296 | ||
297 | var view_mode = false; | |
298 | ||
299 | try { | |
300 | view_mode = document.forms['main_toolbar_form'].view_mode; | |
301 | view_mode = view_mode[view_mode.selectedIndex].value; | |
302 | } catch (e) { | |
303 | // | |
304 | } | |
305 | ||
306 | if (upd_img_pic && (upd_img_pic.src.match("updated.png") || | |
307 | upd_img_pic.src.match("fresh_sign.png"))) { | |
308 | ||
309 | upd_img_pic.src = "images/blank_icon.gif"; | |
310 | ||
311 | cache_invalidate(cache_prefix + getActiveFeedId()); | |
312 | ||
313 | cache_inject(cache_prefix + getActiveFeedId(), | |
314 | $("headlines-frame").innerHTML, | |
315 | get_feed_unread(getActiveFeedId())); | |
316 | ||
317 | } else if (article_is_unread && view_mode == "all_articles") { | |
318 | ||
319 | cache_invalidate(cache_prefix + getActiveFeedId()); | |
320 | ||
321 | cache_inject(cache_prefix + getActiveFeedId(), | |
322 | $("headlines-frame").innerHTML, | |
323 | get_feed_unread(getActiveFeedId())-1); | |
324 | ||
325 | } else if (article_is_unread) { | |
326 | cache_invalidate(cache_prefix + getActiveFeedId()); | |
327 | } | |
328 | ||
329 | markHeadline(id); | |
330 | ||
331 | } catch (e) { | |
332 | exception_error("showArticleInHeadlines", e); | |
333 | } | |
334 | } | |
335 | ||
336 | function article_callback2(transport, id) { | |
337 | try { | |
338 | console.log("article_callback2 " + id); | |
339 | ||
340 | if (!transport.responseText && db) { | |
341 | offlineConfirmModeChange(); | |
342 | return; | |
343 | } | |
344 | ||
345 | if (transport.responseXML) { | |
346 | ||
347 | if (!transport_error_check(transport)) return; | |
348 | ||
349 | /* var ll = $('LL-' + id); | |
350 | var content = $('HLC-' + id); | |
351 | ||
352 | if (ll && content) content.removeChild(ll); */ | |
353 | ||
354 | var upic = $('FUPDPIC-' + id); | |
355 | ||
356 | if (upic) { | |
357 | upic.src = 'images/blank_icon.gif'; | |
358 | } | |
359 | ||
360 | if (id != last_requested_article) { | |
361 | console.log("requested article id is out of sequence, aborting"); | |
362 | return; | |
363 | } | |
364 | ||
365 | active_post_id = id; | |
366 | ||
367 | console.log("looking for articles to cache..."); | |
368 | ||
369 | var articles = transport.responseXML.getElementsByTagName("article"); | |
370 | ||
371 | for (var i = 0; i < articles.length; i++) { | |
372 | var a_id = articles[i].getAttribute("id"); | |
373 | ||
374 | console.log("found id: " + a_id); | |
375 | ||
376 | if (a_id == active_post_id) { | |
377 | console.log("active article, rendering..."); | |
378 | render_article(articles[i].firstChild.nodeValue); | |
379 | } | |
380 | ||
381 | cache_inject(a_id, articles[i].firstChild.nodeValue); | |
382 | } | |
383 | ||
384 | ||
385 | showArticleInHeadlines(id); | |
386 | ||
387 | if (db) { | |
388 | db.execute("UPDATE articles SET unread = 0 WHERE id = ?", [id]); | |
389 | } | |
390 | ||
391 | var reply = transport.responseXML.firstChild.firstChild; | |
392 | ||
393 | } else { | |
394 | console.log("article_callback: returned no XML object"); | |
395 | //var f = $("content-frame"); | |
396 | //f.innerHTML = "<div class='whiteBox'>" + __('Could not display article (missing XML object)') + "</div>"; | |
397 | } | |
398 | ||
399 | var date = new Date(); | |
400 | last_article_view = date.getTime() / 1000; | |
401 | ||
402 | if (typeof correctPNG != 'undefined') { | |
403 | correctPNG(); | |
404 | } | |
405 | ||
406 | if (_reload_feedlist_after_view) { | |
407 | setTimeout('updateFeedList(false, false)', 50); | |
408 | _reload_feedlist_after_view = false; | |
409 | } else { | |
410 | if (transport.responseXML) { | |
411 | var counters = transport.responseXML.getElementsByTagName("counters")[0]; | |
412 | ||
413 | if (counters) { | |
414 | console.log("parsing piggybacked counters: " + counters); | |
415 | parse_counters(counters, false); | |
416 | } else { | |
417 | console.log("counters container not found in reply, requesting..."); | |
418 | request_counters(); | |
419 | } | |
420 | } | |
421 | } | |
422 | ||
423 | notify(""); | |
424 | } catch (e) { | |
425 | exception_error("article_callback2", e, transport); | |
426 | } | |
427 | } | |
428 | ||
429 | function view(id) { | |
430 | try { | |
431 | console.log("loading article: " + id); | |
432 | ||
433 | if (offline_mode) return view_offline(id); | |
434 | ||
435 | var cached_article = cache_find(id); | |
436 | ||
437 | console.log("cache check result: " + (cached_article != false)); | |
438 | ||
439 | enableHotkeys(); | |
440 | hideAuxDlg(); | |
441 | ||
442 | var query = "?op=view&id=" + param_escape(id); | |
443 | ||
444 | var neighbor_ids = getRelativePostIds(active_post_id); | |
445 | ||
446 | /* only request uncached articles */ | |
447 | ||
448 | var cids_to_request = Array(); | |
449 | ||
450 | for (var i = 0; i < neighbor_ids.length; i++) { | |
451 | if (!cache_check(neighbor_ids[i])) { | |
452 | cids_to_request.push(neighbor_ids[i]); | |
453 | } | |
454 | } | |
455 | ||
456 | console.log("additional ids: " + cids_to_request.toString()); | |
457 | ||
458 | /* additional info for piggyback counters */ | |
459 | ||
460 | if (tagsAreDisplayed()) { | |
461 | query = query + "&omode=lt"; | |
462 | } else { | |
463 | query = query + "&omode=flc"; | |
464 | } | |
465 | ||
466 | query = query + "&cids=" + cids_to_request.toString(); | |
467 | ||
468 | var crow = $("RROW-" + id); | |
469 | var article_is_unread = crow.className.match("Unread"); | |
470 | ||
471 | if (!async_counters_work) { | |
472 | query = query + "&csync=true"; | |
473 | } | |
474 | ||
475 | showArticleInHeadlines(id); | |
476 | ||
477 | if (!cached_article) { | |
478 | ||
479 | var upic = $('FUPDPIC-' + id); | |
480 | ||
481 | if (upic) { | |
482 | upic.src = getInitParam("sign_progress"); | |
483 | } | |
484 | ||
485 | } else if (cached_article && article_is_unread) { | |
486 | ||
487 | query = query + "&mode=prefetch"; | |
488 | ||
489 | render_article(cached_article); | |
490 | ||
491 | } else if (cached_article) { | |
492 | ||
493 | query = query + "&mode=prefetch_old"; | |
494 | render_article(cached_article); | |
495 | ||
496 | } | |
497 | ||
498 | cache_expire(); | |
499 | ||
500 | last_requested_article = id; | |
501 | ||
502 | new Ajax.Request("backend.php", { | |
503 | parameters: query, | |
504 | onComplete: function(transport) { | |
505 | article_callback2(transport, id); | |
506 | } }); | |
507 | ||
508 | return false; | |
509 | ||
510 | } catch (e) { | |
511 | exception_error("view", e); | |
512 | } | |
513 | } | |
514 | ||
515 | function tMark(id) { | |
516 | return toggleMark(id); | |
517 | } | |
518 | ||
519 | function tPub(id) { | |
520 | return togglePub(id); | |
521 | } | |
522 | ||
523 | function tMark_afh_off(effect) { | |
524 | try { | |
525 | var elem = effect.effects[0].element; | |
526 | ||
527 | console.log("tMark_afh_off : " + elem.id); | |
528 | ||
529 | if (elem) { | |
530 | elem.src = elem.src.replace("mark_set", "mark_unset"); | |
531 | elem.alt = __("Star article"); | |
532 | Element.show(elem); | |
533 | } | |
534 | ||
535 | } catch (e) { | |
536 | exception_error("tMark_afh_off", e); | |
537 | } | |
538 | } | |
539 | ||
540 | function tPub_afh_off(effect) { | |
541 | try { | |
542 | var elem = effect.effects[0].element; | |
543 | ||
544 | console.log("tPub_afh_off : " + elem.id); | |
545 | ||
546 | if (elem) { | |
547 | elem.src = elem.src.replace("pub_set", "pub_unset"); | |
548 | elem.alt = __("Publish article"); | |
549 | Element.show(elem); | |
550 | } | |
551 | ||
552 | } catch (e) { | |
553 | exception_error("tPub_afh_off", e); | |
554 | } | |
555 | } | |
556 | ||
557 | function toggleMark(id, client_only, no_effects) { | |
558 | ||
559 | try { | |
560 | ||
561 | var query = "?op=rpc&id=" + id + "&subop=mark"; | |
562 | ||
563 | query = query + "&afid=" + getActiveFeedId(); | |
564 | ||
565 | if (tagsAreDisplayed()) { | |
566 | query = query + "&omode=tl"; | |
567 | } else { | |
568 | query = query + "&omode=flc"; | |
569 | } | |
570 | ||
571 | var mark_img = $("FMPIC-" + id); | |
572 | ||
573 | if (!mark_img) return; | |
574 | ||
575 | var vfeedu = $("FEEDU--1"); | |
576 | var crow = $("RROW-" + id); | |
577 | ||
578 | if (mark_img.src.match("mark_unset")) { | |
579 | mark_img.src = mark_img.src.replace("mark_unset", "mark_set"); | |
580 | mark_img.alt = __("Unstar article"); | |
581 | query = query + "&mark=1"; | |
582 | ||
583 | if (db) { | |
584 | db.execute("UPDATE articles SET marked = 1 WHERE id = ?", [id]); | |
585 | } | |
586 | ||
587 | } else { | |
588 | mark_img.alt = __("Please wait..."); | |
589 | query = query + "&mark=0"; | |
590 | ||
591 | if ($("headlinesList") && !no_effects) { | |
592 | Effect.Puff(mark_img, {duration : 0.25, afterFinish: tMark_afh_off}); | |
593 | } else { | |
594 | mark_img.src = mark_img.src.replace("mark_set", "mark_unset"); | |
595 | mark_img.alt = __("Star article"); | |
596 | } | |
597 | ||
598 | if (db) { | |
599 | db.execute("UPDATE articles SET marked = 0 WHERE id = ?", [id]); | |
600 | } | |
601 | ||
602 | } | |
603 | ||
604 | if (!no_effects) update_local_feedlist_counters(); | |
605 | ||
606 | if (!client_only) { | |
607 | console.log(query); | |
608 | ||
609 | new Ajax.Request("backend.php", { | |
610 | parameters: query, | |
611 | onComplete: function(transport) { | |
612 | all_counters_callback2(transport); | |
613 | } }); | |
614 | ||
615 | } | |
616 | ||
617 | } catch (e) { | |
618 | exception_error("toggleMark", e); | |
619 | } | |
620 | } | |
621 | ||
622 | function togglePub(id, client_only, no_effects, note) { | |
623 | ||
624 | try { | |
625 | ||
626 | var query = "?op=rpc&id=" + id + "&subop=publ"; | |
627 | ||
628 | query = query + "&afid=" + getActiveFeedId(); | |
629 | ||
630 | if (note != undefined) { | |
631 | query = query + "¬e=" + param_escape(note); | |
632 | } else { | |
633 | query = query + "¬e=undefined"; | |
634 | } | |
635 | ||
636 | if (tagsAreDisplayed()) { | |
637 | query = query + "&omode=tl"; | |
638 | } else { | |
639 | query = query + "&omode=flc"; | |
640 | } | |
641 | ||
642 | var mark_img = $("FPPIC-" + id); | |
643 | ||
644 | if (!mark_img) return; | |
645 | ||
646 | var vfeedu = $("FEEDU--2"); | |
647 | var crow = $("RROW-" + id); | |
648 | ||
649 | if (mark_img.src.match("pub_unset") || note != undefined) { | |
650 | mark_img.src = mark_img.src.replace("pub_unset", "pub_set"); | |
651 | mark_img.alt = __("Unpublish article"); | |
652 | query = query + "&pub=1"; | |
653 | ||
654 | } else { | |
655 | mark_img.alt = __("Please wait..."); | |
656 | query = query + "&pub=0"; | |
657 | ||
658 | if ($("headlinesList") && !no_effects) { | |
659 | Effect.Puff(mark_img, {duration : 0.25, afterFinish: tPub_afh_off}); | |
660 | } else { | |
661 | mark_img.src = mark_img.src.replace("pub_set", "pub_unset"); | |
662 | mark_img.alt = __("Publish article"); | |
663 | } | |
664 | } | |
665 | ||
666 | if (!client_only) { | |
667 | new Ajax.Request("backend.php", { | |
668 | parameters: query, | |
669 | onComplete: function(transport) { | |
670 | all_counters_callback2(transport); | |
671 | ||
672 | var note = transport.responseXML.getElementsByTagName("note")[0]; | |
673 | ||
674 | if (note) { | |
675 | var note_id = note.getAttribute("id"); | |
676 | var note_size = note.getAttribute("size"); | |
677 | var note_content = note.firstChild.nodeValue; | |
678 | ||
679 | var container = $('POSTNOTE-' + note_id); | |
680 | ||
681 | cache_invalidate(note_id); | |
682 | ||
683 | if (container) { | |
684 | if (note_size == "0") { | |
685 | Element.hide(container); | |
686 | } else { | |
687 | container.innerHTML = note_content; | |
688 | Element.show(container); | |
689 | } | |
690 | } | |
691 | } | |
692 | ||
693 | } }); | |
694 | } | |
695 | ||
696 | } catch (e) { | |
697 | exception_error("togglePub", e); | |
698 | } | |
699 | } | |
700 | ||
701 | function correctHeadlinesOffset(id) { | |
702 | ||
703 | try { | |
704 | ||
705 | var hlist = $("headlinesList"); | |
706 | var container = $("headlinesInnerContainer"); | |
707 | var row = $("RROW-" + id); | |
708 | ||
709 | var viewport = container.offsetHeight; | |
710 | ||
711 | var rel_offset_top = row.offsetTop - container.scrollTop; | |
712 | var rel_offset_bottom = row.offsetTop + row.offsetHeight - container.scrollTop; | |
713 | ||
714 | console.log("Rtop: " + rel_offset_top + " Rbtm: " + rel_offset_bottom); | |
715 | console.log("Vport: " + viewport); | |
716 | ||
717 | if (rel_offset_top <= 0 || rel_offset_top > viewport) { | |
718 | container.scrollTop = row.offsetTop; | |
719 | } else if (rel_offset_bottom > viewport) { | |
720 | ||
721 | /* doesn't properly work with Opera in some cases because | |
722 | Opera fucks up element scrolling */ | |
723 | ||
724 | container.scrollTop = row.offsetTop + row.offsetHeight - viewport; | |
725 | } | |
726 | ||
727 | } catch (e) { | |
728 | exception_error("correctHeadlinesOffset", e); | |
729 | } | |
730 | ||
731 | } | |
732 | ||
733 | function moveToPost(mode) { | |
734 | ||
735 | try { | |
736 | ||
737 | var rows; | |
738 | ||
739 | if (isCdmMode()) { | |
740 | rows = cdmGetVisibleArticles(); | |
741 | } else { | |
742 | rows = getVisibleHeadlineIds(); | |
743 | } | |
744 | ||
745 | var prev_id = false; | |
746 | var next_id = false; | |
747 | ||
748 | if (!$('RROW-' + active_post_id)) { | |
749 | active_post_id = false; | |
750 | } | |
751 | ||
752 | if (active_post_id == false) { | |
753 | next_id = getFirstVisibleHeadlineId(); | |
754 | prev_id = getLastVisibleHeadlineId(); | |
755 | } else { | |
756 | for (var i = 0; i < rows.length; i++) { | |
757 | if (rows[i] == active_post_id) { | |
758 | prev_id = rows[i-1]; | |
759 | next_id = rows[i+1]; | |
760 | } | |
761 | } | |
762 | } | |
763 | ||
764 | if (mode == "next") { | |
765 | if (next_id) { | |
766 | if (isCdmMode()) { | |
767 | ||
768 | cdmExpandArticle(next_id); | |
769 | cdmScrollToArticleId(next_id); | |
770 | ||
771 | } else { | |
772 | correctHeadlinesOffset(next_id); | |
773 | view(next_id, getActiveFeedId()); | |
774 | } | |
775 | } | |
776 | } | |
777 | ||
778 | if (mode == "prev") { | |
779 | if (prev_id) { | |
780 | if (isCdmMode()) { | |
781 | cdmExpandArticle(prev_id); | |
782 | cdmScrollToArticleId(prev_id); | |
783 | } else { | |
784 | correctHeadlinesOffset(prev_id); | |
785 | view(prev_id, getActiveFeedId()); | |
786 | } | |
787 | } | |
788 | } | |
789 | ||
790 | } catch (e) { | |
791 | exception_error("moveToPost", e); | |
792 | } | |
793 | } | |
794 | ||
795 | function toggleSelected(id) { | |
796 | try { | |
797 | ||
798 | var cb = $("RCHK-" + id); | |
799 | ||
800 | var row = $("RROW-" + id); | |
801 | if (row) { | |
802 | var nc = row.className; | |
803 | ||
804 | if (!nc.match("Selected")) { | |
805 | nc = nc + "Selected"; | |
806 | if (cb) { | |
807 | cb.checked = true; | |
808 | } | |
809 | ||
810 | // In CDM basically last selected article == active article | |
811 | if (isCdmMode()) active_post_id = id; | |
812 | } else { | |
813 | nc = nc.replace("Selected", ""); | |
814 | if (cb) { | |
815 | cb.checked = false; | |
816 | } | |
817 | ||
818 | } | |
819 | ||
820 | row.className = nc; | |
821 | } | |
822 | } catch (e) { | |
823 | exception_error("toggleSelected", e); | |
824 | } | |
825 | } | |
826 | ||
827 | function toggleUnread_afh(effect) { | |
828 | try { | |
829 | ||
830 | var elem = effect.element; | |
831 | elem.style.backgroundColor = ""; | |
832 | ||
833 | } catch (e) { | |
834 | exception_error("toggleUnread_afh", e); | |
835 | } | |
836 | } | |
837 | ||
838 | function toggleUnread(id, cmode, effect) { | |
839 | try { | |
840 | ||
841 | var row = $("RROW-" + id); | |
842 | if (row) { | |
843 | var nc = row.className; | |
844 | var is_selected = row.className.match("Selected"); | |
845 | nc = nc.replace("Unread", ""); | |
846 | nc = nc.replace("Selected", ""); | |
847 | ||
848 | // since we are removing selection from the object, uncheck | |
849 | // corresponding checkbox | |
850 | ||
851 | var cb = $("RCHK-" + id); | |
852 | if (cb) { | |
853 | cb.checked = false; | |
854 | } | |
855 | ||
856 | // NOTE: I'm not sure that resetting selection here is a feature -fox | |
857 | ||
858 | if (cmode == undefined || cmode == 2) { | |
859 | if (row.className.match("Unread")) { | |
860 | row.className = nc; | |
861 | ||
862 | if (effect) { | |
863 | new Effect.Highlight(row, {duration: 1, startcolor: "#fff7d5", | |
864 | afterFinish: toggleUnread_afh, | |
865 | queue: { position:'end', scope: 'TMRQ-' + id, limit: 1 } } ); | |
866 | } | |
867 | ||
868 | } else { | |
869 | row.className = nc + "Unread"; | |
870 | } | |
871 | ||
872 | if (db) { | |
873 | db.execute("UPDATE articles SET unread = not unread "+ | |
874 | "WHERE id = ?", [id]); | |
875 | } | |
876 | ||
877 | } else if (cmode == 0) { | |
878 | row.className = nc; | |
879 | ||
880 | if (effect) { | |
881 | new Effect.Highlight(row, {duration: 1, startcolor: "#fff7d5", | |
882 | afterFinish: toggleUnread_afh, | |
883 | queue: { position:'end', scope: 'TMRQ-' + id, limit: 1 } } ); | |
884 | } | |
885 | ||
886 | if (db) { | |
887 | db.execute("UPDATE articles SET unread = 0 "+ | |
888 | "WHERE id = ?", [id]); | |
889 | } | |
890 | ||
891 | } else if (cmode == 1) { | |
892 | row.className = nc + "Unread"; | |
893 | ||
894 | if (db) { | |
895 | db.execute("UPDATE articles SET unread = 1 "+ | |
896 | "WHERE id = ?", [id]); | |
897 | } | |
898 | ||
899 | } | |
900 | ||
901 | update_local_feedlist_counters(); | |
902 | ||
903 | // Disable unmarking as selected for the time being (16.05.08) -fox | |
904 | if (is_selected) row.className = row.className + "Selected"; | |
905 | ||
906 | if (cmode == undefined) cmode = 2; | |
907 | ||
908 | var query = "?op=rpc&subop=catchupSelected" + | |
909 | "&cmode=" + param_escape(cmode) + "&ids=" + param_escape(id); | |
910 | ||
911 | // notify_progress("Loading, please wait..."); | |
912 | ||
913 | new Ajax.Request("backend.php", { | |
914 | parameters: query, | |
915 | onComplete: function(transport) { | |
916 | all_counters_callback2(transport); | |
917 | } }); | |
918 | ||
919 | } | |
920 | ||
921 | } catch (e) { | |
922 | exception_error("toggleUnread", e); | |
923 | } | |
924 | } | |
925 | ||
926 | function selectionRemoveLabel(id) { | |
927 | try { | |
928 | ||
929 | var ids = getSelectedArticleIds2(); | |
930 | ||
931 | if (ids.length == 0) { | |
932 | alert(__("No articles are selected.")); | |
933 | return; | |
934 | } | |
935 | ||
936 | // var ok = confirm(__("Remove selected articles from label?")); | |
937 | ||
938 | // if (ok) { | |
939 | ||
940 | var query = "?op=rpc&subop=removeFromLabel&ids=" + | |
941 | param_escape(ids.toString()) + "&lid=" + param_escape(id); | |
942 | ||
943 | // notify_progress("Loading, please wait..."); | |
944 | ||
945 | cache_invalidate("F:" + (-11 - id)); | |
946 | ||
947 | new Ajax.Request("backend.php", { | |
948 | parameters: query, | |
949 | onComplete: function(transport) { | |
950 | show_labels_in_headlines(transport); | |
951 | all_counters_callback2(transport); | |
952 | } }); | |
953 | ||
954 | // } | |
955 | ||
956 | } catch (e) { | |
957 | exception_error("selectionAssignLabel", e); | |
958 | ||
959 | } | |
960 | } | |
961 | ||
962 | function selectionAssignLabel(id) { | |
963 | try { | |
964 | ||
965 | var ids = getSelectedArticleIds2(); | |
966 | ||
967 | if (ids.length == 0) { | |
968 | alert(__("No articles are selected.")); | |
969 | return; | |
970 | } | |
971 | ||
972 | // var ok = confirm(__("Assign selected articles to label?")); | |
973 | ||
974 | // if (ok) { | |
975 | ||
976 | cache_invalidate("F:" + (-11 - id)); | |
977 | ||
978 | var query = "?op=rpc&subop=assignToLabel&ids=" + | |
979 | param_escape(ids.toString()) + "&lid=" + param_escape(id); | |
980 | ||
981 | // notify_progress("Loading, please wait..."); | |
982 | ||
983 | new Ajax.Request("backend.php", { | |
984 | parameters: query, | |
985 | onComplete: function(transport) { | |
986 | show_labels_in_headlines(transport); | |
987 | all_counters_callback2(transport); | |
988 | } }); | |
989 | ||
990 | // } | |
991 | ||
992 | } catch (e) { | |
993 | exception_error("selectionAssignLabel", e); | |
994 | ||
995 | } | |
996 | } | |
997 | ||
998 | function selectionToggleUnread(set_state, callback_func, no_error) { | |
999 | try { | |
1000 | var rows = getSelectedArticleIds2(); | |
1001 | ||
1002 | if (rows.length == 0 && !no_error) { | |
1003 | alert(__("No articles are selected.")); | |
1004 | return; | |
1005 | } | |
1006 | ||
1007 | for (i = 0; i < rows.length; i++) { | |
1008 | var row = $("RROW-" + rows[i]); | |
1009 | if (row) { | |
1010 | var nc = row.className; | |
1011 | nc = nc.replace("Unread", ""); | |
1012 | nc = nc.replace("Selected", ""); | |
1013 | ||
1014 | if (set_state == undefined) { | |
1015 | if (row.className.match("Unread")) { | |
1016 | row.className = nc + "Selected"; | |
1017 | } else { | |
1018 | row.className = nc + "UnreadSelected"; | |
1019 | } | |
1020 | if (db) { | |
1021 | db.execute("UPDATE articles SET unread = NOT unread WHERE id = ?", | |
1022 | [rows[i]]); | |
1023 | } | |
1024 | } | |
1025 | ||
1026 | if (set_state == false) { | |
1027 | row.className = nc + "Selected"; | |
1028 | if (db) { | |
1029 | db.execute("UPDATE articles SET unread = 0 WHERE id = ?", | |
1030 | [rows[i]]); | |
1031 | } | |
1032 | } | |
1033 | ||
1034 | if (set_state == true) { | |
1035 | row.className = nc + "UnreadSelected"; | |
1036 | if (db) { | |
1037 | db.execute("UPDATE articles SET unread = 1 WHERE id = ?", | |
1038 | [rows[i]]); | |
1039 | } | |
1040 | } | |
1041 | } | |
1042 | } | |
1043 | ||
1044 | if (rows.length > 0) { | |
1045 | ||
1046 | update_local_feedlist_counters(); | |
1047 | ||
1048 | var cmode = ""; | |
1049 | ||
1050 | if (set_state == undefined) { | |
1051 | cmode = "2"; | |
1052 | } else if (set_state == true) { | |
1053 | cmode = "1"; | |
1054 | } else if (set_state == false) { | |
1055 | cmode = "0"; | |
1056 | } | |
1057 | ||
1058 | var query = "?op=rpc&subop=catchupSelected" + | |
1059 | "&cmode=" + cmode + "&ids=" + param_escape(rows.toString()); | |
1060 | ||
1061 | notify_progress("Loading, please wait..."); | |
1062 | ||
1063 | new Ajax.Request("backend.php", { | |
1064 | parameters: query, | |
1065 | onComplete: function(transport) { | |
1066 | catchup_callback2(transport, callback_func); | |
1067 | } }); | |
1068 | ||
1069 | } | |
1070 | ||
1071 | } catch (e) { | |
1072 | exception_error("selectionToggleUnread", e); | |
1073 | } | |
1074 | } | |
1075 | ||
1076 | function selectionToggleMarked() { | |
1077 | try { | |
1078 | ||
1079 | var rows = getSelectedArticleIds2(); | |
1080 | ||
1081 | if (rows.length == 0) { | |
1082 | alert(__("No articles are selected.")); | |
1083 | return; | |
1084 | } | |
1085 | ||
1086 | for (i = 0; i < rows.length; i++) { | |
1087 | toggleMark(rows[i], true, true); | |
1088 | } | |
1089 | ||
1090 | update_local_feedlist_counters(); | |
1091 | ||
1092 | if (rows.length > 0) { | |
1093 | ||
1094 | var query = "?op=rpc&subop=markSelected&ids=" + | |
1095 | param_escape(rows.toString()) + "&cmode=2"; | |
1096 | ||
1097 | query = query + "&afid=" + getActiveFeedId(); | |
1098 | ||
1099 | query = query + "&omode=lc"; | |
1100 | ||
1101 | new Ajax.Request("backend.php", { | |
1102 | parameters: query, | |
1103 | onComplete: function(transport) { | |
1104 | all_counters_callback2(transport); | |
1105 | } }); | |
1106 | ||
1107 | } | |
1108 | ||
1109 | } catch (e) { | |
1110 | exception_error("selectionToggleMarked", e); | |
1111 | } | |
1112 | } | |
1113 | ||
1114 | function selectionTogglePublished() { | |
1115 | try { | |
1116 | ||
1117 | var rows = getSelectedArticleIds2(); | |
1118 | ||
1119 | if (rows.length == 0) { | |
1120 | alert(__("No articles are selected.")); | |
1121 | return; | |
1122 | } | |
1123 | ||
1124 | for (i = 0; i < rows.length; i++) { | |
1125 | togglePub(rows[i], true, true); | |
1126 | } | |
1127 | ||
1128 | if (rows.length > 0) { | |
1129 | ||
1130 | var query = "?op=rpc&subop=publishSelected&ids=" + | |
1131 | param_escape(rows.toString()) + "&cmode=2"; | |
1132 | ||
1133 | query = query + "&afid=" + getActiveFeedId(); | |
1134 | ||
1135 | query = query + "&omode=lc"; | |
1136 | ||
1137 | new Ajax.Request("backend.php", { | |
1138 | parameters: query, | |
1139 | onComplete: function(transport) { | |
1140 | all_counters_callback2(transport); | |
1141 | } }); | |
1142 | ||
1143 | } | |
1144 | ||
1145 | } catch (e) { | |
1146 | exception_error("selectionToggleMarked", e); | |
1147 | } | |
1148 | } | |
1149 | ||
1150 | function cdmGetSelectedArticles() { | |
1151 | var sel_articles = new Array(); | |
1152 | var container = $("headlinesInnerContainer"); | |
1153 | ||
1154 | for (i = 0; i < container.childNodes.length; i++) { | |
1155 | var child = container.childNodes[i]; | |
1156 | ||
1157 | if (child.id && child.id.match("RROW-") && child.className.match("Selected")) { | |
1158 | var c_id = child.id.replace("RROW-", ""); | |
1159 | sel_articles.push(c_id); | |
1160 | } | |
1161 | } | |
1162 | ||
1163 | return sel_articles; | |
1164 | } | |
1165 | ||
1166 | function cdmGetVisibleArticles() { | |
1167 | var sel_articles = new Array(); | |
1168 | var container = $("headlinesInnerContainer"); | |
1169 | ||
1170 | if (!container) return sel_articles; | |
1171 | ||
1172 | for (i = 0; i < container.childNodes.length; i++) { | |
1173 | var child = container.childNodes[i]; | |
1174 | ||
1175 | if (child.id && child.id.match("RROW-")) { | |
1176 | var c_id = child.id.replace("RROW-", ""); | |
1177 | sel_articles.push(c_id); | |
1178 | } | |
1179 | } | |
1180 | ||
1181 | return sel_articles; | |
1182 | } | |
1183 | ||
1184 | function cdmGetUnreadArticles() { | |
1185 | var sel_articles = new Array(); | |
1186 | var container = $("headlinesInnerContainer"); | |
1187 | ||
1188 | for (i = 0; i < container.childNodes.length; i++) { | |
1189 | var child = container.childNodes[i]; | |
1190 | ||
1191 | if (child.id && child.id.match("RROW-") && child.className.match("Unread")) { | |
1192 | var c_id = child.id.replace("RROW-", ""); | |
1193 | sel_articles.push(c_id); | |
1194 | } | |
1195 | } | |
1196 | ||
1197 | return sel_articles; | |
1198 | } | |
1199 | ||
1200 | ||
1201 | // mode = all,none,unread | |
1202 | function cdmSelectArticles(mode) { | |
1203 | var container = $("headlinesInnerContainer"); | |
1204 | ||
1205 | for (i = 0; i < container.childNodes.length; i++) { | |
1206 | var child = container.childNodes[i]; | |
1207 | ||
1208 | if (child.id && child.id.match("RROW-")) { | |
1209 | var aid = child.id.replace("RROW-", ""); | |
1210 | ||
1211 | var cb = $("RCHK-" + aid); | |
1212 | ||
1213 | if (mode == "all") { | |
1214 | if (!child.className.match("Selected")) { | |
1215 | child.className = child.className + "Selected"; | |
1216 | cb.checked = true; | |
1217 | } | |
1218 | } else if (mode == "unread") { | |
1219 | if (child.className.match("Unread") && !child.className.match("Selected")) { | |
1220 | child.className = child.className + "Selected"; | |
1221 | cb.checked = true; | |
1222 | } | |
1223 | } else { | |
1224 | child.className = child.className.replace("Selected", ""); | |
1225 | cb.checked = false; | |
1226 | } | |
1227 | } | |
1228 | } | |
1229 | } | |
1230 | ||
1231 | function catchupPage() { | |
1232 | ||
1233 | var fn = getFeedName(getActiveFeedId(), activeFeedIsCat()); | |
1234 | ||
1235 | var str = __("Mark all visible articles in %s as read?"); | |
1236 | ||
1237 | str = str.replace("%s", fn); | |
1238 | ||
1239 | if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) { | |
1240 | return; | |
1241 | } | |
1242 | ||
1243 | if ($("headlinesList")) { | |
1244 | selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, 'Unread', true); | |
1245 | selectionToggleUnread(false, 'viewCurrentFeed()', true); | |
1246 | selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false); | |
1247 | } else { | |
1248 | cdmSelectArticles('all'); | |
1249 | selectionToggleUnread(false, 'viewCurrentFeed()', true) | |
1250 | cdmSelectArticles('none'); | |
1251 | } | |
1252 | } | |
1253 | ||
1254 | function deleteSelection() { | |
1255 | ||
1256 | try { | |
1257 | ||
1258 | var rows = getSelectedArticleIds2(); | |
1259 | ||
1260 | if (rows.length == 0) { | |
1261 | alert(__("No articles are selected.")); | |
1262 | return; | |
1263 | } | |
1264 | ||
1265 | var fn = getFeedName(getActiveFeedId(), activeFeedIsCat()); | |
1266 | var str; | |
1267 | var op; | |
1268 | ||
1269 | if (getActiveFeedId() != 0) { | |
1270 | str = __("Delete %d selected articles in %s?"); | |
1271 | } else { | |
1272 | str = __("Delete %d selected articles?"); | |
1273 | } | |
1274 | ||
1275 | str = str.replace("%d", rows.length); | |
1276 | str = str.replace("%s", fn); | |
1277 | ||
1278 | if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) { | |
1279 | return; | |
1280 | } | |
1281 | ||
1282 | query = "?op=rpc&subop=delete&ids=" + param_escape(rows); | |
1283 | ||
1284 | console.log(query); | |
1285 | ||
1286 | new Ajax.Request("backend.php", { | |
1287 | parameters: query, | |
1288 | onComplete: function(transport) { | |
1289 | viewCurrentFeed(); | |
1290 | } }); | |
1291 | ||
1292 | } catch (e) { | |
1293 | exception_error("deleteSelection", e); | |
1294 | } | |
1295 | } | |
1296 | ||
1297 | function archiveSelection() { | |
1298 | ||
1299 | try { | |
1300 | ||
1301 | var rows = getSelectedArticleIds2(); | |
1302 | ||
1303 | if (rows.length == 0) { | |
1304 | alert(__("No articles are selected.")); | |
1305 | return; | |
1306 | } | |
1307 | ||
1308 | var fn = getFeedName(getActiveFeedId(), activeFeedIsCat()); | |
1309 | var str; | |
1310 | var op; | |
1311 | ||
1312 | if (getActiveFeedId() != 0) { | |
1313 | str = __("Archive %d selected articles in %s?"); | |
1314 | op = "archive"; | |
1315 | } else { | |
1316 | str = __("Move %d archived articles back?"); | |
1317 | op = "unarchive"; | |
1318 | } | |
1319 | ||
1320 | str = str.replace("%d", rows.length); | |
1321 | str = str.replace("%s", fn); | |
1322 | ||
1323 | if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) { | |
1324 | return; | |
1325 | } | |
1326 | ||
1327 | query = "?op=rpc&subop="+op+"&ids=" + param_escape(rows); | |
1328 | ||
1329 | console.log(query); | |
1330 | ||
1331 | for (var i = 0; i < rows.length; i++) { | |
1332 | cache_invalidate(rows[i]); | |
1333 | } | |
1334 | ||
1335 | new Ajax.Request("backend.php", { | |
1336 | parameters: query, | |
1337 | onComplete: function(transport) { | |
1338 | viewCurrentFeed(); | |
1339 | } }); | |
1340 | ||
1341 | } catch (e) { | |
1342 | exception_error("archiveSelection", e); | |
1343 | } | |
1344 | } | |
1345 | ||
1346 | function catchupSelection() { | |
1347 | ||
1348 | try { | |
1349 | ||
1350 | var rows = getSelectedArticleIds2(); | |
1351 | ||
1352 | if (rows.length == 0) { | |
1353 | alert(__("No articles are selected.")); | |
1354 | return; | |
1355 | } | |
1356 | ||
1357 | var fn = getFeedName(getActiveFeedId(), activeFeedIsCat()); | |
1358 | ||
1359 | var str = __("Mark %d selected articles in %s as read?"); | |
1360 | ||
1361 | str = str.replace("%d", rows.length); | |
1362 | str = str.replace("%s", fn); | |
1363 | ||
1364 | if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) { | |
1365 | return; | |
1366 | } | |
1367 | ||
1368 | if ($("headlinesList")) { | |
1369 | selectionToggleUnread(false, 'viewCurrentFeed()', true); | |
1370 | } else { | |
1371 | selectionToggleUnread(false, 'viewCurrentFeed()', true) | |
1372 | } | |
1373 | ||
1374 | } catch (e) { | |
1375 | exception_error("catchupSelection", e); | |
1376 | } | |
1377 | } | |
1378 | ||
1379 | function editArticleTags(id, feed_id, cdm_enabled) { | |
1380 | displayDlg('editArticleTags', id, | |
1381 | function () { | |
1382 | $("tags_str").focus(); | |
1383 | ||
1384 | new Ajax.Autocompleter('tags_str', 'tags_choices', | |
1385 | "backend.php?op=rpc&subop=completeTags", | |
1386 | { tokens: ',', paramName: "search" }); | |
1387 | }); | |
1388 | } | |
1389 | ||
1390 | function editTagsSave() { | |
1391 | ||
1392 | notify_progress("Saving article tags..."); | |
1393 | ||
1394 | var form = document.forms["tag_edit_form"]; | |
1395 | ||
1396 | var query = Form.serialize("tag_edit_form"); | |
1397 | ||
1398 | query = "?op=rpc&subop=setArticleTags&" + query; | |
1399 | ||
1400 | console.log(query); | |
1401 | ||
1402 | new Ajax.Request("backend.php", { | |
1403 | parameters: query, | |
1404 | onComplete: function(transport) { | |
1405 | try { | |
1406 | console.log("tags saved..."); | |
1407 | ||
1408 | closeInfoBox(); | |
1409 | notify(""); | |
1410 | ||
1411 | if (tagsAreDisplayed()) { | |
1412 | _reload_feedlist_after_view = true; | |
1413 | } | |
1414 | ||
1415 | if (transport.responseXML) { | |
1416 | var tags_str = transport.responseXML.getElementsByTagName("tags-str")[0]; | |
1417 | ||
1418 | if (tags_str) { | |
1419 | var id = tags_str.getAttribute("id"); | |
1420 | ||
1421 | if (id) { | |
1422 | var tags = $("ATSTR-" + id); | |
1423 | if (tags) { | |
1424 | tags.innerHTML = tags_str.firstChild.nodeValue; | |
1425 | } | |
1426 | ||
1427 | cache_invalidate(id); | |
1428 | } | |
1429 | } | |
1430 | } | |
1431 | ||
1432 | } catch (e) { | |
1433 | exception_error("editTagsSave", e); | |
1434 | } | |
1435 | } }); | |
1436 | } | |
1437 | ||
1438 | function editTagsInsert() { | |
1439 | try { | |
1440 | ||
1441 | var form = document.forms["tag_edit_form"]; | |
1442 | ||
1443 | var found_tags = form.found_tags; | |
1444 | var tags_str = form.tags_str; | |
1445 | ||
1446 | var tag = found_tags[found_tags.selectedIndex].value; | |
1447 | ||
1448 | if (tags_str.value.length > 0 && | |
1449 | tags_str.value.lastIndexOf(", ") != tags_str.value.length - 2) { | |
1450 | ||
1451 | tags_str.value = tags_str.value + ", "; | |
1452 | } | |
1453 | ||
1454 | tags_str.value = tags_str.value + tag + ", "; | |
1455 | ||
1456 | found_tags.selectedIndex = 0; | |
1457 | ||
1458 | } catch (e) { | |
1459 | exception_error("editTagsInsert", e); | |
1460 | } | |
1461 | } | |
1462 | ||
1463 | function cdmScrollViewport(where) { | |
1464 | console.log("cdmScrollViewport: " + where); | |
1465 | ||
1466 | var ctr = $("headlinesInnerContainer"); | |
1467 | ||
1468 | if (!ctr) return; | |
1469 | ||
1470 | if (where == "bottom") { | |
1471 | ctr.scrollTop = ctr.scrollHeight; | |
1472 | } else { | |
1473 | ctr.scrollTop = where; | |
1474 | } | |
1475 | } | |
1476 | ||
1477 | function cdmArticleIsBelowViewport(id) { | |
1478 | try { | |
1479 | var ctr = $("headlinesInnerContainer"); | |
1480 | var e = $("RROW-" + id); | |
1481 | ||
1482 | if (!e || !ctr) return; | |
1483 | ||
1484 | // article starts below viewport | |
1485 | ||
1486 | if (ctr.scrollTop < e.offsetTop) { | |
1487 | return true; | |
1488 | } else { | |
1489 | return false; | |
1490 | } | |
1491 | ||
1492 | } catch (e) { | |
1493 | exception_error("cdmArticleIsVisible", e); | |
1494 | } | |
1495 | } | |
1496 | ||
1497 | function cdmArticleIsAboveViewport(id) { | |
1498 | try { | |
1499 | var ctr = $("headlinesInnerContainer"); | |
1500 | var e = $("RROW-" + id); | |
1501 | ||
1502 | if (!e || !ctr) return; | |
1503 | ||
1504 | // article starts above viewport | |
1505 | ||
1506 | if (ctr.scrollTop > e.offsetTop + e.offsetHeight) { | |
1507 | return true; | |
1508 | } else { | |
1509 | return false; | |
1510 | } | |
1511 | ||
1512 | } catch (e) { | |
1513 | exception_error("cdmArticleIsVisible", e); | |
1514 | } | |
1515 | } | |
1516 | ||
1517 | function cdmScrollToArticleId(id) { | |
1518 | try { | |
1519 | var ctr = $("headlinesInnerContainer"); | |
1520 | var e = $("RROW-" + id); | |
1521 | ||
1522 | if (!e || !ctr) return; | |
1523 | ||
1524 | ctr.scrollTop = e.offsetTop; | |
1525 | ||
1526 | } catch (e) { | |
1527 | exception_error("cdmScrollToArticleId", e); | |
1528 | } | |
1529 | } | |
1530 | ||
1531 | function cdmArticleIsActuallyVisible(id) { | |
1532 | try { | |
1533 | var ctr = $("headlinesInnerContainer"); | |
1534 | var e = $("RROW-" + id); | |
1535 | ||
1536 | if (!e || !ctr) return; | |
1537 | ||
1538 | // article fits in viewport OR article is longer than viewport and | |
1539 | // its bottom is visible | |
1540 | ||
1541 | if (ctr.scrollTop <= e.offsetTop && e.offsetTop + e.offsetHeight <= | |
1542 | ctr.scrollTop + ctr.offsetHeight) { | |
1543 | ||
1544 | return true; | |
1545 | ||
1546 | } else if (e.offsetHeight > ctr.offsetHeight && | |
1547 | e.offsetTop + e.offsetHeight >= ctr.scrollTop && | |
1548 | e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight) { | |
1549 | ||
1550 | return true; | |
1551 | ||
1552 | } | |
1553 | ||
1554 | return false; | |
1555 | ||
1556 | } catch (e) { | |
1557 | exception_error("cdmArticleIsVisible", e); | |
1558 | } | |
1559 | } | |
1560 | ||
1561 | function cdmWatchdog() { | |
1562 | ||
1563 | try { | |
1564 | ||
1565 | var ctr = $("headlinesInnerContainer"); | |
1566 | ||
1567 | if (!ctr) return; | |
1568 | ||
1569 | var ids = new Array(); | |
1570 | ||
1571 | var e = ctr.firstChild; | |
1572 | ||
1573 | while (e) { | |
1574 | if (e.className && e.className == "cdmArticleUnread" && e.id && | |
1575 | e.id.match("RROW-")) { | |
1576 | ||
1577 | // article fits in viewport OR article is longer than viewport and | |
1578 | // its bottom is visible | |
1579 | ||
1580 | if (ctr.scrollTop <= e.offsetTop && e.offsetTop + e.offsetHeight <= | |
1581 | ctr.scrollTop + ctr.offsetHeight) { | |
1582 | ||
1583 | // console.log(e.id + " is visible " + e.offsetTop + "." + | |
1584 | // (e.offsetTop + e.offsetHeight) + " vs " + ctr.scrollTop + "." + | |
1585 | // (ctr.scrollTop + ctr.offsetHeight)); | |
1586 | ||
1587 | ids.push(e.id.replace("RROW-", "")); | |
1588 | ||
1589 | } else if (e.offsetHeight > ctr.offsetHeight && | |
1590 | e.offsetTop + e.offsetHeight >= ctr.scrollTop && | |
1591 | e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight) { | |
1592 | ||
1593 | ids.push(e.id.replace("RROW-", "")); | |
1594 | ||
1595 | } | |
1596 | ||
1597 | // method 2: article bottom is visible and is in upper 1/2 of the viewport | |
1598 | ||
1599 | /* if (e.offsetTop + e.offsetHeight >= ctr.scrollTop && | |
1600 | e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight/2) { | |
1601 | ||
1602 | ids.push(e.id.replace("RROW-", "")); | |
1603 | ||
1604 | } */ | |
1605 | ||
1606 | } | |
1607 | ||
1608 | e = e.nextSibling; | |
1609 | } | |
1610 | ||
1611 | console.log("cdmWatchdog, ids= " + ids.toString()); | |
1612 | ||
1613 | if (ids.length > 0) { | |
1614 | ||
1615 | for (var i = 0; i < ids.length; i++) { | |
1616 | var e = $("RROW-" + ids[i]); | |
1617 | if (e) { | |
1618 | e.className = e.className.replace("Unread", ""); | |
1619 | } | |
1620 | } | |
1621 | ||
1622 | var query = "?op=rpc&subop=catchupSelected" + | |
1623 | "&cmode=0" + "&ids=" + param_escape(ids.toString()); | |
1624 | ||
1625 | new Ajax.Request("backend.php", { | |
1626 | parameters: query, | |
1627 | onComplete: function(transport) { | |
1628 | all_counters_callback2(transport); | |
1629 | } }); | |
1630 | ||
1631 | } | |
1632 | ||
1633 | _cdm_wd_timeout = window.setTimeout("cdmWatchdog()", 4000); | |
1634 | ||
1635 | } catch (e) { | |
1636 | exception_error("cdmWatchdog", e); | |
1637 | } | |
1638 | ||
1639 | } | |
1640 | ||
1641 | ||
1642 | function cache_inject(id, article, param) { | |
1643 | try { | |
1644 | if (!cache_check_param(id, param)) { | |
1645 | console.log("cache_article: miss: " + id + " [p=" + param + "]"); | |
1646 | ||
1647 | if (db) { | |
1648 | ||
1649 | var date = new Date(); | |
1650 | var ts = Math.round(date.getTime() / 1000); | |
1651 | ||
1652 | db.execute("INSERT INTO cache (id, article, param, added) VALUES (?, ?, ?, ?)", | |
1653 | [id, article, param, ts]); | |
1654 | } else { | |
1655 | ||
1656 | var cache_obj = {}; | |
1657 | ||
1658 | cache_obj["id"] = id; | |
1659 | cache_obj["data"] = article; | |
1660 | cache_obj["param"] = param; | |
1661 | cache_obj["added"] = new Date(); | |
1662 | ||
1663 | if (param) id = id + ":" + param; | |
1664 | ||
1665 | if (has_local_storage()) | |
1666 | localStorage.setItem(id, JSON.stringify(cache_obj)); | |
1667 | else | |
1668 | article_cache.push(cache_obj); | |
1669 | } | |
1670 | ||
1671 | } else { | |
1672 | console.log("cache_article: hit: " + id + " [p=" + param + "]"); | |
1673 | } | |
1674 | } catch (e) { | |
1675 | exception_error("cache_inject", e); | |
1676 | } | |
1677 | } | |
1678 | ||
1679 | function cache_find(id) { | |
1680 | ||
1681 | if (db) { | |
1682 | var rs = db.execute("SELECT article FROM cache WHERE id = ?", [id]); | |
1683 | var a = false; | |
1684 | ||
1685 | if (rs.isValidRow()) { | |
1686 | var a = rs.field(0); | |
1687 | } | |
1688 | ||
1689 | rs.close(); | |
1690 | ||
1691 | return a; | |
1692 | ||
1693 | } else { | |
1694 | ||
1695 | if (has_local_storage()) { | |
1696 | var cache_obj = localStorage.getItem(id); | |
1697 | ||
1698 | if (cache_obj) { | |
1699 | cache_obj = JSON.parse(cache_obj); | |
1700 | ||
1701 | if (cache_obj) | |
1702 | return cache_obj['data']; | |
1703 | } | |
1704 | ||
1705 | } else { | |
1706 | for (var i = 0; i < article_cache.length; i++) { | |
1707 | if (article_cache[i]["id"] == id) { | |
1708 | return article_cache[i]["data"]; | |
1709 | } | |
1710 | } | |
1711 | } | |
1712 | } | |
1713 | return false; | |
1714 | } | |
1715 | ||
1716 | function cache_find_param(id, param) { | |
1717 | ||
1718 | if (db) { | |
1719 | var rs = db.execute("SELECT article FROM cache WHERE id = ? AND param = ?", | |
1720 | [id, param]); | |
1721 | var a = false; | |
1722 | ||
1723 | if (rs.isValidRow()) { | |
1724 | a = rs.field(0); | |
1725 | } | |
1726 | ||
1727 | rs.close(); | |
1728 | ||
1729 | return a; | |
1730 | ||
1731 | } else { | |
1732 | ||
1733 | if (has_local_storage()) { | |
1734 | var cache_obj = localStorage.getItem(id + ":" + param); | |
1735 | ||
1736 | if (cache_obj) { | |
1737 | cache_obj = JSON.parse(cache_obj); | |
1738 | ||
1739 | if (cache_obj) | |
1740 | return cache_obj['data']; | |
1741 | } | |
1742 | ||
1743 | } else { | |
1744 | for (var i = 0; i < article_cache.length; i++) { | |
1745 | if (article_cache[i]["id"] == id && article_cache[i]["param"] == param) { | |
1746 | return article_cache[i]["data"]; | |
1747 | } | |
1748 | } | |
1749 | } | |
1750 | } | |
1751 | return false; | |
1752 | } | |
1753 | ||
1754 | function cache_check(id) { | |
1755 | ||
1756 | if (db) { | |
1757 | var rs = db.execute("SELECT COUNT(*) AS c FROM cache WHERE id = ?", | |
1758 | [id]); | |
1759 | var a = false; | |
1760 | ||
1761 | if (rs.isValidRow()) { | |
1762 | a = rs.field(0) != "0"; | |
1763 | } | |
1764 | ||
1765 | rs.close(); | |
1766 | ||
1767 | return a; | |
1768 | ||
1769 | } else { | |
1770 | if (has_local_storage) { | |
1771 | if (localStorage.getItem(id)) | |
1772 | return true; | |
1773 | } else { | |
1774 | for (var i = 0; i < article_cache.length; i++) { | |
1775 | if (article_cache[i]["id"] == id) { | |
1776 | return true; | |
1777 | } | |
1778 | } | |
1779 | } | |
1780 | } | |
1781 | return false; | |
1782 | } | |
1783 | ||
1784 | function cache_check_param(id, param) { | |
1785 | ||
1786 | if (db) { | |
1787 | var rs = db.execute("SELECT COUNT(*) AS c FROM cache WHERE id = ? AND param = ?", | |
1788 | [id, param]); | |
1789 | var a = false; | |
1790 | ||
1791 | if (rs.isValidRow()) { | |
1792 | a = rs.field(0) != "0"; | |
1793 | } | |
1794 | ||
1795 | rs.close(); | |
1796 | ||
1797 | return a; | |
1798 | ||
1799 | } else { | |
1800 | ||
1801 | if (has_local_storage) { | |
1802 | if (localStorage.getItem(id + ':' + param)) | |
1803 | return true; | |
1804 | } else { | |
1805 | for (var i = 0; i < article_cache.length; i++) { | |
1806 | if (article_cache[i]["id"] == id && article_cache[i]["param"] == param) { | |
1807 | return true; | |
1808 | } | |
1809 | } | |
1810 | } | |
1811 | } | |
1812 | return false; | |
1813 | } | |
1814 | ||
1815 | function cache_expire() { | |
1816 | if (db) { | |
1817 | var date = new Date(); | |
1818 | var ts = Math.round(date.getTime() / 1000); | |
1819 | ||
1820 | db.execute("DELETE FROM cache WHERE added < ? - 1800 AND id LIKE 'FEEDLIST'", [ts]); | |
1821 | db.execute("DELETE FROM cache WHERE added < ? - 600 AND (id LIKE 'F:%' OR id LIKE 'C:%')", [ts]); | |
1822 | db.execute("DELETE FROM cache WHERE added < ? - 86400", [ts]); | |
1823 | ||
1824 | ||
1825 | } else { | |
1826 | if (has_local_storage()) { | |
1827 | while (localStorage.length > 25) { | |
1828 | localStorage.removeItem(localStorage.key(0)); | |
1829 | } | |
1830 | } else { | |
1831 | while (article_cache.length > 25) { | |
1832 | article_cache.shift(); | |
1833 | } | |
1834 | } | |
1835 | } | |
1836 | } | |
1837 | ||
1838 | function cache_flush() { | |
1839 | article_cache = new Array(); | |
1840 | } | |
1841 | ||
1842 | function cache_invalidate(id) { | |
1843 | try { | |
1844 | ||
1845 | if (db) { | |
1846 | rs = db.execute("DELETE FROM cache WHERE id = ?", [id]); | |
1847 | return rs.rowsAffected != 0; | |
1848 | } else { | |
1849 | ||
1850 | if (has_local_storage()) { | |
1851 | for (var i = 0; i < localStorage.length; i++) { | |
1852 | var key = localStorage.key(i); | |
1853 | ||
1854 | if (key == id || key.indexOf(id + ":") == 0) | |
1855 | localStorage.removeItem(key); | |
1856 | ||
1857 | } | |
1858 | } else { | |
1859 | var i = 0 | |
1860 | ||
1861 | while (i < article_cache.length) { | |
1862 | if (article_cache[i]["id"] == id) { | |
1863 | console.log("cache_invalidate: removed id " + id); | |
1864 | article_cache.splice(i, 1); | |
1865 | return true; | |
1866 | } | |
1867 | i++; | |
1868 | } | |
1869 | } | |
1870 | } | |
1871 | ||
1872 | console.log("cache_invalidate: id not found: " + id); | |
1873 | return false; | |
1874 | } catch (e) { | |
1875 | exception_error("cache_invalidate", e); | |
1876 | } | |
1877 | } | |
1878 | ||
1879 | function getActiveArticleId() { | |
1880 | return active_post_id; | |
1881 | } | |
1882 | ||
1883 | function preloadArticleUnderPointer(id) { | |
1884 | try { | |
1885 | if (getInitParam("bw_limit") == "1") return; | |
1886 | ||
1887 | if (post_under_pointer == id && !cache_check(id)) { | |
1888 | ||
1889 | console.log("trying to preload article " + id); | |
1890 | ||
1891 | var neighbor_ids = getRelativePostIds(id, 1); | |
1892 | ||
1893 | /* only request uncached articles */ | |
1894 | ||
1895 | var cids_to_request = Array(); | |
1896 | ||
1897 | for (var i = 0; i < neighbor_ids.length; i++) { | |
1898 | if (!cache_check(neighbor_ids[i])) { | |
1899 | cids_to_request.push(neighbor_ids[i]); | |
1900 | } | |
1901 | } | |
1902 | console.log("additional ids: " + cids_to_request.toString()); | |
1903 | ||
1904 | cids_to_request.push(id); | |
1905 | ||
1906 | var query = "?op=rpc&subop=getArticles&ids=" + | |
1907 | cids_to_request.toString(); | |
1908 | ||
1909 | new Ajax.Request("backend.php", { | |
1910 | parameters: query, | |
1911 | onComplete: function(transport) { | |
1912 | var articles = transport.responseXML.getElementsByTagName("article"); | |
1913 | ||
1914 | for (var i = 0; i < articles.length; i++) { | |
1915 | var id = articles[i].getAttribute("id"); | |
1916 | if (!cache_check(id)) { | |
1917 | cache_inject(id, articles[i].firstChild.nodeValue); | |
1918 | console.log("preloaded article: " + id); | |
1919 | } | |
1920 | } | |
1921 | } }); | |
1922 | } | |
1923 | } catch (e) { | |
1924 | exception_error("preloadArticleUnderPointer", e); | |
1925 | } | |
1926 | } | |
1927 | ||
1928 | function postMouseIn(id) { | |
1929 | try { | |
1930 | if (post_under_pointer != id) { | |
1931 | post_under_pointer = id; | |
1932 | if (!isCdmMode()) { | |
1933 | window.setTimeout("preloadArticleUnderPointer(" + id + ")", 250); | |
1934 | } | |
1935 | } | |
1936 | ||
1937 | } catch (e) { | |
1938 | exception_error("postMouseIn", e); | |
1939 | } | |
1940 | } | |
1941 | ||
1942 | function postMouseOut(id) { | |
1943 | try { | |
1944 | post_under_pointer = false; | |
1945 | } catch (e) { | |
1946 | exception_error("postMouseOut", e); | |
1947 | } | |
1948 | } | |
1949 | ||
1950 | function headlines_scroll_handler() { | |
1951 | try { | |
1952 | ||
1953 | var e = $("headlinesInnerContainer"); | |
1954 | ||
1955 | var toolbar_form = document.forms["main_toolbar_form"]; | |
1956 | ||
1957 | // console.log((e.scrollTop + e.offsetHeight) + " vs " + e.scrollHeight + " dis? " + | |
1958 | // _infscroll_disable); | |
1959 | ||
1960 | if (e.scrollTop + e.offsetHeight > e.scrollHeight - 100) { | |
1961 | if (!_infscroll_disable) { | |
1962 | console.log("more cowbell!"); | |
1963 | viewNextFeedPage(); | |
1964 | } | |
1965 | } | |
1966 | ||
1967 | } catch (e) { | |
1968 | exception_error("headlines_scroll_handler", e); | |
1969 | } | |
1970 | } | |
1971 | ||
1972 | function catchupRelativeToArticle(below) { | |
1973 | ||
1974 | try { | |
1975 | ||
1976 | ||
1977 | if (!getActiveArticleId()) { | |
1978 | alert(__("No article is selected.")); | |
1979 | return; | |
1980 | } | |
1981 | ||
1982 | var visible_ids; | |
1983 | ||
1984 | if ($("headlinesList")) { | |
1985 | visible_ids = getVisibleHeadlineIds(); | |
1986 | } else { | |
1987 | visible_ids = cdmGetVisibleArticles(); | |
1988 | } | |
1989 | ||
1990 | var ids_to_mark = new Array(); | |
1991 | ||
1992 | if (!below) { | |
1993 | for (var i = 0; i < visible_ids.length; i++) { | |
1994 | if (visible_ids[i] != getActiveArticleId()) { | |
1995 | var e = $("RROW-" + visible_ids[i]); | |
1996 | ||
1997 | if (e && e.className.match("Unread")) { | |
1998 | ids_to_mark.push(visible_ids[i]); | |
1999 | } | |
2000 | } else { | |
2001 | break; | |
2002 | } | |
2003 | } | |
2004 | } else { | |
2005 | for (var i = visible_ids.length-1; i >= 0; i--) { | |
2006 | if (visible_ids[i] != getActiveArticleId()) { | |
2007 | var e = $("RROW-" + visible_ids[i]); | |
2008 | ||
2009 | if (e && e.className.match("Unread")) { | |
2010 | ids_to_mark.push(visible_ids[i]); | |
2011 | } | |
2012 | } else { | |
2013 | break; | |
2014 | } | |
2015 | } | |
2016 | } | |
2017 | ||
2018 | if (ids_to_mark.length == 0) { | |
2019 | alert(__("No articles found to mark")); | |
2020 | } else { | |
2021 | var msg = __("Mark %d article(s) as read?").replace("%d", ids_to_mark.length); | |
2022 | ||
2023 | if (getInitParam("confirm_feed_catchup") != 1 || confirm(msg)) { | |
2024 | ||
2025 | for (var i = 0; i < ids_to_mark.length; i++) { | |
2026 | var e = $("RROW-" + ids_to_mark[i]); | |
2027 | e.className = e.className.replace("Unread", ""); | |
2028 | } | |
2029 | ||
2030 | var query = "?op=rpc&subop=catchupSelected" + | |
2031 | "&cmode=0" + "&ids=" + param_escape(ids_to_mark.toString()); | |
2032 | ||
2033 | new Ajax.Request("backend.php", { | |
2034 | parameters: query, | |
2035 | onComplete: function(transport) { | |
2036 | catchup_callback2(transport); | |
2037 | } }); | |
2038 | ||
2039 | } | |
2040 | } | |
2041 | ||
2042 | } catch (e) { | |
2043 | exception_error("catchupRelativeToArticle", e); | |
2044 | } | |
2045 | } | |
2046 | ||
2047 | function cdmExpandArticle(id) { | |
2048 | try { | |
2049 | ||
2050 | var elem = $("CICD-" + active_post_id); | |
2051 | ||
2052 | if (id == active_post_id && Element.visible(elem)) | |
2053 | return true; | |
2054 | ||
2055 | cdmSelectArticles("none"); | |
2056 | ||
2057 | var old_offset = $("RROW-" + id).offsetTop; | |
2058 | ||
2059 | if (active_post_id && elem) { | |
2060 | Element.hide(elem); | |
2061 | Element.show("CEXC-" + active_post_id); | |
2062 | } | |
2063 | ||
2064 | active_post_id = id; | |
2065 | ||
2066 | elem = $("CICD-" + id); | |
2067 | ||
2068 | if (!Element.visible(elem)) { | |
2069 | Element.show(elem); | |
2070 | Element.hide("CEXC-" + id); | |
2071 | } | |
2072 | ||
2073 | var new_offset = $("RROW-" + id).offsetTop; | |
2074 | ||
2075 | $("headlinesInnerContainer").scrollTop += (new_offset-old_offset); | |
2076 | ||
2077 | if ($("RROW-" + id).offsetTop != old_offset) | |
2078 | $("headlinesInnerContainer").scrollTop = new_offset; | |
2079 | ||
2080 | toggleUnread(id, 0, true); | |
2081 | toggleSelected(id); | |
2082 | ||
2083 | } catch (e) { | |
2084 | exception_error("cdmExpandArticle", e); | |
2085 | } | |
2086 | ||
2087 | return false; | |
2088 | } | |
2089 | ||
2090 | function fixHeadlinesOrder(ids) { | |
2091 | try { | |
2092 | for (var i = 0; i < ids.length; i++) { | |
2093 | var e = $("RROW-" + ids[i]); | |
2094 | ||
2095 | if (e) { | |
2096 | if (i % 2 == 0) { | |
2097 | e.className = e.className.replace("even", "odd"); | |
2098 | } else { | |
2099 | e.className = e.className.replace("odd", "even"); | |
2100 | } | |
2101 | } | |
2102 | } | |
2103 | } catch (e) { | |
2104 | exception_error("fixHeadlinesOrder", e); | |
2105 | } | |
2106 | } | |
2107 | ||
2108 | function hideReadHeadlines() { | |
2109 | try { | |
2110 | ||
2111 | var ids = false; | |
2112 | var vis_ids = new Array(); | |
2113 | ||
2114 | if ($("headlinesList")) { | |
2115 | ids = getVisibleHeadlineIds(); | |
2116 | } else { | |
2117 | ids = cdmGetVisibleArticles(); | |
2118 | } | |
2119 | ||
2120 | var read_headlines_visible = true; | |
2121 | ||
2122 | for (var i = 0; i < ids.length; i++) { | |
2123 | var row = $("RROW-" + ids[i]); | |
2124 | ||
2125 | if (row && row.className) { | |
2126 | if (read_headlines_visible) { | |
2127 | if (row.className.match("Unread") || row.className.match("Selected")) { | |
2128 | Element.show(row); | |
2129 | vis_ids.push(ids[i]); | |
2130 | } else { | |
2131 | //Effect.Fade(row, {duration : 0.3}); | |
2132 | Element.hide(row); | |
2133 | } | |
2134 | } else { | |
2135 | Element.show(row); | |
2136 | vis_ids.push(ids[i]); | |
2137 | } | |
2138 | } | |
2139 | } | |
2140 | ||
2141 | fixHeadlinesOrder(vis_ids); | |
2142 | ||
2143 | read_headlines_visible = !read_headlines_visible; | |
2144 | ||
2145 | } catch (e) { | |
2146 | exception_error("hideReadHeadlines", e); | |
2147 | } | |
2148 | } | |
2149 | ||
2150 | function invertHeadlineSelection() { | |
2151 | try { | |
2152 | var rows = new Array(); | |
2153 | var r = false; | |
2154 | ||
2155 | if (!isCdmMode()) { | |
2156 | r = document.getElementsByTagName("TR"); | |
2157 | } else { | |
2158 | r = document.getElementsByTagName("DIV"); | |
2159 | } | |
2160 | ||
2161 | for (var i = 0; i < r.length; i++) { | |
2162 | if (r[i].id && r[i].id.match("RROW-")) { | |
2163 | rows.push(r[i]); | |
2164 | } | |
2165 | } | |
2166 | ||
2167 | for (var i = 0; i < rows.length; i++) { | |
2168 | var nc = rows[i].className; | |
2169 | var id = rows[i].id.replace("RROW-", ""); | |
2170 | var cb = $("RCHK-" + id); | |
2171 | ||
2172 | if (!rows[i].className.match("Selected")) { | |
2173 | nc = nc + "Selected"; | |
2174 | cb.checked = true; | |
2175 | } else { | |
2176 | nc = nc.replace("Selected", ""); | |
2177 | cb.checked = false; | |
2178 | } | |
2179 | ||
2180 | rows[i].className = nc; | |
2181 | ||
2182 | } | |
2183 | ||
2184 | } catch (e) { | |
2185 | exception_error("invertHeadlineSelection", e); | |
2186 | } | |
2187 | } | |
2188 | ||
2189 | function getArticleUnderPointer() { | |
2190 | return post_under_pointer; | |
2191 | } | |
2192 | ||
2193 | function zoomToArticle(id) { | |
2194 | try { | |
2195 | var w = window.open("backend.php?op=view&mode=zoom&id=" + param_escape(id), | |
2196 | "ttrss_zoom_" + id, | |
2197 | "status=0,toolbar=0,location=0,width=450,height=300,scrollbars=1,menubar=0"); | |
2198 | ||
2199 | } catch (e) { | |
2200 | exception_error("zoomToArticle", e); | |
2201 | } | |
2202 | } | |
2203 | ||
2204 | function scrollArticle(offset) { | |
2205 | try { | |
2206 | if (!isCdmMode()) { | |
2207 | var ci = $("content-insert"); | |
2208 | if (ci) { | |
2209 | ci.scrollTop += offset; | |
2210 | } | |
2211 | } else { | |
2212 | var hi = $("headlinesInnerContainer"); | |
2213 | if (hi) { | |
2214 | hi.scrollTop += offset; | |
2215 | } | |
2216 | ||
2217 | } | |
2218 | } catch (e) { | |
2219 | exception_error("scrollArticle", e); | |
2220 | } | |
2221 | } | |
2222 | ||
2223 | function show_labels_in_headlines(transport) { | |
2224 | try { | |
2225 | if (transport.responseXML) { | |
2226 | var info = transport.responseXML.getElementsByTagName("info-for-headlines")[0]; | |
2227 | ||
2228 | var elems = info.getElementsByTagName("entry"); | |
2229 | ||
2230 | for (var l = 0; l < elems.length; l++) { | |
2231 | var e_id = elems[l].getAttribute("id"); | |
2232 | ||
2233 | if (e_id) { | |
2234 | ||
2235 | var ctr = $("HLLCTR-" + e_id); | |
2236 | ||
2237 | if (ctr) { | |
2238 | ctr.innerHTML = elems[l].firstChild.nodeValue; | |
2239 | } | |
2240 | } | |
2241 | ||
2242 | } | |
2243 | ||
2244 | } | |
2245 | } catch (e) { | |
2246 | exception_error("show_labels_in_headlines", e); | |
2247 | ||
2248 | } | |
2249 | } | |
2250 | ||
2251 | function toggleHeadlineActions() { | |
2252 | try { | |
2253 | var e = $("headlineActionsBody"); | |
2254 | var p = $("headlineActionsDrop"); | |
2255 | ||
2256 | if (!Element.visible(e)) { | |
2257 | Element.show(e); | |
2258 | } else { | |
2259 | Element.hide(e); | |
2260 | } | |
2261 | ||
2262 | e.scrollTop = 0; | |
2263 | e.style.left = (p.offsetLeft + 1) + "px"; | |
2264 | e.style.top = (p.offsetTop + p.offsetHeight + 2) + "px"; | |
2265 | ||
2266 | } catch (e) { | |
2267 | exception_error("toggleHeadlineActions", e); | |
2268 | } | |
2269 | } | |
2270 | ||
2271 | function publishWithNote(id, def_note) { | |
2272 | try { | |
2273 | if (!def_note) def_note = ''; | |
2274 | ||
2275 | var note = prompt(__("Please enter a note for this article:"), def_note); | |
2276 | ||
2277 | if (note != undefined) { | |
2278 | togglePub(id, false, false, note); | |
2279 | } | |
2280 | ||
2281 | } catch (e) { | |
2282 | exception_error("publishWithNote", e); | |
2283 | } | |
2284 | } | |
2285 | ||
2286 | function emailArticle(id) { | |
2287 | try { | |
2288 | if (!id) { | |
2289 | var ids = getSelectedArticleIds2(); | |
2290 | ||
2291 | if (ids.length == 0) { | |
2292 | alert(__("No articles are selected.")); | |
2293 | return; | |
2294 | } | |
2295 | ||
2296 | id = ids.toString(); | |
2297 | } | |
2298 | ||
2299 | displayDlg('emailArticle', id, | |
2300 | function () { | |
2301 | document.forms['article_email_form'].destination.focus(); | |
2302 | ||
2303 | new Ajax.Autocompleter('destination', 'destination_choices', | |
2304 | "backend.php?op=rpc&subop=completeEmails", | |
2305 | { tokens: '', paramName: "search" }); | |
2306 | ||
2307 | }); | |
2308 | ||
2309 | } catch (e) { | |
2310 | exception_error("emailArticle", e); | |
2311 | } | |
2312 | } | |
2313 | ||
2314 | function emailArticleDo() { | |
2315 | try { | |
2316 | var f = document.forms['article_email_form']; | |
2317 | ||
2318 | if (f.destination.value == "") { | |
2319 | alert("Please fill in the destination email."); | |
2320 | return; | |
2321 | } | |
2322 | ||
2323 | if (f.subject.value == "") { | |
2324 | alert("Please fill in the subject."); | |
2325 | return; | |
2326 | } | |
2327 | ||
2328 | var query = Form.serialize("article_email_form"); | |
2329 | ||
2330 | // console.log(query); | |
2331 | ||
2332 | new Ajax.Request("backend.php", { | |
2333 | parameters: query, | |
2334 | onComplete: function(transport) { | |
2335 | try { | |
2336 | ||
2337 | var error = transport.responseXML.getElementsByTagName('error')[0]; | |
2338 | ||
2339 | if (error) { | |
2340 | alert(__('Error sending email:') + ' ' + error.firstChild.nodeValue); | |
2341 | } else { | |
2342 | notify_info('Your message has been sent.'); | |
2343 | closeInfoBox(); | |
2344 | } | |
2345 | ||
2346 | } catch (e) { | |
2347 | exception_error("sendEmailDo", e); | |
2348 | } | |
2349 | ||
2350 | } }); | |
2351 | ||
2352 | } catch (e) { | |
2353 | exception_error("emailArticleDo", e); | |
2354 | } | |
2355 | } | |
2356 | ||
2357 | function cdmDismissArticle(id) { | |
2358 | try { | |
2359 | var elem = $("RROW-" + id); | |
2360 | ||
2361 | toggleUnread(id, 0, true); | |
2362 | ||
2363 | new Effect.Fade(elem, {duration : 0.5}); | |
2364 | ||
2365 | } catch (e) { | |
2366 | exception_error("cdmDismissArticle", e); | |
2367 | } | |
2368 | } |