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