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