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