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