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);
85 if (headlines_count > 0) {
86 console.log("adding some more headlines...");
88 var c = dijit.byId("headlines-frame");
89 var ids = getSelectedArticleIds2();
91 $("headlines-tmp").innerHTML = reply['headlines']['content'];
93 var hsp = $("headlines-spacer");
96 c.domNode.removeChild(hsp);
98 $$("#headlines-tmp > div").each(function(row) {
99 if ($$("#headlines-frame DIV[id="+row.id+"]").length == 0) {
100 row.style.display = 'none';
101 c.domNode.appendChild(row);
105 if (!hsp) hsp = new Element("DIV", {"id": "headlines-spacer"});
107 fixHeadlinesOrder(getLoadedArticleIds());
109 c.domNode.appendChild(hsp);
111 console.log("restore selected ids: " + ids);
113 for (var i = 0; i < ids.length; i++) {
114 markHeadline(ids[i]);
119 $$("#headlines-frame > div[id*=RROW]").each(
121 if (!Element.visible(child))
122 new Effect.Appear(child, { duration : 0.5 });
126 console.log("no new headlines received");
128 var hsp = $("headlines-spacer");
130 if (hsp) hsp.innerHTML = "";
134 if (headlines_count > 0)
135 cache_headlines(feed_id, is_cat, reply['headlines']['toolbar'], $("headlines-frame").innerHTML);
138 for (var i = 0; i < articles.length; i++) {
139 var a_id = articles[i]['id'];
140 cache_set("article:" + a_id, articles[i]['content']);
143 console.log("no cached articles received");
146 // do not precache stuff after fresh feed
148 precache_headlines();
151 parse_counters(counters);
156 console.warn("headlines_callback: returned no XML object");
157 dijit.byId("headlines-frame").attr('content', "<div class='whiteBox'>" +
158 __('Could not update headlines (invalid object received)') + "</div>");
161 _infscroll_request_sent = 0;
166 exception_error("headlines_callback2", e, transport);
170 function render_article(article) {
172 dijit.byId("headlines-wrap-inner").addChild(
173 dijit.byId("content-insert"));
175 var c = dijit.byId("content-insert");
178 c.domNode.scrollTop = 0;
181 c.attr('content', article);
183 correctHeadlinesOffset(getActiveArticleId());
190 exception_error("render_article", e);
194 function showArticleInHeadlines(id) {
198 selectArticles("none");
200 var crow = $("RROW-" + id);
204 var article_is_unread = crow.hasClassName("Unread");
206 crow.removeClassName("Unread");
208 selectArticles('none');
210 var upd_img_pic = $("FUPDPIC-" + id);
212 var view_mode = false;
215 view_mode = document.forms['main_toolbar_form'].view_mode;
216 view_mode = view_mode[view_mode.selectedIndex].value;
221 if (upd_img_pic && (upd_img_pic.src.match("updated.png") ||
222 upd_img_pic.src.match("fresh_sign.png"))) {
224 upd_img_pic.src = "images/blank_icon.gif";
226 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML);
228 } else if (article_is_unread && view_mode == "all_articles") {
229 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML);
234 if (article_is_unread)
235 _force_scheduled_update = true;
238 exception_error("showArticleInHeadlines", e);
242 function article_callback2(transport, id) {
244 console.log("article_callback2 " + id);
246 handle_rpc_json(transport);
248 var reply = JSON.parse(transport.responseText);
252 var upic = $('FUPDPIC-' + id);
254 if (upic) upic.src = 'images/blank_icon.gif';
256 reply.each(function(article) {
257 if (active_post_id == article['id']) {
258 render_article(article['content']);
260 cids_requested.remove(article['id']);
262 cache_set("article:" + article['id'], article['content']);
265 // if (id != last_requested_article) {
266 // console.log("requested article id is out of sequence, aborting");
271 console.warn("article_callback: returned invalid data");
273 render_article("<div class='whiteBox'>" +
274 __('Could not display article (invalid data received)') + "</div>");
280 if (!_infscroll_disable &&
281 $$("#headlines-frame > div[id*=RROW]").last().hasClassName("Selected")) {
291 exception_error("article_callback2", e, transport);
297 console.log("loading article: " + id);
299 var cached_article = cache_get("article:" + id);
301 console.log("cache check result: " + (cached_article != false));
305 var query = "?op=view&id=" + param_escape(id);
307 var neighbor_ids = getRelativePostIds(id);
309 /* only request uncached articles */
311 var cids_to_request = [];
313 for (var i = 0; i < neighbor_ids.length; i++) {
314 if (cids_requested.indexOf(neighbor_ids[i]) == -1)
315 if (!cache_get("article:" + neighbor_ids[i])) {
316 cids_to_request.push(neighbor_ids[i]);
317 cids_requested.push(neighbor_ids[i]);
321 console.log("additional ids: " + cids_to_request.toString());
323 query = query + "&cids=" + cids_to_request.toString();
325 var crow = $("RROW-" + id);
326 var article_is_unread = crow.hasClassName("Unread");
329 showArticleInHeadlines(id);
331 precache_headlines();
333 if (!cached_article) {
335 var upic = $('FUPDPIC-' + id);
338 upic.src = getInitParam("sign_progress");
341 } else if (cached_article && article_is_unread) {
343 query = query + "&mode=prefetch";
345 render_article(cached_article);
347 } else if (cached_article) {
349 query = query + "&mode=prefetch_old";
350 render_article(cached_article);
352 // if we don't need to request any relative ids, we might as well skip
353 // the server roundtrip altogether
354 if (cids_to_request.length == 0) {
357 if (!_infscroll_disable &&
358 $$("#headlines-frame > div[id*=RROW]").last().hasClassName("Selected")) {
370 last_requested_article = id;
374 new Ajax.Request("backend.php", {
376 onComplete: function(transport) {
377 article_callback2(transport, id);
383 exception_error("view", e);
388 return toggleMark(id);
392 return togglePub(id);
395 function toggleMark(id, client_only) {
397 var query = "?op=rpc&id=" + id + "&subop=mark";
399 var img = $("FMPIC-" + id);
403 if (img.src.match("mark_unset")) {
404 img.src = img.src.replace("mark_unset", "mark_set");
405 img.alt = __("Unstar article");
406 query = query + "&mark=1";
409 img.src = img.src.replace("mark_set", "mark_unset");
410 img.alt = __("Star article");
411 query = query + "&mark=0";
414 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML);
417 new Ajax.Request("backend.php", {
419 onComplete: function(transport) {
420 handle_rpc_json(transport);
425 exception_error("toggleMark", e);
429 function togglePub(id, client_only, no_effects, note) {
431 var query = "?op=rpc&id=" + id + "&subop=publ";
433 if (note != undefined) {
434 query = query + "¬e=" + param_escape(note);
436 query = query + "¬e=undefined";
439 var img = $("FPPIC-" + id);
443 if (img.src.match("pub_unset") || note != undefined) {
444 img.src = img.src.replace("pub_unset", "pub_set");
445 img.alt = __("Unpublish article");
446 query = query + "&pub=1";
449 img.src = img.src.replace("pub_set", "pub_unset");
450 img.alt = __("Publish article");
452 query = query + "&pub=0";
455 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML);
458 new Ajax.Request("backend.php", {
460 onComplete: function(transport) {
461 handle_rpc_json(transport);
466 exception_error("togglePub", e);
470 function moveToPost(mode) {
474 var rows = getVisibleArticleIds();
479 if (!$('RROW-' + active_post_id)) {
480 active_post_id = false;
483 if (active_post_id == false) {
484 next_id = getFirstVisibleHeadlineId();
485 prev_id = getLastVisibleHeadlineId();
487 for (var i = 0; i < rows.length; i++) {
488 if (rows[i] == active_post_id) {
495 if (mode == "next") {
499 cdmExpandArticle(next_id);
500 cdmScrollToArticleId(next_id);
503 correctHeadlinesOffset(next_id);
504 view(next_id, getActiveFeedId());
509 if (mode == "prev") {
512 cdmExpandArticle(prev_id);
513 cdmScrollToArticleId(prev_id);
515 correctHeadlinesOffset(prev_id);
516 view(prev_id, getActiveFeedId());
522 exception_error("moveToPost", e);
526 function toggleSelected(id, force_on) {
529 var cb = $("RCHK-" + id);
530 var row = $("RROW-" + id);
533 if (row.hasClassName('Selected') && !force_on) {
534 row.removeClassName('Selected');
535 if (cb) cb.checked = false;
537 row.addClassName('Selected');
538 if (cb) cb.checked = true;
542 exception_error("toggleSelected", e);
546 function toggleUnread_afh(effect) {
549 var elem = effect.element;
550 elem.style.backgroundColor = "";
553 exception_error("toggleUnread_afh", e);
557 function toggleUnread(id, cmode, effect) {
560 var row = $("RROW-" + id);
562 if (cmode == undefined || cmode == 2) {
563 if (row.hasClassName("Unread")) {
564 row.removeClassName("Unread");
567 new Effect.Highlight(row, {duration: 1, startcolor: "#fff7d5",
568 afterFinish: toggleUnread_afh,
569 queue: { position:'end', scope: 'TMRQ-' + id, limit: 1 } } );
573 row.addClassName("Unread");
576 } else if (cmode == 0) {
578 row.removeClassName("Unread");
581 new Effect.Highlight(row, {duration: 1, startcolor: "#fff7d5",
582 afterFinish: toggleUnread_afh,
583 queue: { position:'end', scope: 'TMRQ-' + id, limit: 1 } } );
586 } else if (cmode == 1) {
587 row.addClassName("Unread");
590 if (cmode == undefined) cmode = 2;
592 var query = "?op=rpc&subop=catchupSelected" +
593 "&cmode=" + param_escape(cmode) + "&ids=" + param_escape(id);
595 // notify_progress("Loading, please wait...");
597 new Ajax.Request("backend.php", {
599 onComplete: function(transport) {
600 handle_rpc_json(transport);
606 exception_error("toggleUnread", e);
610 function selectionRemoveLabel(id, ids) {
613 if (!ids) var ids = getSelectedArticleIds2();
615 if (ids.length == 0) {
616 alert(__("No articles are selected."));
620 var query = "?op=rpc&subop=removeFromLabel&ids=" +
621 param_escape(ids.toString()) + "&lid=" + param_escape(id);
625 new Ajax.Request("backend.php", {
627 onComplete: function(transport) {
628 handle_rpc_json(transport);
629 show_labels_in_headlines(transport);
633 exception_error("selectionAssignLabel", e);
638 function selectionAssignLabel(id, ids) {
641 if (!ids) ids = getSelectedArticleIds2();
643 if (ids.length == 0) {
644 alert(__("No articles are selected."));
648 var query = "?op=rpc&subop=assignToLabel&ids=" +
649 param_escape(ids.toString()) + "&lid=" + param_escape(id);
653 new Ajax.Request("backend.php", {
655 onComplete: function(transport) {
656 handle_rpc_json(transport);
657 show_labels_in_headlines(transport);
661 exception_error("selectionAssignLabel", e);
666 function selectionToggleUnread(set_state, callback, no_error) {
668 var rows = getSelectedArticleIds2();
670 if (rows.length == 0 && !no_error) {
671 alert(__("No articles are selected."));
675 for (i = 0; i < rows.length; i++) {
676 var row = $("RROW-" + rows[i]);
678 if (set_state == undefined) {
679 if (row.hasClassName("Unread")) {
680 row.removeClassName("Unread");
682 row.addClassName("Unread");
686 if (set_state == false) {
687 row.removeClassName("Unread");
690 if (set_state == true) {
691 row.addClassName("Unread");
696 if (rows.length > 0) {
700 if (set_state == undefined) {
702 } else if (set_state == true) {
704 } else if (set_state == false) {
708 var query = "?op=rpc&subop=catchupSelected" +
709 "&cmode=" + cmode + "&ids=" + param_escape(rows.toString());
711 notify_progress("Loading, please wait...");
713 new Ajax.Request("backend.php", {
715 onComplete: function(transport) {
716 handle_rpc_json(transport);
717 if (callback) callback(transport);
723 exception_error("selectionToggleUnread", e);
727 function selectionToggleMarked() {
730 var rows = getSelectedArticleIds2();
732 if (rows.length == 0) {
733 alert(__("No articles are selected."));
737 for (i = 0; i < rows.length; i++) {
738 toggleMark(rows[i], true, true);
741 if (rows.length > 0) {
743 var query = "?op=rpc&subop=markSelected&ids=" +
744 param_escape(rows.toString()) + "&cmode=2";
746 new Ajax.Request("backend.php", {
748 onComplete: function(transport) {
749 handle_rpc_json(transport);
755 exception_error("selectionToggleMarked", e);
759 function selectionTogglePublished() {
762 var rows = getSelectedArticleIds2();
764 if (rows.length == 0) {
765 alert(__("No articles are selected."));
769 for (i = 0; i < rows.length; i++) {
770 togglePub(rows[i], true, true);
773 if (rows.length > 0) {
775 var query = "?op=rpc&subop=publishSelected&ids=" +
776 param_escape(rows.toString()) + "&cmode=2";
778 new Ajax.Request("backend.php", {
780 onComplete: function(transport) {
781 handle_rpc_json(transport);
787 exception_error("selectionToggleMarked", e);
791 function getSelectedArticleIds2() {
795 $$("#headlines-frame > div[id*=RROW][class*=Selected]").each(
797 rv.push(child.id.replace("RROW-", ""));
803 function getLoadedArticleIds() {
806 var children = $$("#headlines-frame > div[id*=RROW-]");
808 children.each(function(child) {
809 rv.push(child.id.replace("RROW-", ""));
816 // mode = all,none,unread,invert
817 function selectArticles(mode) {
820 var children = $$("#headlines-frame > div[id*=RROW]");
822 children.each(function(child) {
823 var id = child.id.replace("RROW-", "");
824 var cb = $("RCHK-" + id);
827 child.addClassName("Selected");
829 } else if (mode == "unread") {
830 if (child.hasClassName("Unread")) {
831 child.addClassName("Selected");
834 child.removeClassName("Selected");
837 } else if (mode == "invert") {
838 if (child.hasClassName("Selected")) {
839 child.removeClassName("Selected");
842 child.addClassName("Selected");
847 child.removeClassName("Selected");
853 exception_error("selectArticles", e);
857 function catchupPage() {
859 var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
861 var str = __("Mark all visible articles in %s as read?");
863 str = str.replace("%s", fn);
865 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
869 selectArticles('all');
870 selectionToggleUnread(false, 'viewCurrentFeed()', true)
871 selectArticles('none');
874 function deleteSelection() {
878 var rows = getSelectedArticleIds2();
880 if (rows.length == 0) {
881 alert(__("No articles are selected."));
885 var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
889 if (getActiveFeedId() != 0) {
890 str = __("Delete %d selected articles in %s?");
892 str = __("Delete %d selected articles?");
895 str = str.replace("%d", rows.length);
896 str = str.replace("%s", fn);
898 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
902 query = "?op=rpc&subop=delete&ids=" + param_escape(rows);
906 new Ajax.Request("backend.php", {
908 onComplete: function(transport) {
909 handle_rpc_json(transport);
914 exception_error("deleteSelection", e);
918 function archiveSelection() {
922 var rows = getSelectedArticleIds2();
924 if (rows.length == 0) {
925 alert(__("No articles are selected."));
929 var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
933 if (getActiveFeedId() != 0) {
934 str = __("Archive %d selected articles in %s?");
937 str = __("Move %d archived articles back?");
941 str = str.replace("%d", rows.length);
942 str = str.replace("%s", fn);
944 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
948 query = "?op=rpc&subop="+op+"&ids=" + param_escape(rows);
952 for (var i = 0; i < rows.length; i++) {
953 cache_delete("article:" + rows[i]);
956 new Ajax.Request("backend.php", {
958 onComplete: function(transport) {
959 handle_rpc_json(transport);
964 exception_error("archiveSelection", e);
968 function catchupSelection() {
972 var rows = getSelectedArticleIds2();
974 if (rows.length == 0) {
975 alert(__("No articles are selected."));
979 var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
981 var str = __("Mark %d selected articles in %s as read?");
983 str = str.replace("%d", rows.length);
984 str = str.replace("%s", fn);
986 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
990 selectionToggleUnread(false, 'viewCurrentFeed()', true)
993 exception_error("catchupSelection", e);
997 function editArticleTags(id) {
998 var query = "backend.php?op=dlg&id=editArticleTags¶m=" + param_escape(id);
1000 if (dijit.byId("editTagsDlg"))
1001 dijit.byId("editTagsDlg").destroyRecursive();
1003 dialog = new dijit.Dialog({
1005 title: __("Edit article Tags"),
1006 style: "width: 600px",
1007 execute: function() {
1008 if (this.validate()) {
1009 var query = dojo.objectToQuery(this.attr('value'));
1011 notify_progress("Saving article tags...", true);
1013 new Ajax.Request("backend.php", {
1015 onComplete: function(transport) {
1019 var data = JSON.parse(transport.responseText);
1022 var tags_str = article.tags;
1023 var id = tags_str.id;
1025 var tags = $("ATSTR-" + id);
1026 var tooltip = dijit.byId("ATSTRTIP-" + id);
1028 if (tags) tags.innerHTML = tags_str.content;
1029 if (tooltip) tooltip.attr('label', tags_str.content_full);
1031 cache_delete("article:" + id);
1040 var tmph = dojo.connect(dialog, 'onLoad', function() {
1041 dojo.disconnect(tmph);
1043 new Ajax.Autocompleter('tags_str', 'tags_choices',
1044 "backend.php?op=rpc&subop=completeTags",
1045 { tokens: ',', paramName: "search" });
1052 function cdmScrollToArticleId(id) {
1054 var ctr = $("headlines-frame");
1055 var e = $("RROW-" + id);
1057 if (!e || !ctr) return;
1059 ctr.scrollTop = e.offsetTop;
1062 exception_error("cdmScrollToArticleId", e);
1066 function getActiveArticleId() {
1067 return active_post_id;
1070 function postMouseIn(id) {
1071 post_under_pointer = id;
1074 function postMouseOut(id) {
1075 post_under_pointer = false;
1078 function headlines_scroll_handler(e) {
1080 var hsp = $("headlines-spacer");
1082 if (!_infscroll_disable) {
1083 if (hsp && (e.scrollTop + e.offsetHeight > hsp.offsetTop) ||
1084 e.scrollTop + e.offsetHeight > e.scrollHeight - 100) {
1086 hsp.innerHTML = "<img src='images/indicator_tiny.gif'> " +
1087 __("Loading, please wait...");
1089 loadMoreHeadlines();
1091 //viewNextFeedPage();
1094 if (hsp) hsp.innerHTML = "";
1097 if (getInitParam("cdm_auto_catchup") == 1) {
1099 $$("#headlines-frame > div[id*=RROW][class*=Unread]").each(
1101 if ($("headlines-frame").scrollTop >
1102 (child.offsetTop + child.offsetHeight/2)) {
1104 var id = child.id.replace("RROW-", "");
1106 if (catchup_id_batch.indexOf(id) == -1)
1107 catchup_id_batch.push(id);
1111 if (catchup_id_batch.length > 0 && !_infscroll_request_sent) {
1112 window.clearTimeout(catchup_timeout_id);
1113 catchup_timeout_id = window.setTimeout('catchupBatchedArticles()',
1119 console.warn("headlines_scroll_handler: " + e);
1123 function catchupBatchedArticles() {
1125 if (catchup_id_batch.length > 0 && !_infscroll_request_sent) {
1127 var query = "?op=rpc&subop=catchupSelected" +
1128 "&cmode=0&ids=" + param_escape(catchup_id_batch.toString());
1130 new Ajax.Request("backend.php", {
1132 onComplete: function(transport) {
1133 handle_rpc_json(transport);
1135 catchup_id_batch.each(function(id) {
1136 var elem = $("RROW-" + id);
1137 if (elem) elem.removeClassName("Unread");
1140 catchup_id_batch = [];
1145 exception_error("catchupBatchedArticles", e);
1149 function catchupRelativeToArticle(below) {
1154 if (!getActiveArticleId()) {
1155 alert(__("No article is selected."));
1159 var visible_ids = getVisibleArticleIds();
1161 var ids_to_mark = new Array();
1164 for (var i = 0; i < visible_ids.length; i++) {
1165 if (visible_ids[i] != getActiveArticleId()) {
1166 var e = $("RROW-" + visible_ids[i]);
1168 if (e && e.hasClassName("Unread")) {
1169 ids_to_mark.push(visible_ids[i]);
1176 for (var i = visible_ids.length-1; i >= 0; i--) {
1177 if (visible_ids[i] != getActiveArticleId()) {
1178 var e = $("RROW-" + visible_ids[i]);
1180 if (e && e.hasClassName("Unread")) {
1181 ids_to_mark.push(visible_ids[i]);
1189 if (ids_to_mark.length == 0) {
1190 alert(__("No articles found to mark"));
1192 var msg = __("Mark %d article(s) as read?").replace("%d", ids_to_mark.length);
1194 if (getInitParam("confirm_feed_catchup") != 1 || confirm(msg)) {
1196 for (var i = 0; i < ids_to_mark.length; i++) {
1197 var e = $("RROW-" + ids_to_mark[i]);
1198 e.removeClassName("Unread");
1201 var query = "?op=rpc&subop=catchupSelected" +
1202 "&cmode=0" + "&ids=" + param_escape(ids_to_mark.toString());
1204 new Ajax.Request("backend.php", {
1206 onComplete: function(transport) {
1207 handle_rpc_json(transport);
1214 exception_error("catchupRelativeToArticle", e);
1218 function cdmExpandArticle(id) {
1223 var elem = $("CICD-" + active_post_id);
1225 var upd_img_pic = $("FUPDPIC-" + id);
1227 if (upd_img_pic && (upd_img_pic.src.match("updated.png") ||
1228 upd_img_pic.src.match("fresh_sign.png"))) {
1230 upd_img_pic.src = "images/blank_icon.gif";
1233 if (id == active_post_id && Element.visible(elem))
1236 selectArticles("none");
1238 var old_offset = $("RROW-" + id).offsetTop;
1240 if (active_post_id && elem && !getInitParam("cdm_expanded")) {
1242 Element.show("CEXC-" + active_post_id);
1245 active_post_id = id;
1247 elem = $("CICD-" + id);
1249 if (!Element.visible(elem)) {
1251 Element.hide("CEXC-" + id);
1253 if ($("CWRAP-" + id).innerHTML == "") {
1255 $("FUPDPIC-" + id).src = "images/indicator_tiny.gif";
1257 $("CWRAP-" + id).innerHTML = "<div class=\"insensitive\">" +
1258 __("Loading, please wait...") + "</div>";
1260 var query = "?op=rpc&subop=cdmGetArticle&id=" + param_escape(id);
1262 var neighbor_ids = getRelativePostIds(id);
1264 /* only request uncached articles */
1265 var cids_to_request = [];
1267 for (var i = 0; i < neighbor_ids.length; i++) {
1268 if (cids_requested.indexOf(neighbor_ids[i]) == -1)
1269 if ($("CWRAP-" + neighbor_ids[i]).innerHTML == "") {
1270 cids_to_request.push(neighbor_ids[i]);
1271 cids_requested.push(neighbor_ids[i]);
1275 console.log("additional ids: " + cids_to_request.toString());
1277 query = query + "&cids=" + cids_to_request.toString();
1281 new Ajax.Request("backend.php", {
1283 onComplete: function(transport) {
1285 $("FUPDPIC-" + id).src = 'images/blank_icon.gif';
1287 handle_rpc_json(transport);
1289 var reply = JSON.parse(transport.responseText);
1291 reply.each(function(article) {
1292 $("CWRAP-" + article['id']).innerHTML = article['content']
1293 cids_requested.remove(article['id']);
1300 var new_offset = $("RROW-" + id).offsetTop;
1302 $("headlines-frame").scrollTop += (new_offset-old_offset);
1304 if ($("RROW-" + id).offsetTop != old_offset)
1305 $("headlines-frame").scrollTop = new_offset;
1307 toggleUnread(id, 0, true);
1311 exception_error("cdmExpandArticle", e);
1317 function fixHeadlinesOrder(ids) {
1319 for (var i = 0; i < ids.length; i++) {
1320 var e = $("RROW-" + ids[i]);
1324 e.removeClassName("even");
1325 e.addClassName("odd");
1327 e.removeClassName("odd");
1328 e.addClassName("even");
1333 exception_error("fixHeadlinesOrder", e);
1337 function getArticleUnderPointer() {
1338 return post_under_pointer;
1341 function zoomToArticle(event, id) {
1343 var cached_article = cache_get("article: " + id);
1345 if (dijit.byId("ATAB-" + id))
1346 if (!event || !event.shiftKey)
1347 return dijit.byId("content-tabs").selectChild(dijit.byId("ATAB-" + id));
1349 if (dijit.byId("ATSTRTIP-" + id))
1350 dijit.byId("ATSTRTIP-" + id).destroyRecursive();
1352 if (cached_article) {
1353 //closeArticlePanel();
1355 var article_pane = new dijit.layout.ContentPane({
1356 title: __("Loading...") , content: cached_article,
1357 style: 'padding : 0px;',
1361 dijit.byId("content-tabs").addChild(article_pane);
1363 if (!event || !event.shiftKey)
1364 dijit.byId("content-tabs").selectChild(article_pane);
1366 if ($("PTITLE-" + id))
1367 article_pane.attr('title', $("PTITLE-" + id).innerHTML);
1371 var query = "?op=rpc&subop=getArticles&ids=" + param_escape(id);
1373 notify_progress("Loading, please wait...", true);
1375 new Ajax.Request("backend.php", {
1377 onComplete: function(transport) {
1380 var reply = JSON.parse(transport.responseText);
1383 //closeArticlePanel();
1385 var content = reply[0]['content'];
1387 var article_pane = new dijit.layout.ContentPane({
1388 title: "article-" + id , content: content,
1389 style: 'padding : 0px;',
1393 dijit.byId("content-tabs").addChild(article_pane);
1395 if (!event || !event.shiftKey)
1396 dijit.byId("content-tabs").selectChild(article_pane);
1398 if ($("PTITLE-" + id))
1399 article_pane.attr('title', $("PTITLE-" + id).innerHTML);
1406 exception_error("zoomToArticle", e);
1410 function scrollArticle(offset) {
1413 var ci = $("content-insert");
1415 ci.scrollTop += offset;
1418 var hi = $("headlines-frame");
1420 hi.scrollTop += offset;
1425 exception_error("scrollArticle", e);
1429 function show_labels_in_headlines(transport) {
1431 var data = JSON.parse(transport.responseText);
1434 data['info-for-headlines'].each(function(elem) {
1435 var ctr = $("HLLCTR-" + elem.id);
1437 if (ctr) ctr.innerHTML = elem.labels;
1440 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML);
1444 exception_error("show_labels_in_headlines", e);
1448 /* function toggleHeadlineActions() {
1450 var e = $("headlineActionsBody");
1451 var p = $("headlineActionsDrop");
1453 if (!Element.visible(e)) {
1460 e.style.left = (p.offsetLeft + 1) + "px";
1461 e.style.top = (p.offsetTop + p.offsetHeight + 2) + "px";
1464 exception_error("toggleHeadlineActions", e);
1468 /* function publishWithNote(id, def_note) {
1470 if (!def_note) def_note = '';
1472 var note = prompt(__("Please enter a note for this article:"), def_note);
1474 if (note != undefined) {
1475 togglePub(id, false, false, note);
1479 exception_error("publishWithNote", e);
1483 function emailArticle(id) {
1486 var ids = getSelectedArticleIds2();
1488 if (ids.length == 0) {
1489 alert(__("No articles are selected."));
1493 id = ids.toString();
1496 if (dijit.byId("emailArticleDlg"))
1497 dijit.byId("emailArticleDlg").destroyRecursive();
1499 var query = "backend.php?op=dlg&id=emailArticle¶m=" + param_escape(id);
1501 dialog = new dijit.Dialog({
1502 id: "emailArticleDlg",
1503 title: __("Forward article by email"),
1504 style: "width: 600px",
1505 execute: function() {
1506 if (this.validate()) {
1508 new Ajax.Request("backend.php", {
1509 parameters: dojo.objectToQuery(this.attr('value')),
1510 onComplete: function(transport) {
1512 var reply = JSON.parse(transport.responseText);
1514 var error = reply['error'];
1517 alert(__('Error sending email:') + ' ' + error);
1519 notify_info('Your message has been sent.');
1528 var tmph = dojo.connect(dialog, 'onLoad', function() {
1529 dojo.disconnect(tmph);
1531 new Ajax.Autocompleter('emailArticleDlg_destination', 'emailArticleDlg_dst_choices',
1532 "backend.php?op=rpc&subop=completeEmails",
1533 { tokens: '', paramName: "search" });
1538 /* displayDlg('emailArticle', id,
1540 document.forms['article_email_form'].destination.focus();
1542 new Ajax.Autocompleter('destination', 'destination_choices',
1543 "backend.php?op=rpc&subop=completeEmails",
1544 { tokens: '', paramName: "search" });
1549 exception_error("emailArticle", e);
1553 function dismissArticle(id) {
1555 var elem = $("RROW-" + id);
1557 toggleUnread(id, 0, true);
1559 new Effect.Fade(elem, {duration : 0.5});
1561 active_post_id = false;
1564 exception_error("dismissArticle", e);
1568 function dismissSelectedArticles() {
1571 var ids = getVisibleArticleIds();
1575 for (var i = 0; i < ids.length; i++) {
1576 var elem = $("RROW-" + ids[i]);
1578 if (elem.className && elem.hasClassName("Selected") &&
1579 ids[i] != active_post_id) {
1580 new Effect.Fade(elem, {duration : 0.5});
1588 selectionToggleUnread(false);
1590 fixHeadlinesOrder(tmp);
1593 exception_error("dismissSelectedArticles", e);
1597 function dismissReadArticles() {
1600 var ids = getVisibleArticleIds();
1603 for (var i = 0; i < ids.length; i++) {
1604 var elem = $("RROW-" + ids[i]);
1606 if (elem.className && !elem.hasClassName("Unread") &&
1607 !elem.hasClassName("Selected")) {
1609 new Effect.Fade(elem, {duration : 0.5});
1615 fixHeadlinesOrder(tmp);
1618 exception_error("dismissSelectedArticles", e);
1622 function getVisibleArticleIds() {
1627 getLoadedArticleIds().each(function(id) {
1628 var elem = $("RROW-" + id);
1629 if (elem && Element.visible(elem))
1634 exception_error("getVisibleArticleIds", e);
1640 function cdmClicked(event, id) {
1642 var shift_key = event.shiftKey;
1646 if (!event.ctrlKey) {
1648 if (!getInitParam("cdm_expanded")) {
1649 return cdmExpandArticle(id);
1652 selectArticles("none");
1655 var elem = $("RROW-" + id);
1658 elem.removeClassName("Unread");
1660 var upd_img_pic = $("FUPDPIC-" + id);
1662 if (upd_img_pic && (upd_img_pic.src.match("updated.png") ||
1663 upd_img_pic.src.match("fresh_sign.png"))) {
1665 upd_img_pic.src = "images/blank_icon.gif";
1668 active_post_id = id;
1670 var query = "?op=rpc&subop=catchupSelected" +
1671 "&cmode=0&ids=" + param_escape(id);
1673 new Ajax.Request("backend.php", {
1675 onComplete: function(transport) {
1676 handle_rpc_json(transport);
1683 toggleSelected(id, true);
1684 toggleUnread(id, 0, false);
1685 zoomToArticle(event, id);
1689 exception_error("cdmClicked");
1695 function postClicked(event, id) {
1698 if (!event.ctrlKey) {
1701 postOpenInNewTab(event, id);
1706 exception_error("postClicked");
1710 function hlOpenInNewTab(event, id) {
1711 toggleUnread(id, 0, false);
1712 zoomToArticle(event, id);
1715 function postOpenInNewTab(event, id) {
1716 closeArticlePanel(id);
1717 zoomToArticle(event, id);
1720 function hlClicked(event, id) {
1722 if (event.which == 2) {
1725 } else if (event.altKey) {
1726 openArticleInNewWindow(id);
1727 } else if (!event.ctrlKey) {
1732 toggleUnread(id, 0, false);
1733 zoomToArticle(event, id);
1738 exception_error("hlClicked");
1742 function getFirstVisibleHeadlineId() {
1743 var rows = getVisibleArticleIds();
1748 function getLastVisibleHeadlineId() {
1749 var rows = getVisibleArticleIds();
1750 return rows[rows.length-1];
1753 function openArticleInNewWindow(id) {
1754 toggleUnread(id, 0, false);
1755 window.open("backend.php?op=la&id=" + id);
1758 function isCdmMode() {
1759 return getInitParam("combined_display_mode");
1762 function markHeadline(id) {
1763 var row = $("RROW-" + id);
1765 var check = $("RCHK-" + id);
1768 check.checked = true;
1771 row.addClassName("Selected");
1775 function getRelativePostIds(id, limit) {
1781 if (!limit) limit = 6; //3
1783 var ids = getVisibleArticleIds();
1785 for (var i = 0; i < ids.length; i++) {
1787 for (var k = 1; k <= limit; k++) {
1788 //if (i > k-1) tmp.push(ids[i-k]);
1789 if (i < ids.length-k) tmp.push(ids[i+k]);
1796 exception_error("getRelativePostIds", e);
1802 function correctHeadlinesOffset(id) {
1806 var container = $("headlines-frame");
1807 var row = $("RROW-" + id);
1809 var viewport = container.offsetHeight;
1811 var rel_offset_top = row.offsetTop - container.scrollTop;
1812 var rel_offset_bottom = row.offsetTop + row.offsetHeight - container.scrollTop;
1814 //console.log("Rtop: " + rel_offset_top + " Rbtm: " + rel_offset_bottom);
1815 //console.log("Vport: " + viewport);
1817 if (rel_offset_top <= 0 || rel_offset_top > viewport) {
1818 container.scrollTop = row.offsetTop;
1819 } else if (rel_offset_bottom > viewport) {
1821 /* doesn't properly work with Opera in some cases because
1822 Opera fucks up element scrolling */
1824 container.scrollTop = row.offsetTop + row.offsetHeight - viewport;
1828 exception_error("correctHeadlinesOffset", e);
1833 function headlineActionsChange(elem) {
1836 elem.attr('value', 'false');
1838 exception_error("headlineActionsChange", e);
1842 function closeArticlePanel() {
1844 var tabs = dijit.byId("content-tabs");
1845 var child = tabs.selectedChildWidget;
1847 if (child && tabs.getIndexOfChild(child) > 0) {
1848 tabs.removeChild(child);
1851 if (dijit.byId("content-insert"))
1852 dijit.byId("headlines-wrap-inner").removeChild(
1853 dijit.byId("content-insert"));
1857 function initHeadlinesMenu() {
1859 if (dijit.byId("headlinesMenu"))
1860 dijit.byId("headlinesMenu").destroyRecursive();
1865 nodes = $$("#headlines-frame > div[id*=RROW]");
1867 nodes = $$("#headlines-frame span[id*=RTITLE]");
1870 nodes.each(function(node) {
1874 var menu = new dijit.Menu({
1875 id: "headlinesMenu",
1879 var tmph = dojo.connect(menu, '_openMyself', function (event) {
1880 var callerNode = event.target, match = null, tries = 0;
1882 while (match == null && callerNode && tries <= 3) {
1883 match = callerNode.id.match("^[A-Z]+[-]([0-9]+)$");
1884 callerNode = callerNode.parentNode;
1888 if (match) this.callerRowId = parseInt(match[1]);
1892 /* if (!isCdmMode())
1893 menu.addChild(new dijit.MenuItem({
1894 label: __("View article"),
1895 onClick: function(event) {
1896 view(this.getParent().callerRowId);
1899 menu.addChild(new dijit.MenuItem({
1900 label: __("Open original article"),
1901 onClick: function(event) {
1902 openArticleInNewWindow(this.getParent().callerRowId);
1905 menu.addChild(new dijit.MenuItem({
1906 label: __("View in a tt-rss tab"),
1907 onClick: function(event) {
1908 hlOpenInNewTab(event, this.getParent().callerRowId);
1911 // menu.addChild(new dijit.MenuSeparator());
1913 var labels = dijit.byId("feedTree").model.getItemsInCategory(-2);
1917 menu.addChild(new dijit.MenuSeparator());
1919 var labelAddMenu = new dijit.Menu({ownerMenu: menu});
1920 var labelDelMenu = new dijit.Menu({ownerMenu: menu});
1922 labels.each(function(label) {
1923 var id = label.id[0];
1924 var bare_id = id.substr(id.indexOf(":")+1);
1925 var name = label.name[0];
1927 bare_id = -11-bare_id;
1929 labelAddMenu.addChild(new dijit.MenuItem({
1932 onClick: function(event) {
1933 selectionAssignLabel(this.labelId,
1934 [this.getParent().ownerMenu.callerRowId]);
1937 labelDelMenu.addChild(new dijit.MenuItem({
1940 onClick: function(event) {
1941 selectionRemoveLabel(this.labelId,
1942 [this.getParent().ownerMenu.callerRowId]);
1947 menu.addChild(new dijit.PopupMenuItem({
1948 label: __("Assign label"),
1949 popup: labelAddMenu,
1952 menu.addChild(new dijit.PopupMenuItem({
1953 label: __("Remove label"),
1954 popup: labelDelMenu,
1962 exception_error("initHeadlinesMenu", e);
1966 function tweetArticle(id) {
1968 var query = "?op=rpc&subop=getTweetInfo&id=" + param_escape(id);
1973 var ts = d.getTime();
1975 var w = window.open('backend.php?op=loading', 'ttrss_tweet',
1976 "status=0,toolbar=0,location=0,width=500,height=400,scrollbars=1,menubar=0");
1978 new Ajax.Request("backend.php", {
1980 onComplete: function(transport) {
1981 var ti = JSON.parse(transport.responseText);
1983 var share_url = "http://twitter.com/share?_=" + ts +
1984 "&text=" + param_escape(ti.title) +
1985 "&url=" + param_escape(ti.link);
1987 w.location.href = share_url;
1993 exception_error("tweetArticle", e);
1997 function editArticleNote(id) {
2000 var query = "backend.php?op=dlg&id=editArticleNote¶m=" + param_escape(id);
2002 if (dijit.byId("editNoteDlg"))
2003 dijit.byId("editNoteDlg").destroyRecursive();
2005 dialog = new dijit.Dialog({
2007 title: __("Edit article note"),
2008 style: "width: 600px",
2009 execute: function() {
2010 if (this.validate()) {
2011 var query = dojo.objectToQuery(this.attr('value'));
2013 notify_progress("Saving article note...", true);
2015 new Ajax.Request("backend.php", {
2017 onComplete: function(transport) {
2021 var reply = JSON.parse(transport.responseText);
2023 cache_delete("article:" + id);
2025 var elem = $("POSTNOTE-" + id);
2029 elem.innerHTML = reply.note;
2031 if (reply.raw_length != 0)
2032 new Effect.Appear(elem);
2044 exception_error("editArticleNote", e);
2048 function player(elem) {
2049 var aid = elem.getAttribute("audio-id");
2050 var status = elem.getAttribute("status");
2058 elem.innerHTML = __("Playing...");
2059 elem.title = __("Click to pause");
2060 elem.addClassName("playing");
2064 elem.innerHTML = __("Play");
2065 elem.title = __("Click to play");
2066 elem.removeClassName("playing");
2069 elem.setAttribute("status", status);
2071 alert("Your browser doesn't seem to support HTML5 audio.");
2075 function cache_set(id, obj) {
2076 //console.log("cache_set: " + id);
2079 sessionStorage[id] = obj;
2081 sessionStorage.clear();
2085 function cache_get(id) {
2087 return sessionStorage[id];
2090 function cache_clear() {
2092 sessionStorage.clear();
2095 function cache_delete(id) {
2097 sessionStorage.removeItem(id);
2100 function cache_headlines(feed, is_cat, toolbar_obj, content_obj) {
2101 if (toolbar_obj && content_obj) {
2102 cache_set("feed:" + feed + ":" + is_cat,
2103 JSON.stringify({toolbar: toolbar_obj, content: content_obj}));
2106 obj = cache_get("feed:" + feed + ":" + is_cat);
2109 obj = JSON.parse(obj);
2111 if (toolbar_obj) obj.toolbar = toolbar_obj;
2112 if (content_obj) obj.content = content_obj;
2114 cache_set("feed:" + feed + ":" + is_cat, JSON.stringify(obj));
2118 console.warn("cache_headlines failed: " + e);
2123 function render_local_headlines(feed, is_cat, obj) {
2126 dijit.byId("headlines-toolbar").attr('content',
2129 dijit.byId("headlines-frame").attr('content',
2132 dojo.parser.parse('headlines-toolbar');
2134 $("headlines-frame").scrollTop = 0;
2135 selectArticles('none');
2136 setActiveFeedId(feed, is_cat);
2137 initHeadlinesMenu();
2139 precache_headlines();
2142 exception_error("render_local_headlines", e);
2146 function precache_headlines_idle() {
2148 if (!feed_precache_timeout_id) {
2149 var feeds = dijit.byId("feedTree").getVisibleUnreadFeeds();
2152 feeds.each(function(item) {
2153 if (parseInt(item[0]) > 0 && !cache_get("feed:" + item[0] + ":" + item[1]))
2154 uncached.push(item);
2157 if (uncached.length > 0) {
2158 var rf = uncached[Math.floor(Math.random()*uncached.length)];
2159 viewfeed(rf[0], '', rf[1], 0, true);
2162 precache_idle_timeout_id = setTimeout("precache_headlines_idle()", 5000);
2165 exception_error("precache_headlines_idle", e);
2169 function precache_headlines() {
2172 if (!feed_precache_timeout_id) {
2173 feed_precache_timeout_id = window.setTimeout(function() {
2174 var nuf = getNextUnreadFeed(getActiveFeedId(), activeFeedIsCat());
2175 var nf = dijit.byId("feedTree").getNextFeed(getActiveFeedId(), activeFeedIsCat());
2177 if (nuf && !cache_get("feed:" + nuf + ":" + activeFeedIsCat()))
2178 viewfeed(nuf, '', activeFeedIsCat(), 0, true);
2180 if (nf != nuf && nf && !cache_get("feed:" + nf[0] + ":" + nf[1]))
2181 viewfeed(nf[0], '', nf[1], 0, true);
2183 window.setTimeout(function() {
2184 feed_precache_timeout_id = false;
2191 exception_error("precache_headlines", e);