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