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