1 var active_post_id = false;
3 var article_cache = new Array();
5 var vgroup_last_feed = false;
6 var post_under_pointer = false;
8 var last_requested_article = false;
10 var catchup_id_batch = [];
11 var catchup_timeout_id = false;
12 var feed_precache_timeout_id = false;
13 var precache_idle_timeout_id = false;
15 var cids_requested = [];
17 var has_storage = 'sessionStorage' in window && window['sessionStorage'] !== null;
19 function headlines_callback2(transport, offset, background) {
21 handle_rpc_json(transport);
23 loading_set_progress(25);
25 console.log("headlines_callback2 [offset=" + offset + "] B:" + background);
33 reply = JSON.parse(transport.responseText);
40 is_cat = reply['headlines']['is_cat'];
41 feed_id = reply['headlines']['id'];
44 cache_headlines(feed_id, is_cat, reply['headlines']['toolbar'], reply['headlines']['content']);
48 setActiveFeedId(feed_id, is_cat);
52 $("headlines-frame").scrollTop = 0;
56 var headlines_count = reply['headlines-info']['count'];
58 vgroup_last_feed = reply['headlines-info']['vgroup_last_feed'];
60 if (parseInt(headlines_count) < getInitParam("default_article_limit")) {
61 _infscroll_disable = 1;
63 _infscroll_disable = 0;
66 var counters = reply['counters'];
67 var articles = reply['articles'];
68 var runtime_info = reply['runtime-info'];
71 dijit.byId("headlines-frame").attr('content',
72 reply['headlines']['content']);
74 dijit.byId("headlines-toolbar").attr('content',
75 reply['headlines']['toolbar']);
77 var hsp = $("headlines-spacer");
78 if (!hsp) hsp = new Element("DIV", {"id": "headlines-spacer"});
80 dijit.byId('headlines-frame').domNode.appendChild(hsp);
86 if (headlines_count > 0 && feed_id == getActiveFeedId() && is_cat == activeFeedIsCat()) {
87 console.log("adding some more headlines...");
89 var c = dijit.byId("headlines-frame");
90 var ids = getSelectedArticleIds2();
92 $("headlines-tmp").innerHTML = reply['headlines']['content'];
94 var hsp = $("headlines-spacer");
97 c.domNode.removeChild(hsp);
99 $$("#headlines-tmp > div").each(function(row) {
100 if ($$("#headlines-frame DIV[id="+row.id+"]").length == 0) {
101 row.style.display = 'none';
102 c.domNode.appendChild(row);
106 if (!hsp) hsp = new Element("DIV", {"id": "headlines-spacer"});
108 fixHeadlinesOrder(getLoadedArticleIds());
110 c.domNode.appendChild(hsp);
112 console.log("restore selected ids: " + ids);
114 for (var i = 0; i < ids.length; i++) {
115 markHeadline(ids[i]);
120 $$("#headlines-frame > div[id*=RROW]").each(
122 if (!Element.visible(child))
123 new Effect.Appear(child, { duration : 0.5 });
127 console.log("no new headlines received");
129 var hsp = $("headlines-spacer");
131 if (hsp) hsp.innerHTML = "";
135 if (headlines_count > 0)
136 cache_headlines(feed_id, is_cat, reply['headlines']['toolbar'], $("headlines-frame").innerHTML);
139 for (var i = 0; i < articles.length; i++) {
140 var a_id = articles[i]['id'];
141 cache_set("article:" + a_id, articles[i]['content']);
144 console.log("no cached articles received");
147 // do not precache stuff after fresh feed
149 precache_headlines();
152 parse_counters(counters);
157 console.warn("headlines_callback: returned no XML object");
158 dijit.byId("headlines-frame").attr('content', "<div class='whiteBox'>" +
159 __('Could not update headlines (invalid object received)') + "</div>");
162 _infscroll_request_sent = 0;
167 exception_error("headlines_callback2", e, transport);
171 function render_article(article) {
173 dijit.byId("headlines-wrap-inner").addChild(
174 dijit.byId("content-insert"));
176 var c = dijit.byId("content-insert");
179 c.domNode.scrollTop = 0;
182 c.attr('content', article);
184 correctHeadlinesOffset(getActiveArticleId());
191 exception_error("render_article", e);
195 function showArticleInHeadlines(id) {
199 selectArticles("none");
201 var crow = $("RROW-" + id);
205 var article_is_unread = crow.hasClassName("Unread");
207 crow.removeClassName("Unread");
209 selectArticles('none');
211 var upd_img_pic = $("FUPDPIC-" + id);
213 var view_mode = false;
216 view_mode = document.forms['main_toolbar_form'].view_mode;
217 view_mode = view_mode[view_mode.selectedIndex].value;
222 if (upd_img_pic && (upd_img_pic.src.match("updated.png") ||
223 upd_img_pic.src.match("fresh_sign.png"))) {
225 upd_img_pic.src = "images/blank_icon.gif";
227 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML);
229 } else if (article_is_unread && view_mode == "all_articles") {
230 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML);
235 if (article_is_unread)
236 _force_scheduled_update = true;
239 exception_error("showArticleInHeadlines", e);
243 function article_callback2(transport, id) {
245 console.log("article_callback2 " + id);
247 handle_rpc_json(transport);
249 var reply = JSON.parse(transport.responseText);
253 var upic = $('FUPDPIC-' + id);
255 if (upic) upic.src = 'images/blank_icon.gif';
257 reply.each(function(article) {
258 if (active_post_id == article['id']) {
259 render_article(article['content']);
261 cids_requested.remove(article['id']);
263 cache_set("article:" + article['id'], article['content']);
266 // if (id != last_requested_article) {
267 // console.log("requested article id is out of sequence, aborting");
272 console.warn("article_callback: returned invalid data");
274 render_article("<div class='whiteBox'>" +
275 __('Could not display article (invalid data received)') + "</div>");
281 if (!_infscroll_disable &&
282 $$("#headlines-frame > div[id*=RROW]").last().hasClassName("Selected")) {
292 exception_error("article_callback2", e, transport);
298 console.log("loading article: " + id);
300 var cached_article = cache_get("article:" + id);
302 console.log("cache check result: " + (cached_article != false));
306 var query = "?op=view&id=" + param_escape(id);
308 var neighbor_ids = getRelativePostIds(id);
310 /* only request uncached articles */
312 var cids_to_request = [];
314 for (var i = 0; i < neighbor_ids.length; i++) {
315 if (cids_requested.indexOf(neighbor_ids[i]) == -1)
316 if (!cache_get("article:" + neighbor_ids[i])) {
317 cids_to_request.push(neighbor_ids[i]);
318 cids_requested.push(neighbor_ids[i]);
322 console.log("additional ids: " + cids_to_request.toString());
324 query = query + "&cids=" + cids_to_request.toString();
326 var crow = $("RROW-" + id);
327 var article_is_unread = crow.hasClassName("Unread");
330 showArticleInHeadlines(id);
332 precache_headlines();
334 if (!cached_article) {
336 var upic = $('FUPDPIC-' + id);
339 upic.src = getInitParam("sign_progress");
342 } else if (cached_article && article_is_unread) {
344 query = query + "&mode=prefetch";
346 render_article(cached_article);
348 } else if (cached_article) {
350 query = query + "&mode=prefetch_old";
351 render_article(cached_article);
353 // if we don't need to request any relative ids, we might as well skip
354 // the server roundtrip altogether
355 if (cids_to_request.length == 0) {
358 if (!_infscroll_disable &&
359 $$("#headlines-frame > div[id*=RROW]").last().hasClassName("Selected")) {
371 last_requested_article = id;
375 new Ajax.Request("backend.php", {
377 onComplete: function(transport) {
378 article_callback2(transport, id);
384 exception_error("view", e);
389 return toggleMark(id);
393 return togglePub(id);
396 function toggleMark(id, client_only) {
398 var query = "?op=rpc&id=" + id + "&subop=mark";
400 var img = $("FMPIC-" + id);
404 if (img.src.match("mark_unset")) {
405 img.src = img.src.replace("mark_unset", "mark_set");
406 img.alt = __("Unstar article");
407 query = query + "&mark=1";
410 img.src = img.src.replace("mark_set", "mark_unset");
411 img.alt = __("Star article");
412 query = query + "&mark=0";
415 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML);
418 new Ajax.Request("backend.php", {
420 onComplete: function(transport) {
421 handle_rpc_json(transport);
426 exception_error("toggleMark", e);
430 function togglePub(id, client_only, no_effects, note) {
432 var query = "?op=rpc&id=" + id + "&subop=publ";
434 if (note != undefined) {
435 query = query + "¬e=" + param_escape(note);
437 query = query + "¬e=undefined";
440 var img = $("FPPIC-" + id);
444 if (img.src.match("pub_unset") || note != undefined) {
445 img.src = img.src.replace("pub_unset", "pub_set");
446 img.alt = __("Unpublish article");
447 query = query + "&pub=1";
450 img.src = img.src.replace("pub_set", "pub_unset");
451 img.alt = __("Publish article");
453 query = query + "&pub=0";
456 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML);
459 new Ajax.Request("backend.php", {
461 onComplete: function(transport) {
462 handle_rpc_json(transport);
467 exception_error("togglePub", e);
471 function moveToPost(mode) {
475 var rows = getVisibleArticleIds();
480 if (!$('RROW-' + active_post_id)) {
481 active_post_id = false;
484 if (active_post_id == false) {
485 next_id = getFirstVisibleHeadlineId();
486 prev_id = getLastVisibleHeadlineId();
488 for (var i = 0; i < rows.length; i++) {
489 if (rows[i] == active_post_id) {
496 if (mode == "next") {
500 cdmExpandArticle(next_id);
501 cdmScrollToArticleId(next_id);
504 correctHeadlinesOffset(next_id);
505 view(next_id, getActiveFeedId());
510 if (mode == "prev") {
513 cdmExpandArticle(prev_id);
514 cdmScrollToArticleId(prev_id);
516 correctHeadlinesOffset(prev_id);
517 view(prev_id, getActiveFeedId());
523 exception_error("moveToPost", e);
527 function toggleSelected(id, force_on) {
530 var cb = $("RCHK-" + id);
531 var row = $("RROW-" + id);
534 if (row.hasClassName('Selected') && !force_on) {
535 row.removeClassName('Selected');
536 if (cb) cb.checked = false;
538 row.addClassName('Selected');
539 if (cb) cb.checked = true;
543 exception_error("toggleSelected", e);
547 function toggleUnread_afh(effect) {
550 var elem = effect.element;
551 elem.style.backgroundColor = "";
554 exception_error("toggleUnread_afh", e);
558 function toggleUnread(id, cmode, effect) {
561 var row = $("RROW-" + id);
563 if (cmode == undefined || cmode == 2) {
564 if (row.hasClassName("Unread")) {
565 row.removeClassName("Unread");
568 new Effect.Highlight(row, {duration: 1, startcolor: "#fff7d5",
569 afterFinish: toggleUnread_afh,
570 queue: { position:'end', scope: 'TMRQ-' + id, limit: 1 } } );
574 row.addClassName("Unread");
577 } else if (cmode == 0) {
579 row.removeClassName("Unread");
582 new Effect.Highlight(row, {duration: 1, startcolor: "#fff7d5",
583 afterFinish: toggleUnread_afh,
584 queue: { position:'end', scope: 'TMRQ-' + id, limit: 1 } } );
587 } else if (cmode == 1) {
588 row.addClassName("Unread");
591 if (cmode == undefined) cmode = 2;
593 var query = "?op=rpc&subop=catchupSelected" +
594 "&cmode=" + param_escape(cmode) + "&ids=" + param_escape(id);
596 // notify_progress("Loading, please wait...");
598 new Ajax.Request("backend.php", {
600 onComplete: function(transport) {
601 handle_rpc_json(transport);
607 exception_error("toggleUnread", e);
611 function selectionRemoveLabel(id, ids) {
614 if (!ids) var ids = getSelectedArticleIds2();
616 if (ids.length == 0) {
617 alert(__("No articles are selected."));
621 var query = "?op=rpc&subop=removeFromLabel&ids=" +
622 param_escape(ids.toString()) + "&lid=" + param_escape(id);
626 new Ajax.Request("backend.php", {
628 onComplete: function(transport) {
629 handle_rpc_json(transport);
630 show_labels_in_headlines(transport);
634 exception_error("selectionAssignLabel", e);
639 function selectionAssignLabel(id, ids) {
642 if (!ids) ids = getSelectedArticleIds2();
644 if (ids.length == 0) {
645 alert(__("No articles are selected."));
649 var query = "?op=rpc&subop=assignToLabel&ids=" +
650 param_escape(ids.toString()) + "&lid=" + param_escape(id);
654 new Ajax.Request("backend.php", {
656 onComplete: function(transport) {
657 handle_rpc_json(transport);
658 show_labels_in_headlines(transport);
662 exception_error("selectionAssignLabel", e);
667 function selectionToggleUnread(set_state, callback, no_error) {
669 var rows = getSelectedArticleIds2();
671 if (rows.length == 0 && !no_error) {
672 alert(__("No articles are selected."));
676 for (i = 0; i < rows.length; i++) {
677 var row = $("RROW-" + rows[i]);
679 if (set_state == undefined) {
680 if (row.hasClassName("Unread")) {
681 row.removeClassName("Unread");
683 row.addClassName("Unread");
687 if (set_state == false) {
688 row.removeClassName("Unread");
691 if (set_state == true) {
692 row.addClassName("Unread");
697 if (rows.length > 0) {
701 if (set_state == undefined) {
703 } else if (set_state == true) {
705 } else if (set_state == false) {
709 var query = "?op=rpc&subop=catchupSelected" +
710 "&cmode=" + cmode + "&ids=" + param_escape(rows.toString());
712 notify_progress("Loading, please wait...");
714 new Ajax.Request("backend.php", {
716 onComplete: function(transport) {
717 handle_rpc_json(transport);
718 if (callback) callback(transport);
724 exception_error("selectionToggleUnread", e);
728 function selectionToggleMarked() {
731 var rows = getSelectedArticleIds2();
733 if (rows.length == 0) {
734 alert(__("No articles are selected."));
738 for (i = 0; i < rows.length; i++) {
739 toggleMark(rows[i], true, true);
742 if (rows.length > 0) {
744 var query = "?op=rpc&subop=markSelected&ids=" +
745 param_escape(rows.toString()) + "&cmode=2";
747 new Ajax.Request("backend.php", {
749 onComplete: function(transport) {
750 handle_rpc_json(transport);
756 exception_error("selectionToggleMarked", e);
760 function selectionTogglePublished() {
763 var rows = getSelectedArticleIds2();
765 if (rows.length == 0) {
766 alert(__("No articles are selected."));
770 for (i = 0; i < rows.length; i++) {
771 togglePub(rows[i], true, true);
774 if (rows.length > 0) {
776 var query = "?op=rpc&subop=publishSelected&ids=" +
777 param_escape(rows.toString()) + "&cmode=2";
779 new Ajax.Request("backend.php", {
781 onComplete: function(transport) {
782 handle_rpc_json(transport);
788 exception_error("selectionToggleMarked", e);
792 function getSelectedArticleIds2() {
796 $$("#headlines-frame > div[id*=RROW][class*=Selected]").each(
798 rv.push(child.id.replace("RROW-", ""));
804 function getLoadedArticleIds() {
807 var children = $$("#headlines-frame > div[id*=RROW-]");
809 children.each(function(child) {
810 rv.push(child.id.replace("RROW-", ""));
817 // mode = all,none,unread,invert
818 function selectArticles(mode) {
821 var children = $$("#headlines-frame > div[id*=RROW]");
823 children.each(function(child) {
824 var id = child.id.replace("RROW-", "");
825 var cb = $("RCHK-" + id);
828 child.addClassName("Selected");
830 } else if (mode == "unread") {
831 if (child.hasClassName("Unread")) {
832 child.addClassName("Selected");
835 child.removeClassName("Selected");
838 } else if (mode == "invert") {
839 if (child.hasClassName("Selected")) {
840 child.removeClassName("Selected");
843 child.addClassName("Selected");
848 child.removeClassName("Selected");
854 exception_error("selectArticles", e);
858 function catchupPage() {
860 var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
862 var str = __("Mark all visible articles in %s as read?");
864 str = str.replace("%s", fn);
866 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
870 selectArticles('all');
871 selectionToggleUnread(false, 'viewCurrentFeed()', true)
872 selectArticles('none');
875 function deleteSelection() {
879 var rows = getSelectedArticleIds2();
881 if (rows.length == 0) {
882 alert(__("No articles are selected."));
886 var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
890 if (getActiveFeedId() != 0) {
891 str = __("Delete %d selected articles in %s?");
893 str = __("Delete %d selected articles?");
896 str = str.replace("%d", rows.length);
897 str = str.replace("%s", fn);
899 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
903 query = "?op=rpc&subop=delete&ids=" + param_escape(rows);
907 new Ajax.Request("backend.php", {
909 onComplete: function(transport) {
910 handle_rpc_json(transport);
915 exception_error("deleteSelection", e);
919 function archiveSelection() {
923 var rows = getSelectedArticleIds2();
925 if (rows.length == 0) {
926 alert(__("No articles are selected."));
930 var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
934 if (getActiveFeedId() != 0) {
935 str = __("Archive %d selected articles in %s?");
938 str = __("Move %d archived articles back?");
942 str = str.replace("%d", rows.length);
943 str = str.replace("%s", fn);
945 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
949 query = "?op=rpc&subop="+op+"&ids=" + param_escape(rows);
953 for (var i = 0; i < rows.length; i++) {
954 cache_delete("article:" + rows[i]);
957 new Ajax.Request("backend.php", {
959 onComplete: function(transport) {
960 handle_rpc_json(transport);
965 exception_error("archiveSelection", e);
969 function catchupSelection() {
973 var rows = getSelectedArticleIds2();
975 if (rows.length == 0) {
976 alert(__("No articles are selected."));
980 var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
982 var str = __("Mark %d selected articles in %s as read?");
984 str = str.replace("%d", rows.length);
985 str = str.replace("%s", fn);
987 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
991 selectionToggleUnread(false, 'viewCurrentFeed()', true)
994 exception_error("catchupSelection", e);
998 function editArticleTags(id) {
999 var query = "backend.php?op=dlg&id=editArticleTags¶m=" + param_escape(id);
1001 if (dijit.byId("editTagsDlg"))
1002 dijit.byId("editTagsDlg").destroyRecursive();
1004 dialog = new dijit.Dialog({
1006 title: __("Edit article Tags"),
1007 style: "width: 600px",
1008 execute: function() {
1009 if (this.validate()) {
1010 var query = dojo.objectToQuery(this.attr('value'));
1012 notify_progress("Saving article tags...", true);
1014 new Ajax.Request("backend.php", {
1016 onComplete: function(transport) {
1020 var data = JSON.parse(transport.responseText);
1023 var tags_str = article.tags;
1024 var id = tags_str.id;
1026 var tags = $("ATSTR-" + id);
1027 var tooltip = dijit.byId("ATSTRTIP-" + id);
1029 if (tags) tags.innerHTML = tags_str.content;
1030 if (tooltip) tooltip.attr('label', tags_str.content_full);
1032 cache_delete("article:" + id);
1041 var tmph = dojo.connect(dialog, 'onLoad', function() {
1042 dojo.disconnect(tmph);
1044 new Ajax.Autocompleter('tags_str', 'tags_choices',
1045 "backend.php?op=rpc&subop=completeTags",
1046 { tokens: ',', paramName: "search" });
1053 function cdmScrollToArticleId(id) {
1055 var ctr = $("headlines-frame");
1056 var e = $("RROW-" + id);
1058 if (!e || !ctr) return;
1060 ctr.scrollTop = e.offsetTop;
1063 exception_error("cdmScrollToArticleId", e);
1067 function getActiveArticleId() {
1068 return active_post_id;
1071 function postMouseIn(id) {
1072 post_under_pointer = id;
1075 function postMouseOut(id) {
1076 post_under_pointer = false;
1079 function headlines_scroll_handler(e) {
1081 var hsp = $("headlines-spacer");
1083 if (!_infscroll_disable) {
1084 if (hsp && (e.scrollTop + e.offsetHeight > hsp.offsetTop) ||
1085 e.scrollTop + e.offsetHeight > e.scrollHeight - 100) {
1087 hsp.innerHTML = "<img src='images/indicator_tiny.gif'> " +
1088 __("Loading, please wait...");
1090 loadMoreHeadlines();
1092 //viewNextFeedPage();
1095 if (hsp) hsp.innerHTML = "";
1098 if (getInitParam("cdm_auto_catchup") == 1) {
1100 $$("#headlines-frame > div[id*=RROW][class*=Unread]").each(
1102 if ($("headlines-frame").scrollTop >
1103 (child.offsetTop + child.offsetHeight/2)) {
1105 var id = child.id.replace("RROW-", "");
1107 if (catchup_id_batch.indexOf(id) == -1)
1108 catchup_id_batch.push(id);
1112 if (catchup_id_batch.length > 0 && !_infscroll_request_sent) {
1113 window.clearTimeout(catchup_timeout_id);
1114 catchup_timeout_id = window.setTimeout('catchupBatchedArticles()',
1120 console.warn("headlines_scroll_handler: " + e);
1124 function catchupBatchedArticles() {
1126 if (catchup_id_batch.length > 0 && !_infscroll_request_sent) {
1128 var query = "?op=rpc&subop=catchupSelected" +
1129 "&cmode=0&ids=" + param_escape(catchup_id_batch.toString());
1131 new Ajax.Request("backend.php", {
1133 onComplete: function(transport) {
1134 handle_rpc_json(transport);
1136 catchup_id_batch.each(function(id) {
1137 var elem = $("RROW-" + id);
1138 if (elem) elem.removeClassName("Unread");
1141 catchup_id_batch = [];
1146 exception_error("catchupBatchedArticles", e);
1150 function catchupRelativeToArticle(below) {
1155 if (!getActiveArticleId()) {
1156 alert(__("No article is selected."));
1160 var visible_ids = getVisibleArticleIds();
1162 var ids_to_mark = new Array();
1165 for (var i = 0; i < visible_ids.length; i++) {
1166 if (visible_ids[i] != getActiveArticleId()) {
1167 var e = $("RROW-" + visible_ids[i]);
1169 if (e && e.hasClassName("Unread")) {
1170 ids_to_mark.push(visible_ids[i]);
1177 for (var i = visible_ids.length-1; i >= 0; i--) {
1178 if (visible_ids[i] != getActiveArticleId()) {
1179 var e = $("RROW-" + visible_ids[i]);
1181 if (e && e.hasClassName("Unread")) {
1182 ids_to_mark.push(visible_ids[i]);
1190 if (ids_to_mark.length == 0) {
1191 alert(__("No articles found to mark"));
1193 var msg = __("Mark %d article(s) as read?").replace("%d", ids_to_mark.length);
1195 if (getInitParam("confirm_feed_catchup") != 1 || confirm(msg)) {
1197 for (var i = 0; i < ids_to_mark.length; i++) {
1198 var e = $("RROW-" + ids_to_mark[i]);
1199 e.removeClassName("Unread");
1202 var query = "?op=rpc&subop=catchupSelected" +
1203 "&cmode=0" + "&ids=" + param_escape(ids_to_mark.toString());
1205 new Ajax.Request("backend.php", {
1207 onComplete: function(transport) {
1208 handle_rpc_json(transport);
1215 exception_error("catchupRelativeToArticle", e);
1219 function cdmExpandArticle(id) {
1224 var elem = $("CICD-" + active_post_id);
1226 var upd_img_pic = $("FUPDPIC-" + id);
1228 if (upd_img_pic && (upd_img_pic.src.match("updated.png") ||
1229 upd_img_pic.src.match("fresh_sign.png"))) {
1231 upd_img_pic.src = "images/blank_icon.gif";
1234 if (id == active_post_id && Element.visible(elem))
1237 selectArticles("none");
1239 var old_offset = $("RROW-" + id).offsetTop;
1241 if (active_post_id && elem && !getInitParam("cdm_expanded")) {
1243 Element.show("CEXC-" + active_post_id);
1246 active_post_id = id;
1248 elem = $("CICD-" + id);
1250 if (!Element.visible(elem)) {
1252 Element.hide("CEXC-" + id);
1254 if ($("CWRAP-" + id).innerHTML == "") {
1256 $("FUPDPIC-" + id).src = "images/indicator_tiny.gif";
1258 $("CWRAP-" + id).innerHTML = "<div class=\"insensitive\">" +
1259 __("Loading, please wait...") + "</div>";
1261 var query = "?op=rpc&subop=cdmGetArticle&id=" + param_escape(id);
1263 var neighbor_ids = getRelativePostIds(id);
1265 /* only request uncached articles */
1266 var cids_to_request = [];
1268 for (var i = 0; i < neighbor_ids.length; i++) {
1269 if (cids_requested.indexOf(neighbor_ids[i]) == -1)
1270 if ($("CWRAP-" + neighbor_ids[i]).innerHTML == "") {
1271 cids_to_request.push(neighbor_ids[i]);
1272 cids_requested.push(neighbor_ids[i]);
1276 console.log("additional ids: " + cids_to_request.toString());
1278 query = query + "&cids=" + cids_to_request.toString();
1282 new Ajax.Request("backend.php", {
1284 onComplete: function(transport) {
1286 $("FUPDPIC-" + id).src = 'images/blank_icon.gif';
1288 handle_rpc_json(transport);
1290 var reply = JSON.parse(transport.responseText);
1292 reply.each(function(article) {
1293 $("CWRAP-" + article['id']).innerHTML = article['content']
1294 cids_requested.remove(article['id']);
1301 var new_offset = $("RROW-" + id).offsetTop;
1303 $("headlines-frame").scrollTop += (new_offset-old_offset);
1305 if ($("RROW-" + id).offsetTop != old_offset)
1306 $("headlines-frame").scrollTop = new_offset;
1308 toggleUnread(id, 0, true);
1312 exception_error("cdmExpandArticle", e);
1318 function fixHeadlinesOrder(ids) {
1320 for (var i = 0; i < ids.length; i++) {
1321 var e = $("RROW-" + ids[i]);
1325 e.removeClassName("even");
1326 e.addClassName("odd");
1328 e.removeClassName("odd");
1329 e.addClassName("even");
1334 exception_error("fixHeadlinesOrder", e);
1338 function getArticleUnderPointer() {
1339 return post_under_pointer;
1342 function zoomToArticle(event, id) {
1344 var cached_article = cache_get("article: " + id);
1346 if (dijit.byId("ATAB-" + id))
1347 if (!event || !event.shiftKey)
1348 return dijit.byId("content-tabs").selectChild(dijit.byId("ATAB-" + id));
1350 if (dijit.byId("ATSTRTIP-" + id))
1351 dijit.byId("ATSTRTIP-" + id).destroyRecursive();
1353 if (cached_article) {
1354 //closeArticlePanel();
1356 var article_pane = new dijit.layout.ContentPane({
1357 title: __("Loading...") , content: cached_article,
1358 style: 'padding : 0px;',
1362 dijit.byId("content-tabs").addChild(article_pane);
1364 if (!event || !event.shiftKey)
1365 dijit.byId("content-tabs").selectChild(article_pane);
1367 if ($("PTITLE-" + id))
1368 article_pane.attr('title', $("PTITLE-" + id).innerHTML);
1372 var query = "?op=rpc&subop=getArticles&ids=" + param_escape(id);
1374 notify_progress("Loading, please wait...", true);
1376 new Ajax.Request("backend.php", {
1378 onComplete: function(transport) {
1381 var reply = JSON.parse(transport.responseText);
1384 //closeArticlePanel();
1386 var content = reply[0]['content'];
1388 var article_pane = new dijit.layout.ContentPane({
1389 title: "article-" + id , content: content,
1390 style: 'padding : 0px;',
1394 dijit.byId("content-tabs").addChild(article_pane);
1396 if (!event || !event.shiftKey)
1397 dijit.byId("content-tabs").selectChild(article_pane);
1399 if ($("PTITLE-" + id))
1400 article_pane.attr('title', $("PTITLE-" + id).innerHTML);
1407 exception_error("zoomToArticle", e);
1411 function scrollArticle(offset) {
1414 var ci = $("content-insert");
1416 ci.scrollTop += offset;
1419 var hi = $("headlines-frame");
1421 hi.scrollTop += offset;
1426 exception_error("scrollArticle", e);
1430 function show_labels_in_headlines(transport) {
1432 var data = JSON.parse(transport.responseText);
1435 data['info-for-headlines'].each(function(elem) {
1436 var ctr = $("HLLCTR-" + elem.id);
1438 if (ctr) ctr.innerHTML = elem.labels;
1441 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML);
1445 exception_error("show_labels_in_headlines", e);
1449 /* function toggleHeadlineActions() {
1451 var e = $("headlineActionsBody");
1452 var p = $("headlineActionsDrop");
1454 if (!Element.visible(e)) {
1461 e.style.left = (p.offsetLeft + 1) + "px";
1462 e.style.top = (p.offsetTop + p.offsetHeight + 2) + "px";
1465 exception_error("toggleHeadlineActions", e);
1469 /* function publishWithNote(id, def_note) {
1471 if (!def_note) def_note = '';
1473 var note = prompt(__("Please enter a note for this article:"), def_note);
1475 if (note != undefined) {
1476 togglePub(id, false, false, note);
1480 exception_error("publishWithNote", e);
1484 function emailArticle(id) {
1487 var ids = getSelectedArticleIds2();
1489 if (ids.length == 0) {
1490 alert(__("No articles are selected."));
1494 id = ids.toString();
1497 if (dijit.byId("emailArticleDlg"))
1498 dijit.byId("emailArticleDlg").destroyRecursive();
1500 var query = "backend.php?op=dlg&id=emailArticle¶m=" + param_escape(id);
1502 dialog = new dijit.Dialog({
1503 id: "emailArticleDlg",
1504 title: __("Forward article by email"),
1505 style: "width: 600px",
1506 execute: function() {
1507 if (this.validate()) {
1509 new Ajax.Request("backend.php", {
1510 parameters: dojo.objectToQuery(this.attr('value')),
1511 onComplete: function(transport) {
1513 var reply = JSON.parse(transport.responseText);
1515 var error = reply['error'];
1518 alert(__('Error sending email:') + ' ' + error);
1520 notify_info('Your message has been sent.');
1529 var tmph = dojo.connect(dialog, 'onLoad', function() {
1530 dojo.disconnect(tmph);
1532 new Ajax.Autocompleter('emailArticleDlg_destination', 'emailArticleDlg_dst_choices',
1533 "backend.php?op=rpc&subop=completeEmails",
1534 { tokens: '', paramName: "search" });
1539 /* displayDlg('emailArticle', id,
1541 document.forms['article_email_form'].destination.focus();
1543 new Ajax.Autocompleter('destination', 'destination_choices',
1544 "backend.php?op=rpc&subop=completeEmails",
1545 { tokens: '', paramName: "search" });
1550 exception_error("emailArticle", e);
1554 function dismissArticle(id) {
1556 var elem = $("RROW-" + id);
1558 toggleUnread(id, 0, true);
1560 new Effect.Fade(elem, {duration : 0.5});
1562 active_post_id = false;
1565 exception_error("dismissArticle", e);
1569 function dismissSelectedArticles() {
1572 var ids = getVisibleArticleIds();
1576 for (var i = 0; i < ids.length; i++) {
1577 var elem = $("RROW-" + ids[i]);
1579 if (elem.className && elem.hasClassName("Selected") &&
1580 ids[i] != active_post_id) {
1581 new Effect.Fade(elem, {duration : 0.5});
1589 selectionToggleUnread(false);
1591 fixHeadlinesOrder(tmp);
1594 exception_error("dismissSelectedArticles", e);
1598 function dismissReadArticles() {
1601 var ids = getVisibleArticleIds();
1604 for (var i = 0; i < ids.length; i++) {
1605 var elem = $("RROW-" + ids[i]);
1607 if (elem.className && !elem.hasClassName("Unread") &&
1608 !elem.hasClassName("Selected")) {
1610 new Effect.Fade(elem, {duration : 0.5});
1616 fixHeadlinesOrder(tmp);
1619 exception_error("dismissSelectedArticles", e);
1623 function getVisibleArticleIds() {
1628 getLoadedArticleIds().each(function(id) {
1629 var elem = $("RROW-" + id);
1630 if (elem && Element.visible(elem))
1635 exception_error("getVisibleArticleIds", e);
1641 function cdmClicked(event, id) {
1643 var shift_key = event.shiftKey;
1647 if (!event.ctrlKey) {
1649 if (!getInitParam("cdm_expanded")) {
1650 return cdmExpandArticle(id);
1653 selectArticles("none");
1656 var elem = $("RROW-" + id);
1659 elem.removeClassName("Unread");
1661 var upd_img_pic = $("FUPDPIC-" + id);
1663 if (upd_img_pic && (upd_img_pic.src.match("updated.png") ||
1664 upd_img_pic.src.match("fresh_sign.png"))) {
1666 upd_img_pic.src = "images/blank_icon.gif";
1669 active_post_id = id;
1671 var query = "?op=rpc&subop=catchupSelected" +
1672 "&cmode=0&ids=" + param_escape(id);
1674 new Ajax.Request("backend.php", {
1676 onComplete: function(transport) {
1677 handle_rpc_json(transport);
1684 toggleSelected(id, true);
1685 toggleUnread(id, 0, false);
1686 zoomToArticle(event, id);
1690 exception_error("cdmClicked");
1696 function postClicked(event, id) {
1699 if (!event.ctrlKey) {
1702 postOpenInNewTab(event, id);
1707 exception_error("postClicked");
1711 function hlOpenInNewTab(event, id) {
1712 toggleUnread(id, 0, false);
1713 zoomToArticle(event, id);
1716 function postOpenInNewTab(event, id) {
1717 closeArticlePanel(id);
1718 zoomToArticle(event, id);
1721 function hlClicked(event, id) {
1723 if (event.which == 2) {
1726 } else if (event.altKey) {
1727 openArticleInNewWindow(id);
1728 } else if (!event.ctrlKey) {
1733 toggleUnread(id, 0, false);
1734 zoomToArticle(event, id);
1739 exception_error("hlClicked");
1743 function getFirstVisibleHeadlineId() {
1744 var rows = getVisibleArticleIds();
1749 function getLastVisibleHeadlineId() {
1750 var rows = getVisibleArticleIds();
1751 return rows[rows.length-1];
1754 function openArticleInNewWindow(id) {
1755 toggleUnread(id, 0, false);
1756 window.open("backend.php?op=la&id=" + id);
1759 function isCdmMode() {
1760 return getInitParam("combined_display_mode");
1763 function markHeadline(id) {
1764 var row = $("RROW-" + id);
1766 var check = $("RCHK-" + id);
1769 check.checked = true;
1772 row.addClassName("Selected");
1776 function getRelativePostIds(id, limit) {
1782 if (!limit) limit = 6; //3
1784 var ids = getVisibleArticleIds();
1786 for (var i = 0; i < ids.length; i++) {
1788 for (var k = 1; k <= limit; k++) {
1789 //if (i > k-1) tmp.push(ids[i-k]);
1790 if (i < ids.length-k) tmp.push(ids[i+k]);
1797 exception_error("getRelativePostIds", e);
1803 function correctHeadlinesOffset(id) {
1807 var container = $("headlines-frame");
1808 var row = $("RROW-" + id);
1810 var viewport = container.offsetHeight;
1812 var rel_offset_top = row.offsetTop - container.scrollTop;
1813 var rel_offset_bottom = row.offsetTop + row.offsetHeight - container.scrollTop;
1815 //console.log("Rtop: " + rel_offset_top + " Rbtm: " + rel_offset_bottom);
1816 //console.log("Vport: " + viewport);
1818 if (rel_offset_top <= 0 || rel_offset_top > viewport) {
1819 container.scrollTop = row.offsetTop;
1820 } else if (rel_offset_bottom > viewport) {
1822 /* doesn't properly work with Opera in some cases because
1823 Opera fucks up element scrolling */
1825 container.scrollTop = row.offsetTop + row.offsetHeight - viewport;
1829 exception_error("correctHeadlinesOffset", e);
1834 function headlineActionsChange(elem) {
1837 elem.attr('value', 'false');
1839 exception_error("headlineActionsChange", e);
1843 function closeArticlePanel() {
1845 var tabs = dijit.byId("content-tabs");
1846 var child = tabs.selectedChildWidget;
1848 if (child && tabs.getIndexOfChild(child) > 0) {
1849 tabs.removeChild(child);
1852 if (dijit.byId("content-insert"))
1853 dijit.byId("headlines-wrap-inner").removeChild(
1854 dijit.byId("content-insert"));
1858 function initHeadlinesMenu() {
1860 if (dijit.byId("headlinesMenu"))
1861 dijit.byId("headlinesMenu").destroyRecursive();
1866 nodes = $$("#headlines-frame > div[id*=RROW]");
1868 nodes = $$("#headlines-frame span[id*=RTITLE]");
1871 nodes.each(function(node) {
1875 var menu = new dijit.Menu({
1876 id: "headlinesMenu",
1880 var tmph = dojo.connect(menu, '_openMyself', function (event) {
1881 var callerNode = event.target, match = null, tries = 0;
1883 while (match == null && callerNode && tries <= 3) {
1884 match = callerNode.id.match("^[A-Z]+[-]([0-9]+)$");
1885 callerNode = callerNode.parentNode;
1889 if (match) this.callerRowId = parseInt(match[1]);
1893 /* if (!isCdmMode())
1894 menu.addChild(new dijit.MenuItem({
1895 label: __("View article"),
1896 onClick: function(event) {
1897 view(this.getParent().callerRowId);
1900 menu.addChild(new dijit.MenuItem({
1901 label: __("Open original article"),
1902 onClick: function(event) {
1903 openArticleInNewWindow(this.getParent().callerRowId);
1906 menu.addChild(new dijit.MenuItem({
1907 label: __("View in a tt-rss tab"),
1908 onClick: function(event) {
1909 hlOpenInNewTab(event, this.getParent().callerRowId);
1912 // menu.addChild(new dijit.MenuSeparator());
1914 var labels = dijit.byId("feedTree").model.getItemsInCategory(-2);
1918 menu.addChild(new dijit.MenuSeparator());
1920 var labelAddMenu = new dijit.Menu({ownerMenu: menu});
1921 var labelDelMenu = new dijit.Menu({ownerMenu: menu});
1923 labels.each(function(label) {
1924 var id = label.id[0];
1925 var bare_id = id.substr(id.indexOf(":")+1);
1926 var name = label.name[0];
1928 bare_id = -11-bare_id;
1930 labelAddMenu.addChild(new dijit.MenuItem({
1933 onClick: function(event) {
1934 selectionAssignLabel(this.labelId,
1935 [this.getParent().ownerMenu.callerRowId]);
1938 labelDelMenu.addChild(new dijit.MenuItem({
1941 onClick: function(event) {
1942 selectionRemoveLabel(this.labelId,
1943 [this.getParent().ownerMenu.callerRowId]);
1948 menu.addChild(new dijit.PopupMenuItem({
1949 label: __("Assign label"),
1950 popup: labelAddMenu,
1953 menu.addChild(new dijit.PopupMenuItem({
1954 label: __("Remove label"),
1955 popup: labelDelMenu,
1963 exception_error("initHeadlinesMenu", e);
1967 function tweetArticle(id) {
1969 var query = "?op=rpc&subop=getTweetInfo&id=" + param_escape(id);
1974 var ts = d.getTime();
1976 var w = window.open('backend.php?op=loading', 'ttrss_tweet',
1977 "status=0,toolbar=0,location=0,width=500,height=400,scrollbars=1,menubar=0");
1979 new Ajax.Request("backend.php", {
1981 onComplete: function(transport) {
1982 var ti = JSON.parse(transport.responseText);
1984 var share_url = "http://twitter.com/share?_=" + ts +
1985 "&text=" + param_escape(ti.title) +
1986 "&url=" + param_escape(ti.link);
1988 w.location.href = share_url;
1994 exception_error("tweetArticle", e);
1998 function editArticleNote(id) {
2001 var query = "backend.php?op=dlg&id=editArticleNote¶m=" + param_escape(id);
2003 if (dijit.byId("editNoteDlg"))
2004 dijit.byId("editNoteDlg").destroyRecursive();
2006 dialog = new dijit.Dialog({
2008 title: __("Edit article note"),
2009 style: "width: 600px",
2010 execute: function() {
2011 if (this.validate()) {
2012 var query = dojo.objectToQuery(this.attr('value'));
2014 notify_progress("Saving article note...", true);
2016 new Ajax.Request("backend.php", {
2018 onComplete: function(transport) {
2022 var reply = JSON.parse(transport.responseText);
2024 cache_delete("article:" + id);
2026 var elem = $("POSTNOTE-" + id);
2030 elem.innerHTML = reply.note;
2032 if (reply.raw_length != 0)
2033 new Effect.Appear(elem);
2045 exception_error("editArticleNote", e);
2049 function player(elem) {
2050 var aid = elem.getAttribute("audio-id");
2051 var status = elem.getAttribute("status");
2059 elem.innerHTML = __("Playing...");
2060 elem.title = __("Click to pause");
2061 elem.addClassName("playing");
2065 elem.innerHTML = __("Play");
2066 elem.title = __("Click to play");
2067 elem.removeClassName("playing");
2070 elem.setAttribute("status", status);
2072 alert("Your browser doesn't seem to support HTML5 audio.");
2076 function cache_set(id, obj) {
2077 //console.log("cache_set: " + id);
2080 sessionStorage[id] = obj;
2082 sessionStorage.clear();
2086 function cache_get(id) {
2088 return sessionStorage[id];
2091 function cache_clear() {
2093 sessionStorage.clear();
2096 function cache_delete(id) {
2098 sessionStorage.removeItem(id);
2101 function cache_headlines(feed, is_cat, toolbar_obj, content_obj) {
2102 if (toolbar_obj && content_obj) {
2103 cache_set("feed:" + feed + ":" + is_cat,
2104 JSON.stringify({toolbar: toolbar_obj, content: content_obj}));
2107 obj = cache_get("feed:" + feed + ":" + is_cat);
2110 obj = JSON.parse(obj);
2112 if (toolbar_obj) obj.toolbar = toolbar_obj;
2113 if (content_obj) obj.content = content_obj;
2115 cache_set("feed:" + feed + ":" + is_cat, JSON.stringify(obj));
2119 console.warn("cache_headlines failed: " + e);
2124 function render_local_headlines(feed, is_cat, obj) {
2127 dijit.byId("headlines-toolbar").attr('content',
2130 dijit.byId("headlines-frame").attr('content',
2133 dojo.parser.parse('headlines-toolbar');
2135 $("headlines-frame").scrollTop = 0;
2136 selectArticles('none');
2137 setActiveFeedId(feed, is_cat);
2138 initHeadlinesMenu();
2140 precache_headlines();
2143 exception_error("render_local_headlines", e);
2147 function precache_headlines_idle() {
2149 if (!feed_precache_timeout_id) {
2150 var feeds = dijit.byId("feedTree").getVisibleUnreadFeeds();
2153 feeds.each(function(item) {
2154 if (parseInt(item[0]) > 0 && !cache_get("feed:" + item[0] + ":" + item[1]))
2155 uncached.push(item);
2158 if (uncached.length > 0) {
2159 var rf = uncached[Math.floor(Math.random()*uncached.length)];
2160 viewfeed(rf[0], '', rf[1], 0, true);
2163 precache_idle_timeout_id = setTimeout("precache_headlines_idle()", 5000);
2166 exception_error("precache_headlines_idle", e);
2170 function precache_headlines() {
2173 if (!feed_precache_timeout_id) {
2174 feed_precache_timeout_id = window.setTimeout(function() {
2175 var nuf = getNextUnreadFeed(getActiveFeedId(), activeFeedIsCat());
2176 var nf = dijit.byId("feedTree").getNextFeed(getActiveFeedId(), activeFeedIsCat());
2178 if (nuf && !cache_get("feed:" + nuf + ":" + activeFeedIsCat()))
2179 viewfeed(nuf, '', activeFeedIsCat(), 0, true);
2181 if (nf != nuf && nf && !cache_get("feed:" + nf[0] + ":" + nf[1]))
2182 viewfeed(nf[0], '', nf[1], 0, true);
2184 window.setTimeout(function() {
2185 feed_precache_timeout_id = false;
2191 exception_error("precache_headlines", e);
2195 function shareArticle(id) {
2197 if (dijit.byId("shareArticleDlg"))
2198 dijit.byId("shareArticleDlg").destroyRecursive();
2200 var query = "backend.php?op=dlg&id=shareArticle¶m=" + param_escape(id);
2202 dialog = new dijit.Dialog({
2203 id: "shareArticleDlg",
2204 title: __("Share article by URL"),
2205 style: "width: 600px",
2211 exception_error("emailArticle", e);