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 row.style.display = 'none';
100 c.domNode.appendChild(row);
103 if (!hsp) hsp = new Element("DIV", {"id": "headlines-spacer"});
105 fixHeadlinesOrder(getLoadedArticleIds());
107 c.domNode.appendChild(hsp);
109 console.log("restore selected ids: " + ids);
111 for (var i = 0; i < ids.length; i++) {
112 markHeadline(ids[i]);
117 $$("#headlines-frame > div[id*=RROW]").each(
119 if (!Element.visible(child))
120 new Effect.Appear(child, { duration : 0.5 });
124 console.log("no new headlines received");
126 var hsp = $("headlines-spacer");
128 if (hsp) hsp.innerHTML = "";
132 if (headlines_count > 0)
133 cache_headlines(feed_id, is_cat, reply['headlines']['toolbar'], $("headlines-frame").innerHTML);
136 for (var i = 0; i < articles.length; i++) {
137 var a_id = articles[i]['id'];
138 cache_set("article:" + a_id, articles[i]['content']);
141 console.log("no cached articles received");
144 // do not precache stuff after fresh feed
146 precache_headlines();
149 parse_counters(counters);
154 console.warn("headlines_callback: returned no XML object");
155 dijit.byId("headlines-frame").attr('content', "<div class='whiteBox'>" +
156 __('Could not update headlines (invalid object received)') + "</div>");
159 _infscroll_request_sent = 0;
164 exception_error("headlines_callback2", e, transport);
168 function render_article(article) {
170 dijit.byId("headlines-wrap-inner").addChild(
171 dijit.byId("content-insert"));
173 var c = dijit.byId("content-insert");
176 c.domNode.scrollTop = 0;
179 c.attr('content', article);
181 correctHeadlinesOffset(getActiveArticleId());
188 exception_error("render_article", e);
192 function showArticleInHeadlines(id) {
196 selectArticles("none");
198 var crow = $("RROW-" + id);
202 var article_is_unread = crow.hasClassName("Unread");
204 crow.removeClassName("Unread");
206 selectArticles('none');
208 var upd_img_pic = $("FUPDPIC-" + id);
210 var view_mode = false;
213 view_mode = document.forms['main_toolbar_form'].view_mode;
214 view_mode = view_mode[view_mode.selectedIndex].value;
219 if (upd_img_pic && (upd_img_pic.src.match("updated.png") ||
220 upd_img_pic.src.match("fresh_sign.png"))) {
222 upd_img_pic.src = "images/blank_icon.gif";
224 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML);
226 } else if (article_is_unread && view_mode == "all_articles") {
227 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML);
232 if (article_is_unread)
233 _force_scheduled_update = true;
236 exception_error("showArticleInHeadlines", e);
240 function article_callback2(transport, id) {
242 console.log("article_callback2 " + id);
244 handle_rpc_json(transport);
246 var reply = JSON.parse(transport.responseText);
250 var upic = $('FUPDPIC-' + id);
252 if (upic) upic.src = 'images/blank_icon.gif';
254 reply.each(function(article) {
255 if (active_post_id == article['id']) {
256 render_article(article['content']);
258 cids_requested.remove(article['id']);
260 cache_set("article:" + article['id'], article['content']);
263 // if (id != last_requested_article) {
264 // console.log("requested article id is out of sequence, aborting");
269 console.warn("article_callback: returned invalid data");
271 render_article("<div class='whiteBox'>" +
272 __('Could not display article (invalid data received)') + "</div>");
279 exception_error("article_callback2", e, transport);
285 console.log("loading article: " + id);
287 var cached_article = cache_get("article:" + id);
289 console.log("cache check result: " + (cached_article != false));
293 var query = "?op=view&id=" + param_escape(id);
295 var neighbor_ids = getRelativePostIds(id);
297 /* only request uncached articles */
299 var cids_to_request = [];
301 for (var i = 0; i < neighbor_ids.length; i++) {
302 if (cids_requested.indexOf(neighbor_ids[i]) == -1)
303 if (!cache_get("article:" + neighbor_ids[i])) {
304 cids_to_request.push(neighbor_ids[i]);
305 cids_requested.push(neighbor_ids[i]);
309 console.log("additional ids: " + cids_to_request.toString());
311 query = query + "&cids=" + cids_to_request.toString();
313 var crow = $("RROW-" + id);
314 var article_is_unread = crow.hasClassName("Unread");
317 showArticleInHeadlines(id);
319 precache_headlines();
321 if (!cached_article) {
323 var upic = $('FUPDPIC-' + id);
326 upic.src = getInitParam("sign_progress");
329 } else if (cached_article && article_is_unread) {
331 query = query + "&mode=prefetch";
333 render_article(cached_article);
335 } else if (cached_article) {
337 query = query + "&mode=prefetch_old";
338 render_article(cached_article);
340 // if we don't need to request any relative ids, we might as well skip
341 // the server roundtrip altogether
342 if (cids_to_request.length == 0)
346 last_requested_article = id;
350 new Ajax.Request("backend.php", {
352 onComplete: function(transport) {
353 article_callback2(transport, id);
359 exception_error("view", e);
364 return toggleMark(id);
368 return togglePub(id);
371 function toggleMark(id, client_only) {
373 var query = "?op=rpc&id=" + id + "&subop=mark";
375 var img = $("FMPIC-" + id);
379 if (img.src.match("mark_unset")) {
380 img.src = img.src.replace("mark_unset", "mark_set");
381 img.alt = __("Unstar article");
382 query = query + "&mark=1";
385 img.src = img.src.replace("mark_set", "mark_unset");
386 img.alt = __("Star article");
387 query = query + "&mark=0";
390 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML);
393 new Ajax.Request("backend.php", {
395 onComplete: function(transport) {
396 handle_rpc_json(transport);
401 exception_error("toggleMark", e);
405 function togglePub(id, client_only, no_effects, note) {
407 var query = "?op=rpc&id=" + id + "&subop=publ";
409 if (note != undefined) {
410 query = query + "¬e=" + param_escape(note);
412 query = query + "¬e=undefined";
415 var img = $("FPPIC-" + id);
419 if (img.src.match("pub_unset") || note != undefined) {
420 img.src = img.src.replace("pub_unset", "pub_set");
421 img.alt = __("Unpublish article");
422 query = query + "&pub=1";
425 img.src = img.src.replace("pub_set", "pub_unset");
426 img.alt = __("Publish article");
428 query = query + "&pub=0";
431 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML);
434 new Ajax.Request("backend.php", {
436 onComplete: function(transport) {
437 handle_rpc_json(transport);
442 exception_error("togglePub", e);
446 function moveToPost(mode) {
450 var rows = getVisibleArticleIds();
455 if (!$('RROW-' + active_post_id)) {
456 active_post_id = false;
459 if (active_post_id == false) {
460 next_id = getFirstVisibleHeadlineId();
461 prev_id = getLastVisibleHeadlineId();
463 for (var i = 0; i < rows.length; i++) {
464 if (rows[i] == active_post_id) {
471 if (mode == "next") {
475 cdmExpandArticle(next_id);
476 cdmScrollToArticleId(next_id);
479 correctHeadlinesOffset(next_id);
480 view(next_id, getActiveFeedId());
485 if (mode == "prev") {
488 cdmExpandArticle(prev_id);
489 cdmScrollToArticleId(prev_id);
491 correctHeadlinesOffset(prev_id);
492 view(prev_id, getActiveFeedId());
498 exception_error("moveToPost", e);
502 function toggleSelected(id, force_on) {
505 var cb = $("RCHK-" + id);
506 var row = $("RROW-" + id);
509 if (row.hasClassName('Selected') && !force_on) {
510 row.removeClassName('Selected');
511 if (cb) cb.checked = false;
513 row.addClassName('Selected');
514 if (cb) cb.checked = true;
518 exception_error("toggleSelected", e);
522 function toggleUnread_afh(effect) {
525 var elem = effect.element;
526 elem.style.backgroundColor = "";
529 exception_error("toggleUnread_afh", e);
533 function toggleUnread(id, cmode, effect) {
536 var row = $("RROW-" + id);
538 if (cmode == undefined || cmode == 2) {
539 if (row.hasClassName("Unread")) {
540 row.removeClassName("Unread");
543 new Effect.Highlight(row, {duration: 1, startcolor: "#fff7d5",
544 afterFinish: toggleUnread_afh,
545 queue: { position:'end', scope: 'TMRQ-' + id, limit: 1 } } );
549 row.addClassName("Unread");
552 } else if (cmode == 0) {
554 row.removeClassName("Unread");
557 new Effect.Highlight(row, {duration: 1, startcolor: "#fff7d5",
558 afterFinish: toggleUnread_afh,
559 queue: { position:'end', scope: 'TMRQ-' + id, limit: 1 } } );
562 } else if (cmode == 1) {
563 row.addClassName("Unread");
566 if (cmode == undefined) cmode = 2;
568 var query = "?op=rpc&subop=catchupSelected" +
569 "&cmode=" + param_escape(cmode) + "&ids=" + param_escape(id);
571 // notify_progress("Loading, please wait...");
573 new Ajax.Request("backend.php", {
575 onComplete: function(transport) {
576 handle_rpc_json(transport);
582 exception_error("toggleUnread", e);
586 function selectionRemoveLabel(id, ids) {
589 if (!ids) var ids = getSelectedArticleIds2();
591 if (ids.length == 0) {
592 alert(__("No articles are selected."));
596 var query = "?op=rpc&subop=removeFromLabel&ids=" +
597 param_escape(ids.toString()) + "&lid=" + param_escape(id);
601 new Ajax.Request("backend.php", {
603 onComplete: function(transport) {
604 handle_rpc_json(transport);
605 show_labels_in_headlines(transport);
609 exception_error("selectionAssignLabel", e);
614 function selectionAssignLabel(id, ids) {
617 if (!ids) ids = getSelectedArticleIds2();
619 if (ids.length == 0) {
620 alert(__("No articles are selected."));
624 var query = "?op=rpc&subop=assignToLabel&ids=" +
625 param_escape(ids.toString()) + "&lid=" + param_escape(id);
629 new Ajax.Request("backend.php", {
631 onComplete: function(transport) {
632 handle_rpc_json(transport);
633 show_labels_in_headlines(transport);
637 exception_error("selectionAssignLabel", e);
642 function selectionToggleUnread(set_state, callback, no_error) {
644 var rows = getSelectedArticleIds2();
646 if (rows.length == 0 && !no_error) {
647 alert(__("No articles are selected."));
651 for (i = 0; i < rows.length; i++) {
652 var row = $("RROW-" + rows[i]);
654 if (set_state == undefined) {
655 if (row.hasClassName("Unread")) {
656 row.removeClassName("Unread");
658 row.addClassName("Unread");
662 if (set_state == false) {
663 row.removeClassName("Unread");
666 if (set_state == true) {
667 row.addClassName("Unread");
672 if (rows.length > 0) {
676 if (set_state == undefined) {
678 } else if (set_state == true) {
680 } else if (set_state == false) {
684 var query = "?op=rpc&subop=catchupSelected" +
685 "&cmode=" + cmode + "&ids=" + param_escape(rows.toString());
687 notify_progress("Loading, please wait...");
689 new Ajax.Request("backend.php", {
691 onComplete: function(transport) {
692 handle_rpc_json(transport);
693 if (callback) callback(transport);
699 exception_error("selectionToggleUnread", e);
703 function selectionToggleMarked() {
706 var rows = getSelectedArticleIds2();
708 if (rows.length == 0) {
709 alert(__("No articles are selected."));
713 for (i = 0; i < rows.length; i++) {
714 toggleMark(rows[i], true, true);
717 if (rows.length > 0) {
719 var query = "?op=rpc&subop=markSelected&ids=" +
720 param_escape(rows.toString()) + "&cmode=2";
722 new Ajax.Request("backend.php", {
724 onComplete: function(transport) {
725 handle_rpc_json(transport);
731 exception_error("selectionToggleMarked", e);
735 function selectionTogglePublished() {
738 var rows = getSelectedArticleIds2();
740 if (rows.length == 0) {
741 alert(__("No articles are selected."));
745 for (i = 0; i < rows.length; i++) {
746 togglePub(rows[i], true, true);
749 if (rows.length > 0) {
751 var query = "?op=rpc&subop=publishSelected&ids=" +
752 param_escape(rows.toString()) + "&cmode=2";
754 new Ajax.Request("backend.php", {
756 onComplete: function(transport) {
757 handle_rpc_json(transport);
763 exception_error("selectionToggleMarked", e);
767 function getSelectedArticleIds2() {
771 $$("#headlines-frame > div[id*=RROW][class*=Selected]").each(
773 rv.push(child.id.replace("RROW-", ""));
779 function getLoadedArticleIds() {
782 var children = $$("#headlines-frame > div[id*=RROW-]");
784 children.each(function(child) {
785 rv.push(child.id.replace("RROW-", ""));
792 // mode = all,none,unread,invert
793 function selectArticles(mode) {
796 var children = $$("#headlines-frame > div[id*=RROW]");
798 children.each(function(child) {
799 var id = child.id.replace("RROW-", "");
800 var cb = $("RCHK-" + id);
803 child.addClassName("Selected");
805 } else if (mode == "unread") {
806 if (child.hasClassName("Unread")) {
807 child.addClassName("Selected");
810 child.removeClassName("Selected");
813 } else if (mode == "invert") {
814 if (child.hasClassName("Selected")) {
815 child.removeClassName("Selected");
818 child.addClassName("Selected");
823 child.removeClassName("Selected");
829 exception_error("selectArticles", e);
833 function catchupPage() {
835 var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
837 var str = __("Mark all visible articles in %s as read?");
839 str = str.replace("%s", fn);
841 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
845 selectArticles('all');
846 selectionToggleUnread(false, 'viewCurrentFeed()', true)
847 selectArticles('none');
850 function deleteSelection() {
854 var rows = getSelectedArticleIds2();
856 if (rows.length == 0) {
857 alert(__("No articles are selected."));
861 var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
865 if (getActiveFeedId() != 0) {
866 str = __("Delete %d selected articles in %s?");
868 str = __("Delete %d selected articles?");
871 str = str.replace("%d", rows.length);
872 str = str.replace("%s", fn);
874 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
878 query = "?op=rpc&subop=delete&ids=" + param_escape(rows);
882 new Ajax.Request("backend.php", {
884 onComplete: function(transport) {
885 handle_rpc_json(transport);
890 exception_error("deleteSelection", e);
894 function archiveSelection() {
898 var rows = getSelectedArticleIds2();
900 if (rows.length == 0) {
901 alert(__("No articles are selected."));
905 var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
909 if (getActiveFeedId() != 0) {
910 str = __("Archive %d selected articles in %s?");
913 str = __("Move %d archived articles back?");
917 str = str.replace("%d", rows.length);
918 str = str.replace("%s", fn);
920 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
924 query = "?op=rpc&subop="+op+"&ids=" + param_escape(rows);
928 for (var i = 0; i < rows.length; i++) {
929 cache_delete("article:" + rows[i]);
932 new Ajax.Request("backend.php", {
934 onComplete: function(transport) {
935 handle_rpc_json(transport);
940 exception_error("archiveSelection", e);
944 function catchupSelection() {
948 var rows = getSelectedArticleIds2();
950 if (rows.length == 0) {
951 alert(__("No articles are selected."));
955 var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
957 var str = __("Mark %d selected articles in %s as read?");
959 str = str.replace("%d", rows.length);
960 str = str.replace("%s", fn);
962 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
966 selectionToggleUnread(false, 'viewCurrentFeed()', true)
969 exception_error("catchupSelection", e);
973 function editArticleTags(id) {
974 var query = "backend.php?op=dlg&id=editArticleTags¶m=" + param_escape(id);
976 if (dijit.byId("editTagsDlg"))
977 dijit.byId("editTagsDlg").destroyRecursive();
979 dialog = new dijit.Dialog({
981 title: __("Edit article Tags"),
982 style: "width: 600px",
983 execute: function() {
984 if (this.validate()) {
985 var query = dojo.objectToQuery(this.attr('value'));
987 notify_progress("Saving article tags...", true);
989 new Ajax.Request("backend.php", {
991 onComplete: function(transport) {
995 var data = JSON.parse(transport.responseText);
998 var tags_str = data.tags_str;
999 var id = tags_str.id;
1001 var tags = $("ATSTR-" + id);
1002 var tooltip = dijit.byId("ATSTRTIP-" + id);
1004 if (tags) tags.innerHTML = tags_str.content;
1005 if (tooltip) tooltip.attr('label', tags_str.content_full);
1007 cache_delete("article:" + id);
1016 var tmph = dojo.connect(dialog, 'onLoad', function() {
1017 dojo.disconnect(tmph);
1019 new Ajax.Autocompleter('tags_str', 'tags_choices',
1020 "backend.php?op=rpc&subop=completeTags",
1021 { tokens: ',', paramName: "search" });
1028 function cdmScrollToArticleId(id) {
1030 var ctr = $("headlines-frame");
1031 var e = $("RROW-" + id);
1033 if (!e || !ctr) return;
1035 ctr.scrollTop = e.offsetTop;
1038 exception_error("cdmScrollToArticleId", e);
1042 function getActiveArticleId() {
1043 return active_post_id;
1046 function postMouseIn(id) {
1047 post_under_pointer = id;
1050 function postMouseOut(id) {
1051 post_under_pointer = false;
1054 function headlines_scroll_handler(e) {
1056 var hsp = $("headlines-spacer");
1058 if (!_infscroll_disable) {
1059 if (hsp && (e.scrollTop + e.offsetHeight > hsp.offsetTop) ||
1060 e.scrollTop + e.offsetHeight > e.scrollHeight - 100) {
1062 hsp.innerHTML = "<img src='images/indicator_tiny.gif'> " +
1063 __("Loading, please wait...");
1065 loadMoreHeadlines();
1067 //viewNextFeedPage();
1070 if (hsp) hsp.innerHTML = "";
1073 if (getInitParam("cdm_auto_catchup") == 1) {
1075 $$("#headlines-frame > div[id*=RROW][class*=Unread]").each(
1077 if ($("headlines-frame").scrollTop >
1078 (child.offsetTop + child.offsetHeight/2)) {
1080 var id = child.id.replace("RROW-", "");
1082 if (catchup_id_batch.indexOf(id) == -1)
1083 catchup_id_batch.push(id);
1087 if (catchup_id_batch.length > 0 && !_infscroll_request_sent) {
1088 window.clearTimeout(catchup_timeout_id);
1089 catchup_timeout_id = window.setTimeout('catchupBatchedArticles()',
1095 console.warn("headlines_scroll_handler: " + e);
1099 function catchupBatchedArticles() {
1101 if (catchup_id_batch.length > 0 && !_infscroll_request_sent) {
1103 var query = "?op=rpc&subop=catchupSelected" +
1104 "&cmode=0&ids=" + param_escape(catchup_id_batch.toString());
1106 new Ajax.Request("backend.php", {
1108 onComplete: function(transport) {
1109 handle_rpc_json(transport);
1111 catchup_id_batch.each(function(id) {
1112 var elem = $("RROW-" + id);
1113 if (elem) elem.removeClassName("Unread");
1116 catchup_id_batch = [];
1121 exception_error("catchupBatchedArticles", e);
1125 function catchupRelativeToArticle(below) {
1130 if (!getActiveArticleId()) {
1131 alert(__("No article is selected."));
1135 var visible_ids = getVisibleArticleIds();
1137 var ids_to_mark = new Array();
1140 for (var i = 0; i < visible_ids.length; i++) {
1141 if (visible_ids[i] != getActiveArticleId()) {
1142 var e = $("RROW-" + visible_ids[i]);
1144 if (e && e.hasClassName("Unread")) {
1145 ids_to_mark.push(visible_ids[i]);
1152 for (var i = visible_ids.length-1; i >= 0; i--) {
1153 if (visible_ids[i] != getActiveArticleId()) {
1154 var e = $("RROW-" + visible_ids[i]);
1156 if (e && e.hasClassName("Unread")) {
1157 ids_to_mark.push(visible_ids[i]);
1165 if (ids_to_mark.length == 0) {
1166 alert(__("No articles found to mark"));
1168 var msg = __("Mark %d article(s) as read?").replace("%d", ids_to_mark.length);
1170 if (getInitParam("confirm_feed_catchup") != 1 || confirm(msg)) {
1172 for (var i = 0; i < ids_to_mark.length; i++) {
1173 var e = $("RROW-" + ids_to_mark[i]);
1174 e.removeClassName("Unread");
1177 var query = "?op=rpc&subop=catchupSelected" +
1178 "&cmode=0" + "&ids=" + param_escape(ids_to_mark.toString());
1180 new Ajax.Request("backend.php", {
1182 onComplete: function(transport) {
1183 handle_rpc_json(transport);
1190 exception_error("catchupRelativeToArticle", e);
1194 function cdmExpandArticle(id) {
1199 var elem = $("CICD-" + active_post_id);
1201 var upd_img_pic = $("FUPDPIC-" + id);
1203 if (upd_img_pic && (upd_img_pic.src.match("updated.png") ||
1204 upd_img_pic.src.match("fresh_sign.png"))) {
1206 upd_img_pic.src = "images/blank_icon.gif";
1209 if (id == active_post_id && Element.visible(elem))
1212 selectArticles("none");
1214 var old_offset = $("RROW-" + id).offsetTop;
1216 if (active_post_id && elem && !getInitParam("cdm_expanded")) {
1218 Element.show("CEXC-" + active_post_id);
1221 active_post_id = id;
1223 elem = $("CICD-" + id);
1225 if (!Element.visible(elem)) {
1227 Element.hide("CEXC-" + id);
1229 if ($("CWRAP-" + id).innerHTML == "") {
1231 $("FUPDPIC-" + id).src = "images/indicator_tiny.gif";
1233 $("CWRAP-" + id).innerHTML = "<div class=\"insensitive\">" +
1234 __("Loading, please wait...") + "</div>";
1236 var query = "?op=rpc&subop=cdmGetArticle&id=" + param_escape(id);
1238 var neighbor_ids = getRelativePostIds(id);
1240 /* only request uncached articles */
1241 var cids_to_request = [];
1243 for (var i = 0; i < neighbor_ids.length; i++) {
1244 if (cids_requested.indexOf(neighbor_ids[i]) == -1)
1245 if ($("CWRAP-" + neighbor_ids[i]).innerHTML == "") {
1246 cids_to_request.push(neighbor_ids[i]);
1247 cids_requested.push(neighbor_ids[i]);
1251 console.log("additional ids: " + cids_to_request.toString());
1253 query = query + "&cids=" + cids_to_request.toString();
1257 new Ajax.Request("backend.php", {
1259 onComplete: function(transport) {
1261 $("FUPDPIC-" + id).src = 'images/blank_icon.gif';
1263 handle_rpc_json(transport);
1265 var reply = JSON.parse(transport.responseText);
1267 reply.each(function(article) {
1268 $("CWRAP-" + article['id']).innerHTML = article['content']
1269 cids_requested.remove(article['id']);
1276 var new_offset = $("RROW-" + id).offsetTop;
1278 $("headlines-frame").scrollTop += (new_offset-old_offset);
1280 if ($("RROW-" + id).offsetTop != old_offset)
1281 $("headlines-frame").scrollTop = new_offset;
1283 toggleUnread(id, 0, true);
1287 exception_error("cdmExpandArticle", e);
1293 function fixHeadlinesOrder(ids) {
1295 for (var i = 0; i < ids.length; i++) {
1296 var e = $("RROW-" + ids[i]);
1300 e.removeClassName("even");
1301 e.addClassName("odd");
1303 e.removeClassName("odd");
1304 e.addClassName("even");
1309 exception_error("fixHeadlinesOrder", e);
1313 function getArticleUnderPointer() {
1314 return post_under_pointer;
1317 function zoomToArticle(event, id) {
1319 var cached_article = cache_get("article: " + id);
1321 if (dijit.byId("ATAB-" + id))
1322 if (!event || !event.shiftKey)
1323 return dijit.byId("content-tabs").selectChild(dijit.byId("ATAB-" + id));
1325 if (dijit.byId("ATSTRTIP-" + id))
1326 dijit.byId("ATSTRTIP-" + id).destroyRecursive();
1328 if (cached_article) {
1329 //closeArticlePanel();
1331 var article_pane = new dijit.layout.ContentPane({
1332 title: __("Loading...") , content: cached_article,
1333 style: 'padding : 0px;',
1337 dijit.byId("content-tabs").addChild(article_pane);
1339 if (!event || !event.shiftKey)
1340 dijit.byId("content-tabs").selectChild(article_pane);
1342 if ($("PTITLE-" + id))
1343 article_pane.attr('title', $("PTITLE-" + id).innerHTML);
1347 var query = "?op=rpc&subop=getArticles&ids=" + param_escape(id);
1349 notify_progress("Loading, please wait...", true);
1351 new Ajax.Request("backend.php", {
1353 onComplete: function(transport) {
1356 var reply = JSON.parse(transport.responseText);
1359 //closeArticlePanel();
1361 var content = reply[0]['content'];
1363 var article_pane = new dijit.layout.ContentPane({
1364 title: "article-" + id , content: content,
1365 style: 'padding : 0px;',
1369 dijit.byId("content-tabs").addChild(article_pane);
1371 if (!event || !event.shiftKey)
1372 dijit.byId("content-tabs").selectChild(article_pane);
1374 if ($("PTITLE-" + id))
1375 article_pane.attr('title', $("PTITLE-" + id).innerHTML);
1382 exception_error("zoomToArticle", e);
1386 function scrollArticle(offset) {
1389 var ci = $("content-insert");
1391 ci.scrollTop += offset;
1394 var hi = $("headlines-frame");
1396 hi.scrollTop += offset;
1401 exception_error("scrollArticle", e);
1405 function show_labels_in_headlines(transport) {
1407 var data = JSON.parse(transport.responseText);
1410 data['info-for-headlines'].each(function(elem) {
1411 var ctr = $("HLLCTR-" + elem.id);
1413 if (ctr) ctr.innerHTML = elem.labels;
1416 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML);
1420 exception_error("show_labels_in_headlines", e);
1424 /* function toggleHeadlineActions() {
1426 var e = $("headlineActionsBody");
1427 var p = $("headlineActionsDrop");
1429 if (!Element.visible(e)) {
1436 e.style.left = (p.offsetLeft + 1) + "px";
1437 e.style.top = (p.offsetTop + p.offsetHeight + 2) + "px";
1440 exception_error("toggleHeadlineActions", e);
1444 /* function publishWithNote(id, def_note) {
1446 if (!def_note) def_note = '';
1448 var note = prompt(__("Please enter a note for this article:"), def_note);
1450 if (note != undefined) {
1451 togglePub(id, false, false, note);
1455 exception_error("publishWithNote", e);
1459 function emailArticle(id) {
1462 var ids = getSelectedArticleIds2();
1464 if (ids.length == 0) {
1465 alert(__("No articles are selected."));
1469 id = ids.toString();
1472 if (dijit.byId("emailArticleDlg"))
1473 dijit.byId("emailArticleDlg").destroyRecursive();
1475 var query = "backend.php?op=dlg&id=emailArticle¶m=" + param_escape(id);
1477 dialog = new dijit.Dialog({
1478 id: "emailArticleDlg",
1479 title: __("Forward article by email"),
1480 style: "width: 600px",
1481 execute: function() {
1482 if (this.validate()) {
1484 new Ajax.Request("backend.php", {
1485 parameters: dojo.objectToQuery(this.attr('value')),
1486 onComplete: function(transport) {
1488 var reply = JSON.parse(transport.responseText);
1490 var error = reply['error'];
1493 alert(__('Error sending email:') + ' ' + error);
1495 notify_info('Your message has been sent.');
1504 var tmph = dojo.connect(dialog, 'onLoad', function() {
1505 dojo.disconnect(tmph);
1507 new Ajax.Autocompleter('emailArticleDlg_destination', 'emailArticleDlg_dst_choices',
1508 "backend.php?op=rpc&subop=completeEmails",
1509 { tokens: '', paramName: "search" });
1514 /* displayDlg('emailArticle', id,
1516 document.forms['article_email_form'].destination.focus();
1518 new Ajax.Autocompleter('destination', 'destination_choices',
1519 "backend.php?op=rpc&subop=completeEmails",
1520 { tokens: '', paramName: "search" });
1525 exception_error("emailArticle", e);
1529 function dismissArticle(id) {
1531 var elem = $("RROW-" + id);
1533 toggleUnread(id, 0, true);
1535 new Effect.Fade(elem, {duration : 0.5});
1537 active_post_id = false;
1540 exception_error("dismissArticle", e);
1544 function dismissSelectedArticles() {
1547 var ids = getVisibleArticleIds();
1551 for (var i = 0; i < ids.length; i++) {
1552 var elem = $("RROW-" + ids[i]);
1554 if (elem.className && elem.hasClassName("Selected") &&
1555 ids[i] != active_post_id) {
1556 new Effect.Fade(elem, {duration : 0.5});
1564 selectionToggleUnread(false);
1566 fixHeadlinesOrder(tmp);
1569 exception_error("dismissSelectedArticles", e);
1573 function dismissReadArticles() {
1576 var ids = getVisibleArticleIds();
1579 for (var i = 0; i < ids.length; i++) {
1580 var elem = $("RROW-" + ids[i]);
1582 if (elem.className && !elem.hasClassName("Unread") &&
1583 !elem.hasClassName("Selected")) {
1585 new Effect.Fade(elem, {duration : 0.5});
1591 fixHeadlinesOrder(tmp);
1594 exception_error("dismissSelectedArticles", e);
1598 function getVisibleArticleIds() {
1603 getLoadedArticleIds().each(function(id) {
1604 var elem = $("RROW-" + id);
1605 if (elem && Element.visible(elem))
1610 exception_error("getVisibleArticleIds", e);
1616 function cdmClicked(event, id) {
1618 var shift_key = event.shiftKey;
1622 if (!event.ctrlKey) {
1624 if (!getInitParam("cdm_expanded")) {
1625 return cdmExpandArticle(id);
1628 selectArticles("none");
1631 var elem = $("RROW-" + id);
1634 elem.removeClassName("Unread");
1636 var upd_img_pic = $("FUPDPIC-" + id);
1638 if (upd_img_pic && (upd_img_pic.src.match("updated.png") ||
1639 upd_img_pic.src.match("fresh_sign.png"))) {
1641 upd_img_pic.src = "images/blank_icon.gif";
1644 active_post_id = id;
1646 var query = "?op=rpc&subop=catchupSelected" +
1647 "&cmode=0&ids=" + param_escape(id);
1649 new Ajax.Request("backend.php", {
1651 onComplete: function(transport) {
1652 handle_rpc_json(transport);
1659 toggleSelected(id, true);
1660 toggleUnread(id, 0, false);
1661 zoomToArticle(event, id);
1665 exception_error("cdmClicked");
1671 function postClicked(event, id) {
1674 if (!event.ctrlKey) {
1677 postOpenInNewTab(event, id);
1682 exception_error("postClicked");
1686 function hlOpenInNewTab(event, id) {
1687 toggleUnread(id, 0, false);
1688 zoomToArticle(event, id);
1691 function postOpenInNewTab(event, id) {
1692 closeArticlePanel(id);
1693 zoomToArticle(event, id);
1696 function hlClicked(event, id) {
1698 if (event.which == 2) {
1701 } else if (event.altKey) {
1702 openArticleInNewWindow(id);
1703 } else if (!event.ctrlKey) {
1708 toggleUnread(id, 0, false);
1709 zoomToArticle(event, id);
1714 exception_error("hlClicked");
1718 function getFirstVisibleHeadlineId() {
1719 var rows = getVisibleArticleIds();
1724 function getLastVisibleHeadlineId() {
1725 var rows = getVisibleArticleIds();
1726 return rows[rows.length-1];
1729 function openArticleInNewWindow(id) {
1730 toggleUnread(id, 0, false);
1731 window.open("backend.php?op=la&id=" + id);
1734 function isCdmMode() {
1735 return getInitParam("combined_display_mode");
1738 function markHeadline(id) {
1739 var row = $("RROW-" + id);
1741 var check = $("RCHK-" + id);
1744 check.checked = true;
1747 row.addClassName("Selected");
1751 function getRelativePostIds(id, limit) {
1757 if (!limit) limit = 6; //3
1759 var ids = getVisibleArticleIds();
1761 for (var i = 0; i < ids.length; i++) {
1763 for (var k = 1; k <= limit; k++) {
1764 //if (i > k-1) tmp.push(ids[i-k]);
1765 if (i < ids.length-k) tmp.push(ids[i+k]);
1772 exception_error("getRelativePostIds", e);
1778 function correctHeadlinesOffset(id) {
1782 var container = $("headlines-frame");
1783 var row = $("RROW-" + id);
1785 var viewport = container.offsetHeight;
1787 var rel_offset_top = row.offsetTop - container.scrollTop;
1788 var rel_offset_bottom = row.offsetTop + row.offsetHeight - container.scrollTop;
1790 //console.log("Rtop: " + rel_offset_top + " Rbtm: " + rel_offset_bottom);
1791 //console.log("Vport: " + viewport);
1793 if (rel_offset_top <= 0 || rel_offset_top > viewport) {
1794 container.scrollTop = row.offsetTop;
1795 } else if (rel_offset_bottom > viewport) {
1797 /* doesn't properly work with Opera in some cases because
1798 Opera fucks up element scrolling */
1800 container.scrollTop = row.offsetTop + row.offsetHeight - viewport;
1804 exception_error("correctHeadlinesOffset", e);
1809 function headlineActionsChange(elem) {
1812 elem.attr('value', 'false');
1814 exception_error("headlineActionsChange", e);
1818 function closeArticlePanel() {
1820 var tabs = dijit.byId("content-tabs");
1821 var child = tabs.selectedChildWidget;
1823 if (child && tabs.getIndexOfChild(child) > 0) {
1824 tabs.removeChild(child);
1827 if (dijit.byId("content-insert"))
1828 dijit.byId("headlines-wrap-inner").removeChild(
1829 dijit.byId("content-insert"));
1833 function initHeadlinesMenu() {
1835 if (dijit.byId("headlinesMenu"))
1836 dijit.byId("headlinesMenu").destroyRecursive();
1841 nodes = $$("#headlines-frame > div[id*=RROW]");
1843 nodes = $$("#headlines-frame span[id*=RTITLE]");
1846 nodes.each(function(node) {
1850 var menu = new dijit.Menu({
1851 id: "headlinesMenu",
1855 var tmph = dojo.connect(menu, '_openMyself', function (event) {
1856 var callerNode = event.target, match = null, tries = 0;
1858 while (match == null && callerNode && tries <= 3) {
1859 match = callerNode.id.match("^[A-Z]+[-]([0-9]+)$");
1860 callerNode = callerNode.parentNode;
1864 if (match) this.callerRowId = parseInt(match[1]);
1868 /* if (!isCdmMode())
1869 menu.addChild(new dijit.MenuItem({
1870 label: __("View article"),
1871 onClick: function(event) {
1872 view(this.getParent().callerRowId);
1875 menu.addChild(new dijit.MenuItem({
1876 label: __("Open original article"),
1877 onClick: function(event) {
1878 openArticleInNewWindow(this.getParent().callerRowId);
1881 menu.addChild(new dijit.MenuItem({
1882 label: __("View in a tt-rss tab"),
1883 onClick: function(event) {
1884 hlOpenInNewTab(event, this.getParent().callerRowId);
1887 // menu.addChild(new dijit.MenuSeparator());
1889 var labels = dijit.byId("feedTree").model.getItemsInCategory(-2);
1893 menu.addChild(new dijit.MenuSeparator());
1895 var labelAddMenu = new dijit.Menu({ownerMenu: menu});
1896 var labelDelMenu = new dijit.Menu({ownerMenu: menu});
1898 labels.each(function(label) {
1899 var id = label.id[0];
1900 var bare_id = id.substr(id.indexOf(":")+1);
1901 var name = label.name[0];
1903 bare_id = -11-bare_id;
1905 labelAddMenu.addChild(new dijit.MenuItem({
1908 onClick: function(event) {
1909 selectionAssignLabel(this.labelId,
1910 [this.getParent().ownerMenu.callerRowId]);
1913 labelDelMenu.addChild(new dijit.MenuItem({
1916 onClick: function(event) {
1917 selectionRemoveLabel(this.labelId,
1918 [this.getParent().ownerMenu.callerRowId]);
1923 menu.addChild(new dijit.PopupMenuItem({
1924 label: __("Assign label"),
1925 popup: labelAddMenu,
1928 menu.addChild(new dijit.PopupMenuItem({
1929 label: __("Remove label"),
1930 popup: labelDelMenu,
1938 exception_error("initHeadlinesMenu", e);
1942 function tweetArticle(id) {
1944 var query = "?op=rpc&subop=getTweetInfo&id=" + param_escape(id);
1949 var ts = d.getTime();
1951 var w = window.open('backend.php?op=loading', 'ttrss_tweet',
1952 "status=0,toolbar=0,location=0,width=500,height=400,scrollbars=1,menubar=0");
1954 new Ajax.Request("backend.php", {
1956 onComplete: function(transport) {
1957 var ti = JSON.parse(transport.responseText);
1959 var share_url = "http://twitter.com/share?_=" + ts +
1960 "&text=" + param_escape(ti.title) +
1961 "&url=" + param_escape(ti.link);
1963 w.location.href = share_url;
1969 exception_error("tweetArticle", e);
1973 function editArticleNote(id) {
1976 var query = "backend.php?op=dlg&id=editArticleNote¶m=" + param_escape(id);
1978 if (dijit.byId("editNoteDlg"))
1979 dijit.byId("editNoteDlg").destroyRecursive();
1981 dialog = new dijit.Dialog({
1983 title: __("Edit article note"),
1984 style: "width: 600px",
1985 execute: function() {
1986 if (this.validate()) {
1987 var query = dojo.objectToQuery(this.attr('value'));
1989 notify_progress("Saving article note...", true);
1991 new Ajax.Request("backend.php", {
1993 onComplete: function(transport) {
1997 var reply = JSON.parse(transport.responseText);
1999 cache_delete("article:" + id);
2001 var elem = $("POSTNOTE-" + id);
2005 elem.innerHTML = reply.note;
2007 if (reply.raw_length != 0)
2008 new Effect.Appear(elem);
2020 exception_error("editArticleNote", e);
2024 function player(elem) {
2025 var aid = elem.getAttribute("audio-id");
2026 var status = elem.getAttribute("status");
2034 elem.innerHTML = __("Playing...");
2035 elem.title = __("Click to pause");
2036 elem.addClassName("playing");
2040 elem.innerHTML = __("Play");
2041 elem.title = __("Click to play");
2042 elem.removeClassName("playing");
2045 elem.setAttribute("status", status);
2047 alert("Your browser doesn't seem to support HTML5 audio.");
2051 function cache_set(id, obj) {
2052 //console.log("cache_set: " + id);
2055 sessionStorage[id] = obj;
2057 if (e == QUOTA_EXCEEDED_ERR)
2058 sessionStorage.clear();
2062 function cache_get(id) {
2064 return sessionStorage[id];
2067 function cache_clear() {
2069 sessionStorage.clear();
2072 function cache_delete(id) {
2074 sessionStorage.removeItem(id);
2077 function cache_headlines(feed, is_cat, toolbar_obj, content_obj) {
2078 if (toolbar_obj && content_obj) {
2079 cache_set("feed:" + feed + ":" + is_cat,
2080 JSON.stringify({toolbar: toolbar_obj, content: content_obj}));
2083 obj = cache_get("feed:" + feed + ":" + is_cat);
2086 obj = JSON.parse(obj);
2088 if (toolbar_obj) obj.toolbar = toolbar_obj;
2089 if (content_obj) obj.content = content_obj;
2091 cache_set("feed:" + feed + ":" + is_cat, JSON.stringify(obj));
2095 console.warn("cache_headlines failed: " + e);
2100 function render_local_headlines(feed, is_cat, obj) {
2103 dijit.byId("headlines-toolbar").attr('content',
2106 dijit.byId("headlines-frame").attr('content',
2109 dojo.parser.parse('headlines-toolbar');
2111 $("headlines-frame").scrollTop = 0;
2112 selectArticles('none');
2113 setActiveFeedId(feed, is_cat);
2114 initHeadlinesMenu();
2116 precache_headlines();
2119 exception_error("render_local_headlines", e);
2123 function precache_headlines_idle() {
2125 if (!feed_precache_timeout_id) {
2126 var feeds = dijit.byId("feedTree").getVisibleUnreadFeeds();
2129 feeds.each(function(item) {
2130 if (parseInt(item[0]) > 0 && !cache_get("feed:" + item[0] + ":" + item[1]))
2131 uncached.push(item);
2134 if (uncached.length > 0) {
2135 var rf = uncached[Math.floor(Math.random()*uncached.length)];
2136 viewfeed(rf[0], '', rf[1], 0, true);
2139 precache_idle_timeout_id = setTimeout("precache_headlines_idle()", 5000);
2142 exception_error("precache_headlines_idle", e);
2146 function precache_headlines() {
2149 if (!feed_precache_timeout_id) {
2150 feed_precache_timeout_id = window.setTimeout(function() {
2151 var nuf = getNextUnreadFeed(getActiveFeedId(), activeFeedIsCat());
2152 var nf = dijit.byId("feedTree").getNextFeed(getActiveFeedId(), activeFeedIsCat());
2154 if (nuf && !cache_get("feed:" + nuf + ":" + activeFeedIsCat()))
2155 viewfeed(nuf, '', activeFeedIsCat(), 0, true);
2157 if (nf != nuf && nf && !cache_get("feed:" + nf[0] + ":" + nf[1]))
2158 viewfeed(nf[0], '', nf[1], 0, true);
2160 window.setTimeout(function() {
2161 feed_precache_timeout_id = false;
2168 exception_error("precache_headlines", e);