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