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) {
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" });
1096 var query = "backend.php?op=dlg&id=editArticleTags¶m=" + param_escape(id);
1098 if (dijit.byId("editTagsDlg"))
1099 dijit.byId("editTagsDlg").destroyRecursive();
1101 dialog = new dijit.Dialog({
1103 title: __("Edit article Tags"),
1104 style: "width: 600px",
1105 execute: function() {
1106 if (this.validate()) {
1107 var query = dojo.objectToQuery(this.attr('value'));
1109 notify_progress("Saving article tags...", true);
1111 new Ajax.Request("backend.php", {
1113 onComplete: function(transport) {
1117 if (transport.responseXML) {
1118 var tags_str = transport.responseXML.getElementsByTagName("tags-str")[0];
1121 var id = tags_str.getAttribute("id");
1124 var tags = $("ATSTR-" + id);
1126 tags.innerHTML = tags_str.firstChild.nodeValue;
1129 cache_invalidate(id);
1140 var tmph = dojo.connect(dialog, 'onLoad', function() {
1141 dojo.disconnect(tmph);
1143 new Ajax.Autocompleter('tags_str', 'tags_choices',
1144 "backend.php?op=rpc&subop=completeTags",
1145 { tokens: ',', paramName: "search" });
1152 function cdmScrollToArticleId(id) {
1154 var ctr = $("headlines-frame");
1155 var e = $("RROW-" + id);
1157 if (!e || !ctr) return;
1159 ctr.scrollTop = e.offsetTop;
1162 exception_error("cdmScrollToArticleId", e);
1166 function cdmWatchdog() {
1170 var ctr = $("headlines-frame");
1174 var ids = new Array();
1176 var e = ctr.firstChild;
1179 if (e.className && e.hasClassName("Unread") && e.id &&
1180 e.id.match("RROW-")) {
1182 // article fits in viewport OR article is longer than viewport and
1183 // its bottom is visible
1185 if (ctr.scrollTop <= e.offsetTop && e.offsetTop + e.offsetHeight <=
1186 ctr.scrollTop + ctr.offsetHeight) {
1188 // console.log(e.id + " is visible " + e.offsetTop + "." +
1189 // (e.offsetTop + e.offsetHeight) + " vs " + ctr.scrollTop + "." +
1190 // (ctr.scrollTop + ctr.offsetHeight));
1192 ids.push(e.id.replace("RROW-", ""));
1194 } else if (e.offsetHeight > ctr.offsetHeight &&
1195 e.offsetTop + e.offsetHeight >= ctr.scrollTop &&
1196 e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight) {
1198 ids.push(e.id.replace("RROW-", ""));
1202 // method 2: article bottom is visible and is in upper 1/2 of the viewport
1204 /* if (e.offsetTop + e.offsetHeight >= ctr.scrollTop &&
1205 e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight/2) {
1207 ids.push(e.id.replace("RROW-", ""));
1216 console.log("cdmWatchdog, ids= " + ids.toString());
1218 if (ids.length > 0) {
1220 for (var i = 0; i < ids.length; i++) {
1221 var e = $("RROW-" + ids[i]);
1223 e.removeClassName("Unread");
1227 var query = "?op=rpc&subop=catchupSelected" +
1228 "&cmode=0" + "&ids=" + param_escape(ids.toString());
1230 new Ajax.Request("backend.php", {
1232 onComplete: function(transport) {
1233 handle_rpc_reply(transport);
1238 _cdm_wd_timeout = window.setTimeout("cdmWatchdog()", 4000);
1241 exception_error("cdmWatchdog", e);
1247 function cache_inject(id, article, param) {
1250 if (!cache_check_param(id, param)) {
1251 //console.log("cache_article: miss: " + id + " [p=" + param + "]");
1253 var date = new Date();
1254 var ts = Math.round(date.getTime() / 1000);
1258 cache_obj["id"] = id;
1259 cache_obj["data"] = article;
1260 cache_obj["param"] = param;
1262 if (param) id = id + ":" + param;
1264 cache_added["TS:" + id] = ts;
1266 if (has_local_storage())
1267 sessionStorage.setItem(id, JSON.stringify(cache_obj));
1269 article_cache.push(cache_obj);
1272 //console.log("cache_article: hit: " + id + " [p=" + param + "]");
1275 exception_error("cache_inject", e);
1279 function cache_find(id) {
1281 if (has_local_storage()) {
1282 var cache_obj = sessionStorage.getItem(id);
1285 cache_obj = JSON.parse(cache_obj);
1288 return cache_obj['data'];
1292 for (var i = 0; i < article_cache.length; i++) {
1293 if (article_cache[i]["id"] == id) {
1294 return article_cache[i]["data"];
1301 function cache_find_param(id, param) {
1303 if (has_local_storage()) {
1305 if (param) id = id + ":" + param;
1307 var cache_obj = sessionStorage.getItem(id);
1310 cache_obj = JSON.parse(cache_obj);
1313 return cache_obj['data'];
1317 for (var i = 0; i < article_cache.length; i++) {
1318 if (article_cache[i]["id"] == id && article_cache[i]["param"] == param) {
1319 return article_cache[i]["data"];
1327 function cache_check(id) {
1328 if (has_local_storage()) {
1329 if (sessionStorage.getItem(id))
1332 for (var i = 0; i < article_cache.length; i++) {
1333 if (article_cache[i]["id"] == id) {
1341 function cache_check_param(id, param) {
1342 if (has_local_storage()) {
1344 if (param) id = id + ":" + param;
1346 if (sessionStorage.getItem(id))
1350 for (var i = 0; i < article_cache.length; i++) {
1351 if (article_cache[i]["id"] == id && article_cache[i]["param"] == param) {
1359 function cache_expire() {
1360 if (has_local_storage()) {
1362 var date = new Date();
1363 var timestamp = Math.round(date.getTime() / 1000);
1365 for (var i = 0; i < sessionStorage.length; i++) {
1367 var id = sessionStorage.key(i);
1369 if (timestamp - cache_added["TS:" + id] > 180) {
1370 sessionStorage.removeItem(id);
1375 while (article_cache.length > 25) {
1376 article_cache.shift();
1381 function cache_flush() {
1382 if (has_local_storage()) {
1383 sessionStorage.clear();
1385 article_cache = new Array();
1389 function cache_invalidate(id) {
1391 if (has_local_storage()) {
1395 for (var i = 0; i < sessionStorage.length; i++) {
1396 var key = sessionStorage.key(i);
1398 // console.warn("cache_invalidate: " + key_id + " cmp " + id);
1400 if (key == id || key.indexOf(id + ":") == 0) {
1401 sessionStorage.removeItem(key);
1412 while (i < article_cache.length) {
1413 if (article_cache[i]["id"] == id) {
1414 //console.log("cache_invalidate: removed id " + id);
1415 article_cache.splice(i, 1);
1422 //console.log("cache_invalidate: id not found: " + id);
1425 exception_error("cache_invalidate", e);
1429 function getActiveArticleId() {
1430 return active_post_id;
1433 function preloadBatchedArticles() {
1436 var query = "?op=rpc&subop=getArticles&ids=" +
1437 preload_id_batch.toString();
1439 new Ajax.Request("backend.php", {
1441 onComplete: function(transport) {
1443 preload_id_batch = [];
1445 var articles = transport.responseXML.getElementsByTagName("article");
1447 for (var i = 0; i < articles.length; i++) {
1448 var id = articles[i].getAttribute("id");
1449 if (!cache_check(id)) {
1450 cache_inject(id, articles[i].firstChild.nodeValue);
1451 console.log("preloaded article: " + id);
1457 exception_error("preloadBatchedArticles", e);
1461 function preloadArticleUnderPointer(id) {
1463 if (getInitParam("bw_limit") == "1") return;
1465 if (post_under_pointer == id && !cache_check(id)) {
1467 console.log("trying to preload article " + id);
1469 var neighbor_ids = getRelativePostIds(id, 1);
1471 /* only request uncached articles */
1473 if (preload_id_batch.indexOf(id) == -1) {
1474 for (var i = 0; i < neighbor_ids.length; i++) {
1475 if (!cache_check(neighbor_ids[i])) {
1476 preload_id_batch.push(neighbor_ids[i]);
1481 if (preload_id_batch.indexOf(id) == -1)
1482 preload_id_batch.push(id);
1484 //console.log("preload ids batch: " + preload_id_batch.toString());
1486 window.clearTimeout(preload_timeout_id);
1487 preload_batch_timeout_id = window.setTimeout('preloadBatchedArticles()', 1000);
1491 exception_error("preloadArticleUnderPointer", e);
1495 function postMouseIn(id) {
1497 if (post_under_pointer != id) {
1498 post_under_pointer = id;
1500 window.setTimeout("preloadArticleUnderPointer(" + id + ")", 250);
1505 exception_error("postMouseIn", e);
1509 function postMouseOut(id) {
1511 post_under_pointer = false;
1513 exception_error("postMouseOut", e);
1517 function headlines_scroll_handler(e) {
1520 if (e.scrollTop + e.offsetHeight > e.scrollHeight - 100) {
1521 if (!_infscroll_disable) {
1527 exception_error("headlines_scroll_handler", e);
1531 function catchupRelativeToArticle(below) {
1536 if (!getActiveArticleId()) {
1537 alert(__("No article is selected."));
1541 var visible_ids = getVisibleArticleIds();
1543 var ids_to_mark = new Array();
1546 for (var i = 0; i < visible_ids.length; i++) {
1547 if (visible_ids[i] != getActiveArticleId()) {
1548 var e = $("RROW-" + visible_ids[i]);
1550 if (e && e.hasClassName("Unread")) {
1551 ids_to_mark.push(visible_ids[i]);
1558 for (var i = visible_ids.length-1; i >= 0; i--) {
1559 if (visible_ids[i] != getActiveArticleId()) {
1560 var e = $("RROW-" + visible_ids[i]);
1562 if (e && e.hasClassName("Unread")) {
1563 ids_to_mark.push(visible_ids[i]);
1571 if (ids_to_mark.length == 0) {
1572 alert(__("No articles found to mark"));
1574 var msg = __("Mark %d article(s) as read?").replace("%d", ids_to_mark.length);
1576 if (getInitParam("confirm_feed_catchup") != 1 || confirm(msg)) {
1578 for (var i = 0; i < ids_to_mark.length; i++) {
1579 var e = $("RROW-" + ids_to_mark[i]);
1580 e.removeClassName("Unread");
1583 var query = "?op=rpc&subop=catchupSelected" +
1584 "&cmode=0" + "&ids=" + param_escape(ids_to_mark.toString());
1586 new Ajax.Request("backend.php", {
1588 onComplete: function(transport) {
1589 catchup_callback2(transport);
1596 exception_error("catchupRelativeToArticle", e);
1600 function cdmExpandArticle(id) {
1605 var elem = $("CICD-" + active_post_id);
1607 var upd_img_pic = $("FUPDPIC-" + id);
1609 if (upd_img_pic && (upd_img_pic.src.match("updated.png") ||
1610 upd_img_pic.src.match("fresh_sign.png"))) {
1612 upd_img_pic.src = "images/blank_icon.gif";
1615 if (id == active_post_id && Element.visible(elem))
1618 selectArticles("none");
1620 var old_offset = $("RROW-" + id).offsetTop;
1622 if (active_post_id && elem && !getInitParam("cdm_expanded")) {
1624 Element.show("CEXC-" + active_post_id);
1627 active_post_id = id;
1629 elem = $("CICD-" + id);
1631 if (!Element.visible(elem)) {
1633 Element.hide("CEXC-" + id);
1635 if ($("CWRAP-" + id).innerHTML == "") {
1637 $("FUPDPIC-" + id).src = "images/indicator_tiny.gif";
1639 $("CWRAP-" + id).innerHTML = "<div class=\"insensitive\">" +
1640 __("Loading, please wait...") + "</div>";
1642 var query = "?op=rpc&subop=cdmGetArticle&id=" + param_escape(id);
1644 //console.log(query);
1646 new Ajax.Request("backend.php", {
1648 onComplete: function(transport) {
1649 $("FUPDPIC-" + id).src = 'images/blank_icon.gif';
1651 if (transport.responseXML) {
1652 var article = transport.responseXML.getElementsByTagName("article")[0];
1653 var recv_id = article.getAttribute("id");
1656 $("CWRAP-" + id).innerHTML = article.firstChild.nodeValue;
1659 $("CWRAP-" + id).innerHTML = __("Unable to load article.");
1667 var new_offset = $("RROW-" + id).offsetTop;
1669 $("headlines-frame").scrollTop += (new_offset-old_offset);
1671 if ($("RROW-" + id).offsetTop != old_offset)
1672 $("headlines-frame").scrollTop = new_offset;
1674 toggleUnread(id, 0, true);
1678 exception_error("cdmExpandArticle", e);
1684 function fixHeadlinesOrder(ids) {
1686 for (var i = 0; i < ids.length; i++) {
1687 var e = $("RROW-" + ids[i]);
1691 e.removeClassName("even");
1692 e.addClassName("odd");
1694 e.removeClassName("odd");
1695 e.addClassName("even");
1700 exception_error("fixHeadlinesOrder", e);
1704 function getArticleUnderPointer() {
1705 return post_under_pointer;
1708 function zoomToArticle(event, id) {
1710 var cached_article = cache_find(id);
1712 if (dijit.byId("ATAB-" + id))
1713 if (!event || !event.shiftKey)
1714 return dijit.byId("content-tabs").selectChild(dijit.byId("ATAB-" + id));
1716 if (cached_article) {
1717 //closeArticlePanel();
1719 var article_pane = new dijit.layout.ContentPane({
1720 title: __("Loading...") , content: cached_article,
1721 style: 'padding : 0px;',
1725 dijit.byId("content-tabs").addChild(article_pane);
1727 $$("#ATAB-"+id+" a.twitter-share-button").each(
1728 function(btn) { var tbtn = new twttr.TweetButton(btn); tbtn.render(); });
1730 if (!event || !event.shiftKey)
1731 dijit.byId("content-tabs").selectChild(article_pane);
1733 if ($("PTITLE-" + id))
1734 article_pane.attr('title', $("PTITLE-" + id).innerHTML);
1738 var query = "?op=rpc&subop=getArticles&ids=" + param_escape(id);
1740 notify_progress("Loading, please wait...", true);
1742 new Ajax.Request("backend.php", {
1744 onComplete: function(transport) {
1747 if (transport.responseXML) {
1748 //closeArticlePanel();
1750 var article = transport.responseXML.getElementsByTagName("article")[0];
1751 var content = article.firstChild.nodeValue;
1753 var article_pane = new dijit.layout.ContentPane({
1754 title: "article-" + id , content: content,
1755 style: 'padding : 0px;',
1759 dijit.byId("content-tabs").addChild(article_pane);
1761 $$("#ATAB-"+id+" a.twitter-share-button").each(
1762 function(btn) { var tbtn = new twttr.TweetButton(btn);
1765 if (!event || !event.shiftKey)
1766 dijit.byId("content-tabs").selectChild(article_pane);
1768 if ($("PTITLE-" + id))
1769 article_pane.attr('title', $("PTITLE-" + id).innerHTML);
1776 exception_error("zoomToArticle", e);
1780 function scrollArticle(offset) {
1783 var ci = $("content-insert");
1785 ci.scrollTop += offset;
1788 var hi = $("headlines-frame");
1790 hi.scrollTop += offset;
1795 exception_error("scrollArticle", e);
1799 function show_labels_in_headlines(transport) {
1801 if (transport.responseXML) {
1802 var info = transport.responseXML.getElementsByTagName("info-for-headlines")[0];
1804 var elems = info.getElementsByTagName("entry");
1806 for (var l = 0; l < elems.length; l++) {
1807 var e_id = elems[l].getAttribute("id");
1811 var ctr = $("HLLCTR-" + e_id);
1814 ctr.innerHTML = elems[l].firstChild.nodeValue;
1822 exception_error("show_labels_in_headlines", e);
1827 function toggleHeadlineActions() {
1829 var e = $("headlineActionsBody");
1830 var p = $("headlineActionsDrop");
1832 if (!Element.visible(e)) {
1839 e.style.left = (p.offsetLeft + 1) + "px";
1840 e.style.top = (p.offsetTop + p.offsetHeight + 2) + "px";
1843 exception_error("toggleHeadlineActions", e);
1847 function publishWithNote(id, def_note) {
1849 if (!def_note) def_note = '';
1851 var note = prompt(__("Please enter a note for this article:"), def_note);
1853 if (note != undefined) {
1854 togglePub(id, false, false, note);
1858 exception_error("publishWithNote", e);
1862 function emailArticle(id) {
1865 var ids = getSelectedArticleIds2();
1867 if (ids.length == 0) {
1868 alert(__("No articles are selected."));
1872 id = ids.toString();
1875 if (dijit.byId("emailArticleDlg"))
1876 dijit.byId("emailArticleDlg").destroyRecursive();
1878 var query = "backend.php?op=dlg&id=emailArticle¶m=" + param_escape(id);
1880 dialog = new dijit.Dialog({
1881 id: "emailArticleDlg",
1882 title: __("Forward article by email"),
1883 style: "width: 600px",
1884 execute: function() {
1885 if (this.validate()) {
1887 new Ajax.Request("backend.php", {
1888 parameters: dojo.objectToQuery(this.attr('value')),
1889 onComplete: function(transport) {
1891 var error = transport.responseXML.getElementsByTagName('error')[0];
1894 alert(__('Error sending email:') + ' ' + error.firstChild.nodeValue);
1896 notify_info('Your message has been sent.');
1905 var tmph = dojo.connect(dialog, 'onLoad', function() {
1906 dojo.disconnect(tmph);
1908 new Ajax.Autocompleter('emailArticleDlg_destination', 'emailArticleDlg_dst_choices',
1909 "backend.php?op=rpc&subop=completeEmails",
1910 { tokens: '', paramName: "search" });
1915 /* displayDlg('emailArticle', id,
1917 document.forms['article_email_form'].destination.focus();
1919 new Ajax.Autocompleter('destination', 'destination_choices',
1920 "backend.php?op=rpc&subop=completeEmails",
1921 { tokens: '', paramName: "search" });
1926 exception_error("emailArticle", e);
1930 function dismissArticle(id) {
1932 var elem = $("RROW-" + id);
1934 toggleUnread(id, 0, true);
1936 new Effect.Fade(elem, {duration : 0.5});
1938 active_post_id = false;
1941 exception_error("dismissArticle", e);
1945 function dismissSelectedArticles() {
1948 var ids = getVisibleArticleIds();
1952 for (var i = 0; i < ids.length; i++) {
1953 var elem = $("RROW-" + ids[i]);
1955 if (elem.className && elem.hasClassName("Selected") &&
1956 ids[i] != active_post_id) {
1957 new Effect.Fade(elem, {duration : 0.5});
1965 selectionToggleUnread(false);
1967 fixHeadlinesOrder(tmp);
1970 exception_error("dismissSelectedArticles", e);
1974 function dismissReadArticles() {
1977 var ids = getVisibleArticleIds();
1980 for (var i = 0; i < ids.length; i++) {
1981 var elem = $("RROW-" + ids[i]);
1983 if (elem.className && !elem.hasClassName("Unread") &&
1984 !elem.hasClassName("Selected")) {
1986 new Effect.Fade(elem, {duration : 0.5});
1992 fixHeadlinesOrder(tmp);
1995 exception_error("dismissSelectedArticles", e);
1999 function getVisibleArticleIds() {
2004 getLoadedArticleIds().each(function(id) {
2005 var elem = $("RROW-" + id);
2006 if (elem && Element.visible(elem))
2011 exception_error("getVisibleArticleIds", e);
2017 function cdmClicked(event, id) {
2019 var shift_key = event.shiftKey;
2023 if (!event.ctrlKey) {
2025 if (!getInitParam("cdm_expanded")) {
2026 return cdmExpandArticle(id);
2029 selectArticles("none");
2032 var elem = $("RROW-" + id);
2035 elem.removeClassName("Unread");
2037 var upd_img_pic = $("FUPDPIC-" + id);
2039 if (upd_img_pic && (upd_img_pic.src.match("updated.png") ||
2040 upd_img_pic.src.match("fresh_sign.png"))) {
2042 upd_img_pic.src = "images/blank_icon.gif";
2045 active_post_id = id;
2047 var query = "?op=rpc&subop=catchupSelected" +
2048 "&cmode=0&ids=" + param_escape(id);
2050 new Ajax.Request("backend.php", {
2052 onComplete: function(transport) {
2053 handle_rpc_reply(transport);
2058 toggleSelected(id, true);
2059 toggleUnread(id, 0, false);
2060 zoomToArticle(event, id);
2064 exception_error("cdmClicked");
2070 function postClicked(event, id) {
2073 if (!event.ctrlKey) {
2076 postOpenInNewTab(event, id);
2081 exception_error("postClicked");
2085 function hlOpenInNewTab(event, id) {
2086 toggleUnread(id, 0, false);
2087 zoomToArticle(event, id);
2090 function postOpenInNewTab(event, id) {
2091 closeArticlePanel(id);
2092 zoomToArticle(event, id);
2095 function hlClicked(event, id) {
2098 openArticleInNewWindow(id);
2099 } else if (!event.ctrlKey) {
2104 toggleUnread(id, 0, false);
2105 zoomToArticle(event, id);
2110 exception_error("hlClicked");
2114 function getFirstVisibleHeadlineId() {
2115 var rows = getVisibleArticleIds();
2120 function getLastVisibleHeadlineId() {
2121 var rows = getVisibleArticleIds();
2122 return rows[rows.length-1];
2125 function openArticleInNewWindow(id) {
2126 toggleUnread(id, 0, false);
2127 window.open("backend.php?op=la&id=" + id);
2130 function isCdmMode() {
2131 return getInitParam("combined_display_mode");
2134 function markHeadline(id) {
2135 var row = $("RROW-" + id);
2137 var check = $("RCHK-" + id);
2140 check.checked = true;
2143 row.addClassName("Selected");
2147 function getRelativePostIds(id, limit) {
2153 if (!limit) limit = 3;
2155 var ids = getVisibleArticleIds();
2157 for (var i = 0; i < ids.length; i++) {
2159 for (var k = 1; k <= limit; k++) {
2160 if (i > k-1) tmp.push(ids[i-k]);
2161 if (i < ids.length-k) tmp.push(ids[i+k]);
2168 exception_error("getRelativePostIds", e);
2174 function correctHeadlinesOffset(id) {
2178 var container = $("headlines-frame");
2179 var row = $("RROW-" + id);
2181 var viewport = container.offsetHeight;
2183 var rel_offset_top = row.offsetTop - container.scrollTop;
2184 var rel_offset_bottom = row.offsetTop + row.offsetHeight - container.scrollTop;
2186 //console.log("Rtop: " + rel_offset_top + " Rbtm: " + rel_offset_bottom);
2187 //console.log("Vport: " + viewport);
2189 if (rel_offset_top <= 0 || rel_offset_top > viewport) {
2190 container.scrollTop = row.offsetTop;
2191 } else if (rel_offset_bottom > viewport) {
2193 /* doesn't properly work with Opera in some cases because
2194 Opera fucks up element scrolling */
2196 container.scrollTop = row.offsetTop + row.offsetHeight - viewport;
2200 exception_error("correctHeadlinesOffset", e);
2205 function headlineActionsChange(elem) {
2208 elem.attr('value', 'false');
2210 exception_error("headlineActionsChange", e);
2214 function closeArticlePanel() {
2216 var tabs = dijit.byId("content-tabs");
2217 var child = tabs.selectedChildWidget;
2219 if (child && tabs.getIndexOfChild(child) > 0) {
2220 tabs.removeChild(child);
2223 if (dijit.byId("content-insert"))
2224 dijit.byId("headlines-wrap-inner").removeChild(
2225 dijit.byId("content-insert"));
2229 function initHeadlinesMenu() {
2231 if (dijit.byId("headlinesMenu"))
2232 dijit.byId("headlinesMenu").destroyRecursive();
2237 nodes = $$("#headlines-frame > div[id*=RROW]");
2239 nodes = $$("#headlines-frame span[id*=RTITLE]");
2242 nodes.each(function(node) {
2246 var menu = new dijit.Menu({
2247 id: "headlinesMenu",
2251 var tmph = dojo.connect(menu, '_openMyself', function (event) {
2252 var callerNode = event.target, match = null, tries = 0;
2254 while (match == null && callerNode && tries <= 3) {
2255 match = callerNode.id.match("^[A-Z]+[-]([0-9]+)$");
2256 callerNode = callerNode.parentNode;
2260 if (match) this.callerRowId = parseInt(match[1]);
2265 menu.addChild(new dijit.MenuItem({
2266 label: __("View article"),
2267 onClick: function(event) {
2268 view(this.getParent().callerRowId);
2271 menu.addChild(new dijit.MenuItem({
2272 label: __("View in a new tab"),
2273 onClick: function(event) {
2274 hlOpenInNewTab(event, this.getParent().callerRowId);
2277 menu.addChild(new dijit.MenuSeparator());
2279 menu.addChild(new dijit.MenuItem({
2280 label: __("Open original article"),
2281 onClick: function(event) {
2282 openArticleInNewWindow(this.getParent().callerRowId);
2285 var labels = dijit.byId("feedTree").model.getItemsInCategory(-2);
2289 menu.addChild(new dijit.MenuSeparator());
2291 var labelsMenu = new dijit.Menu({ownerMenu: menu});
2293 labels.each(function(label) {
2294 var id = label.id[0];
2295 var bare_id = id.substr(id.indexOf(":")+1);
2296 var name = label.name[0];
2298 bare_id = -11-bare_id;
2300 labelsMenu.addChild(new dijit.MenuItem({
2303 onClick: function(event) {
2304 //console.log(this.labelId);
2305 //console.log(this.getParent().ownerMenu.callerRowId);
2306 selectionAssignLabel(this.labelId,
2307 [this.getParent().ownerMenu.callerRowId]);
2311 menu.addChild(new dijit.PopupMenuItem({
2312 label: __("Labels"),
2320 exception_error("initHeadlinesMenu", e);