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 headlines_callback() {
49 if (xmlhttp.readyState == 4) {
50 debug("headlines_callback");
51 var f = document.getElementById("headlines-frame");
53 if (feed_cur_page == 0) {
54 debug("resetting headlines scrollTop");
59 if (xmlhttp.responseXML) {
60 var headlines = xmlhttp.responseXML.getElementsByTagName("headlines")[0];
61 var counters = xmlhttp.responseXML.getElementsByTagName("counters")[0];
62 var articles = xmlhttp.responseXML.getElementsByTagName("article");
63 var runtime_info = xmlhttp.responseXML.getElementsByTagName("runtime-info");
65 if (feed_cur_page == 0) {
67 f.innerHTML = headlines.firstChild.nodeValue;
69 debug("headlines_callback: returned no data");
70 f.innerHTML = "<div class='whiteBox'>" + __('Could not update headlines (missing XML data)') + "</div>";
75 debug("adding some more headlines...");
77 var c = document.getElementById("headlinesList");
80 c = document.getElementById("headlinesInnerContainer");
83 c.innerHTML = c.innerHTML + headlines.firstChild.nodeValue;
85 debug("headlines_callback: returned no data");
86 notify_error("Error while trying to load more headlines");
92 for (var i = 0; i < articles.length; i++) {
93 var a_id = articles[i].getAttribute("id");
94 debug("found id: " + a_id);
95 cache_inject(a_id, articles[i].firstChild.nodeValue);
98 debug("no cached articles received");
102 debug("parsing piggybacked counters: " + counters);
103 parse_counters(counters, false);
105 debug("counters container not found in reply");
109 debug("parsing runtime info: " + runtime_info[0]);
110 parse_runtime_info(runtime_info[0]);
112 debug("counters container not found in reply");
116 debug("headlines_callback: returned no XML object");
117 f.innerHTML = "<div class='whiteBox'>" + __('Could not update headlines (missing XML object)') + "</div>";
120 if (typeof correctPNG != 'undefined') {
124 if (_cdm_wd_timeout) window.clearTimeout(_cdm_wd_timeout);
126 if (!document.getElementById("headlinesList") &&
127 getInitParam("cdm_auto_catchup") == 1) {
128 debug("starting CDM watchdog");
129 _cdm_wd_timeout = window.setTimeout("cdmWatchdog()", 5000);
130 _cdm_wd_vishist = new Array();
132 debug("not in CDM mode or watchdog disabled");
135 if (_tag_cdm_scroll) {
137 document.getElementById("headlinesInnerContainer").scrollTop = _tag_cdm_scroll;
138 _tag_cdm_scroll = false;
139 debug("resetting headlinesInner scrollTop");
148 function render_article(article) {
150 var f = document.getElementById("content-frame");
155 f.innerHTML = article;
158 exception_error("render_article", e);
162 function article_callback() {
163 if (xmlhttp.readyState == 4) {
164 debug("article_callback");
167 if (xmlhttp.responseXML) {
168 var reply = xmlhttp.responseXML.firstChild.firstChild;
170 var articles = xmlhttp.responseXML.getElementsByTagName("article");
172 for (var i = 0; i < articles.length; i++) {
173 var a_id = articles[i].getAttribute("id");
175 debug("found id: " + a_id);
177 if (a_id == active_post_id) {
178 debug("active article, rendering...");
179 render_article(articles[i].firstChild.nodeValue);
182 cache_inject(a_id, articles[i].firstChild.nodeValue);
186 debug("article_callback: returned no XML object");
187 var f = document.getElementById("content-frame");
188 f.innerHTML = "<div class='whiteBox'>" + __('Could not display article (missing XML object)') + "</div>";
191 exception_error("article_callback", e);
194 var date = new Date();
195 last_article_view = date.getTime() / 1000;
197 if (typeof correctPNG != 'undefined') {
201 if (_reload_feedlist_after_view) {
202 setTimeout('updateFeedList(false, false)', 50);
203 _reload_feedlist_after_view = false;
205 var counters = xmlhttp.responseXML.getElementsByTagName("counters")[0];
208 debug("parsing piggybacked counters: " + counters);
209 parse_counters(counters, false);
211 debug("counters container not found in reply");
219 function view(id, feed_id, skip_history) {
222 debug("loading article: " + id + "/" + feed_id);
224 active_real_feed_id = feed_id;
226 var cached_article = cache_find(id);
228 debug("cache check result: " + (cached_article != false));
232 //setActiveFeedId(feed_id);
234 var query = "backend.php?op=view&id=" + param_escape(id) +
235 "&feed=" + param_escape(feed_id);
237 var date = new Date();
239 if (!xmlhttp_ready(xmlhttp) && last_article_view < date.getTime() / 1000 - 15) {
240 debug("<b>xmlhttp seems to be stuck at view, aborting</b>");
243 debug("trying alternative reset method for Safari");
244 xmlhttp = Ajax.getTransport();
248 if (xmlhttp_ready(xmlhttp)) {
252 cleanSelected("headlinesList");
254 var crow = document.getElementById("RROW-" + active_post_id);
256 var article_is_unread = crow.className.match("Unread");
257 debug("article is unread: " + article_is_unread);
259 crow.className = crow.className.replace("Unread", "");
261 var upd_img_pic = document.getElementById("FUPDPIC-" + active_post_id);
264 upd_img_pic.src = "images/blank_icon.gif";
267 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
268 markHeadline(active_post_id);
270 var neighbor_ids = getRelativePostIds(active_post_id);
272 /* only request uncached articles */
274 var cids_to_request = Array();
276 for (var i = 0; i < neighbor_ids.length; i++) {
277 if (!cache_check(neighbor_ids[i])) {
278 cids_to_request.push(neighbor_ids[i]);
282 debug("additional ids: " + cids_to_request.toString());
284 /* additional info for piggyback counters */
286 if (tagsAreDisplayed()) {
287 query = query + "&omode=lt";
289 query = query + "&omode=flc";
292 var date = new Date();
293 var timestamp = Math.round(date.getTime() / 1000);
294 query = query + "&ts=" + timestamp;
296 query = query + "&cids=" + cids_to_request.toString();
298 if (!cached_article) {
300 notify_progress("Loading, please wait...");
304 xmlhttp.open("GET", query, true);
305 xmlhttp.onreadystatechange=article_callback;
307 } else if (cached_article && article_is_unread) {
309 query = query + "&mode=prefetch";
313 xmlhttp.open("GET", query, true);
314 xmlhttp.onreadystatechange=article_callback;
317 render_article(cached_article);
319 } else if (cached_article) {
321 query = query + "&mode=prefetch_old";
325 xmlhttp.open("GET", query, true);
326 xmlhttp.onreadystatechange=article_callback;
329 render_article(cached_article);
336 debug("xmlhttp busy (@view)");
341 exception_error("view", e);
346 return toggleMark(id);
350 return togglePub(id);
353 function tMark_afh_off(effect) {
355 var elem = effect.effects[0].element;
357 debug("tMark_afh_off : " + elem.id);
360 elem.src = elem.src.replace("mark_set", "mark_unset");
361 elem.alt = __("Star article");
366 exception_error("tMark_afh_off", e);
370 function tPub_afh_off(effect) {
372 var elem = effect.effects[0].element;
374 debug("tPub_afh_off : " + elem.id);
377 elem.src = elem.src.replace("pub_set", "pub_unset");
378 elem.alt = __("Publish article");
383 exception_error("tPub_afh_off", e);
387 function toggleMark(id, client_only, no_effects) {
391 var query = "backend.php?op=rpc&id=" + id + "&subop=mark";
393 query = query + "&afid=" + getActiveFeedId();
395 if (tagsAreDisplayed()) {
396 query = query + "&omode=tl";
398 query = query + "&omode=flc";
401 var mark_img = document.getElementById("FMPIC-" + id);
402 var vfeedu = document.getElementById("FEEDU--1");
403 var crow = document.getElementById("RROW-" + id);
405 if (mark_img.src.match("mark_unset")) {
406 mark_img.src = mark_img.src.replace("mark_unset", "mark_set");
407 mark_img.alt = __("Unstar article");
408 query = query + "&mark=1";
410 /* if (vfeedu && crow.className.match("Unread")) {
411 vfeedu.innerHTML = (+vfeedu.innerHTML) + 1;
415 //mark_img.src = "images/mark_unset.png";
416 mark_img.alt = __("Please wait...");
417 query = query + "&mark=0";
419 /* if (vfeedu && crow.className.match("Unread")) {
420 vfeedu.innerHTML = (+vfeedu.innerHTML) - 1;
423 if (document.getElementById("headlinesList") && !no_effects) {
424 Effect.Puff(mark_img, {duration : 0.25, afterFinish: tMark_afh_off});
426 mark_img.src = mark_img.src.replace("mark_set", "mark_unset");
427 mark_img.alt = __("Star article");
431 /* var vfeedctr = document.getElementById("FEEDCTR--1");
432 var vfeedr = document.getElementById("FEEDR--1");
434 if (vfeedu && vfeedctr) {
435 if ((+vfeedu.innerHTML) > 0) {
436 if (crow.className.match("Unread") && !vfeedr.className.match("Unread")) {
437 vfeedr.className = vfeedr.className + "Unread";
438 vfeedctr.className = "odd";
441 vfeedctr.className = "invisible";
442 vfeedr.className = vfeedr.className.replace("Unread", "");
446 debug("toggle starred for aid " + id);
448 //new Ajax.Request(query); */
453 new Ajax.Request(query, {
454 onComplete: function(transport) {
455 all_counters_callback2(transport);
461 exception_error("toggleMark", e);
465 function togglePub(id, client_only, no_effects) {
469 var query = "backend.php?op=rpc&id=" + id + "&subop=publ";
471 query = query + "&afid=" + getActiveFeedId();
473 if (tagsAreDisplayed()) {
474 query = query + "&omode=tl";
476 query = query + "&omode=flc";
479 var mark_img = document.getElementById("FPPIC-" + id);
480 var vfeedu = document.getElementById("FEEDU--2");
481 var crow = document.getElementById("RROW-" + id);
483 if (mark_img.src.match("pub_unset")) {
484 mark_img.src = mark_img.src.replace("pub_unset", "pub_set");
485 mark_img.alt = __("Unpublish article");
486 query = query + "&pub=1";
488 /* if (vfeedu && crow.className.match("Unread")) {
489 vfeedu.innerHTML = (+vfeedu.innerHTML) + 1;
493 //mark_img.src = "images/pub_unset.png";
494 mark_img.alt = __("Please wait...");
495 query = query + "&pub=0";
497 /* if (vfeedu && crow.className.match("Unread")) {
498 vfeedu.innerHTML = (+vfeedu.innerHTML) - 1;
501 if (document.getElementById("headlinesList") && !no_effects) {
502 Effect.Puff(mark_img, {duration : 0.25, afterFinish: tPub_afh_off});
504 mark_img.src = mark_img.src.replace("pub_set", "pub_unset");
505 mark_img.alt = __("Publish article");
509 /* var vfeedctr = document.getElementById("FEEDCTR--2");
510 var vfeedr = document.getElementById("FEEDR--2");
512 if (vfeedu && vfeedctr) {
513 if ((+vfeedu.innerHTML) > 0) {
514 if (crow.className.match("Unread") && !vfeedr.className.match("Unread")) {
515 vfeedr.className = vfeedr.className + "Unread";
516 vfeedctr.className = "odd";
519 vfeedctr.className = "invisible";
520 vfeedr.className = vfeedr.className.replace("Unread", "");
524 debug("toggle published for aid " + id);
526 new Ajax.Request(query); */
529 new Ajax.Request(query, {
530 onComplete: function(transport) {
531 all_counters_callback2(transport);
537 exception_error("togglePub", e);
541 function correctHeadlinesOffset(id) {
545 var hlist = document.getElementById("headlinesList");
546 var container = document.getElementById("headlinesInnerContainer");
547 var row = document.getElementById("RROW-" + id);
549 var viewport = container.offsetHeight;
551 var rel_offset_top = row.offsetTop - container.scrollTop;
552 var rel_offset_bottom = row.offsetTop + row.offsetHeight - container.scrollTop;
554 debug("Rtop: " + rel_offset_top + " Rbtm: " + rel_offset_bottom);
555 debug("Vport: " + viewport);
557 if (rel_offset_top <= 0 || rel_offset_top > viewport) {
558 container.scrollTop = row.offsetTop;
559 } else if (rel_offset_bottom > viewport) {
561 /* doesn't properly work with Opera in some cases because
562 Opera fucks up element scrolling */
564 container.scrollTop = row.offsetTop + row.offsetHeight - viewport;
568 exception_error("correctHeadlinesOffset", e);
573 function moveToPost(mode) {
575 // check for combined mode
576 if (!document.getElementById("headlinesList"))
579 var rows = getVisibleHeadlineIds();
584 if (!document.getElementById('RROW-' + active_post_id)) {
585 active_post_id = false;
588 if (active_post_id == false) {
589 next_id = getFirstVisibleHeadlineId();
590 prev_id = getLastVisibleHeadlineId();
592 for (var i = 0; i < rows.length; i++) {
593 if (rows[i] == active_post_id) {
600 if (mode == "next") {
602 correctHeadlinesOffset(next_id);
603 view(next_id, getActiveFeedId());
607 if (mode == "prev") {
609 correctHeadlinesOffset(prev_id);
610 view(prev_id, getActiveFeedId());
615 function toggleUnread(id, cmode) {
618 var row = document.getElementById("RROW-" + id);
620 var nc = row.className;
621 nc = nc.replace("Unread", "");
622 nc = nc.replace("Selected", "");
624 if (row.className.match("Unread")) {
627 row.className = nc + "Unread";
630 if (!cmode) cmode = 2;
632 var query = "backend.php?op=rpc&subop=catchupSelected&ids=" +
633 param_escape(id) + "&cmode=" + param_escape(cmode);
635 // notify_progress("Loading, please wait...");
637 new Ajax.Request(query, {
638 onComplete: function(transport) {
639 all_counters_callback2(transport);
646 exception_error("toggleUnread", e);
650 function selectionToggleUnread(cdm_mode, set_state, callback_func, no_error) {
652 /* if (!xmlhttp_ready(xmlhttp_rpc)) {
660 rows = cdmGetSelectedArticles();
662 rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
665 if (rows.length == 0 && !no_error) {
666 alert(__("No articles are selected."));
670 for (i = 0; i < rows.length; i++) {
671 var row = document.getElementById("RROW-" + rows[i]);
673 var nc = row.className;
674 nc = nc.replace("Unread", "");
675 nc = nc.replace("Selected", "");
677 if (set_state == undefined) {
678 if (row.className.match("Unread")) {
679 row.className = nc + "Selected";
681 row.className = nc + "UnreadSelected";
685 if (set_state == false) {
686 row.className = nc + "Selected";
689 if (set_state == true) {
690 row.className = nc + "UnreadSelected";
695 if (rows.length > 0) {
699 if (set_state == undefined) {
701 } else if (set_state == true) {
703 } else if (set_state == false) {
707 var query = "backend.php?op=rpc&subop=catchupSelected&ids=" +
708 param_escape(rows.toString()) + "&cmode=" + cmode;
710 // _catchup_callback_func = callback_func;
712 debug(callback_func);
714 notify_progress("Loading, please wait...");
716 /* xmlhttp_rpc.open("GET", query, true);
717 xmlhttp_rpc.onreadystatechange=catchup_callback;
718 xmlhttp_rpc.send(null); */
720 new Ajax.Request(query, {
721 onComplete: function(transport) {
722 catchup_callback2(transport, callback_func);
728 exception_error("selectionToggleUnread", e);
732 function selectionToggleMarked(cdm_mode) {
738 rows = cdmGetSelectedArticles();
740 rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
743 if (rows.length == 0) {
744 alert(__("No articles are selected."));
748 for (i = 0; i < rows.length; i++) {
749 toggleMark(rows[i], true, true);
752 if (rows.length > 0) {
754 var query = "backend.php?op=rpc&subop=markSelected&ids=" +
755 param_escape(rows.toString()) + "&cmode=2";
757 query = query + "&afid=" + getActiveFeedId();
759 /* if (tagsAreDisplayed()) {
760 query = query + "&omode=tl";
762 query = query + "&omode=flc";
765 query = query + "&omode=lc";
767 new Ajax.Request(query, {
768 onComplete: function(transport) {
769 all_counters_callback2(transport);
775 exception_error("selectionToggleMarked", e);
779 function selectionTogglePublished(cdm_mode) {
785 rows = cdmGetSelectedArticles();
787 rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
790 if (rows.length == 0) {
791 alert(__("No articles are selected."));
795 for (i = 0; i < rows.length; i++) {
796 togglePub(rows[i], true, true);
799 if (rows.length > 0) {
801 var query = "backend.php?op=rpc&subop=publishSelected&ids=" +
802 param_escape(rows.toString()) + "&cmode=2";
804 query = query + "&afid=" + getActiveFeedId();
806 /* if (tagsAreDisplayed()) {
807 query = query + "&omode=tl";
809 query = query + "&omode=flc";
812 query = query + "&omode=lc";
814 new Ajax.Request(query, {
815 onComplete: function(transport) {
816 all_counters_callback2(transport);
822 exception_error("selectionToggleMarked", e);
826 function cdmGetSelectedArticles() {
827 var sel_articles = new Array();
828 var container = document.getElementById("headlinesInnerContainer");
830 for (i = 0; i < container.childNodes.length; i++) {
831 var child = container.childNodes[i];
833 if (child.id.match("RROW-") && child.className.match("Selected")) {
834 var c_id = child.id.replace("RROW-", "");
835 sel_articles.push(c_id);
842 function cdmGetVisibleArticles() {
843 var sel_articles = new Array();
844 var container = document.getElementById("headlinesInnerContainer");
846 for (i = 0; i < container.childNodes.length; i++) {
847 var child = container.childNodes[i];
849 if (child.id.match("RROW-")) {
850 var c_id = child.id.replace("RROW-", "");
851 sel_articles.push(c_id);
858 function cdmGetUnreadArticles() {
859 var sel_articles = new Array();
860 var container = document.getElementById("headlinesInnerContainer");
862 for (i = 0; i < container.childNodes.length; i++) {
863 var child = container.childNodes[i];
865 if (child.id.match("RROW-") && child.className.match("Unread")) {
866 var c_id = child.id.replace("RROW-", "");
867 sel_articles.push(c_id);
875 // mode = all,none,unread
876 function cdmSelectArticles(mode) {
877 var container = document.getElementById("headlinesInnerContainer");
879 for (i = 0; i < container.childNodes.length; i++) {
880 var child = container.childNodes[i];
882 if (child.id.match("RROW-")) {
883 var aid = child.id.replace("RROW-", "");
885 var cb = document.getElementById("RCHK-" + aid);
888 if (!child.className.match("Selected")) {
889 child.className = child.className + "Selected";
892 } else if (mode == "unread") {
893 if (child.className.match("Unread") && !child.className.match("Selected")) {
894 child.className = child.className + "Selected";
898 child.className = child.className.replace("Selected", "");
905 function catchupPage() {
907 var fn = getFeedName(getActiveFeedId(), active_feed_is_cat);
909 var str = __("Mark all visible articles in %s as read?");
911 str = str.replace("%s", fn);
913 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
917 if (document.getElementById("headlinesList")) {
918 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, 'Unread', true);
919 selectionToggleUnread(false, false, 'viewCurrentFeed()', true);
920 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
922 cdmSelectArticles('all');
923 selectionToggleUnread(true, false, 'viewCurrentFeed()', true)
924 cdmSelectArticles('none');
928 function catchupSelection() {
934 if (document.getElementById("headlinesList")) {
935 rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
937 rows = cdmGetSelectedArticles();
940 if (rows.length == 0) {
941 alert(__("No articles are selected."));
946 var fn = getFeedName(getActiveFeedId(), active_feed_is_cat);
948 var str = __("Mark all selected articles in %s as read?");
950 str = str.replace("%s", fn);
952 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
956 if (document.getElementById("headlinesList")) {
957 selectionToggleUnread(false, false, 'viewCurrentFeed()', true);
958 // selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
960 selectionToggleUnread(true, false, 'viewCurrentFeed()', true)
961 // cdmSelectArticles('none');
965 exception_error("catchupSelection", e);
970 function labelFromSearch(search, search_mode, match_on, feed_id, is_cat) {
972 if (!xmlhttp_ready(xmlhttp_rpc)) {
976 var title = prompt(__("Please enter label title:"), "");
980 var query = "backend.php?op=labelFromSearch&search=" + param_escape(search) +
981 "&smode=" + param_escape(search_mode) + "&match=" + param_escape(match_on) +
982 "&feed=" + param_escape(feed_id) + "&is_cat=" + param_escape(is_cat) +
983 "&title=" + param_escape(title);
985 debug("LFS: " + query);
987 xmlhttp_rpc.open("GET", query, true);
988 xmlhttp_rpc.onreadystatechange=dlg_frefresh_callback;
989 xmlhttp_rpc.send(null);
994 function editArticleTags(id, feed_id, cdm_enabled) {
995 _tag_active_post_id = id;
996 _tag_active_feed_id = feed_id;
997 _tag_active_cdm = cdm_enabled;
999 cache_invalidate(id);
1002 _tag_cdm_scroll = document.getElementById("headlinesInnerContainer").scrollTop;
1004 displayDlg('editArticleTags', id);
1008 function tag_saved_callback() {
1009 if (xmlhttp_rpc.readyState == 4) {
1011 debug("in tag_saved_callback");
1016 if (tagsAreDisplayed()) {
1017 _reload_feedlist_after_view = true;
1020 if (!_tag_active_cdm) {
1021 if (active_post_id == _tag_active_post_id) {
1022 debug("reloading current article");
1023 view(_tag_active_post_id, _tag_active_feed_id);
1026 debug("reloading current feed");
1031 exception_error("catchup_callback", e);
1036 function editTagsSave() {
1038 if (!xmlhttp_ready(xmlhttp_rpc)) {
1039 printLockingError();
1042 notify_progress("Saving article tags...");
1044 var form = document.forms["tag_edit_form"];
1046 var query = Form.serialize("tag_edit_form");
1048 query = "backend.php?op=rpc&subop=setArticleTags&" + query;
1052 xmlhttp_rpc.open("GET", query, true);
1053 xmlhttp_rpc.onreadystatechange=tag_saved_callback;
1054 xmlhttp_rpc.send(null);
1058 function editTagsInsert() {
1061 var form = document.forms["tag_edit_form"];
1063 var found_tags = form.found_tags;
1064 var tags_str = form.tags_str;
1066 var tag = found_tags[found_tags.selectedIndex].value;
1068 if (tags_str.value.length > 0 &&
1069 tags_str.value.lastIndexOf(", ") != tags_str.value.length - 2) {
1071 tags_str.value = tags_str.value + ", ";
1074 tags_str.value = tags_str.value + tag + ", ";
1076 found_tags.selectedIndex = 0;
1079 exception_error(e, "editTagsInsert");
1083 function cdmWatchdog() {
1087 var ctr = document.getElementById("headlinesInnerContainer");
1091 var ids = new Array();
1093 var e = ctr.firstChild;
1096 if (e.className && e.className == "cdmArticleUnread" && e.id &&
1097 e.id.match("RROW-")) {
1099 // article fits in viewport OR article is longer than viewport and
1100 // its bottom is visible
1102 if (ctr.scrollTop <= e.offsetTop && e.offsetTop + e.offsetHeight <=
1103 ctr.scrollTop + ctr.offsetHeight) {
1105 // debug(e.id + " is visible " + e.offsetTop + "." +
1106 // (e.offsetTop + e.offsetHeight) + " vs " + ctr.scrollTop + "." +
1107 // (ctr.scrollTop + ctr.offsetHeight));
1109 ids.push(e.id.replace("RROW-", ""));
1111 } else if (e.offsetHeight > ctr.offsetHeight &&
1112 e.offsetTop + e.offsetHeight >= ctr.scrollTop &&
1113 e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight) {
1115 ids.push(e.id.replace("RROW-", ""));
1119 // method 2: article bottom is visible and is in upper 1/2 of the viewport
1121 /* if (e.offsetTop + e.offsetHeight >= ctr.scrollTop &&
1122 e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight/2) {
1124 ids.push(e.id.replace("RROW-", ""));
1133 debug("cdmWatchdog, ids= " + ids.toString());
1135 if (ids.length > 0) {
1137 for (var i = 0; i < ids.length; i++) {
1138 var e = document.getElementById("RROW-" + ids[i]);
1140 e.className = e.className.replace("Unread", "");
1144 var query = "backend.php?op=rpc&subop=catchupSelected&ids=" +
1145 param_escape(ids.toString()) + "&cmode=0";
1147 new Ajax.Request(query, {
1148 onComplete: function(transport) {
1149 all_counters_callback2(transport);
1154 _cdm_wd_timeout = window.setTimeout("cdmWatchdog()", 4000);
1157 exception_error(e, "cdmWatchdog");
1163 function cache_inject(id, article) {
1164 if (!cache_check(id)) {
1165 debug("cache_article: miss: " + id);
1167 var cache_obj = new Array();
1169 cache_obj["id"] = id;
1170 cache_obj["data"] = article;
1172 article_cache.push(cache_obj);
1175 debug("cache_article: hit: " + id);
1179 function cache_find(id) {
1180 for (var i = 0; i < article_cache.length; i++) {
1181 if (article_cache[i]["id"] == id) {
1182 return article_cache[i]["data"];
1188 function cache_check(id) {
1189 for (var i = 0; i < article_cache.length; i++) {
1190 if (article_cache[i]["id"] == id) {
1197 function cache_expire() {
1198 while (article_cache.length > 20) {
1199 article_cache.shift();
1203 function cache_invalidate(id) {
1208 while (i < article_cache.length) {
1209 if (article_cache[i]["id"] == id) {
1210 debug("cache_invalidate: removed id " + id);
1211 article_cache.splice(i, 1);
1216 debug("cache_invalidate: id not found: " + id);
1219 exception_error("cache_invalidate", e);
1223 function getActiveArticleId() {
1224 return active_post_id;
1227 function cdmMouseIn(elem) {
1229 if (elem.id && elem.id.match("RROW-")) {
1230 var id = elem.id.replace("RROW-", "");
1231 active_post_id = id;
1234 exception_error("cdmMouseIn", e);
1239 function cdmMouseOut(elem) {
1240 active_post_id = false;
1243 function headlines_scroll_handler() {
1246 var e = document.getElementById("headlinesInnerContainer");
1248 if (e.scrollTop + e.offsetHeight > e.scrollHeight - 300) {
1249 debug("more cowbell!");
1255 exception_error("headlines_scroll_handler", e);
1259 function catchupRelativeToArticle(below) {
1263 if (!xmlhttp_ready(xmlhttp_rpc)) {
1264 printLockingError();
1267 if (!getActiveArticleId()) {
1268 alert(__("No article is selected."));
1274 if (document.getElementById("headlinesList")) {
1275 visible_ids = getVisibleHeadlineIds();
1277 visible_ids = cdmGetVisibleArticles();
1280 var ids_to_mark = new Array();
1283 for (var i = 0; i < visible_ids.length; i++) {
1284 if (visible_ids[i] != getActiveArticleId()) {
1285 var e = document.getElementById("RROW-" + visible_ids[i]);
1287 if (e && e.className.match("Unread")) {
1288 ids_to_mark.push(visible_ids[i]);
1295 for (var i = visible_ids.length-1; i >= 0; i--) {
1296 if (visible_ids[i] != getActiveArticleId()) {
1297 var e = document.getElementById("RROW-" + visible_ids[i]);
1299 if (e && e.className.match("Unread")) {
1300 ids_to_mark.push(visible_ids[i]);
1308 if (ids_to_mark.length == 0) {
1309 alert(__("No articles found to mark"));
1311 var msg = __("Mark %d article(s) as read?").replace("%d", ids_to_mark.length);
1315 for (var i = 0; i < ids_to_mark.length; i++) {
1316 var e = document.getElementById("RROW-" + ids_to_mark[i]);
1317 e.className = e.className.replace("Unread", "");
1320 var query = "backend.php?op=rpc&subop=catchupSelected&ids=" +
1321 param_escape(ids_to_mark.toString()) + "&cmode=0";
1323 xmlhttp_rpc.open("GET", query, true);
1324 xmlhttp_rpc.onreadystatechange=catchup_callback;
1325 xmlhttp_rpc.send(null);
1331 exception_error("catchupRelativeToArticle", e);