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