1 var active_post_id = false;
2 var last_article_view = false;
3 var active_real_feed_id = false;
5 var _tag_active_post_id = false;
6 var _tag_active_feed_id = false;
7 var _tag_active_cdm = false;
9 // FIXME: kludge, to restore scrollTop after tag editor terminates
10 var _tag_cdm_scroll = false;
12 // FIXME: kludges, needs proper implementation
13 var _reload_feedlist_after_view = false;
15 var _cdm_wd_timeout = false;
16 var _cdm_wd_vishist = new Array();
18 var article_cache = new Array();
20 function catchup_callback() {
21 if (xmlhttp_rpc.readyState == 4) {
23 debug("catchup_callback");
25 all_counters_callback2(xmlhttp_rpc);
26 if (_catchup_callback_func) {
27 setTimeout(_catchup_callback_func, 10);
30 exception_error("catchup_callback", e);
35 function catchup_callback2(transport, callback) {
37 debug("catchup_callback2 " + transport + ", " + callback);
39 all_counters_callback2(transport);
41 setTimeout(callback, 10);
44 exception_error("catchup_callback2", e);
48 function clean_feed_selections() {
50 var feeds = document.getElementById("feedList").getElementsByTagName("LI");
52 for (var i = 0; i < feeds.length; i++) {
53 if (feeds[i].id && feeds[i].id.match("FEEDR-")) {
54 feeds[i].className = feeds[i].className.replace("Selected", "");
58 exception_error("clean_feed_selections", e);
62 function headlines_callback2(transport, active_feed_id, is_cat, feed_cur_page) {
65 debug("headlines_callback2 [page=" + feed_cur_page + "]");
67 clean_feed_selections();
69 setActiveFeedId(active_feed_id);
71 if (is_cat != undefined) {
72 active_feed_is_cat = is_cat;
76 var feedr = document.getElementById("FEEDR-" + active_feed_id);
77 if (feedr && !feedr.className.match("Selected")) {
78 feedr.className = feedr.className + "Selected";
82 var f = document.getElementById("headlines-frame");
84 if (feed_cur_page == 0) {
85 debug("resetting headlines scrollTop");
90 if (transport.responseXML) {
91 var headlines = transport.responseXML.getElementsByTagName("headlines")[0];
92 var headlines_count_obj = transport.responseXML.getElementsByTagName("headlines-count")[0];
93 var headlines_unread_obj = transport.responseXML.getElementsByTagName("headlines-unread")[0];
94 var disable_cache_obj = transport.responseXML.getElementsByTagName("disable-cache")[0];
96 var headlines_count = headlines_count_obj.getAttribute("value");
97 var headlines_unread = headlines_unread_obj.getAttribute("value");
98 var disable_cache = disable_cache_obj.getAttribute("value") != "0";
100 if (headlines_count == 0) _infscroll_disable = 1;
102 var counters = transport.responseXML.getElementsByTagName("counters")[0];
103 var articles = transport.responseXML.getElementsByTagName("article");
104 var runtime_info = transport.responseXML.getElementsByTagName("runtime-info");
106 if (feed_cur_page == 0) {
108 f.innerHTML = headlines.firstChild.nodeValue;
110 var cache_prefix = "";
118 cache_invalidate(cache_prefix + active_feed_id);
120 if (!disable_cache) {
121 cache_inject(cache_prefix + active_feed_id,
122 headlines.firstChild.nodeValue, headlines_unread);
126 debug("headlines_callback: returned no data");
127 f.innerHTML = "<div class='whiteBox'>" + __('Could not update headlines (missing XML data)') + "</div>";
132 if (headlines_count > 0) {
133 debug("adding some more headlines...");
135 var c = document.getElementById("headlinesList");
138 c = document.getElementById("headlinesInnerContainer");
141 var ids = getSelectedArticleIds2();
143 c.innerHTML = c.innerHTML + headlines.firstChild.nodeValue;
145 debug("restore selected ids: " + ids);
147 for (var i = 0; i < ids.length; i++) {
148 markHeadline(ids[i]);
152 debug("no new headlines received");
155 debug("headlines_callback: returned no data");
156 notify_error("Error while trying to load more headlines");
162 for (var i = 0; i < articles.length; i++) {
163 var a_id = articles[i].getAttribute("id");
164 debug("found id: " + a_id);
165 cache_inject(a_id, articles[i].firstChild.nodeValue);
168 debug("no cached articles received");
172 debug("parsing piggybacked counters: " + counters);
173 parse_counters(counters, false);
175 debug("counters container not found in reply");
179 debug("parsing runtime info: " + runtime_info[0]);
180 parse_runtime_info(runtime_info[0]);
182 debug("counters container not found in reply");
186 debug("headlines_callback: returned no XML object");
187 f.innerHTML = "<div class='whiteBox'>" + __('Could not update headlines (missing XML object)') + "</div>";
190 if (typeof correctPNG != 'undefined') {
194 if (_cdm_wd_timeout) window.clearTimeout(_cdm_wd_timeout);
196 if (!document.getElementById("headlinesList") &&
197 getInitParam("cdm_auto_catchup") == 1) {
198 debug("starting CDM watchdog");
199 _cdm_wd_timeout = window.setTimeout("cdmWatchdog()", 5000);
200 _cdm_wd_vishist = new Array();
202 debug("not in CDM mode or watchdog disabled");
205 if (_tag_cdm_scroll) {
207 document.getElementById("headlinesInnerContainer").scrollTop = _tag_cdm_scroll;
208 _tag_cdm_scroll = false;
209 debug("resetting headlinesInner scrollTop");
214 _feed_cur_page = feed_cur_page;
215 _infscroll_request_sent = 0;
219 exception_error("headlines_callback2", e);
223 function render_article(article) {
225 var f = document.getElementById("content-frame");
230 f.innerHTML = article;
233 exception_error("render_article", e);
237 function showArticleInHeadlines(id) {
241 cleanSelected("headlinesList");
243 var crow = document.getElementById("RROW-" + id);
247 var article_is_unread = crow.className.match("Unread");
249 crow.className = crow.className.replace("Unread", "");
251 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
253 var upd_img_pic = document.getElementById("FUPDPIC-" + id);
255 var cache_prefix = "";
257 if (activeFeedIsCat()) {
263 var view_mode = false;
266 view_mode = document.forms['main_toolbar_form'].view_mode;
267 view_mode = view_mode[view_mode.selectedIndex].value;
269 exception_error("showArticleInHeadlines/viewmode", e, true);
272 if (upd_img_pic && upd_img_pic.src.match("updated.png")) {
273 upd_img_pic.src = "images/blank_icon.gif";
275 cache_invalidate(cache_prefix + getActiveFeedId());
277 cache_inject(cache_prefix + getActiveFeedId(),
278 document.getElementById("headlines-frame").innerHTML,
279 get_feed_unread(getActiveFeedId()));
281 } else if (article_is_unread && view_mode == "all_articles") {
283 cache_invalidate(cache_prefix + getActiveFeedId());
285 cache_inject(cache_prefix + getActiveFeedId(),
286 document.getElementById("headlines-frame").innerHTML,
287 get_feed_unread(getActiveFeedId())-1);
289 } else if (article_is_unread) {
290 cache_invalidate(cache_prefix + getActiveFeedId());
296 exception_error("showArticleInHeadlines", e);
300 function article_callback2(transport, id, feed_id) {
302 debug("article_callback2 " + id);
304 if (transport.responseXML) {
306 active_real_feed_id = feed_id;
309 showArticleInHeadlines(id);
311 var reply = transport.responseXML.firstChild.firstChild;
313 var articles = transport.responseXML.getElementsByTagName("article");
315 for (var i = 0; i < articles.length; i++) {
316 var a_id = articles[i].getAttribute("id");
318 debug("found id: " + a_id);
320 if (a_id == active_post_id) {
321 debug("active article, rendering...");
322 render_article(articles[i].firstChild.nodeValue);
325 cache_inject(a_id, articles[i].firstChild.nodeValue);
329 debug("article_callback: returned no XML object");
330 var f = document.getElementById("content-frame");
331 f.innerHTML = "<div class='whiteBox'>" + __('Could not display article (missing XML object)') + "</div>";
334 var date = new Date();
335 last_article_view = date.getTime() / 1000;
337 if (typeof correctPNG != 'undefined') {
341 if (_reload_feedlist_after_view) {
342 setTimeout('updateFeedList(false, false)', 50);
343 _reload_feedlist_after_view = false;
345 var counters = transport.responseXML.getElementsByTagName("counters")[0];
348 debug("parsing piggybacked counters: " + counters);
349 parse_counters(counters, false);
351 debug("counters container not found in reply");
357 exception_error("article_callback2", e);
361 function view(id, feed_id, skip_history) {
364 debug("loading article: " + id + "/" + feed_id);
366 var cached_article = cache_find(id);
368 debug("cache check result: " + (cached_article != false));
372 //setActiveFeedId(feed_id);
374 var query = "backend.php?op=view&id=" + param_escape(id) +
375 "&feed=" + param_escape(feed_id);
377 var date = new Date();
379 var neighbor_ids = getRelativePostIds(active_post_id);
381 /* only request uncached articles */
383 var cids_to_request = Array();
385 for (var i = 0; i < neighbor_ids.length; i++) {
386 if (!cache_check(neighbor_ids[i])) {
387 cids_to_request.push(neighbor_ids[i]);
391 debug("additional ids: " + cids_to_request.toString());
393 /* additional info for piggyback counters */
395 if (tagsAreDisplayed()) {
396 query = query + "&omode=lt";
398 query = query + "&omode=flc";
401 var date = new Date();
402 var timestamp = Math.round(date.getTime() / 1000);
403 query = query + "&ts=" + timestamp;
405 query = query + "&cids=" + cids_to_request.toString();
407 var crow = document.getElementById("RROW-" + id);
408 var article_is_unread = crow.className.match("Unread");
410 showArticleInHeadlines(id);
412 if (!cached_article) {
414 notify_progress("Loading, please wait...");
416 } else if (cached_article && article_is_unread) {
418 query = query + "&mode=prefetch";
420 render_article(cached_article);
422 } else if (cached_article) {
424 query = query + "&mode=prefetch_old";
425 render_article(cached_article);
430 new Ajax.Request(query, {
431 onComplete: function(transport) {
432 article_callback2(transport, id, feed_id);
436 exception_error("view", e);
441 return toggleMark(id);
445 return togglePub(id);
448 function tMark_afh_off(effect) {
450 var elem = effect.effects[0].element;
452 debug("tMark_afh_off : " + elem.id);
455 elem.src = elem.src.replace("mark_set", "mark_unset");
456 elem.alt = __("Star article");
461 exception_error("tMark_afh_off", e);
465 function tPub_afh_off(effect) {
467 var elem = effect.effects[0].element;
469 debug("tPub_afh_off : " + elem.id);
472 elem.src = elem.src.replace("pub_set", "pub_unset");
473 elem.alt = __("Publish article");
478 exception_error("tPub_afh_off", e);
482 function toggleMark(id, client_only, no_effects) {
486 var query = "backend.php?op=rpc&id=" + id + "&subop=mark";
488 query = query + "&afid=" + getActiveFeedId();
490 if (tagsAreDisplayed()) {
491 query = query + "&omode=tl";
493 query = query + "&omode=flc";
496 var mark_img = document.getElementById("FMPIC-" + id);
497 var vfeedu = document.getElementById("FEEDU--1");
498 var crow = document.getElementById("RROW-" + id);
500 if (mark_img.src.match("mark_unset")) {
501 mark_img.src = mark_img.src.replace("mark_unset", "mark_set");
502 mark_img.alt = __("Unstar article");
503 query = query + "&mark=1";
505 /* if (vfeedu && crow.className.match("Unread")) {
506 vfeedu.innerHTML = (+vfeedu.innerHTML) + 1;
510 //mark_img.src = "images/mark_unset.png";
511 mark_img.alt = __("Please wait...");
512 query = query + "&mark=0";
514 /* if (vfeedu && crow.className.match("Unread")) {
515 vfeedu.innerHTML = (+vfeedu.innerHTML) - 1;
518 if (document.getElementById("headlinesList") && !no_effects) {
519 Effect.Puff(mark_img, {duration : 0.25, afterFinish: tMark_afh_off});
521 mark_img.src = mark_img.src.replace("mark_set", "mark_unset");
522 mark_img.alt = __("Star article");
526 /* var vfeedctr = document.getElementById("FEEDCTR--1");
527 var vfeedr = document.getElementById("FEEDR--1");
529 if (vfeedu && vfeedctr) {
530 if ((+vfeedu.innerHTML) > 0) {
531 if (crow.className.match("Unread") && !vfeedr.className.match("Unread")) {
532 vfeedr.className = vfeedr.className + "Unread";
533 vfeedctr.className = "odd";
536 vfeedctr.className = "invisible";
537 vfeedr.className = vfeedr.className.replace("Unread", "");
541 debug("toggle starred for aid " + id);
543 //new Ajax.Request(query); */
548 new Ajax.Request(query, {
549 onComplete: function(transport) {
550 all_counters_callback2(transport);
556 exception_error("toggleMark", e);
560 function togglePub(id, client_only, no_effects) {
564 var query = "backend.php?op=rpc&id=" + id + "&subop=publ";
566 query = query + "&afid=" + getActiveFeedId();
568 if (tagsAreDisplayed()) {
569 query = query + "&omode=tl";
571 query = query + "&omode=flc";
574 var mark_img = document.getElementById("FPPIC-" + id);
575 var vfeedu = document.getElementById("FEEDU--2");
576 var crow = document.getElementById("RROW-" + id);
578 if (mark_img.src.match("pub_unset")) {
579 mark_img.src = mark_img.src.replace("pub_unset", "pub_set");
580 mark_img.alt = __("Unpublish article");
581 query = query + "&pub=1";
583 /* if (vfeedu && crow.className.match("Unread")) {
584 vfeedu.innerHTML = (+vfeedu.innerHTML) + 1;
588 //mark_img.src = "images/pub_unset.png";
589 mark_img.alt = __("Please wait...");
590 query = query + "&pub=0";
592 /* if (vfeedu && crow.className.match("Unread")) {
593 vfeedu.innerHTML = (+vfeedu.innerHTML) - 1;
596 if (document.getElementById("headlinesList") && !no_effects) {
597 Effect.Puff(mark_img, {duration : 0.25, afterFinish: tPub_afh_off});
599 mark_img.src = mark_img.src.replace("pub_set", "pub_unset");
600 mark_img.alt = __("Publish article");
604 /* var vfeedctr = document.getElementById("FEEDCTR--2");
605 var vfeedr = document.getElementById("FEEDR--2");
607 if (vfeedu && vfeedctr) {
608 if ((+vfeedu.innerHTML) > 0) {
609 if (crow.className.match("Unread") && !vfeedr.className.match("Unread")) {
610 vfeedr.className = vfeedr.className + "Unread";
611 vfeedctr.className = "odd";
614 vfeedctr.className = "invisible";
615 vfeedr.className = vfeedr.className.replace("Unread", "");
619 debug("toggle published for aid " + id);
621 new Ajax.Request(query); */
624 new Ajax.Request(query, {
625 onComplete: function(transport) {
626 all_counters_callback2(transport);
632 exception_error("togglePub", e);
636 function correctHeadlinesOffset(id) {
640 var hlist = document.getElementById("headlinesList");
641 var container = document.getElementById("headlinesInnerContainer");
642 var row = document.getElementById("RROW-" + id);
644 var viewport = container.offsetHeight;
646 var rel_offset_top = row.offsetTop - container.scrollTop;
647 var rel_offset_bottom = row.offsetTop + row.offsetHeight - container.scrollTop;
649 debug("Rtop: " + rel_offset_top + " Rbtm: " + rel_offset_bottom);
650 debug("Vport: " + viewport);
652 if (rel_offset_top <= 0 || rel_offset_top > viewport) {
653 container.scrollTop = row.offsetTop;
654 } else if (rel_offset_bottom > viewport) {
656 /* doesn't properly work with Opera in some cases because
657 Opera fucks up element scrolling */
659 container.scrollTop = row.offsetTop + row.offsetHeight - viewport;
663 exception_error("correctHeadlinesOffset", e);
668 function moveToPost(mode) {
670 // check for combined mode
671 if (!document.getElementById("headlinesList"))
674 var rows = getVisibleHeadlineIds();
679 if (!document.getElementById('RROW-' + active_post_id)) {
680 active_post_id = false;
683 if (active_post_id == false) {
684 next_id = getFirstVisibleHeadlineId();
685 prev_id = getLastVisibleHeadlineId();
687 for (var i = 0; i < rows.length; i++) {
688 if (rows[i] == active_post_id) {
695 if (mode == "next") {
697 correctHeadlinesOffset(next_id);
698 view(next_id, getActiveFeedId());
702 if (mode == "prev") {
704 correctHeadlinesOffset(prev_id);
705 view(prev_id, getActiveFeedId());
710 function toggleUnread(id, cmode) {
713 var row = document.getElementById("RROW-" + id);
715 var nc = row.className;
716 nc = nc.replace("Unread", "");
717 nc = nc.replace("Selected", "");
719 if (cmode == undefined || cmode == 2) {
720 if (row.className.match("Unread")) {
723 row.className = nc + "Unread";
725 } else if (cmode == 0) {
727 } else if (cmode == 1) {
728 row.className = nc + "Unread";
731 if (cmode == undefined) cmode = 2;
733 var query = "backend.php?op=rpc&subop=catchupSelected&ids=" +
734 param_escape(id) + "&cmode=" + param_escape(cmode);
736 // notify_progress("Loading, please wait...");
738 new Ajax.Request(query, {
739 onComplete: function(transport) {
740 all_counters_callback2(transport);
747 exception_error("toggleUnread", e);
751 function selectionToggleUnread(cdm_mode, set_state, callback_func, no_error) {
756 rows = cdmGetSelectedArticles();
758 rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
761 if (rows.length == 0 && !no_error) {
762 alert(__("No articles are selected."));
766 for (i = 0; i < rows.length; i++) {
767 var row = document.getElementById("RROW-" + rows[i]);
769 var nc = row.className;
770 nc = nc.replace("Unread", "");
771 nc = nc.replace("Selected", "");
773 if (set_state == undefined) {
774 if (row.className.match("Unread")) {
775 row.className = nc + "Selected";
777 row.className = nc + "UnreadSelected";
781 if (set_state == false) {
782 row.className = nc + "Selected";
785 if (set_state == true) {
786 row.className = nc + "UnreadSelected";
791 if (rows.length > 0) {
795 if (set_state == undefined) {
797 } else if (set_state == true) {
799 } else if (set_state == false) {
803 var query = "backend.php?op=rpc&subop=catchupSelected&ids=" +
804 param_escape(rows.toString()) + "&cmode=" + cmode;
806 notify_progress("Loading, please wait...");
808 new Ajax.Request(query, {
809 onComplete: function(transport) {
810 catchup_callback2(transport, callback_func);
816 exception_error("selectionToggleUnread", e);
820 function selectionToggleMarked(cdm_mode) {
826 rows = cdmGetSelectedArticles();
828 rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
831 if (rows.length == 0) {
832 alert(__("No articles are selected."));
836 for (i = 0; i < rows.length; i++) {
837 toggleMark(rows[i], true, true);
840 if (rows.length > 0) {
842 var query = "backend.php?op=rpc&subop=markSelected&ids=" +
843 param_escape(rows.toString()) + "&cmode=2";
845 query = query + "&afid=" + getActiveFeedId();
847 /* if (tagsAreDisplayed()) {
848 query = query + "&omode=tl";
850 query = query + "&omode=flc";
853 query = query + "&omode=lc";
855 new Ajax.Request(query, {
856 onComplete: function(transport) {
857 all_counters_callback2(transport);
863 exception_error("selectionToggleMarked", e);
867 function selectionTogglePublished(cdm_mode) {
873 rows = cdmGetSelectedArticles();
875 rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
878 if (rows.length == 0) {
879 alert(__("No articles are selected."));
883 for (i = 0; i < rows.length; i++) {
884 togglePub(rows[i], true, true);
887 if (rows.length > 0) {
889 var query = "backend.php?op=rpc&subop=publishSelected&ids=" +
890 param_escape(rows.toString()) + "&cmode=2";
892 query = query + "&afid=" + getActiveFeedId();
894 /* if (tagsAreDisplayed()) {
895 query = query + "&omode=tl";
897 query = query + "&omode=flc";
900 query = query + "&omode=lc";
902 new Ajax.Request(query, {
903 onComplete: function(transport) {
904 all_counters_callback2(transport);
910 exception_error("selectionToggleMarked", e);
914 function cdmGetSelectedArticles() {
915 var sel_articles = new Array();
916 var container = document.getElementById("headlinesInnerContainer");
918 for (i = 0; i < container.childNodes.length; i++) {
919 var child = container.childNodes[i];
921 if (child.id.match("RROW-") && child.className.match("Selected")) {
922 var c_id = child.id.replace("RROW-", "");
923 sel_articles.push(c_id);
930 function cdmGetVisibleArticles() {
931 var sel_articles = new Array();
932 var container = document.getElementById("headlinesInnerContainer");
934 for (i = 0; i < container.childNodes.length; i++) {
935 var child = container.childNodes[i];
937 if (child.id.match("RROW-")) {
938 var c_id = child.id.replace("RROW-", "");
939 sel_articles.push(c_id);
946 function cdmGetUnreadArticles() {
947 var sel_articles = new Array();
948 var container = document.getElementById("headlinesInnerContainer");
950 for (i = 0; i < container.childNodes.length; i++) {
951 var child = container.childNodes[i];
953 if (child.id.match("RROW-") && child.className.match("Unread")) {
954 var c_id = child.id.replace("RROW-", "");
955 sel_articles.push(c_id);
963 // mode = all,none,unread
964 function cdmSelectArticles(mode) {
965 var container = document.getElementById("headlinesInnerContainer");
967 for (i = 0; i < container.childNodes.length; i++) {
968 var child = container.childNodes[i];
970 if (child.id.match("RROW-")) {
971 var aid = child.id.replace("RROW-", "");
973 var cb = document.getElementById("RCHK-" + aid);
976 if (!child.className.match("Selected")) {
977 child.className = child.className + "Selected";
980 } else if (mode == "unread") {
981 if (child.className.match("Unread") && !child.className.match("Selected")) {
982 child.className = child.className + "Selected";
986 child.className = child.className.replace("Selected", "");
993 function catchupPage() {
995 var fn = getFeedName(getActiveFeedId(), active_feed_is_cat);
997 var str = __("Mark all visible articles in %s as read?");
999 str = str.replace("%s", fn);
1001 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
1005 if (document.getElementById("headlinesList")) {
1006 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, 'Unread', true);
1007 selectionToggleUnread(false, false, 'viewCurrentFeed()', true);
1008 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
1010 cdmSelectArticles('all');
1011 selectionToggleUnread(true, false, 'viewCurrentFeed()', true)
1012 cdmSelectArticles('none');
1016 function catchupSelection() {
1022 if (document.getElementById("headlinesList")) {
1023 rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
1025 rows = cdmGetSelectedArticles();
1028 if (rows.length == 0) {
1029 alert(__("No articles are selected."));
1034 var fn = getFeedName(getActiveFeedId(), active_feed_is_cat);
1036 var str = __("Mark %d selected articles in %s as read?");
1038 str = str.replace("%d", rows.length);
1039 str = str.replace("%s", fn);
1041 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
1045 if (document.getElementById("headlinesList")) {
1046 selectionToggleUnread(false, false, 'viewCurrentFeed()', true);
1047 // selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
1049 selectionToggleUnread(true, false, 'viewCurrentFeed()', true)
1050 // cdmSelectArticles('none');
1054 exception_error("catchupSelection", e);
1059 function labelFromSearch(search, search_mode, match_on, feed_id, is_cat) {
1061 if (!xmlhttp_ready(xmlhttp_rpc)) {
1062 printLockingError();
1065 var title = prompt(__("Please enter label title:"), "");
1069 var query = "backend.php?op=labelFromSearch&search=" + param_escape(search) +
1070 "&smode=" + param_escape(search_mode) + "&match=" + param_escape(match_on) +
1071 "&feed=" + param_escape(feed_id) + "&is_cat=" + param_escape(is_cat) +
1072 "&title=" + param_escape(title);
1074 debug("LFS: " + query);
1076 new Ajax.Request(query, {
1077 onComplete: function(transport) {
1078 dlg_frefresh_callback(transport);
1083 function editArticleTags(id, feed_id, cdm_enabled) {
1084 _tag_active_post_id = id;
1085 _tag_active_feed_id = feed_id;
1086 _tag_active_cdm = cdm_enabled;
1088 cache_invalidate(id);
1091 _tag_cdm_scroll = document.getElementById("headlinesInnerContainer").scrollTop;
1093 displayDlg('editArticleTags', id);
1097 function tag_saved_callback(transport) {
1099 debug("in tag_saved_callback");
1104 if (tagsAreDisplayed()) {
1105 _reload_feedlist_after_view = true;
1108 if (!_tag_active_cdm) {
1109 if (active_post_id == _tag_active_post_id) {
1110 debug("reloading current article");
1111 view(_tag_active_post_id, _tag_active_feed_id);
1114 debug("reloading current feed");
1119 exception_error("catchup_callback", e);
1123 function editTagsSave() {
1125 notify_progress("Saving article tags...");
1127 var form = document.forms["tag_edit_form"];
1129 var query = Form.serialize("tag_edit_form");
1131 query = "backend.php?op=rpc&subop=setArticleTags&" + query;
1135 new Ajax.Request(query, {
1136 onComplete: function(transport) {
1137 tag_saved_callback(transport);
1142 function editTagsInsert() {
1145 var form = document.forms["tag_edit_form"];
1147 var found_tags = form.found_tags;
1148 var tags_str = form.tags_str;
1150 var tag = found_tags[found_tags.selectedIndex].value;
1152 if (tags_str.value.length > 0 &&
1153 tags_str.value.lastIndexOf(", ") != tags_str.value.length - 2) {
1155 tags_str.value = tags_str.value + ", ";
1158 tags_str.value = tags_str.value + tag + ", ";
1160 found_tags.selectedIndex = 0;
1163 exception_error(e, "editTagsInsert");
1167 function cdmWatchdog() {
1171 var ctr = document.getElementById("headlinesInnerContainer");
1175 var ids = new Array();
1177 var e = ctr.firstChild;
1180 if (e.className && e.className == "cdmArticleUnread" && e.id &&
1181 e.id.match("RROW-")) {
1183 // article fits in viewport OR article is longer than viewport and
1184 // its bottom is visible
1186 if (ctr.scrollTop <= e.offsetTop && e.offsetTop + e.offsetHeight <=
1187 ctr.scrollTop + ctr.offsetHeight) {
1189 // debug(e.id + " is visible " + e.offsetTop + "." +
1190 // (e.offsetTop + e.offsetHeight) + " vs " + ctr.scrollTop + "." +
1191 // (ctr.scrollTop + ctr.offsetHeight));
1193 ids.push(e.id.replace("RROW-", ""));
1195 } else if (e.offsetHeight > ctr.offsetHeight &&
1196 e.offsetTop + e.offsetHeight >= ctr.scrollTop &&
1197 e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight) {
1199 ids.push(e.id.replace("RROW-", ""));
1203 // method 2: article bottom is visible and is in upper 1/2 of the viewport
1205 /* if (e.offsetTop + e.offsetHeight >= ctr.scrollTop &&
1206 e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight/2) {
1208 ids.push(e.id.replace("RROW-", ""));
1217 debug("cdmWatchdog, ids= " + ids.toString());
1219 if (ids.length > 0) {
1221 for (var i = 0; i < ids.length; i++) {
1222 var e = document.getElementById("RROW-" + ids[i]);
1224 e.className = e.className.replace("Unread", "");
1228 var query = "backend.php?op=rpc&subop=catchupSelected&ids=" +
1229 param_escape(ids.toString()) + "&cmode=0";
1231 new Ajax.Request(query, {
1232 onComplete: function(transport) {
1233 all_counters_callback2(transport);
1238 _cdm_wd_timeout = window.setTimeout("cdmWatchdog()", 4000);
1241 exception_error(e, "cdmWatchdog");
1247 function cache_inject(id, article, param) {
1248 if (!cache_check_param(id, param)) {
1249 debug("cache_article: miss: " + id + " [p=" + param + "]");
1251 var cache_obj = new Array();
1253 cache_obj["id"] = id;
1254 cache_obj["data"] = article;
1255 cache_obj["param"] = param;
1257 article_cache.push(cache_obj);
1260 debug("cache_article: hit: " + id + " [p=" + param + "]");
1264 function cache_find(id) {
1265 for (var i = 0; i < article_cache.length; i++) {
1266 if (article_cache[i]["id"] == id) {
1267 return article_cache[i]["data"];
1273 function cache_find_param(id, param) {
1274 for (var i = 0; i < article_cache.length; i++) {
1275 if (article_cache[i]["id"] == id && article_cache[i]["param"] == param) {
1276 return article_cache[i]["data"];
1282 function cache_check(id) {
1283 for (var i = 0; i < article_cache.length; i++) {
1284 if (article_cache[i]["id"] == id) {
1291 function cache_check_param(id, param) {
1292 for (var i = 0; i < article_cache.length; i++) {
1294 // debug("cache_check_param " + article_cache[i]["id"] + ":" +
1295 // article_cache[i]["param"] + " vs " + id + ":" + param);
1297 if (article_cache[i]["id"] == id && article_cache[i]["param"] == param) {
1304 function cache_expire() {
1305 while (article_cache.length > 20) {
1306 article_cache.shift();
1310 function cache_invalidate(id) {
1315 while (i < article_cache.length) {
1316 if (article_cache[i]["id"] == id) {
1317 debug("cache_invalidate: removed id " + id);
1318 article_cache.splice(i, 1);
1323 debug("cache_invalidate: id not found: " + id);
1326 exception_error("cache_invalidate", e);
1330 function getActiveArticleId() {
1331 return active_post_id;
1334 function cdmMouseIn(elem) {
1336 if (elem.id && elem.id.match("RROW-")) {
1337 var id = elem.id.replace("RROW-", "");
1338 active_post_id = id;
1341 exception_error("cdmMouseIn", e);
1346 function cdmMouseOut(elem) {
1347 active_post_id = false;
1350 function headlines_scroll_handler() {
1353 var e = document.getElementById("headlinesInnerContainer");
1355 // don't do infinite scrolling when Limit == All
1357 var toolbar_form = document.forms["main_toolbar_form"];
1359 var limit = toolbar_form.limit[toolbar_form.limit.selectedIndex];
1360 if (limit.value != 0) {
1361 if (e.scrollTop + e.offsetHeight > e.scrollHeight - 50) {
1362 if (!_infscroll_disable) {
1363 debug("more cowbell!");
1370 exception_error("headlines_scroll_handler", e);
1374 function catchupRelativeToArticle(below) {
1378 if (!xmlhttp_ready(xmlhttp_rpc)) {
1379 printLockingError();
1382 if (!getActiveArticleId()) {
1383 alert(__("No article is selected."));
1389 if (document.getElementById("headlinesList")) {
1390 visible_ids = getVisibleHeadlineIds();
1392 visible_ids = cdmGetVisibleArticles();
1395 var ids_to_mark = new Array();
1398 for (var i = 0; i < visible_ids.length; i++) {
1399 if (visible_ids[i] != getActiveArticleId()) {
1400 var e = document.getElementById("RROW-" + visible_ids[i]);
1402 if (e && e.className.match("Unread")) {
1403 ids_to_mark.push(visible_ids[i]);
1410 for (var i = visible_ids.length-1; i >= 0; i--) {
1411 if (visible_ids[i] != getActiveArticleId()) {
1412 var e = document.getElementById("RROW-" + visible_ids[i]);
1414 if (e && e.className.match("Unread")) {
1415 ids_to_mark.push(visible_ids[i]);
1423 if (ids_to_mark.length == 0) {
1424 alert(__("No articles found to mark"));
1426 var msg = __("Mark %d article(s) as read?").replace("%d", ids_to_mark.length);
1430 for (var i = 0; i < ids_to_mark.length; i++) {
1431 var e = document.getElementById("RROW-" + ids_to_mark[i]);
1432 e.className = e.className.replace("Unread", "");
1435 var query = "backend.php?op=rpc&subop=catchupSelected&ids=" +
1436 param_escape(ids_to_mark.toString()) + "&cmode=0";
1438 new Ajax.Request(query, {
1439 onComplete: function(transport) {
1440 catchup_callback2(transport);
1447 exception_error("catchupRelativeToArticle", e);
1451 function cdmExpandArticle(a_id) {
1453 var id = 'CICD-' + a_id;
1455 Effect.Appear(id, {duration : 0.5,
1456 beforeStart: function(effect) {
1457 var h_id = 'CICH-' + a_id;
1458 var h_elem = document.getElementById(h_id);
1459 if (h_elem) { h_elem.style.display = "none"; }
1461 toggleUnread(a_id, 0);
1466 exception_error("appearBlockElementF", e);