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