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_callback2(transport, active_feed_id, is_cat, feed_cur_page) {
51 debug("headlines_callback2 [page=" + feed_cur_page + "]");
53 var feeds = document.getElementById("feedList").getElementsByTagName("LI");
55 for (var i = 0; i < feeds.length; i++) {
56 if (feeds[i].id && feeds[i].id.match("FEEDR-")) {
57 feeds[i].className = feeds[i].className.replace("Selected", "");
61 setActiveFeedId(active_feed_id);
63 if (is_cat != undefined) {
64 active_feed_is_cat = is_cat;
68 var feedr = document.getElementById("FEEDR-" + active_feed_id);
69 if (feedr && !feedr.className.match("Selected")) {
70 feedr.className = feedr.className + "Selected";
74 var f = document.getElementById("headlines-frame");
76 if (feed_cur_page == 0) {
77 debug("resetting headlines scrollTop");
82 if (transport.responseXML) {
83 var headlines = transport.responseXML.getElementsByTagName("headlines")[0];
84 var headlines_count_obj = transport.responseXML.getElementsByTagName("headlines-count")[0];
86 var headlines_count = headlines_count_obj.getAttribute("value");
88 if (headlines_count == 0) _infscroll_disable = 1;
90 var counters = transport.responseXML.getElementsByTagName("counters")[0];
91 var articles = transport.responseXML.getElementsByTagName("article");
92 var runtime_info = transport.responseXML.getElementsByTagName("runtime-info");
94 if (feed_cur_page == 0) {
96 f.innerHTML = headlines.firstChild.nodeValue;
98 debug("headlines_callback: returned no data");
99 f.innerHTML = "<div class='whiteBox'>" + __('Could not update headlines (missing XML data)') + "</div>";
104 if (headlines_count > 0) {
105 debug("adding some more headlines...");
107 var c = document.getElementById("headlinesList");
110 c = document.getElementById("headlinesInnerContainer");
113 c.innerHTML = c.innerHTML + headlines.firstChild.nodeValue;
115 debug("no new headlines received");
118 debug("headlines_callback: returned no data");
119 notify_error("Error while trying to load more headlines");
125 for (var i = 0; i < articles.length; i++) {
126 var a_id = articles[i].getAttribute("id");
127 debug("found id: " + a_id);
128 cache_inject(a_id, articles[i].firstChild.nodeValue);
131 debug("no cached articles received");
135 debug("parsing piggybacked counters: " + counters);
136 parse_counters(counters, false);
138 debug("counters container not found in reply");
142 debug("parsing runtime info: " + runtime_info[0]);
143 parse_runtime_info(runtime_info[0]);
145 debug("counters container not found in reply");
149 debug("headlines_callback: returned no XML object");
150 f.innerHTML = "<div class='whiteBox'>" + __('Could not update headlines (missing XML object)') + "</div>";
153 if (typeof correctPNG != 'undefined') {
157 if (_cdm_wd_timeout) window.clearTimeout(_cdm_wd_timeout);
159 if (!document.getElementById("headlinesList") &&
160 getInitParam("cdm_auto_catchup") == 1) {
161 debug("starting CDM watchdog");
162 _cdm_wd_timeout = window.setTimeout("cdmWatchdog()", 5000);
163 _cdm_wd_vishist = new Array();
165 debug("not in CDM mode or watchdog disabled");
168 if (_tag_cdm_scroll) {
170 document.getElementById("headlinesInnerContainer").scrollTop = _tag_cdm_scroll;
171 _tag_cdm_scroll = false;
172 debug("resetting headlinesInner scrollTop");
177 _feed_cur_page = feed_cur_page;
181 exception_error("headlines_callback2", e);
185 function render_article(article) {
187 var f = document.getElementById("content-frame");
192 f.innerHTML = article;
195 exception_error("render_article", e);
199 function showArticleInHeadlines(id) {
203 cleanSelected("headlinesList");
205 var crow = document.getElementById("RROW-" + id);
206 var article_is_unread = crow.className.match("Unread");
208 crow.className = crow.className.replace("Unread", "");
210 var upd_img_pic = document.getElementById("FUPDPIC-" + id);
213 upd_img_pic.src = "images/blank_icon.gif";
216 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
220 exception_error("showArticleInHeadlines", e);
224 function article_callback2(transport, id, feed_id) {
226 debug("article_callback2 " + id);
228 if (transport.responseXML) {
230 active_real_feed_id = feed_id;
233 showArticleInHeadlines(id);
235 var reply = transport.responseXML.firstChild.firstChild;
237 var articles = transport.responseXML.getElementsByTagName("article");
239 for (var i = 0; i < articles.length; i++) {
240 var a_id = articles[i].getAttribute("id");
242 debug("found id: " + a_id);
244 if (a_id == active_post_id) {
245 debug("active article, rendering...");
246 render_article(articles[i].firstChild.nodeValue);
249 cache_inject(a_id, articles[i].firstChild.nodeValue);
253 debug("article_callback: returned no XML object");
254 var f = document.getElementById("content-frame");
255 f.innerHTML = "<div class='whiteBox'>" + __('Could not display article (missing XML object)') + "</div>";
258 var date = new Date();
259 last_article_view = date.getTime() / 1000;
261 if (typeof correctPNG != 'undefined') {
265 if (_reload_feedlist_after_view) {
266 setTimeout('updateFeedList(false, false)', 50);
267 _reload_feedlist_after_view = false;
269 var counters = transport.responseXML.getElementsByTagName("counters")[0];
272 debug("parsing piggybacked counters: " + counters);
273 parse_counters(counters, false);
275 debug("counters container not found in reply");
281 exception_error("article_callback2", e);
285 function view(id, feed_id, skip_history) {
288 debug("loading article: " + id + "/" + feed_id);
290 var cached_article = cache_find(id);
292 debug("cache check result: " + (cached_article != false));
296 //setActiveFeedId(feed_id);
298 var query = "backend.php?op=view&id=" + param_escape(id) +
299 "&feed=" + param_escape(feed_id);
301 var date = new Date();
303 /* if (!xmlhttp_ready(xmlhttp) && last_article_view < date.getTime() / 1000 - 15) {
304 debug("<b>xmlhttp seems to be stuck at view, aborting</b>");
307 debug("trying alternative reset method for Safari");
308 xmlhttp = Ajax.getTransport();
312 if (xmlhttp_ready(xmlhttp)) { */
314 var neighbor_ids = getRelativePostIds(active_post_id);
316 /* only request uncached articles */
318 var cids_to_request = Array();
320 for (var i = 0; i < neighbor_ids.length; i++) {
321 if (!cache_check(neighbor_ids[i])) {
322 cids_to_request.push(neighbor_ids[i]);
326 debug("additional ids: " + cids_to_request.toString());
328 /* additional info for piggyback counters */
330 if (tagsAreDisplayed()) {
331 query = query + "&omode=lt";
333 query = query + "&omode=flc";
336 var date = new Date();
337 var timestamp = Math.round(date.getTime() / 1000);
338 query = query + "&ts=" + timestamp;
340 query = query + "&cids=" + cids_to_request.toString();
342 var crow = document.getElementById("RROW-" + id);
343 var article_is_unread = crow.className.match("Unread");
345 showArticleInHeadlines(id);
347 if (!cached_article) {
349 notify_progress("Loading, please wait...");
351 } else if (cached_article && article_is_unread) {
353 query = query + "&mode=prefetch";
355 render_article(cached_article);
357 } else if (cached_article) {
359 query = query + "&mode=prefetch_old";
360 render_article(cached_article);
365 new Ajax.Request(query, {
366 onComplete: function(transport) {
367 article_callback2(transport, id, feed_id);
371 exception_error("view", e);
376 return toggleMark(id);
380 return togglePub(id);
383 function tMark_afh_off(effect) {
385 var elem = effect.effects[0].element;
387 debug("tMark_afh_off : " + elem.id);
390 elem.src = elem.src.replace("mark_set", "mark_unset");
391 elem.alt = __("Star article");
396 exception_error("tMark_afh_off", e);
400 function tPub_afh_off(effect) {
402 var elem = effect.effects[0].element;
404 debug("tPub_afh_off : " + elem.id);
407 elem.src = elem.src.replace("pub_set", "pub_unset");
408 elem.alt = __("Publish article");
413 exception_error("tPub_afh_off", e);
417 function toggleMark(id, client_only, no_effects) {
421 var query = "backend.php?op=rpc&id=" + id + "&subop=mark";
423 query = query + "&afid=" + getActiveFeedId();
425 if (tagsAreDisplayed()) {
426 query = query + "&omode=tl";
428 query = query + "&omode=flc";
431 var mark_img = document.getElementById("FMPIC-" + id);
432 var vfeedu = document.getElementById("FEEDU--1");
433 var crow = document.getElementById("RROW-" + id);
435 if (mark_img.src.match("mark_unset")) {
436 mark_img.src = mark_img.src.replace("mark_unset", "mark_set");
437 mark_img.alt = __("Unstar article");
438 query = query + "&mark=1";
440 /* if (vfeedu && crow.className.match("Unread")) {
441 vfeedu.innerHTML = (+vfeedu.innerHTML) + 1;
445 //mark_img.src = "images/mark_unset.png";
446 mark_img.alt = __("Please wait...");
447 query = query + "&mark=0";
449 /* if (vfeedu && crow.className.match("Unread")) {
450 vfeedu.innerHTML = (+vfeedu.innerHTML) - 1;
453 if (document.getElementById("headlinesList") && !no_effects) {
454 Effect.Puff(mark_img, {duration : 0.25, afterFinish: tMark_afh_off});
456 mark_img.src = mark_img.src.replace("mark_set", "mark_unset");
457 mark_img.alt = __("Star article");
461 /* var vfeedctr = document.getElementById("FEEDCTR--1");
462 var vfeedr = document.getElementById("FEEDR--1");
464 if (vfeedu && vfeedctr) {
465 if ((+vfeedu.innerHTML) > 0) {
466 if (crow.className.match("Unread") && !vfeedr.className.match("Unread")) {
467 vfeedr.className = vfeedr.className + "Unread";
468 vfeedctr.className = "odd";
471 vfeedctr.className = "invisible";
472 vfeedr.className = vfeedr.className.replace("Unread", "");
476 debug("toggle starred for aid " + id);
478 //new Ajax.Request(query); */
483 new Ajax.Request(query, {
484 onComplete: function(transport) {
485 all_counters_callback2(transport);
491 exception_error("toggleMark", e);
495 function togglePub(id, client_only, no_effects) {
499 var query = "backend.php?op=rpc&id=" + id + "&subop=publ";
501 query = query + "&afid=" + getActiveFeedId();
503 if (tagsAreDisplayed()) {
504 query = query + "&omode=tl";
506 query = query + "&omode=flc";
509 var mark_img = document.getElementById("FPPIC-" + id);
510 var vfeedu = document.getElementById("FEEDU--2");
511 var crow = document.getElementById("RROW-" + id);
513 if (mark_img.src.match("pub_unset")) {
514 mark_img.src = mark_img.src.replace("pub_unset", "pub_set");
515 mark_img.alt = __("Unpublish article");
516 query = query + "&pub=1";
518 /* if (vfeedu && crow.className.match("Unread")) {
519 vfeedu.innerHTML = (+vfeedu.innerHTML) + 1;
523 //mark_img.src = "images/pub_unset.png";
524 mark_img.alt = __("Please wait...");
525 query = query + "&pub=0";
527 /* if (vfeedu && crow.className.match("Unread")) {
528 vfeedu.innerHTML = (+vfeedu.innerHTML) - 1;
531 if (document.getElementById("headlinesList") && !no_effects) {
532 Effect.Puff(mark_img, {duration : 0.25, afterFinish: tPub_afh_off});
534 mark_img.src = mark_img.src.replace("pub_set", "pub_unset");
535 mark_img.alt = __("Publish article");
539 /* var vfeedctr = document.getElementById("FEEDCTR--2");
540 var vfeedr = document.getElementById("FEEDR--2");
542 if (vfeedu && vfeedctr) {
543 if ((+vfeedu.innerHTML) > 0) {
544 if (crow.className.match("Unread") && !vfeedr.className.match("Unread")) {
545 vfeedr.className = vfeedr.className + "Unread";
546 vfeedctr.className = "odd";
549 vfeedctr.className = "invisible";
550 vfeedr.className = vfeedr.className.replace("Unread", "");
554 debug("toggle published for aid " + id);
556 new Ajax.Request(query); */
559 new Ajax.Request(query, {
560 onComplete: function(transport) {
561 all_counters_callback2(transport);
567 exception_error("togglePub", e);
571 function correctHeadlinesOffset(id) {
575 var hlist = document.getElementById("headlinesList");
576 var container = document.getElementById("headlinesInnerContainer");
577 var row = document.getElementById("RROW-" + id);
579 var viewport = container.offsetHeight;
581 var rel_offset_top = row.offsetTop - container.scrollTop;
582 var rel_offset_bottom = row.offsetTop + row.offsetHeight - container.scrollTop;
584 debug("Rtop: " + rel_offset_top + " Rbtm: " + rel_offset_bottom);
585 debug("Vport: " + viewport);
587 if (rel_offset_top <= 0 || rel_offset_top > viewport) {
588 container.scrollTop = row.offsetTop;
589 } else if (rel_offset_bottom > viewport) {
591 /* doesn't properly work with Opera in some cases because
592 Opera fucks up element scrolling */
594 container.scrollTop = row.offsetTop + row.offsetHeight - viewport;
598 exception_error("correctHeadlinesOffset", e);
603 function moveToPost(mode) {
605 // check for combined mode
606 if (!document.getElementById("headlinesList"))
609 var rows = getVisibleHeadlineIds();
614 if (!document.getElementById('RROW-' + active_post_id)) {
615 active_post_id = false;
618 if (active_post_id == false) {
619 next_id = getFirstVisibleHeadlineId();
620 prev_id = getLastVisibleHeadlineId();
622 for (var i = 0; i < rows.length; i++) {
623 if (rows[i] == active_post_id) {
630 if (mode == "next") {
632 correctHeadlinesOffset(next_id);
633 view(next_id, getActiveFeedId());
637 if (mode == "prev") {
639 correctHeadlinesOffset(prev_id);
640 view(prev_id, getActiveFeedId());
645 function toggleUnread(id, cmode) {
648 var row = document.getElementById("RROW-" + id);
650 var nc = row.className;
651 nc = nc.replace("Unread", "");
652 nc = nc.replace("Selected", "");
654 if (row.className.match("Unread")) {
657 row.className = nc + "Unread";
660 if (!cmode) cmode = 2;
662 var query = "backend.php?op=rpc&subop=catchupSelected&ids=" +
663 param_escape(id) + "&cmode=" + param_escape(cmode);
665 // notify_progress("Loading, please wait...");
667 new Ajax.Request(query, {
668 onComplete: function(transport) {
669 all_counters_callback2(transport);
676 exception_error("toggleUnread", e);
680 function selectionToggleUnread(cdm_mode, set_state, callback_func, no_error) {
682 /* if (!xmlhttp_ready(xmlhttp_rpc)) {
690 rows = cdmGetSelectedArticles();
692 rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
695 if (rows.length == 0 && !no_error) {
696 alert(__("No articles are selected."));
700 for (i = 0; i < rows.length; i++) {
701 var row = document.getElementById("RROW-" + rows[i]);
703 var nc = row.className;
704 nc = nc.replace("Unread", "");
705 nc = nc.replace("Selected", "");
707 if (set_state == undefined) {
708 if (row.className.match("Unread")) {
709 row.className = nc + "Selected";
711 row.className = nc + "UnreadSelected";
715 if (set_state == false) {
716 row.className = nc + "Selected";
719 if (set_state == true) {
720 row.className = nc + "UnreadSelected";
725 if (rows.length > 0) {
729 if (set_state == undefined) {
731 } else if (set_state == true) {
733 } else if (set_state == false) {
737 var query = "backend.php?op=rpc&subop=catchupSelected&ids=" +
738 param_escape(rows.toString()) + "&cmode=" + cmode;
740 // _catchup_callback_func = callback_func;
742 debug(callback_func);
744 notify_progress("Loading, please wait...");
746 /* xmlhttp_rpc.open("GET", query, true);
747 xmlhttp_rpc.onreadystatechange=catchup_callback;
748 xmlhttp_rpc.send(null); */
750 new Ajax.Request(query, {
751 onComplete: function(transport) {
752 catchup_callback2(transport, callback_func);
758 exception_error("selectionToggleUnread", e);
762 function selectionToggleMarked(cdm_mode) {
768 rows = cdmGetSelectedArticles();
770 rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
773 if (rows.length == 0) {
774 alert(__("No articles are selected."));
778 for (i = 0; i < rows.length; i++) {
779 toggleMark(rows[i], true, true);
782 if (rows.length > 0) {
784 var query = "backend.php?op=rpc&subop=markSelected&ids=" +
785 param_escape(rows.toString()) + "&cmode=2";
787 query = query + "&afid=" + getActiveFeedId();
789 /* if (tagsAreDisplayed()) {
790 query = query + "&omode=tl";
792 query = query + "&omode=flc";
795 query = query + "&omode=lc";
797 new Ajax.Request(query, {
798 onComplete: function(transport) {
799 all_counters_callback2(transport);
805 exception_error("selectionToggleMarked", e);
809 function selectionTogglePublished(cdm_mode) {
815 rows = cdmGetSelectedArticles();
817 rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
820 if (rows.length == 0) {
821 alert(__("No articles are selected."));
825 for (i = 0; i < rows.length; i++) {
826 togglePub(rows[i], true, true);
829 if (rows.length > 0) {
831 var query = "backend.php?op=rpc&subop=publishSelected&ids=" +
832 param_escape(rows.toString()) + "&cmode=2";
834 query = query + "&afid=" + getActiveFeedId();
836 /* if (tagsAreDisplayed()) {
837 query = query + "&omode=tl";
839 query = query + "&omode=flc";
842 query = query + "&omode=lc";
844 new Ajax.Request(query, {
845 onComplete: function(transport) {
846 all_counters_callback2(transport);
852 exception_error("selectionToggleMarked", e);
856 function cdmGetSelectedArticles() {
857 var sel_articles = new Array();
858 var container = document.getElementById("headlinesInnerContainer");
860 for (i = 0; i < container.childNodes.length; i++) {
861 var child = container.childNodes[i];
863 if (child.id.match("RROW-") && child.className.match("Selected")) {
864 var c_id = child.id.replace("RROW-", "");
865 sel_articles.push(c_id);
872 function cdmGetVisibleArticles() {
873 var sel_articles = new Array();
874 var container = document.getElementById("headlinesInnerContainer");
876 for (i = 0; i < container.childNodes.length; i++) {
877 var child = container.childNodes[i];
879 if (child.id.match("RROW-")) {
880 var c_id = child.id.replace("RROW-", "");
881 sel_articles.push(c_id);
888 function cdmGetUnreadArticles() {
889 var sel_articles = new Array();
890 var container = document.getElementById("headlinesInnerContainer");
892 for (i = 0; i < container.childNodes.length; i++) {
893 var child = container.childNodes[i];
895 if (child.id.match("RROW-") && child.className.match("Unread")) {
896 var c_id = child.id.replace("RROW-", "");
897 sel_articles.push(c_id);
905 // mode = all,none,unread
906 function cdmSelectArticles(mode) {
907 var container = document.getElementById("headlinesInnerContainer");
909 for (i = 0; i < container.childNodes.length; i++) {
910 var child = container.childNodes[i];
912 if (child.id.match("RROW-")) {
913 var aid = child.id.replace("RROW-", "");
915 var cb = document.getElementById("RCHK-" + aid);
918 if (!child.className.match("Selected")) {
919 child.className = child.className + "Selected";
922 } else if (mode == "unread") {
923 if (child.className.match("Unread") && !child.className.match("Selected")) {
924 child.className = child.className + "Selected";
928 child.className = child.className.replace("Selected", "");
935 function catchupPage() {
937 var fn = getFeedName(getActiveFeedId(), active_feed_is_cat);
939 var str = __("Mark all visible articles in %s as read?");
941 str = str.replace("%s", fn);
943 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
947 if (document.getElementById("headlinesList")) {
948 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, 'Unread', true);
949 selectionToggleUnread(false, false, 'viewCurrentFeed()', true);
950 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
952 cdmSelectArticles('all');
953 selectionToggleUnread(true, false, 'viewCurrentFeed()', true)
954 cdmSelectArticles('none');
958 function catchupSelection() {
964 if (document.getElementById("headlinesList")) {
965 rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
967 rows = cdmGetSelectedArticles();
970 if (rows.length == 0) {
971 alert(__("No articles are selected."));
976 var fn = getFeedName(getActiveFeedId(), active_feed_is_cat);
978 var str = __("Mark %d selected articles in %s as read?");
980 str = str.replace("%d", rows.length);
981 str = str.replace("%s", fn);
983 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
987 if (document.getElementById("headlinesList")) {
988 selectionToggleUnread(false, false, 'viewCurrentFeed()', true);
989 // selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
991 selectionToggleUnread(true, false, 'viewCurrentFeed()', true)
992 // cdmSelectArticles('none');
996 exception_error("catchupSelection", e);
1001 function labelFromSearch(search, search_mode, match_on, feed_id, is_cat) {
1003 if (!xmlhttp_ready(xmlhttp_rpc)) {
1004 printLockingError();
1007 var title = prompt(__("Please enter label title:"), "");
1011 var query = "backend.php?op=labelFromSearch&search=" + param_escape(search) +
1012 "&smode=" + param_escape(search_mode) + "&match=" + param_escape(match_on) +
1013 "&feed=" + param_escape(feed_id) + "&is_cat=" + param_escape(is_cat) +
1014 "&title=" + param_escape(title);
1016 debug("LFS: " + query);
1018 xmlhttp_rpc.open("GET", query, true);
1019 xmlhttp_rpc.onreadystatechange=dlg_frefresh_callback;
1020 xmlhttp_rpc.send(null);
1025 function editArticleTags(id, feed_id, cdm_enabled) {
1026 _tag_active_post_id = id;
1027 _tag_active_feed_id = feed_id;
1028 _tag_active_cdm = cdm_enabled;
1030 cache_invalidate(id);
1033 _tag_cdm_scroll = document.getElementById("headlinesInnerContainer").scrollTop;
1035 displayDlg('editArticleTags', id);
1039 function tag_saved_callback() {
1040 if (xmlhttp_rpc.readyState == 4) {
1042 debug("in tag_saved_callback");
1047 if (tagsAreDisplayed()) {
1048 _reload_feedlist_after_view = true;
1051 if (!_tag_active_cdm) {
1052 if (active_post_id == _tag_active_post_id) {
1053 debug("reloading current article");
1054 view(_tag_active_post_id, _tag_active_feed_id);
1057 debug("reloading current feed");
1062 exception_error("catchup_callback", e);
1067 function editTagsSave() {
1069 if (!xmlhttp_ready(xmlhttp_rpc)) {
1070 printLockingError();
1073 notify_progress("Saving article tags...");
1075 var form = document.forms["tag_edit_form"];
1077 var query = Form.serialize("tag_edit_form");
1079 query = "backend.php?op=rpc&subop=setArticleTags&" + query;
1083 xmlhttp_rpc.open("GET", query, true);
1084 xmlhttp_rpc.onreadystatechange=tag_saved_callback;
1085 xmlhttp_rpc.send(null);
1089 function editTagsInsert() {
1092 var form = document.forms["tag_edit_form"];
1094 var found_tags = form.found_tags;
1095 var tags_str = form.tags_str;
1097 var tag = found_tags[found_tags.selectedIndex].value;
1099 if (tags_str.value.length > 0 &&
1100 tags_str.value.lastIndexOf(", ") != tags_str.value.length - 2) {
1102 tags_str.value = tags_str.value + ", ";
1105 tags_str.value = tags_str.value + tag + ", ";
1107 found_tags.selectedIndex = 0;
1110 exception_error(e, "editTagsInsert");
1114 function cdmWatchdog() {
1118 var ctr = document.getElementById("headlinesInnerContainer");
1122 var ids = new Array();
1124 var e = ctr.firstChild;
1127 if (e.className && e.className == "cdmArticleUnread" && e.id &&
1128 e.id.match("RROW-")) {
1130 // article fits in viewport OR article is longer than viewport and
1131 // its bottom is visible
1133 if (ctr.scrollTop <= e.offsetTop && e.offsetTop + e.offsetHeight <=
1134 ctr.scrollTop + ctr.offsetHeight) {
1136 // debug(e.id + " is visible " + e.offsetTop + "." +
1137 // (e.offsetTop + e.offsetHeight) + " vs " + ctr.scrollTop + "." +
1138 // (ctr.scrollTop + ctr.offsetHeight));
1140 ids.push(e.id.replace("RROW-", ""));
1142 } else if (e.offsetHeight > ctr.offsetHeight &&
1143 e.offsetTop + e.offsetHeight >= ctr.scrollTop &&
1144 e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight) {
1146 ids.push(e.id.replace("RROW-", ""));
1150 // method 2: article bottom is visible and is in upper 1/2 of the viewport
1152 /* if (e.offsetTop + e.offsetHeight >= ctr.scrollTop &&
1153 e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight/2) {
1155 ids.push(e.id.replace("RROW-", ""));
1164 debug("cdmWatchdog, ids= " + ids.toString());
1166 if (ids.length > 0) {
1168 for (var i = 0; i < ids.length; i++) {
1169 var e = document.getElementById("RROW-" + ids[i]);
1171 e.className = e.className.replace("Unread", "");
1175 var query = "backend.php?op=rpc&subop=catchupSelected&ids=" +
1176 param_escape(ids.toString()) + "&cmode=0";
1178 new Ajax.Request(query, {
1179 onComplete: function(transport) {
1180 all_counters_callback2(transport);
1185 _cdm_wd_timeout = window.setTimeout("cdmWatchdog()", 4000);
1188 exception_error(e, "cdmWatchdog");
1194 function cache_inject(id, article) {
1195 if (!cache_check(id)) {
1196 debug("cache_article: miss: " + id);
1198 var cache_obj = new Array();
1200 cache_obj["id"] = id;
1201 cache_obj["data"] = article;
1203 article_cache.push(cache_obj);
1206 debug("cache_article: hit: " + id);
1210 function cache_find(id) {
1211 for (var i = 0; i < article_cache.length; i++) {
1212 if (article_cache[i]["id"] == id) {
1213 return article_cache[i]["data"];
1219 function cache_check(id) {
1220 for (var i = 0; i < article_cache.length; i++) {
1221 if (article_cache[i]["id"] == id) {
1228 function cache_expire() {
1229 while (article_cache.length > 20) {
1230 article_cache.shift();
1234 function cache_invalidate(id) {
1239 while (i < article_cache.length) {
1240 if (article_cache[i]["id"] == id) {
1241 debug("cache_invalidate: removed id " + id);
1242 article_cache.splice(i, 1);
1247 debug("cache_invalidate: id not found: " + id);
1250 exception_error("cache_invalidate", e);
1254 function getActiveArticleId() {
1255 return active_post_id;
1258 function cdmMouseIn(elem) {
1260 if (elem.id && elem.id.match("RROW-")) {
1261 var id = elem.id.replace("RROW-", "");
1262 active_post_id = id;
1265 exception_error("cdmMouseIn", e);
1270 function cdmMouseOut(elem) {
1271 active_post_id = false;
1274 function headlines_scroll_handler() {
1277 var e = document.getElementById("headlinesInnerContainer");
1279 if (e.scrollTop + e.offsetHeight > e.scrollHeight - 300) {
1280 if (!_infscroll_disable) {
1281 debug("more cowbell!");
1287 exception_error("headlines_scroll_handler", e);
1291 function catchupRelativeToArticle(below) {
1295 if (!xmlhttp_ready(xmlhttp_rpc)) {
1296 printLockingError();
1299 if (!getActiveArticleId()) {
1300 alert(__("No article is selected."));
1306 if (document.getElementById("headlinesList")) {
1307 visible_ids = getVisibleHeadlineIds();
1309 visible_ids = cdmGetVisibleArticles();
1312 var ids_to_mark = new Array();
1315 for (var i = 0; i < visible_ids.length; i++) {
1316 if (visible_ids[i] != getActiveArticleId()) {
1317 var e = document.getElementById("RROW-" + visible_ids[i]);
1319 if (e && e.className.match("Unread")) {
1320 ids_to_mark.push(visible_ids[i]);
1327 for (var i = visible_ids.length-1; i >= 0; i--) {
1328 if (visible_ids[i] != getActiveArticleId()) {
1329 var e = document.getElementById("RROW-" + visible_ids[i]);
1331 if (e && e.className.match("Unread")) {
1332 ids_to_mark.push(visible_ids[i]);
1340 if (ids_to_mark.length == 0) {
1341 alert(__("No articles found to mark"));
1343 var msg = __("Mark %d article(s) as read?").replace("%d", ids_to_mark.length);
1347 for (var i = 0; i < ids_to_mark.length; i++) {
1348 var e = document.getElementById("RROW-" + ids_to_mark[i]);
1349 e.className = e.className.replace("Unread", "");
1352 var query = "backend.php?op=rpc&subop=catchupSelected&ids=" +
1353 param_escape(ids_to_mark.toString()) + "&cmode=0";
1355 xmlhttp_rpc.open("GET", query, true);
1356 xmlhttp_rpc.onreadystatechange=catchup_callback;
1357 xmlhttp_rpc.send(null);
1363 exception_error("catchupRelativeToArticle", e);