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