1 var active_post_id = false;
2 var last_article_view = false;
3 var active_real_feed_id = false;
5 var _cdm_wd_timeout = false;
6 var _cdm_wd_vishist = new Array();
8 var article_cache = new Array();
10 var vgroup_last_feed = false;
11 var post_under_pointer = false;
13 var last_requested_article = false;
15 var preload_id_batch = [];
16 var preload_timeout_id = false;
20 function catchup_callback2(transport, callback) {
22 console.log("catchup_callback2 " + transport + ", " + callback);
24 handle_rpc_reply(transport);
26 setTimeout(callback, 10);
29 exception_error("catchup_callback2", e, transport);
33 function headlines_callback2(transport, feed_cur_page) {
36 if (!handle_rpc_reply(transport)) return;
38 loading_set_progress(25);
40 console.log("headlines_callback2 [page=" + feed_cur_page + "]");
42 if (!transport_error_check(transport)) return;
47 if (transport.responseXML) {
48 var headlines = transport.responseXML.getElementsByTagName("headlines")[0];
50 is_cat = headlines.getAttribute("is_cat");
51 feed_id = headlines.getAttribute("id");
52 setActiveFeedId(feed_id, is_cat);
56 var update_btn = document.forms["main_toolbar_form"].update;
58 update_btn.disabled = !(feed_id >= 0 && !is_cat);
61 if (feed_cur_page == 0) {
62 $("headlines-frame").scrollTop = 0;
66 if (transport.responseXML) {
67 var response = transport.responseXML;
69 var headlines = response.getElementsByTagName("headlines")[0];
71 var headlines_content = headlines.getElementsByTagName("content")[0];
72 var headlines_toolbar = headlines.getElementsByTagName("toolbar")[0];
74 var headlines_info = response.getElementsByTagName("headlines-info")[0];
77 headlines_info = JSON.parse(headlines_info.firstChild.nodeValue);
79 console.error("didn't find headlines-info object in response");
83 var headlines_count = headlines_info.count;
84 var headlines_unread = headlines_info.unread;
85 var disable_cache = headlines_info.disable_cache;
87 vgroup_last_feed = headlines_info.vgroup_last_feed;
89 if (parseInt(headlines_count) < getInitParam("default_article_limit")) {
90 _infscroll_disable = 1;
92 _infscroll_disable = 0;
95 var counters = response.getElementsByTagName("counters")[0];
96 var articles = response.getElementsByTagName("article");
97 var runtime_info = response.getElementsByTagName("runtime-info");
99 if (feed_cur_page == 0) {
101 dijit.byId("headlines-frame").attr('content',
102 headlines_content.firstChild.nodeValue);
104 dijit.byId("headlines-toolbar").attr('content',
105 headlines_toolbar.firstChild.nodeValue);
107 $$("#headlines-frame a.twitter-share-button").each(
108 function(btn) { var tbtn = new twttr.TweetButton(btn);
113 var cache_prefix = "";
121 cache_invalidate(cache_prefix + feed_id);
123 if (!disable_cache) {
124 cache_inject(cache_prefix + feed_id,
125 $("headlines-frame").innerHTML, headlines_unread);
129 console.warn("headlines_callback: returned no data");
130 dijit.byId("headlines-frame").attr('content',
131 "<div class='whiteBox'>" +
132 __('Could not update headlines (missing XML data)') + "</div>");
137 if (headlines_count > 0) {
138 console.log("adding some more headlines...");
140 var c = dijit.byId("headlines-frame");
141 var ids = getSelectedArticleIds2();
143 c.attr('content', c.attr('content') +
144 headlines_content.firstChild.nodeValue);
146 $$("#headlines-frame a.twitter-share-button").each(
147 function(btn) { var tbtn = new twttr.TweetButton(btn);
150 console.log("restore selected ids: " + ids);
152 for (var i = 0; i < ids.length; i++) {
153 markHeadline(ids[i]);
159 console.log("no new headlines received");
162 console.warn("headlines_callback: returned no data");
163 notify_error("Error while trying to load more headlines");
169 for (var i = 0; i < articles.length; i++) {
170 var a_id = articles[i].getAttribute("id");
171 //console.log("found id: " + a_id);
172 cache_inject(a_id, articles[i].firstChild.nodeValue);
175 console.log("no cached articles received");
179 parse_counters(counters);
184 parse_runtime_info(runtime_info[0]);
188 console.warn("headlines_callback: returned no XML object");
189 dijit.byId("headlines-frame").attr('content', "<div class='whiteBox'>" +
190 __('Could not update headlines (missing XML object)') + "</div>");
194 if (_cdm_wd_timeout) window.clearTimeout(_cdm_wd_timeout);
197 getActiveFeedId() != -3 &&
198 getInitParam("cdm_auto_catchup") == 1) {
199 console.log("starting CDM watchdog");
200 _cdm_wd_timeout = window.setTimeout("cdmWatchdog()", 5000);
201 _cdm_wd_vishist = new Array();
203 console.log("not in CDM mode or watchdog disabled");
206 _feed_cur_page = feed_cur_page;
207 _infscroll_request_sent = 0;
212 exception_error("headlines_callback2", e, transport);
216 function render_article(article) {
218 dijit.byId("headlines-wrap-inner").addChild(
219 dijit.byId("content-insert"));
221 var c = dijit.byId("content-insert");
224 c.domNode.scrollTop = 0;
227 c.attr('content', article);
229 correctHeadlinesOffset(getActiveArticleId());
231 $$("#content-insert a.twitter-share-button").each(
232 function(btn) { var tbtn = new twttr.TweetButton(btn); tbtn.render(); });
235 exception_error("render_article", e);
239 function showArticleInHeadlines(id) {
243 selectArticles("none");
245 var crow = $("RROW-" + id);
249 var article_is_unread = crow.hasClassName("Unread");
251 crow.removeClassName("Unread");
253 selectArticles('none');
255 var upd_img_pic = $("FUPDPIC-" + id);
257 var cache_prefix = "";
259 if (activeFeedIsCat()) {
265 var view_mode = false;
268 view_mode = document.forms['main_toolbar_form'].view_mode;
269 view_mode = view_mode[view_mode.selectedIndex].value;
274 if (upd_img_pic && (upd_img_pic.src.match("updated.png") ||
275 upd_img_pic.src.match("fresh_sign.png"))) {
277 upd_img_pic.src = "images/blank_icon.gif";
279 cache_invalidate(cache_prefix + getActiveFeedId());
281 cache_inject(cache_prefix + getActiveFeedId(),
282 $("headlines-frame").innerHTML,
283 getFeedUnread(getActiveFeedId()));
285 } else if (article_is_unread && view_mode == "all_articles") {
287 cache_invalidate(cache_prefix + getActiveFeedId());
289 cache_inject(cache_prefix + getActiveFeedId(),
290 $("headlines-frame").innerHTML,
291 getFeedUnread(getActiveFeedId())-1);
293 } else if (article_is_unread) {
294 cache_invalidate(cache_prefix + getActiveFeedId());
299 if (article_is_unread)
300 _force_scheduled_update = true;
303 exception_error("showArticleInHeadlines", e);
307 function article_callback2(transport, id) {
309 console.log("article_callback2 " + id);
311 if (!handle_rpc_reply(transport)) return;
313 if (transport.responseXML) {
315 if (!transport_error_check(transport)) return;
317 var upic = $('FUPDPIC-' + id);
320 upic.src = 'images/blank_icon.gif';
323 if (id != last_requested_article) {
324 console.log("requested article id is out of sequence, aborting");
328 // active_post_id = id;
330 //console.log("looking for articles to cache...");
332 var articles = transport.responseXML.getElementsByTagName("article");
334 for (var i = 0; i < articles.length; i++) {
335 var a_id = articles[i].getAttribute("id");
337 //console.log("found id: " + a_id);
339 if (a_id == active_post_id) {
340 //console.log("active article, rendering...");
341 render_article(articles[i].firstChild.nodeValue);
344 cache_inject(a_id, articles[i].firstChild.nodeValue);
348 // showArticleInHeadlines(id);
350 var reply = transport.responseXML.firstChild.firstChild;
353 console.warn("article_callback: returned no XML object");
354 //var f = $("content-frame");
355 //f.innerHTML = "<div class='whiteBox'>" + __('Could not display article (missing XML object)') + "</div>";
358 var date = new Date();
359 last_article_view = date.getTime() / 1000;
365 exception_error("article_callback2", e, transport);
371 console.log("loading article: " + id);
373 var cached_article = cache_find(id);
375 console.log("cache check result: " + (cached_article != false));
379 var query = "?op=view&id=" + param_escape(id);
381 var neighbor_ids = getRelativePostIds(active_post_id);
383 /* only request uncached articles */
385 var cids_to_request = Array();
387 for (var i = 0; i < neighbor_ids.length; i++) {
388 if (!cache_check(neighbor_ids[i])) {
389 cids_to_request.push(neighbor_ids[i]);
393 console.log("additional ids: " + cids_to_request.toString());
395 query = query + "&cids=" + cids_to_request.toString();
397 var crow = $("RROW-" + id);
398 var article_is_unread = crow.hasClassName("Unread");
401 showArticleInHeadlines(id);
403 if (!cached_article) {
405 var upic = $('FUPDPIC-' + id);
408 upic.src = getInitParam("sign_progress");
411 } else if (cached_article && article_is_unread) {
413 query = query + "&mode=prefetch";
415 render_article(cached_article);
417 } else if (cached_article) {
419 query = query + "&mode=prefetch_old";
420 render_article(cached_article);
426 last_requested_article = id;
428 new Ajax.Request("backend.php", {
430 onComplete: function(transport) {
431 article_callback2(transport, id);
437 exception_error("view", e);
442 return toggleMark(id);
446 return togglePub(id);
449 function toggleMark(id, client_only) {
451 var query = "?op=rpc&id=" + id + "&subop=mark";
453 var img = $("FMPIC-" + id);
457 if (img.src.match("mark_unset")) {
458 img.src = img.src.replace("mark_unset", "mark_set");
459 img.alt = __("Unstar article");
460 query = query + "&mark=1";
463 img.src = img.src.replace("mark_set", "mark_unset");
464 img.alt = __("Star article");
465 query = query + "&mark=0";
469 new Ajax.Request("backend.php", {
471 onComplete: function(transport) {
472 handle_rpc_reply(transport);
477 exception_error("toggleMark", e);
481 function togglePub(id, client_only, no_effects, note) {
483 var query = "?op=rpc&id=" + id + "&subop=publ";
485 if (note != undefined) {
486 query = query + "¬e=" + param_escape(note);
488 query = query + "¬e=undefined";
491 var img = $("FPPIC-" + id);
495 if (img.src.match("pub_unset") || note != undefined) {
496 img.src = img.src.replace("pub_unset", "pub_set");
497 img.alt = __("Unpublish article");
498 query = query + "&pub=1";
501 img.src = img.src.replace("pub_set", "pub_unset");
502 img.alt = __("Publish article");
504 query = query + "&pub=0";
508 new Ajax.Request("backend.php", {
510 onComplete: function(transport) {
511 handle_rpc_reply(transport);
513 var note = transport.responseXML.getElementsByTagName("note")[0];
516 var note_id = note.getAttribute("id");
517 var note_size = note.getAttribute("size");
518 var note_content = note.firstChild.nodeValue;
520 var container = $('POSTNOTE-' + note_id);
522 cache_invalidate(note_id);
525 if (note_size == "0") {
526 Element.hide(container);
528 container.innerHTML = note_content;
529 Element.show(container);
538 exception_error("togglePub", e);
542 function moveToPost(mode) {
546 var rows = getVisibleArticleIds();
551 if (!$('RROW-' + active_post_id)) {
552 active_post_id = false;
555 if (active_post_id == false) {
556 next_id = getFirstVisibleHeadlineId();
557 prev_id = getLastVisibleHeadlineId();
559 for (var i = 0; i < rows.length; i++) {
560 if (rows[i] == active_post_id) {
567 if (mode == "next") {
571 cdmExpandArticle(next_id);
572 cdmScrollToArticleId(next_id);
575 correctHeadlinesOffset(next_id);
576 view(next_id, getActiveFeedId());
581 if (mode == "prev") {
584 cdmExpandArticle(prev_id);
585 cdmScrollToArticleId(prev_id);
587 correctHeadlinesOffset(prev_id);
588 view(prev_id, getActiveFeedId());
594 exception_error("moveToPost", e);
598 function toggleSelected(id, force_on) {
601 var cb = $("RCHK-" + id);
602 var row = $("RROW-" + id);
605 if (row.hasClassName('Selected') && !force_on) {
606 row.removeClassName('Selected');
607 if (cb) cb.checked = false;
609 row.addClassName('Selected');
610 if (cb) cb.checked = true;
614 exception_error("toggleSelected", e);
618 function toggleUnread_afh(effect) {
621 var elem = effect.element;
622 elem.style.backgroundColor = "";
625 exception_error("toggleUnread_afh", e);
629 function toggleUnread(id, cmode, effect) {
632 var row = $("RROW-" + id);
634 if (cmode == undefined || cmode == 2) {
635 if (row.hasClassName("Unread")) {
636 row.removeClassName("Unread");
639 new Effect.Highlight(row, {duration: 1, startcolor: "#fff7d5",
640 afterFinish: toggleUnread_afh,
641 queue: { position:'end', scope: 'TMRQ-' + id, limit: 1 } } );
645 row.addClassName("Unread");
648 } else if (cmode == 0) {
650 row.removeClassName("Unread");
653 new Effect.Highlight(row, {duration: 1, startcolor: "#fff7d5",
654 afterFinish: toggleUnread_afh,
655 queue: { position:'end', scope: 'TMRQ-' + id, limit: 1 } } );
658 } else if (cmode == 1) {
659 row.addClassName("Unread");
662 if (cmode == undefined) cmode = 2;
664 var query = "?op=rpc&subop=catchupSelected" +
665 "&cmode=" + param_escape(cmode) + "&ids=" + param_escape(id);
667 // notify_progress("Loading, please wait...");
669 new Ajax.Request("backend.php", {
671 onComplete: function(transport) {
672 handle_rpc_reply(transport);
678 exception_error("toggleUnread", e);
682 function selectionRemoveLabel(id, ids) {
685 if (!ids) var ids = getSelectedArticleIds2();
687 if (ids.length == 0) {
688 alert(__("No articles are selected."));
692 // var ok = confirm(__("Remove selected articles from label?"));
696 var query = "?op=rpc&subop=removeFromLabel&ids=" +
697 param_escape(ids.toString()) + "&lid=" + param_escape(id);
701 // notify_progress("Loading, please wait...");
703 cache_invalidate("F:" + (-11 - id));
705 new Ajax.Request("backend.php", {
707 onComplete: function(transport) {
708 show_labels_in_headlines(transport);
709 handle_rpc_reply(transport);
715 exception_error("selectionAssignLabel", e);
720 function selectionAssignLabel(id, ids) {
723 if (!ids) ids = getSelectedArticleIds2();
725 if (ids.length == 0) {
726 alert(__("No articles are selected."));
730 // var ok = confirm(__("Assign selected articles to label?"));
734 cache_invalidate("F:" + (-11 - id));
736 var query = "?op=rpc&subop=assignToLabel&ids=" +
737 param_escape(ids.toString()) + "&lid=" + param_escape(id);
741 // notify_progress("Loading, please wait...");
743 new Ajax.Request("backend.php", {
745 onComplete: function(transport) {
746 show_labels_in_headlines(transport);
747 handle_rpc_reply(transport);
753 exception_error("selectionAssignLabel", e);
758 function selectionToggleUnread(set_state, callback_func, no_error) {
760 var rows = getSelectedArticleIds2();
762 if (rows.length == 0 && !no_error) {
763 alert(__("No articles are selected."));
767 for (i = 0; i < rows.length; i++) {
768 var row = $("RROW-" + rows[i]);
770 if (set_state == undefined) {
771 if (row.hasClassName("Unread")) {
772 row.removeClassName("Unread");
774 row.addClassName("Unread");
778 if (set_state == false) {
779 row.removeClassName("Unread");
782 if (set_state == true) {
783 row.addClassName("Unread");
788 if (rows.length > 0) {
792 if (set_state == undefined) {
794 } else if (set_state == true) {
796 } else if (set_state == false) {
800 var query = "?op=rpc&subop=catchupSelected" +
801 "&cmode=" + cmode + "&ids=" + param_escape(rows.toString());
803 notify_progress("Loading, please wait...");
805 new Ajax.Request("backend.php", {
807 onComplete: function(transport) {
808 catchup_callback2(transport, callback_func);
814 exception_error("selectionToggleUnread", e);
818 function selectionToggleMarked() {
821 var rows = getSelectedArticleIds2();
823 if (rows.length == 0) {
824 alert(__("No articles are selected."));
828 for (i = 0; i < rows.length; i++) {
829 toggleMark(rows[i], true, true);
832 if (rows.length > 0) {
834 var query = "?op=rpc&subop=markSelected&ids=" +
835 param_escape(rows.toString()) + "&cmode=2";
837 new Ajax.Request("backend.php", {
839 onComplete: function(transport) {
840 handle_rpc_reply(transport);
846 exception_error("selectionToggleMarked", e);
850 function selectionTogglePublished() {
853 var rows = getSelectedArticleIds2();
855 if (rows.length == 0) {
856 alert(__("No articles are selected."));
860 for (i = 0; i < rows.length; i++) {
861 togglePub(rows[i], true, true);
864 if (rows.length > 0) {
866 var query = "?op=rpc&subop=publishSelected&ids=" +
867 param_escape(rows.toString()) + "&cmode=2";
869 new Ajax.Request("backend.php", {
871 onComplete: function(transport) {
872 handle_rpc_reply(transport);
878 exception_error("selectionToggleMarked", e);
882 function getSelectedArticleIds2() {
886 $$("#headlines-frame > div[id*=RROW][class*=Selected]").each(
888 rv.push(child.id.replace("RROW-", ""));
894 function getLoadedArticleIds() {
897 var children = $$("#headlines-frame > div[id*=RROW-]");
899 children.each(function(child) {
900 rv.push(child.id.replace("RROW-", ""));
907 // mode = all,none,unread,invert
908 function selectArticles(mode) {
911 var children = $$("#headlines-frame > div[id*=RROW]");
913 children.each(function(child) {
914 var id = child.id.replace("RROW-", "");
915 var cb = $("RCHK-" + id);
918 child.addClassName("Selected");
920 } else if (mode == "unread") {
921 if (child.hasClassName("Unread")) {
922 child.addClassName("Selected");
925 child.removeClassName("Selected");
928 } else if (mode == "invert") {
929 if (child.hasClassName("Selected")) {
930 child.removeClassName("Selected");
933 child.addClassName("Selected");
938 child.removeClassName("Selected");
944 exception_error("selectArticles", e);
948 function catchupPage() {
950 var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
952 var str = __("Mark all visible articles in %s as read?");
954 str = str.replace("%s", fn);
956 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
960 selectArticles('all');
961 selectionToggleUnread(false, 'viewCurrentFeed()', true)
962 selectArticles('none');
965 function deleteSelection() {
969 var rows = getSelectedArticleIds2();
971 if (rows.length == 0) {
972 alert(__("No articles are selected."));
976 var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
980 if (getActiveFeedId() != 0) {
981 str = __("Delete %d selected articles in %s?");
983 str = __("Delete %d selected articles?");
986 str = str.replace("%d", rows.length);
987 str = str.replace("%s", fn);
989 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
993 query = "?op=rpc&subop=delete&ids=" + param_escape(rows);
997 new Ajax.Request("backend.php", {
999 onComplete: function(transport) {
1004 exception_error("deleteSelection", e);
1008 function archiveSelection() {
1012 var rows = getSelectedArticleIds2();
1014 if (rows.length == 0) {
1015 alert(__("No articles are selected."));
1019 var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
1023 if (getActiveFeedId() != 0) {
1024 str = __("Archive %d selected articles in %s?");
1027 str = __("Move %d archived articles back?");
1031 str = str.replace("%d", rows.length);
1032 str = str.replace("%s", fn);
1034 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
1038 query = "?op=rpc&subop="+op+"&ids=" + param_escape(rows);
1042 for (var i = 0; i < rows.length; i++) {
1043 cache_invalidate(rows[i]);
1046 new Ajax.Request("backend.php", {
1048 onComplete: function(transport) {
1053 exception_error("archiveSelection", e);
1057 function catchupSelection() {
1061 var rows = getSelectedArticleIds2();
1063 if (rows.length == 0) {
1064 alert(__("No articles are selected."));
1068 var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
1070 var str = __("Mark %d selected articles in %s as read?");
1072 str = str.replace("%d", rows.length);
1073 str = str.replace("%s", fn);
1075 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
1079 selectionToggleUnread(false, 'viewCurrentFeed()', true)
1082 exception_error("catchupSelection", e);
1086 function editArticleTags(id, feed_id, cdm_enabled) {
1087 displayDlg('editArticleTags', id,
1089 $("tags_str").focus();
1091 new Ajax.Autocompleter('tags_str', 'tags_choices',
1092 "backend.php?op=rpc&subop=completeTags",
1093 { tokens: ',', paramName: "search" });
1097 function editTagsSave() {
1099 notify_progress("Saving article tags...");
1101 var form = document.forms["tag_edit_form"];
1103 var query = Form.serialize("tag_edit_form");
1105 query = "?op=rpc&subop=setArticleTags&" + query;
1109 new Ajax.Request("backend.php", {
1111 onComplete: function(transport) {
1113 //console.log("tags saved...");
1118 if (transport.responseXML) {
1119 var tags_str = transport.responseXML.getElementsByTagName("tags-str")[0];
1122 var id = tags_str.getAttribute("id");
1125 var tags = $("ATSTR-" + id);
1127 tags.innerHTML = tags_str.firstChild.nodeValue;
1130 cache_invalidate(id);
1136 exception_error("editTagsSave", e);
1141 function editTagsInsert() {
1144 var form = document.forms["tag_edit_form"];
1146 var found_tags = form.found_tags;
1147 var tags_str = form.tags_str;
1149 var tag = found_tags[found_tags.selectedIndex].value;
1151 if (tags_str.value.length > 0 &&
1152 tags_str.value.lastIndexOf(", ") != tags_str.value.length - 2) {
1154 tags_str.value = tags_str.value + ", ";
1157 tags_str.value = tags_str.value + tag + ", ";
1159 found_tags.selectedIndex = 0;
1162 exception_error("editTagsInsert", e);
1166 function cdmScrollToArticleId(id) {
1168 var ctr = $("headlines-frame");
1169 var e = $("RROW-" + id);
1171 if (!e || !ctr) return;
1173 ctr.scrollTop = e.offsetTop;
1176 exception_error("cdmScrollToArticleId", e);
1180 function cdmWatchdog() {
1184 var ctr = $("headlines-frame");
1188 var ids = new Array();
1190 var e = ctr.firstChild;
1193 if (e.className && e.hasClassName("Unread") && e.id &&
1194 e.id.match("RROW-")) {
1196 // article fits in viewport OR article is longer than viewport and
1197 // its bottom is visible
1199 if (ctr.scrollTop <= e.offsetTop && e.offsetTop + e.offsetHeight <=
1200 ctr.scrollTop + ctr.offsetHeight) {
1202 // console.log(e.id + " is visible " + e.offsetTop + "." +
1203 // (e.offsetTop + e.offsetHeight) + " vs " + ctr.scrollTop + "." +
1204 // (ctr.scrollTop + ctr.offsetHeight));
1206 ids.push(e.id.replace("RROW-", ""));
1208 } else if (e.offsetHeight > ctr.offsetHeight &&
1209 e.offsetTop + e.offsetHeight >= ctr.scrollTop &&
1210 e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight) {
1212 ids.push(e.id.replace("RROW-", ""));
1216 // method 2: article bottom is visible and is in upper 1/2 of the viewport
1218 /* if (e.offsetTop + e.offsetHeight >= ctr.scrollTop &&
1219 e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight/2) {
1221 ids.push(e.id.replace("RROW-", ""));
1230 console.log("cdmWatchdog, ids= " + ids.toString());
1232 if (ids.length > 0) {
1234 for (var i = 0; i < ids.length; i++) {
1235 var e = $("RROW-" + ids[i]);
1237 e.removeClassName("Unread");
1241 var query = "?op=rpc&subop=catchupSelected" +
1242 "&cmode=0" + "&ids=" + param_escape(ids.toString());
1244 new Ajax.Request("backend.php", {
1246 onComplete: function(transport) {
1247 handle_rpc_reply(transport);
1252 _cdm_wd_timeout = window.setTimeout("cdmWatchdog()", 4000);
1255 exception_error("cdmWatchdog", e);
1261 function cache_inject(id, article, param) {
1264 if (!cache_check_param(id, param)) {
1265 //console.log("cache_article: miss: " + id + " [p=" + param + "]");
1267 var date = new Date();
1268 var ts = Math.round(date.getTime() / 1000);
1272 cache_obj["id"] = id;
1273 cache_obj["data"] = article;
1274 cache_obj["param"] = param;
1276 if (param) id = id + ":" + param;
1278 cache_added["TS:" + id] = ts;
1280 if (has_local_storage())
1281 sessionStorage.setItem(id, JSON.stringify(cache_obj));
1283 article_cache.push(cache_obj);
1286 //console.log("cache_article: hit: " + id + " [p=" + param + "]");
1289 exception_error("cache_inject", e);
1293 function cache_find(id) {
1295 if (has_local_storage()) {
1296 var cache_obj = sessionStorage.getItem(id);
1299 cache_obj = JSON.parse(cache_obj);
1302 return cache_obj['data'];
1306 for (var i = 0; i < article_cache.length; i++) {
1307 if (article_cache[i]["id"] == id) {
1308 return article_cache[i]["data"];
1315 function cache_find_param(id, param) {
1317 if (has_local_storage()) {
1319 if (param) id = id + ":" + param;
1321 var cache_obj = sessionStorage.getItem(id);
1324 cache_obj = JSON.parse(cache_obj);
1327 return cache_obj['data'];
1331 for (var i = 0; i < article_cache.length; i++) {
1332 if (article_cache[i]["id"] == id && article_cache[i]["param"] == param) {
1333 return article_cache[i]["data"];
1341 function cache_check(id) {
1342 if (has_local_storage()) {
1343 if (sessionStorage.getItem(id))
1346 for (var i = 0; i < article_cache.length; i++) {
1347 if (article_cache[i]["id"] == id) {
1355 function cache_check_param(id, param) {
1356 if (has_local_storage()) {
1358 if (param) id = id + ":" + param;
1360 if (sessionStorage.getItem(id))
1364 for (var i = 0; i < article_cache.length; i++) {
1365 if (article_cache[i]["id"] == id && article_cache[i]["param"] == param) {
1373 function cache_expire() {
1374 if (has_local_storage()) {
1376 var date = new Date();
1377 var timestamp = Math.round(date.getTime() / 1000);
1379 for (var i = 0; i < sessionStorage.length; i++) {
1381 var id = sessionStorage.key(i);
1383 if (timestamp - cache_added["TS:" + id] > 180) {
1384 sessionStorage.removeItem(id);
1389 while (article_cache.length > 25) {
1390 article_cache.shift();
1395 function cache_flush() {
1396 if (has_local_storage()) {
1397 sessionStorage.clear();
1399 article_cache = new Array();
1403 function cache_invalidate(id) {
1405 if (has_local_storage()) {
1409 for (var i = 0; i < sessionStorage.length; i++) {
1410 var key = sessionStorage.key(i);
1412 // console.warn("cache_invalidate: " + key_id + " cmp " + id);
1414 if (key == id || key.indexOf(id + ":") == 0) {
1415 sessionStorage.removeItem(key);
1426 while (i < article_cache.length) {
1427 if (article_cache[i]["id"] == id) {
1428 //console.log("cache_invalidate: removed id " + id);
1429 article_cache.splice(i, 1);
1436 //console.log("cache_invalidate: id not found: " + id);
1439 exception_error("cache_invalidate", e);
1443 function getActiveArticleId() {
1444 return active_post_id;
1447 function preloadBatchedArticles() {
1450 var query = "?op=rpc&subop=getArticles&ids=" +
1451 preload_id_batch.toString();
1453 new Ajax.Request("backend.php", {
1455 onComplete: function(transport) {
1457 preload_id_batch = [];
1459 var articles = transport.responseXML.getElementsByTagName("article");
1461 for (var i = 0; i < articles.length; i++) {
1462 var id = articles[i].getAttribute("id");
1463 if (!cache_check(id)) {
1464 cache_inject(id, articles[i].firstChild.nodeValue);
1465 console.log("preloaded article: " + id);
1471 exception_error("preloadBatchedArticles", e);
1475 function preloadArticleUnderPointer(id) {
1477 if (getInitParam("bw_limit") == "1") return;
1479 if (post_under_pointer == id && !cache_check(id)) {
1481 console.log("trying to preload article " + id);
1483 var neighbor_ids = getRelativePostIds(id, 1);
1485 /* only request uncached articles */
1487 if (preload_id_batch.indexOf(id) == -1) {
1488 for (var i = 0; i < neighbor_ids.length; i++) {
1489 if (!cache_check(neighbor_ids[i])) {
1490 preload_id_batch.push(neighbor_ids[i]);
1495 if (preload_id_batch.indexOf(id) == -1)
1496 preload_id_batch.push(id);
1498 //console.log("preload ids batch: " + preload_id_batch.toString());
1500 window.clearTimeout(preload_timeout_id);
1501 preload_batch_timeout_id = window.setTimeout('preloadBatchedArticles()', 1000);
1505 exception_error("preloadArticleUnderPointer", e);
1509 function postMouseIn(id) {
1511 if (post_under_pointer != id) {
1512 post_under_pointer = id;
1514 window.setTimeout("preloadArticleUnderPointer(" + id + ")", 250);
1519 exception_error("postMouseIn", e);
1523 function postMouseOut(id) {
1525 post_under_pointer = false;
1527 exception_error("postMouseOut", e);
1531 function headlines_scroll_handler(e) {
1534 if (e.scrollTop + e.offsetHeight > e.scrollHeight - 100) {
1535 if (!_infscroll_disable) {
1541 exception_error("headlines_scroll_handler", e);
1545 function catchupRelativeToArticle(below) {
1550 if (!getActiveArticleId()) {
1551 alert(__("No article is selected."));
1555 var visible_ids = getVisibleArticleIds();
1557 var ids_to_mark = new Array();
1560 for (var i = 0; i < visible_ids.length; i++) {
1561 if (visible_ids[i] != getActiveArticleId()) {
1562 var e = $("RROW-" + visible_ids[i]);
1564 if (e && e.hasClassName("Unread")) {
1565 ids_to_mark.push(visible_ids[i]);
1572 for (var i = visible_ids.length-1; i >= 0; i--) {
1573 if (visible_ids[i] != getActiveArticleId()) {
1574 var e = $("RROW-" + visible_ids[i]);
1576 if (e && e.hasClassName("Unread")) {
1577 ids_to_mark.push(visible_ids[i]);
1585 if (ids_to_mark.length == 0) {
1586 alert(__("No articles found to mark"));
1588 var msg = __("Mark %d article(s) as read?").replace("%d", ids_to_mark.length);
1590 if (getInitParam("confirm_feed_catchup") != 1 || confirm(msg)) {
1592 for (var i = 0; i < ids_to_mark.length; i++) {
1593 var e = $("RROW-" + ids_to_mark[i]);
1594 e.removeClassName("Unread");
1597 var query = "?op=rpc&subop=catchupSelected" +
1598 "&cmode=0" + "&ids=" + param_escape(ids_to_mark.toString());
1600 new Ajax.Request("backend.php", {
1602 onComplete: function(transport) {
1603 catchup_callback2(transport);
1610 exception_error("catchupRelativeToArticle", e);
1614 function cdmExpandArticle(id) {
1619 var elem = $("CICD-" + active_post_id);
1621 var upd_img_pic = $("FUPDPIC-" + id);
1623 if (upd_img_pic && (upd_img_pic.src.match("updated.png") ||
1624 upd_img_pic.src.match("fresh_sign.png"))) {
1626 upd_img_pic.src = "images/blank_icon.gif";
1629 if (id == active_post_id && Element.visible(elem))
1632 selectArticles("none");
1634 var old_offset = $("RROW-" + id).offsetTop;
1636 if (active_post_id && elem && !getInitParam("cdm_expanded")) {
1638 Element.show("CEXC-" + active_post_id);
1641 active_post_id = id;
1643 elem = $("CICD-" + id);
1645 if (!Element.visible(elem)) {
1647 Element.hide("CEXC-" + id);
1649 if ($("CWRAP-" + id).innerHTML == "") {
1651 $("FUPDPIC-" + id).src = "images/indicator_tiny.gif";
1653 $("CWRAP-" + id).innerHTML = "<div class=\"insensitive\">" +
1654 __("Loading, please wait...") + "</div>";
1656 var query = "?op=rpc&subop=cdmGetArticle&id=" + param_escape(id);
1658 //console.log(query);
1660 new Ajax.Request("backend.php", {
1662 onComplete: function(transport) {
1663 $("FUPDPIC-" + id).src = 'images/blank_icon.gif';
1665 if (transport.responseXML) {
1666 var article = transport.responseXML.getElementsByTagName("article")[0];
1667 var recv_id = article.getAttribute("id");
1670 $("CWRAP-" + id).innerHTML = article.firstChild.nodeValue;
1673 $("CWRAP-" + id).innerHTML = __("Unable to load article.");
1681 var new_offset = $("RROW-" + id).offsetTop;
1683 $("headlines-frame").scrollTop += (new_offset-old_offset);
1685 if ($("RROW-" + id).offsetTop != old_offset)
1686 $("headlines-frame").scrollTop = new_offset;
1688 toggleUnread(id, 0, true);
1692 exception_error("cdmExpandArticle", e);
1698 function fixHeadlinesOrder(ids) {
1700 for (var i = 0; i < ids.length; i++) {
1701 var e = $("RROW-" + ids[i]);
1705 e.removeClassName("even");
1706 e.addClassName("odd");
1708 e.removeClassName("odd");
1709 e.addClassName("even");
1714 exception_error("fixHeadlinesOrder", e);
1718 function getArticleUnderPointer() {
1719 return post_under_pointer;
1722 function zoomToArticle(event, id) {
1724 var cached_article = cache_find(id);
1726 if (dijit.byId("ATAB-" + id))
1727 if (!event || !event.shiftKey)
1728 return dijit.byId("content-tabs").selectChild(dijit.byId("ATAB-" + id));
1730 if (cached_article) {
1731 //closeArticlePanel();
1733 var article_pane = new dijit.layout.ContentPane({
1734 title: __("Loading...") , content: cached_article,
1735 style: 'padding : 0px;',
1739 dijit.byId("content-tabs").addChild(article_pane);
1741 $$("#ATAB-"+id+" a.twitter-share-button").each(
1742 function(btn) { var tbtn = new twttr.TweetButton(btn); tbtn.render(); });
1744 if (!event || !event.shiftKey)
1745 dijit.byId("content-tabs").selectChild(article_pane);
1747 if ($("PTITLE-" + id))
1748 article_pane.attr('title', $("PTITLE-" + id).innerHTML);
1752 var query = "?op=rpc&subop=getArticles&ids=" + param_escape(id);
1754 notify_progress("Loading, please wait...", true);
1756 new Ajax.Request("backend.php", {
1758 onComplete: function(transport) {
1761 if (transport.responseXML) {
1762 //closeArticlePanel();
1764 var article = transport.responseXML.getElementsByTagName("article")[0];
1765 var content = article.firstChild.nodeValue;
1767 var article_pane = new dijit.layout.ContentPane({
1768 title: "article-" + id , content: content,
1769 style: 'padding : 0px;',
1773 dijit.byId("content-tabs").addChild(article_pane);
1775 $$("#ATAB-"+id+" a.twitter-share-button").each(
1776 function(btn) { var tbtn = new twttr.TweetButton(btn);
1779 if (!event || !event.shiftKey)
1780 dijit.byId("content-tabs").selectChild(article_pane);
1782 if ($("PTITLE-" + id))
1783 article_pane.attr('title', $("PTITLE-" + id).innerHTML);
1790 exception_error("zoomToArticle", e);
1794 function scrollArticle(offset) {
1797 var ci = $("content-insert");
1799 ci.scrollTop += offset;
1802 var hi = $("headlines-frame");
1804 hi.scrollTop += offset;
1809 exception_error("scrollArticle", e);
1813 function show_labels_in_headlines(transport) {
1815 if (transport.responseXML) {
1816 var info = transport.responseXML.getElementsByTagName("info-for-headlines")[0];
1818 var elems = info.getElementsByTagName("entry");
1820 for (var l = 0; l < elems.length; l++) {
1821 var e_id = elems[l].getAttribute("id");
1825 var ctr = $("HLLCTR-" + e_id);
1828 ctr.innerHTML = elems[l].firstChild.nodeValue;
1836 exception_error("show_labels_in_headlines", e);
1841 function toggleHeadlineActions() {
1843 var e = $("headlineActionsBody");
1844 var p = $("headlineActionsDrop");
1846 if (!Element.visible(e)) {
1853 e.style.left = (p.offsetLeft + 1) + "px";
1854 e.style.top = (p.offsetTop + p.offsetHeight + 2) + "px";
1857 exception_error("toggleHeadlineActions", e);
1861 function publishWithNote(id, def_note) {
1863 if (!def_note) def_note = '';
1865 var note = prompt(__("Please enter a note for this article:"), def_note);
1867 if (note != undefined) {
1868 togglePub(id, false, false, note);
1872 exception_error("publishWithNote", e);
1876 function emailArticle(id) {
1879 var ids = getSelectedArticleIds2();
1881 if (ids.length == 0) {
1882 alert(__("No articles are selected."));
1886 id = ids.toString();
1889 if (dijit.byId("emailArticleDlg"))
1890 dijit.byId("emailArticleDlg").destroyRecursive();
1892 var query = "backend.php?op=dlg&id=emailArticle¶m=" + param_escape(id);
1894 dialog = new dijit.Dialog({
1895 id: "emailArticleDlg",
1896 title: __("Forward article by email"),
1897 style: "width: 600px",
1898 execute: function() {
1899 if (this.validate()) {
1901 new Ajax.Request("backend.php", {
1902 parameters: dojo.objectToQuery(this.attr('value')),
1903 onComplete: function(transport) {
1905 var error = transport.responseXML.getElementsByTagName('error')[0];
1908 alert(__('Error sending email:') + ' ' + error.firstChild.nodeValue);
1910 notify_info('Your message has been sent.');
1919 var tmph = dojo.connect(dialog, 'onLoad', function() {
1920 dojo.disconnect(tmph);
1922 new Ajax.Autocompleter('emailArticleDlg_destination', 'emailArticleDlg_dst_choices',
1923 "backend.php?op=rpc&subop=completeEmails",
1924 { tokens: '', paramName: "search" });
1929 /* displayDlg('emailArticle', id,
1931 document.forms['article_email_form'].destination.focus();
1933 new Ajax.Autocompleter('destination', 'destination_choices',
1934 "backend.php?op=rpc&subop=completeEmails",
1935 { tokens: '', paramName: "search" });
1940 exception_error("emailArticle", e);
1944 function dismissArticle(id) {
1946 var elem = $("RROW-" + id);
1948 toggleUnread(id, 0, true);
1950 new Effect.Fade(elem, {duration : 0.5});
1952 active_post_id = false;
1955 exception_error("dismissArticle", e);
1959 function dismissSelectedArticles() {
1962 var ids = getVisibleArticleIds();
1966 for (var i = 0; i < ids.length; i++) {
1967 var elem = $("RROW-" + ids[i]);
1969 if (elem.className && elem.hasClassName("Selected") &&
1970 ids[i] != active_post_id) {
1971 new Effect.Fade(elem, {duration : 0.5});
1979 selectionToggleUnread(false);
1981 fixHeadlinesOrder(tmp);
1984 exception_error("dismissSelectedArticles", e);
1988 function dismissReadArticles() {
1991 var ids = getVisibleArticleIds();
1994 for (var i = 0; i < ids.length; i++) {
1995 var elem = $("RROW-" + ids[i]);
1997 if (elem.className && !elem.hasClassName("Unread") &&
1998 !elem.hasClassName("Selected")) {
2000 new Effect.Fade(elem, {duration : 0.5});
2006 fixHeadlinesOrder(tmp);
2009 exception_error("dismissSelectedArticles", e);
2013 function getVisibleArticleIds() {
2018 getLoadedArticleIds().each(function(id) {
2019 var elem = $("RROW-" + id);
2020 if (elem && Element.visible(elem))
2025 exception_error("getVisibleArticleIds", e);
2031 function cdmClicked(event, id) {
2033 var shift_key = event.shiftKey;
2037 if (!event.ctrlKey) {
2039 if (!getInitParam("cdm_expanded")) {
2040 return cdmExpandArticle(id);
2043 selectArticles("none");
2046 var elem = $("RROW-" + id);
2049 elem.removeClassName("Unread");
2051 var upd_img_pic = $("FUPDPIC-" + id);
2053 if (upd_img_pic && (upd_img_pic.src.match("updated.png") ||
2054 upd_img_pic.src.match("fresh_sign.png"))) {
2056 upd_img_pic.src = "images/blank_icon.gif";
2059 active_post_id = id;
2061 var query = "?op=rpc&subop=catchupSelected" +
2062 "&cmode=0&ids=" + param_escape(id);
2064 new Ajax.Request("backend.php", {
2066 onComplete: function(transport) {
2067 handle_rpc_reply(transport);
2072 toggleSelected(id, true);
2073 toggleUnread(id, 0, false);
2074 zoomToArticle(event, id);
2078 exception_error("cdmClicked");
2084 function postClicked(event, id) {
2087 if (!event.ctrlKey) {
2090 postOpenInNewTab(event, id);
2095 exception_error("postClicked");
2099 function hlOpenInNewTab(event, id) {
2100 toggleUnread(id, 0, false);
2101 zoomToArticle(event, id);
2104 function postOpenInNewTab(event, id) {
2105 closeArticlePanel(id);
2106 zoomToArticle(event, id);
2109 function hlClicked(event, id) {
2112 openArticleInNewWindow(id);
2113 } else if (!event.ctrlKey) {
2118 toggleUnread(id, 0, false);
2119 zoomToArticle(event, id);
2124 exception_error("hlClicked");
2128 function getFirstVisibleHeadlineId() {
2129 var rows = getVisibleArticleIds();
2134 function getLastVisibleHeadlineId() {
2135 var rows = getVisibleArticleIds();
2136 return rows[rows.length-1];
2139 function openArticleInNewWindow(id) {
2140 toggleUnread(id, 0, false);
2141 window.open("backend.php?op=la&id=" + id);
2144 function isCdmMode() {
2145 return getInitParam("combined_display_mode");
2148 function markHeadline(id) {
2149 var row = $("RROW-" + id);
2151 var check = $("RCHK-" + id);
2154 check.checked = true;
2157 row.addClassName("Selected");
2161 function getRelativePostIds(id, limit) {
2167 if (!limit) limit = 3;
2169 var ids = getVisibleArticleIds();
2171 for (var i = 0; i < ids.length; i++) {
2173 for (var k = 1; k <= limit; k++) {
2174 if (i > k-1) tmp.push(ids[i-k]);
2175 if (i < ids.length-k) tmp.push(ids[i+k]);
2182 exception_error("getRelativePostIds", e);
2188 function correctHeadlinesOffset(id) {
2192 var container = $("headlines-frame");
2193 var row = $("RROW-" + id);
2195 var viewport = container.offsetHeight;
2197 var rel_offset_top = row.offsetTop - container.scrollTop;
2198 var rel_offset_bottom = row.offsetTop + row.offsetHeight - container.scrollTop;
2200 //console.log("Rtop: " + rel_offset_top + " Rbtm: " + rel_offset_bottom);
2201 //console.log("Vport: " + viewport);
2203 if (rel_offset_top <= 0 || rel_offset_top > viewport) {
2204 container.scrollTop = row.offsetTop;
2205 } else if (rel_offset_bottom > viewport) {
2207 /* doesn't properly work with Opera in some cases because
2208 Opera fucks up element scrolling */
2210 container.scrollTop = row.offsetTop + row.offsetHeight - viewport;
2214 exception_error("correctHeadlinesOffset", e);
2219 function headlineActionsChange(elem) {
2222 elem.attr('value', 'false');
2224 exception_error("headlineActionsChange", e);
2228 function closeArticlePanel() {
2230 var tabs = dijit.byId("content-tabs");
2231 var child = tabs.selectedChildWidget;
2233 if (child && tabs.getIndexOfChild(child) > 0) {
2234 tabs.removeChild(child);
2237 if (dijit.byId("content-insert"))
2238 dijit.byId("headlines-wrap-inner").removeChild(
2239 dijit.byId("content-insert"));
2243 function initHeadlinesMenu() {
2245 if (dijit.byId("headlinesMenu"))
2246 dijit.byId("headlinesMenu").destroyRecursive();
2251 nodes = $$("#headlines-frame > div[id*=RROW]");
2253 nodes = $$("#headlines-frame span[id*=RTITLE]");
2256 nodes.each(function(node) {
2260 var menu = new dijit.Menu({
2261 id: "headlinesMenu",
2265 var tmph = dojo.connect(menu, '_openMyself', function (event) {
2266 var callerNode = event.target, match = null, tries = 0;
2268 while (match == null && callerNode && tries <= 3) {
2269 match = callerNode.id.match("^[A-Z]+[-]([0-9]+)$");
2270 callerNode = callerNode.parentNode;
2274 if (match) this.callerRowId = parseInt(match[1]);
2279 menu.addChild(new dijit.MenuItem({
2280 label: __("View article"),
2281 onClick: function(event) {
2282 view(this.getParent().callerRowId);
2285 menu.addChild(new dijit.MenuItem({
2286 label: __("View in a new tab"),
2287 onClick: function(event) {
2288 hlOpenInNewTab(event, this.getParent().callerRowId);
2291 menu.addChild(new dijit.MenuSeparator());
2293 menu.addChild(new dijit.MenuItem({
2294 label: __("Open original article"),
2295 onClick: function(event) {
2296 openArticleInNewWindow(this.getParent().callerRowId);
2299 var labels = dijit.byId("feedTree").model.getItemsInCategory(-2);
2303 menu.addChild(new dijit.MenuSeparator());
2305 var labelsMenu = new dijit.Menu({ownerMenu: menu});
2307 labels.each(function(label) {
2308 var id = label.id[0];
2309 var bare_id = id.substr(id.indexOf(":")+1);
2310 var name = label.name[0];
2312 bare_id = -11-bare_id;
2314 labelsMenu.addChild(new dijit.MenuItem({
2317 onClick: function(event) {
2318 //console.log(this.labelId);
2319 //console.log(this.getParent().ownerMenu.callerRowId);
2320 selectionAssignLabel(this.labelId,
2321 [this.getParent().ownerMenu.callerRowId]);
2325 menu.addChild(new dijit.PopupMenuItem({
2326 label: __("Labels"),
2334 exception_error("initHeadlinesMenu", e);