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