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