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