1 var article_cache = new Array();
3 var _active_article_id = 0;
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;
13 var cids_requested = [];
14 var loaded_article_ids = [];
15 var _last_headlines_update = 0;
16 var current_first_id = 0;
18 var _catchup_request_sent = false;
20 var has_storage = 'sessionStorage' in window && window['sessionStorage'] !== null;
22 function headlines_callback2(transport, offset, background, infscroll_req) {
24 handle_rpc_json(transport);
26 console.log("headlines_callback2 [offset=" + offset + "] B:" + background + " I:" + infscroll_req);
34 reply = JSON.parse(transport.responseText);
41 is_cat = reply['headlines']['is_cat'];
42 feed_id = reply['headlines']['id'];
45 var content = reply['headlines']['content'];
47 content = content + "<div id='headlines-spacer'></div>";
51 if (feed_id != -7 && (feed_id != getActiveFeedId() || is_cat != activeFeedIsCat()))
54 /* dijit.getEnclosingWidget(
55 document.forms["main_toolbar_form"].update).attr('disabled',
56 is_cat || feed_id <= 0); */
59 if (infscroll_req == false) {
60 $("headlines-frame").scrollTop = 0;
62 $("floatingTitle").style.visibility = "hidden";
63 $("floatingTitle").setAttribute("rowid", 0);
64 $("floatingTitle").innerHTML = "";
68 $("headlines-frame").removeClassName("cdm");
69 $("headlines-frame").removeClassName("normal");
71 $("headlines-frame").addClassName(isCdmMode() ? "cdm" : "normal");
73 var headlines_count = reply['headlines-info']['count'];
75 vgroup_last_feed = reply['headlines-info']['vgroup_last_feed'];
77 if (parseInt(headlines_count) < 30) {
78 _infscroll_disable = 1;
80 _infscroll_disable = 0;
83 current_first_id = reply['headlines']['first_id'];
84 var counters = reply['counters'];
85 var articles = reply['articles'];
86 //var runtime_info = reply['runtime-info'];
88 if (infscroll_req == false) {
89 loaded_article_ids = [];
91 dojo.html.set($("headlines-toolbar"),
92 reply['headlines']['toolbar'],
93 {parseContent: true});
95 /*dojo.html.set($("headlines-frame"),
96 reply['headlines']['content'],
97 {parseContent: true});
99 $$("#headlines-frame div[id*='RROW']").each(function(row) {
100 loaded_article_ids.push(row.id);
103 $("headlines-frame").innerHTML = '';
105 var tmp = new Element("div");
106 tmp.innerHTML = reply['headlines']['content'];
107 dojo.parser.parse(tmp);
109 while (tmp.hasChildNodes()) {
110 var row = tmp.removeChild(tmp.firstChild);
112 if (loaded_article_ids.indexOf(row.id) == -1 || row.hasClassName("cdmFeedTitle")) {
113 dijit.byId("headlines-frame").domNode.appendChild(row);
115 loaded_article_ids.push(row.id);
119 var hsp = $("headlines-spacer");
120 if (!hsp) hsp = new Element("DIV", {"id": "headlines-spacer"});
121 dijit.byId('headlines-frame').domNode.appendChild(hsp);
125 if (_infscroll_disable)
126 hsp.innerHTML = "<a href='#' onclick='openNextUnreadFeed()'>" +
127 __("Click to open next unread feed.") + "</a>";
130 $("feed_title").innerHTML += "<span id='cancel_search'>" +
131 " (<a href='#' onclick='cancelSearch()'>" + __("Cancel search") + "</a>)" +
137 if (headlines_count > 0 && feed_id == getActiveFeedId() && is_cat == activeFeedIsCat()) {
138 console.log("adding some more headlines: " + headlines_count);
140 var c = dijit.byId("headlines-frame");
141 var ids = getSelectedArticleIds2();
143 var hsp = $("headlines-spacer");
146 c.domNode.removeChild(hsp);
148 var tmp = new Element("div");
149 tmp.innerHTML = reply['headlines']['content'];
150 dojo.parser.parse(tmp);
152 while (tmp.hasChildNodes()) {
153 var row = tmp.removeChild(tmp.firstChild);
155 if (loaded_article_ids.indexOf(row.id) == -1 || row.hasClassName("cdmFeedTitle")) {
156 dijit.byId("headlines-frame").domNode.appendChild(row);
158 loaded_article_ids.push(row.id);
162 if (!hsp) hsp = new Element("DIV", {"id": "headlines-spacer"});
163 c.domNode.appendChild(hsp);
165 if (headlines_count < 30) _infscroll_disable = true;
167 console.log("restore selected ids: " + ids);
169 for (var i = 0; i < ids.length; i++) {
170 markHeadline(ids[i]);
175 if (_infscroll_disable) {
176 hsp.innerHTML = "<a href='#' onclick='openNextUnreadFeed()'>" +
177 __("Click to open next unread feed.") + "</a>";
181 console.log("no new headlines received");
183 var first_id_changed = reply['headlines']['first_id_changed'];
184 console.log("first id changed:" + first_id_changed);
186 var hsp = $("headlines-spacer");
189 if (first_id_changed) {
190 hsp.innerHTML = "<a href='#' onclick='viewCurrentFeed()'>" +
191 __("New articles found, reload feed to continue.") + "</a>";
193 hsp.innerHTML = "<a href='#' onclick='openNextUnreadFeed()'>" +
194 __("Click to open next unread feed.") + "</a>";
203 for (var i = 0; i < articles.length; i++) {
204 var a_id = articles[i]['id'];
205 cache_set("article:" + a_id, articles[i]['content']);
208 console.log("no cached articles received");
212 parse_counters(counters);
214 request_counters(true);
217 console.error("Invalid object received: " + transport.responseText);
218 dijit.byId("headlines-frame").attr('content', "<div class='whiteBox'>" +
219 __('Could not update headlines (invalid object received - see error console for details)') +
223 _infscroll_request_sent = 0;
224 _last_headlines_update = new Date().getTime();
226 unpackVisibleHeadlines();
228 // if we have some more space in the buffer, why not try to fill it
230 if (!_infscroll_disable && $("headlines-spacer") &&
231 $("headlines-spacer").offsetTop < $("headlines-frame").offsetHeight) {
233 window.setTimeout(function() {
241 exception_error("headlines_callback2", e, transport);
245 function render_article(article) {
247 dijit.byId("headlines-wrap-inner").addChild(
248 dijit.byId("content-insert"));
250 var c = dijit.byId("content-insert");
253 c.domNode.scrollTop = 0;
256 c.attr('content', article);
257 PluginHost.run(PluginHost.HOOK_ARTICLE_RENDERED, c.domNode);
259 correctHeadlinesOffset(getActiveArticleId());
266 exception_error("render_article", e);
270 function showArticleInHeadlines(id, noexpand) {
273 selectArticles("none");
275 var crow = $("RROW-" + id);
279 var article_is_unread = crow.hasClassName("Unread");
282 crow.removeClassName("Unread");
283 crow.addClassName("active");
285 selectArticles('none');
287 var view_mode = false;
290 view_mode = document.forms['main_toolbar_form'].view_mode;
291 view_mode = view_mode[view_mode.selectedIndex].value;
298 if (article_is_unread && !noexpand)
299 _force_scheduled_update = true;
302 exception_error("showArticleInHeadlines", e);
306 function article_callback2(transport, id) {
308 console.log("article_callback2 " + id);
310 handle_rpc_json(transport);
315 reply = JSON.parse(transport.responseText);
322 reply.each(function(article) {
323 if (getActiveArticleId() == article['id']) {
324 render_article(article['content']);
326 cids_requested.remove(article['id']);
328 cache_set("article:" + article['id'], article['content']);
331 // if (id != last_requested_article) {
332 // console.log("requested article id is out of sequence, aborting");
337 console.error("Invalid object received: " + transport.responseText);
339 render_article("<div class='whiteBox'>" +
340 __('Could not display article (invalid object received - see error console for details)') + "</div>");
343 var unread_in_buffer = $$("#headlines-frame > div[id*=RROW][class*=Unread]").length
344 request_counters(unread_in_buffer == 0);
348 exception_error("article_callback2", e, transport);
352 function view(id, activefeed, noexpand) {
354 var oldrow = $("RROW-" + getActiveArticleId());
355 if (oldrow) oldrow.removeClassName("active");
357 var crow = $("RROW-" + id);
361 setActiveArticleId(id);
362 showArticleInHeadlines(id, noexpand);
366 console.log("loading article: " + id);
368 var cached_article = cache_get("article:" + id);
370 console.log("cache check result: " + (cached_article != false));
372 var query = "?op=article&method=view&id=" + param_escape(id);
374 var neighbor_ids = getRelativePostIds(id);
376 /* only request uncached articles */
378 var cids_to_request = [];
380 for (var i = 0; i < neighbor_ids.length; i++) {
381 if (cids_requested.indexOf(neighbor_ids[i]) == -1)
382 if (!cache_get("article:" + neighbor_ids[i])) {
383 cids_to_request.push(neighbor_ids[i]);
384 cids_requested.push(neighbor_ids[i]);
388 console.log("additional ids: " + cids_to_request.toString());
390 query = query + "&cids=" + cids_to_request.toString();
392 var article_is_unread = crow.hasClassName("Unread");
394 setActiveArticleId(id);
395 showArticleInHeadlines(id);
397 if (cached_article && article_is_unread) {
399 query = query + "&mode=prefetch";
401 render_article(cached_article);
403 } else if (cached_article) {
405 query = query + "&mode=prefetch_old";
406 render_article(cached_article);
408 // if we don't need to request any relative ids, we might as well skip
409 // the server roundtrip altogether
410 if (cids_to_request.length == 0) {
415 last_requested_article = id;
419 if (article_is_unread) {
420 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
423 new Ajax.Request("backend.php", {
425 onComplete: function(transport) {
426 article_callback2(transport, id);
432 exception_error("view", e);
436 function toggleMark(id, client_only) {
438 var query = "?op=rpc&id=" + id + "&method=mark";
440 var row = $("RROW-" + id);
445 var row_imgs = row.getElementsByClassName("markedPic");
447 for (var i = 0; i < row_imgs.length; i++)
448 imgs.push(row_imgs[i]);
450 var ft = $("floatingTitle");
452 if (ft && ft.getAttribute("rowid") == "RROW-" + id) {
453 var fte = ft.getElementsByClassName("markedPic");
455 for (var i = 0; i < fte.length; i++)
459 for (i = 0; i < imgs.length; i++) {
462 if (!row.hasClassName("marked")) {
463 img.src = img.src.replace("mark_unset", "mark_set");
464 img.alt = __("Unstar article");
465 query = query + "&mark=1";
467 img.src = img.src.replace("mark_set", "mark_unset");
468 img.alt = __("Star article");
469 query = query + "&mark=0";
473 row.toggleClassName("marked");
476 new Ajax.Request("backend.php", {
478 onComplete: function(transport) {
479 handle_rpc_json(transport);
484 exception_error("toggleMark", e);
488 function togglePub(id, client_only, no_effects, note) {
490 var query = "?op=rpc&id=" + id + "&method=publ";
492 if (note != undefined) {
493 query = query + "¬e=" + param_escape(note);
495 query = query + "¬e=undefined";
498 var row = $("RROW-" + id);
503 var row_imgs = row.getElementsByClassName("pubPic");
505 for (var i = 0; i < row_imgs.length; i++)
506 imgs.push(row_imgs[i]);
508 var ft = $("floatingTitle");
510 if (ft && ft.getAttribute("rowid") == "RROW-" + id) {
511 var fte = ft.getElementsByClassName("pubPic");
513 for (var i = 0; i < fte.length; i++)
517 for (i = 0; i < imgs.length; i++) {
520 if (!row.hasClassName("published") || note != undefined) {
521 img.src = img.src.replace("pub_unset", "pub_set");
522 img.alt = __("Unpublish article");
523 query = query + "&pub=1";
525 img.src = img.src.replace("pub_set", "pub_unset");
526 img.alt = __("Publish article");
527 query = query + "&pub=0";
531 if (note != undefined)
532 row.addClassName("published");
534 row.toggleClassName("published");
537 new Ajax.Request("backend.php", {
539 onComplete: function(transport) {
540 handle_rpc_json(transport);
545 exception_error("togglePub", e);
549 function moveToPost(mode, noscroll, noexpand) {
553 var rows = getVisibleArticleIds();
558 if (!$('RROW-' + getActiveArticleId())) {
559 setActiveArticleId(0);
562 if (!getActiveArticleId()) {
564 prev_id = rows[rows.length-1]
566 for (var i = 0; i < rows.length; i++) {
567 if (rows[i] == getActiveArticleId()) {
569 // Account for adjacent identical article ids.
570 if (i > 0) prev_id = rows[i-1];
572 for (var j = i+1; j < rows.length; j++) {
573 if (rows[j] != getActiveArticleId()) {
583 console.log("cur: " + getActiveArticleId() + " next: " + next_id);
585 if (mode == "next") {
586 if (next_id || getActiveArticleId()) {
589 var article = $("RROW-" + getActiveArticleId());
590 var ctr = $("headlines-frame");
592 if (!noscroll && article && article.offsetTop + article.offsetHeight >
593 ctr.scrollTop + ctr.offsetHeight) {
595 scrollArticle(ctr.offsetHeight/4);
597 } else if (next_id) {
598 cdmExpandArticle(next_id, noexpand);
599 cdmScrollToArticleId(next_id, true);
602 } else if (next_id) {
603 correctHeadlinesOffset(next_id);
604 view(next_id, getActiveFeedId(), noexpand);
609 if (mode == "prev") {
610 if (prev_id || getActiveArticleId()) {
613 var article = $("RROW-" + getActiveArticleId());
614 var prev_article = $("RROW-" + prev_id);
615 var ctr = $("headlines-frame");
617 if (!getInitParam("cdm_expanded")) {
619 if (!noscroll && article && article.offsetTop < ctr.scrollTop) {
620 scrollArticle(-ctr.offsetHeight/4);
622 cdmExpandArticle(prev_id, noexpand);
623 cdmScrollToArticleId(prev_id, true);
627 if (!noscroll && article && article.offsetTop < ctr.scrollTop) {
628 scrollArticle(-ctr.offsetHeight/3);
629 } else if (!noscroll && prev_article &&
630 prev_article.offsetTop < ctr.scrollTop) {
631 cdmExpandArticle(prev_id, noexpand);
632 scrollArticle(-ctr.offsetHeight/4);
633 } else if (prev_id) {
634 cdmExpandArticle(prev_id, noexpand);
635 cdmScrollToArticleId(prev_id, noscroll);
639 } else if (prev_id) {
640 correctHeadlinesOffset(prev_id);
641 view(prev_id, getActiveFeedId(), noexpand);
647 exception_error("moveToPost", e);
651 function toggleSelected(id, force_on) {
653 var row = $("RROW-" + id);
656 var cb = dijit.getEnclosingWidget(
657 row.getElementsByClassName("rchk")[0]);
659 if (row.hasClassName('Selected') && !force_on) {
660 row.removeClassName('Selected');
661 if (cb) cb.attr("checked", false);
663 row.addClassName('Selected');
664 if (cb) cb.attr("checked", true);
668 updateSelectedPrompt();
670 exception_error("toggleSelected", e);
674 function updateSelectedPrompt() {
676 var count = getSelectedArticleIds2().size();
677 var elem = $("selected_prompt");
680 elem.innerHTML = ngettext("%d article selected",
681 "%d articles selected", count).replace("%d", count);
690 exception_error("updateSelectedPrompt", e);
694 function toggleUnread_afh(effect) {
697 var elem = effect.element;
698 elem.style.backgroundColor = "";
701 exception_error("toggleUnread_afh", e);
705 function toggleUnread(id, cmode, effect) {
708 var row = $("RROW-" + id);
710 var tmpClassName = row.className;
712 if (cmode == undefined || cmode == 2) {
713 if (row.hasClassName("Unread")) {
714 row.removeClassName("Unread");
717 row.addClassName("Unread");
720 } else if (cmode == 0) {
722 row.removeClassName("Unread");
724 } else if (cmode == 1) {
725 row.addClassName("Unread");
728 if (cmode == undefined) cmode = 2;
730 var query = "?op=rpc&method=catchupSelected" +
731 "&cmode=" + param_escape(cmode) + "&ids=" + param_escape(id);
733 // notify_progress("Loading, please wait...");
735 if (tmpClassName != row.className) {
736 new Ajax.Request("backend.php", {
738 onComplete: function (transport) {
739 handle_rpc_json(transport);
747 exception_error("toggleUnread", e);
751 function selectionRemoveLabel(id, ids) {
754 if (!ids) ids = getSelectedArticleIds2();
756 if (ids.length == 0) {
757 alert(__("No articles are selected."));
761 var query = "?op=article&method=removeFromLabel&ids=" +
762 param_escape(ids.toString()) + "&lid=" + param_escape(id);
766 new Ajax.Request("backend.php", {
768 onComplete: function(transport) {
769 handle_rpc_json(transport);
770 show_labels_in_headlines(transport);
774 exception_error("selectionAssignLabel", e);
779 function selectionAssignLabel(id, ids) {
782 if (!ids) ids = getSelectedArticleIds2();
784 if (ids.length == 0) {
785 alert(__("No articles are selected."));
789 var query = "?op=article&method=assignToLabel&ids=" +
790 param_escape(ids.toString()) + "&lid=" + param_escape(id);
794 new Ajax.Request("backend.php", {
796 onComplete: function(transport) {
797 handle_rpc_json(transport);
798 show_labels_in_headlines(transport);
802 exception_error("selectionAssignLabel", e);
807 function selectionToggleUnread(set_state, callback, no_error, ids) {
809 var rows = ids ? ids : getSelectedArticleIds2();
811 if (rows.length == 0 && !no_error) {
812 alert(__("No articles are selected."));
816 for (var i = 0; i < rows.length; i++) {
817 var row = $("RROW-" + rows[i]);
819 if (set_state == undefined) {
820 if (row.hasClassName("Unread")) {
821 row.removeClassName("Unread");
823 row.addClassName("Unread");
827 if (set_state == false) {
828 row.removeClassName("Unread");
831 if (set_state == true) {
832 row.addClassName("Unread");
837 updateFloatingTitle(true);
839 if (rows.length > 0) {
843 if (set_state == undefined) {
845 } else if (set_state == true) {
847 } else if (set_state == false) {
851 var query = "?op=rpc&method=catchupSelected" +
852 "&cmode=" + cmode + "&ids=" + param_escape(rows.toString());
854 notify_progress("Loading, please wait...");
856 new Ajax.Request("backend.php", {
858 onComplete: function(transport) {
859 handle_rpc_json(transport);
860 if (callback) callback(transport);
866 exception_error("selectionToggleUnread", e);
871 function selectionToggleMarked(sel_state, callback, no_error, ids) {
874 var rows = ids ? ids : getSelectedArticleIds2();
876 if (rows.length == 0 && !no_error) {
877 alert(__("No articles are selected."));
881 for (var i = 0; i < rows.length; i++) {
882 toggleMark(rows[i], true, true);
885 if (rows.length > 0) {
887 var query = "?op=rpc&method=markSelected&ids=" +
888 param_escape(rows.toString()) + "&cmode=2";
890 new Ajax.Request("backend.php", {
892 onComplete: function(transport) {
893 handle_rpc_json(transport);
894 if (callback) callback(transport);
900 exception_error("selectionToggleMarked", e);
905 function selectionTogglePublished(sel_state, callback, no_error, ids) {
908 var rows = ids ? ids : getSelectedArticleIds2();
910 if (rows.length == 0 && !no_error) {
911 alert(__("No articles are selected."));
915 for (var i = 0; i < rows.length; i++) {
916 togglePub(rows[i], true, true);
919 if (rows.length > 0) {
921 var query = "?op=rpc&method=publishSelected&ids=" +
922 param_escape(rows.toString()) + "&cmode=2";
924 new Ajax.Request("backend.php", {
926 onComplete: function(transport) {
927 handle_rpc_json(transport);
933 exception_error("selectionToggleMarked", e);
937 function getSelectedArticleIds2() {
941 $$("#headlines-frame > div[id*=RROW][class*=Selected]").each(
943 rv.push(child.id.replace("RROW-", ""));
949 function getLoadedArticleIds() {
952 var children = $$("#headlines-frame > div[id*=RROW-]");
954 children.each(function(child) {
955 rv.push(child.id.replace("RROW-", ""));
962 // mode = all,none,unread,invert,marked,published
963 function selectArticles(mode, query) {
966 if (!query) query = "#headlines-frame > div[id*=RROW]";
968 var children = $$(query);
970 children.each(function(child) {
971 var id = child.id.replace("RROW-", "");
973 var cb = dijit.getEnclosingWidget(
974 child.getElementsByClassName("rchk")[0]);
977 child.addClassName("Selected");
978 if (cb) cb.attr("checked", true);
979 } else if (mode == "unread") {
980 if (child.hasClassName("Unread")) {
981 child.addClassName("Selected");
982 if (cb) cb.attr("checked", true);
984 child.removeClassName("Selected");
985 if (cb) cb.attr("checked", false);
987 } else if (mode == "marked") {
988 if (child.hasClassName("marked")) {
989 child.addClassName("Selected");
990 if (cb) cb.attr("checked", true);
992 child.removeClassName("Selected");
993 if (cb) cb.attr("checked", false);
995 } else if (mode == "published") {
996 if (child.hasClassName("published")) {
997 child.addClassName("Selected");
998 if (cb) cb.attr("checked", true);
1000 child.removeClassName("Selected");
1001 if (cb) cb.attr("checked", false);
1004 } else if (mode == "invert") {
1005 if (child.hasClassName("Selected")) {
1006 child.removeClassName("Selected");
1007 if (cb) cb.attr("checked", false);
1009 child.addClassName("Selected");
1010 if (cb) cb.attr("checked", true);
1014 child.removeClassName("Selected");
1015 if (cb) cb.attr("checked", false);
1019 updateSelectedPrompt();
1022 exception_error("selectArticles", e);
1026 function deleteSelection() {
1030 var rows = getSelectedArticleIds2();
1032 if (rows.length == 0) {
1033 alert(__("No articles are selected."));
1037 var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
1040 if (getActiveFeedId() != 0) {
1041 str = ngettext("Delete %d selected article in %s?", "Delete %d selected articles in %s?" , rows.length);
1043 str = ngettext("Delete %d selected article?", "Delete %d selected articles?", rows.length);
1046 str = str.replace("%d", rows.length);
1047 str = str.replace("%s", fn);
1049 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
1053 query = "?op=rpc&method=delete&ids=" + param_escape(rows);
1057 new Ajax.Request("backend.php", {
1059 onComplete: function(transport) {
1060 handle_rpc_json(transport);
1065 exception_error("deleteSelection", e);
1069 function archiveSelection() {
1073 var rows = getSelectedArticleIds2();
1075 if (rows.length == 0) {
1076 alert(__("No articles are selected."));
1080 var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
1084 if (getActiveFeedId() != 0) {
1085 str = ngettext("Archive %d selected article in %s?", "Archive %d selected articles in %s?", rows.length);
1088 str = ngettext("Move %d archived article back?", "Move %d archived articles back?", rows.length);
1090 str += " " + __("Please note that unstarred articles might get purged on next feed update.");
1095 str = str.replace("%d", rows.length);
1096 str = str.replace("%s", fn);
1098 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
1102 query = "?op=rpc&method="+op+"&ids=" + param_escape(rows);
1106 for (var i = 0; i < rows.length; i++) {
1107 cache_delete("article:" + rows[i]);
1110 new Ajax.Request("backend.php", {
1112 onComplete: function(transport) {
1113 handle_rpc_json(transport);
1118 exception_error("archiveSelection", e);
1122 function catchupSelection() {
1126 var rows = getSelectedArticleIds2();
1128 if (rows.length == 0) {
1129 alert(__("No articles are selected."));
1133 var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
1135 var str = ngettext("Mark %d selected article in %s as read?", "Mark %d selected articles in %s as read?", rows.length);
1137 str = str.replace("%d", rows.length);
1138 str = str.replace("%s", fn);
1140 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
1144 selectionToggleUnread(false, 'viewCurrentFeed()', true);
1147 exception_error("catchupSelection", e);
1151 function editArticleTags(id) {
1152 var query = "backend.php?op=article&method=editArticleTags¶m=" + param_escape(id);
1154 if (dijit.byId("editTagsDlg"))
1155 dijit.byId("editTagsDlg").destroyRecursive();
1157 dialog = new dijit.Dialog({
1159 title: __("Edit article Tags"),
1160 style: "width: 600px",
1161 execute: function() {
1162 if (this.validate()) {
1163 var query = dojo.objectToQuery(this.attr('value'));
1165 notify_progress("Saving article tags...", true);
1167 new Ajax.Request("backend.php", {
1169 onComplete: function(transport) {
1174 var data = JSON.parse(transport.responseText);
1181 var tags = $("ATSTR-" + id);
1182 var tooltip = dijit.byId("ATSTRTIP-" + id);
1184 if (tags) tags.innerHTML = data.content;
1185 if (tooltip) tooltip.attr('label', data.content_full);
1188 exception_error("editArticleTags/inner", e);
1197 var tmph = dojo.connect(dialog, 'onLoad', function() {
1198 dojo.disconnect(tmph);
1200 new Ajax.Autocompleter('tags_str', 'tags_choices',
1201 "backend.php?op=article&method=completeTags",
1202 { tokens: ',', paramName: "search" });
1209 function cdmScrollToArticleId(id, force) {
1211 var ctr = $("headlines-frame");
1212 var e = $("RROW-" + id);
1214 if (!e || !ctr) return;
1216 if (force || e.offsetTop+e.offsetHeight > (ctr.scrollTop+ctr.offsetHeight) ||
1217 e.offsetTop < ctr.scrollTop) {
1219 // expanded cdm has a 4px margin now
1220 ctr.scrollTop = parseInt(e.offsetTop) - 4;
1224 exception_error("cdmScrollToArticleId", e);
1228 function setActiveArticleId(id) {
1229 console.log("setActiveArticleId:" + id);
1231 _active_article_id = id;
1232 PluginHost.run(PluginHost.HOOK_ARTICLE_SET_ACTIVE, _active_article_id);
1235 function getActiveArticleId() {
1236 return _active_article_id;
1239 function postMouseIn(e, id) {
1240 post_under_pointer = id;
1243 function postMouseOut(id) {
1244 post_under_pointer = false;
1247 function unpackVisibleHeadlines() {
1249 if (!isCdmMode() || !getInitParam("cdm_expanded")) return;
1251 $$("#headlines-frame > div[id*=RROW]").each(
1253 if (child.offsetTop <= $("headlines-frame").scrollTop +
1254 $("headlines-frame").offsetHeight) {
1256 var cencw = $("CENCW-" + child.id.replace("RROW-", ""));
1259 cencw.innerHTML = htmlspecialchars_decode(cencw.innerHTML);
1260 cencw.setAttribute('id', '');
1262 PluginHost.run(PluginHost.HOOK_ARTICLE_RENDERED_CDM, child);
1264 Element.show(cencw);
1271 exception_error("unpackVisibleHeadlines", e);
1275 function headlines_scroll_handler(e) {
1277 var hsp = $("headlines-spacer");
1279 unpackVisibleHeadlines();
1281 // set topmost child in the buffer as active
1282 if (isCdmMode() && getInitParam("cdm_auto_catchup") == 1 &&
1283 getSelectedArticleIds2().length <= 1 &&
1284 getInitParam("cdm_expanded")) {
1285 var rows = $$("#headlines-frame > div[id*=RROW]");
1287 for (var i = 0; i < rows.length; i++) {
1288 var child = rows[i];
1290 if ($("headlines-frame").scrollTop <= child.offsetTop &&
1291 child.offsetTop - $("headlines-frame").scrollTop < 100 &&
1292 child.id.replace("RROW-", "") != _active_article_id) {
1294 if (_active_article_id) {
1295 var row = $("RROW-" + _active_article_id);
1296 if (row) row.removeClassName("active");
1299 _active_article_id = child.id.replace("RROW-", "");
1300 showArticleInHeadlines(_active_article_id, true);
1301 updateSelectedPrompt();
1307 if (!_infscroll_disable) {
1308 if (hsp && hsp.offsetTop - 250 <= e.scrollTop + e.offsetHeight) {
1310 hsp.innerHTML = "<span class='loading'><img src='images/indicator_tiny.gif'> " +
1311 __("Loading, please wait...") + "</span>";
1313 loadMoreHeadlines();
1320 updateFloatingTitle();
1323 catchupCurrentBatchIfNeeded();
1325 if (getInitParam("cdm_auto_catchup") == 1) {
1327 // let's get DOM some time to settle down
1328 var ts = new Date().getTime();
1329 if (ts - _last_headlines_update < 100) return;
1331 $$("#headlines-frame > div[id*=RROW][class*=Unread]").each(
1333 if (child.hasClassName("Unread") && $("headlines-frame").scrollTop >
1334 (child.offsetTop + child.offsetHeight/2)) {
1336 var id = child.id.replace("RROW-", "");
1338 if (catchup_id_batch.indexOf(id) == -1)
1339 catchup_id_batch.push(id);
1341 //console.log("auto_catchup_batch: " + catchup_id_batch.toString());
1346 if (_infscroll_disable) {
1347 var child = $$("#headlines-frame div[id*=RROW]").last();
1349 if (child && $("headlines-frame").scrollTop >
1350 (child.offsetTop + child.offsetHeight - 50)) {
1352 console.log("we seem to be at an end");
1354 if (getInitParam("on_catchup_show_next_feed") == "1") {
1355 openNextUnreadFeed();
1362 console.warn("headlines_scroll_handler: " + e);
1366 function openNextUnreadFeed() {
1368 var is_cat = activeFeedIsCat();
1369 var nuf = getNextUnreadFeed(getActiveFeedId(), is_cat);
1370 if (nuf) viewfeed({feed: nuf, is_cat: is_cat});
1372 exception_error("openNextUnreadFeed", e);
1376 function catchupBatchedArticles() {
1378 if (catchup_id_batch.length > 0 && !_infscroll_request_sent && !_catchup_request_sent) {
1380 console.log("catchupBatchedArticles: working");
1382 // make a copy of the array
1383 var batch = catchup_id_batch.slice();
1384 var query = "?op=rpc&method=catchupSelected" +
1385 "&cmode=0&ids=" + param_escape(batch.toString());
1389 _catchup_request_sent = true;
1391 new Ajax.Request("backend.php", {
1393 onComplete: function(transport) {
1394 handle_rpc_json(transport);
1396 _catchup_request_sent = false;
1398 reply = JSON.parse(transport.responseText);
1399 var batch = reply.ids;
1401 batch.each(function(id) {
1403 var elem = $("RROW-" + id);
1404 if (elem) elem.removeClassName("Unread");
1405 catchup_id_batch.remove(id);
1408 updateFloatingTitle(true);
1414 exception_error("catchupBatchedArticles", e);
1418 function catchupRelativeToArticle(below, id) {
1422 if (!id) id = getActiveArticleId();
1425 alert(__("No article is selected."));
1429 var visible_ids = getVisibleArticleIds();
1431 var ids_to_mark = new Array();
1434 for (var i = 0; i < visible_ids.length; i++) {
1435 if (visible_ids[i] != id) {
1436 var e = $("RROW-" + visible_ids[i]);
1438 if (e && e.hasClassName("Unread")) {
1439 ids_to_mark.push(visible_ids[i]);
1446 for (var i = visible_ids.length-1; i >= 0; i--) {
1447 if (visible_ids[i] != id) {
1448 var e = $("RROW-" + visible_ids[i]);
1450 if (e && e.hasClassName("Unread")) {
1451 ids_to_mark.push(visible_ids[i]);
1459 if (ids_to_mark.length == 0) {
1460 alert(__("No articles found to mark"));
1462 var msg = ngettext("Mark %d article as read?", "Mark %d articles as read?", ids_to_mark.length).replace("%d", ids_to_mark.length);
1464 if (getInitParam("confirm_feed_catchup") != 1 || confirm(msg)) {
1466 for (var i = 0; i < ids_to_mark.length; i++) {
1467 var e = $("RROW-" + ids_to_mark[i]);
1468 e.removeClassName("Unread");
1471 var query = "?op=rpc&method=catchupSelected" +
1472 "&cmode=0" + "&ids=" + param_escape(ids_to_mark.toString());
1474 new Ajax.Request("backend.php", {
1476 onComplete: function(transport) {
1477 handle_rpc_json(transport);
1484 exception_error("catchupRelativeToArticle", e);
1488 function cdmCollapseArticle(event, id, unmark) {
1490 if (unmark == undefined) unmark = true;
1492 var row = $("RROW-" + id);
1493 var elem = $("CICD-" + id);
1496 var collapse = $$("div#RROW-" + id +
1497 " span[class='collapseBtn']")[0];
1500 Element.show("CEXC-" + id);
1501 Element.hide(collapse);
1504 row.removeClassName("active");
1506 markHeadline(id, false);
1508 if (id == getActiveArticleId()) {
1509 setActiveArticleId(0);
1512 updateSelectedPrompt();
1515 if (event) Event.stop(event);
1517 PluginHost.run(PluginHost.HOOK_ARTICLE_COLLAPSED, id);
1519 if (row.offsetTop < $("headlines-frame").scrollTop)
1520 scrollToRowId(row.id);
1522 $("floatingTitle").style.visibility = "hidden";
1523 $("floatingTitle").setAttribute("rowid", false);
1527 exception_error("cdmCollapseArticle", e);
1531 function cdmExpandArticle(id, noexpand) {
1533 console.log("cdmExpandArticle " + id);
1535 if (!$("RROW-" + id)) return false;
1537 var oldrow = $("RROW-" + getActiveArticleId());
1539 var elem = $("CICD-" + getActiveArticleId());
1541 if (id == getActiveArticleId() && Element.visible(elem))
1544 selectArticles("none");
1546 var old_offset = $("RROW-" + id).offsetTop;
1548 if (getActiveArticleId() && elem && !getInitParam("cdm_expanded")) {
1549 var collapse = $$("div#RROW-" + getActiveArticleId() +
1550 " span[class='collapseBtn']")[0];
1553 Element.show("CEXC-" + getActiveArticleId());
1554 Element.hide(collapse);
1557 if (oldrow) oldrow.removeClassName("active");
1559 setActiveArticleId(id);
1561 elem = $("CICD-" + id);
1563 var collapse = $$("div#RROW-" + id +
1564 " span[class='collapseBtn']")[0];
1566 var cencw = $("CENCW-" + id);
1568 if (!Element.visible(elem) && !noexpand) {
1570 cencw.innerHTML = htmlspecialchars_decode(cencw.innerHTML);
1571 cencw.setAttribute('id', '');
1572 Element.show(cencw);
1576 Element.hide("CEXC-" + id);
1577 Element.show(collapse);
1580 var new_offset = $("RROW-" + id).offsetTop;
1582 if (old_offset > new_offset)
1583 $("headlines-frame").scrollTop -= (old_offset-new_offset);
1586 if (catchup_id_batch.indexOf(id) == -1)
1587 catchup_id_batch.push(id);
1589 catchupCurrentBatchIfNeeded();
1593 $("RROW-" + id).addClassName("active");
1595 PluginHost.run(PluginHost.HOOK_ARTICLE_EXPANDED, id);
1598 exception_error("cdmExpandArticle", e);
1604 function getArticleUnderPointer() {
1605 return post_under_pointer;
1608 function scrollArticle(offset) {
1611 var ci = $("content-insert");
1613 ci.scrollTop += offset;
1616 var hi = $("headlines-frame");
1618 hi.scrollTop += offset;
1623 exception_error("scrollArticle", e);
1627 function show_labels_in_headlines(transport) {
1629 var data = JSON.parse(transport.responseText);
1632 data['info-for-headlines'].each(function(elem) {
1633 $$(".HLLCTR-" + elem.id).each(function(ctr) {
1634 ctr.innerHTML = elem.labels;
1639 exception_error("show_labels_in_headlines", e);
1643 function dismissArticle(id) {
1645 var elem = $("RROW-" + id);
1649 toggleUnread(id, 0, true);
1651 new Effect.Fade(elem, {duration : 0.5});
1653 // Remove the content, too
1654 var elem_content = $("CICD-" + id);
1656 Element.remove(elem_content);
1659 if (id == getActiveArticleId()) {
1660 setActiveArticleId(0);
1664 exception_error("dismissArticle", e);
1668 function dismissSelectedArticles() {
1671 var ids = getVisibleArticleIds();
1675 for (var i = 0; i < ids.length; i++) {
1676 var elem = $("RROW-" + ids[i]);
1678 if (elem.className && elem.hasClassName("Selected") &&
1679 ids[i] != getActiveArticleId()) {
1680 new Effect.Fade(elem, {duration : 0.5});
1683 // Remove the content, too
1684 var elem_content = $("CICD-" + ids[i]);
1686 Element.remove(elem_content);
1694 selectionToggleUnread(false);
1698 exception_error("dismissSelectedArticles", e);
1702 function dismissReadArticles() {
1705 var ids = getVisibleArticleIds();
1708 for (var i = 0; i < ids.length; i++) {
1709 var elem = $("RROW-" + ids[i]);
1711 if (elem.className && !elem.hasClassName("Unread") &&
1712 !elem.hasClassName("Selected")) {
1714 new Effect.Fade(elem, {duration : 0.5});
1716 // Remove the content, too
1717 var elem_content = $("CICD-" + ids[i]);
1719 Element.remove(elem_content);
1727 exception_error("dismissReadArticles", e);
1731 // we don't really hide rows anymore
1732 function getVisibleArticleIds() {
1733 return getLoadedArticleIds();
1739 getLoadedArticleIds().each(function(id) {
1740 var elem = $("RROW-" + id);
1741 if (elem && Element.visible(elem))
1746 exception_error("getVisibleArticleIds", e);
1752 function cdmClicked(event, id) {
1754 //var shift_key = event.shiftKey;
1756 if (!event.ctrlKey) {
1758 if (!getInitParam("cdm_expanded")) {
1759 return cdmExpandArticle(id);
1762 var elem = $("RROW-" + getActiveArticleId());
1764 if (elem) elem.removeClassName("active");
1766 selectArticles("none");
1769 var elem = $("RROW-" + id);
1770 var article_is_unread = elem.hasClassName("Unread");
1772 elem.removeClassName("Unread");
1773 elem.addClassName("active");
1775 setActiveArticleId(id);
1777 if (article_is_unread) {
1778 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
1779 updateFloatingTitle(true);
1782 var query = "?op=rpc&method=catchupSelected" +
1783 "&cmode=0&ids=" + param_escape(id);
1785 new Ajax.Request("backend.php", {
1787 onComplete: function(transport) {
1788 handle_rpc_json(transport);
1791 return !event.shiftKey;
1794 } else if (event.target.parents(".cdmHeader").length > 0) {
1796 toggleSelected(id, true);
1798 var elem = $("RROW-" + id);
1799 var article_is_unread = elem.hasClassName("Unread");
1801 if (article_is_unread) {
1802 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
1805 toggleUnread(id, 0, false);
1807 openArticleInNewWindow(id);
1810 var unread_in_buffer = $$("#headlines-frame > div[id*=RROW][class*=Unread]").length
1811 request_counters(unread_in_buffer == 0);
1814 exception_error("cdmClicked");
1820 function hlClicked(event, id) {
1822 if (event.which == 2) {
1825 } else if (event.ctrlKey) {
1826 toggleSelected(id, true);
1827 toggleUnread(id, 0, false);
1828 openArticleInNewWindow(id);
1836 exception_error("hlClicked");
1840 function getFirstVisibleHeadlineId() {
1841 var rows = getVisibleArticleIds();
1846 function getLastVisibleHeadlineId() {
1847 var rows = getVisibleArticleIds();
1848 return rows[rows.length-1];
1851 function openArticleInNewWindow(id) {
1852 toggleUnread(id, 0, false);
1853 window.open("backend.php?op=article&method=redirect&id=" + id);
1856 function isCdmMode() {
1857 return getInitParam("combined_display_mode");
1860 function markHeadline(id, marked) {
1861 if (marked == undefined) marked = true;
1863 var row = $("RROW-" + id);
1865 var check = dijit.getEnclosingWidget(
1866 row.getElementsByClassName("rchk")[0]);
1869 check.attr("checked", marked);
1873 row.addClassName("Selected");
1875 row.removeClassName("Selected");
1879 function getRelativePostIds(id, limit) {
1885 if (!limit) limit = 6; //3
1887 var ids = getVisibleArticleIds();
1889 for (var i = 0; i < ids.length; i++) {
1891 for (var k = 1; k <= limit; k++) {
1892 //if (i > k-1) tmp.push(ids[i-k]);
1893 if (i < ids.length-k) tmp.push(ids[i+k]);
1900 exception_error("getRelativePostIds", e);
1906 function correctHeadlinesOffset(id) {
1910 var container = $("headlines-frame");
1911 var row = $("RROW-" + id);
1913 if (!container || !row) return;
1915 var viewport = container.offsetHeight;
1917 var rel_offset_top = row.offsetTop - container.scrollTop;
1918 var rel_offset_bottom = row.offsetTop + row.offsetHeight - container.scrollTop;
1920 //console.log("Rtop: " + rel_offset_top + " Rbtm: " + rel_offset_bottom);
1921 //console.log("Vport: " + viewport);
1923 if (rel_offset_top <= 0 || rel_offset_top > viewport) {
1924 container.scrollTop = row.offsetTop;
1925 } else if (rel_offset_bottom > viewport) {
1927 /* doesn't properly work with Opera in some cases because
1928 Opera fucks up element scrolling */
1930 container.scrollTop = row.offsetTop + row.offsetHeight - viewport;
1934 exception_error("correctHeadlinesOffset", e);
1939 function headlineActionsChange(elem) {
1942 elem.attr('value', 'false');
1944 exception_error("headlineActionsChange", e);
1948 function closeArticlePanel() {
1950 if (dijit.byId("content-insert"))
1951 dijit.byId("headlines-wrap-inner").removeChild(
1952 dijit.byId("content-insert"));
1955 function initFloatingMenu() {
1957 if (dijit.byId("floatingMenu"))
1958 dijit.byId("floatingMenu").destroyRecursive();
1960 var menu = new dijit.Menu({
1962 targetNodeIds: ["floatingTitle"]
1965 var id = $("floatingTitle").getAttribute("rowid").replace("RROW-", "");
1967 headlinesMenuCommon(menu, id);
1971 exception_error("initFloatingMenu", e);
1975 function headlinesMenuCommon(menu, base_id) {
1978 menu.addChild(new dijit.MenuItem({
1979 label: __("Open original article"),
1980 onClick: function(event) {
1981 openArticleInNewWindow(base_id ? base_id : this.getParent().callerRowId);
1984 menu.addChild(new dijit.MenuItem({
1985 label: __("Display article URL"),
1986 onClick: function(event) {
1987 displayArticleUrl(base_id ? base_id : this.getParent().callerRowId);
1990 menu.addChild(new dijit.MenuSeparator());
1992 menu.addChild(new dijit.MenuItem({
1993 label: __("Toggle unread"),
1994 onClick: function(event) {
1995 var ids = getSelectedArticleIds2();
1997 var id = (base_id ? base_id : this.getParent().callerRowId) + "";
1998 ids = ids.size() != 0 && ids.indexOf(id) != -1 ? ids : [id];
2000 selectionToggleUnread(undefined, false, true, ids);
2003 menu.addChild(new dijit.MenuItem({
2004 label: __("Toggle starred"),
2005 onClick: function(event) {
2006 var ids = getSelectedArticleIds2();
2008 var id = (base_id ? base_id : this.getParent().callerRowId) + "";
2009 ids = ids.size() != 0 && ids.indexOf(id) != -1 ? ids : [id];
2011 selectionToggleMarked(undefined, false, true, ids);
2014 menu.addChild(new dijit.MenuItem({
2015 label: __("Toggle published"),
2016 onClick: function(event) {
2017 var ids = getSelectedArticleIds2();
2019 var id = (base_id ? base_id : this.getParent().callerRowId) + "";
2020 ids = ids.size() != 0 && ids.indexOf(id) != -1 ? ids : [id];
2022 selectionTogglePublished(undefined, false, true, ids);
2025 menu.addChild(new dijit.MenuSeparator());
2027 menu.addChild(new dijit.MenuItem({
2028 label: __("Mark above as read"),
2029 onClick: function(event) {
2030 catchupRelativeToArticle(0, base_id ? base_id : this.getParent().callerRowId);
2033 menu.addChild(new dijit.MenuItem({
2034 label: __("Mark below as read"),
2035 onClick: function(event) {
2036 catchupRelativeToArticle(1, base_id ? base_id : this.getParent().callerRowId);
2040 var labels = dijit.byId("feedTree").model.getItemsInCategory(-2);
2044 menu.addChild(new dijit.MenuSeparator());
2046 var labelAddMenu = new dijit.Menu({ownerMenu: menu});
2047 var labelDelMenu = new dijit.Menu({ownerMenu: menu});
2049 labels.each(function(label) {
2050 var id = label.id[0];
2051 var bare_id = id.substr(id.indexOf(":")+1);
2052 var name = label.name[0];
2054 bare_id = feed_to_label_id(bare_id);
2056 labelAddMenu.addChild(new dijit.MenuItem({
2059 onClick: function(event) {
2060 var ids = getSelectedArticleIds2();
2062 var id = (base_id ? base_id : this.getParent().ownerMenu.callerRowId) + "";
2064 ids = ids.size() != 0 && ids.indexOf(id) != -1 ? ids : [id];
2066 selectionAssignLabel(this.labelId, ids);
2069 labelDelMenu.addChild(new dijit.MenuItem({
2072 onClick: function(event) {
2073 var ids = getSelectedArticleIds2();
2075 var id = (base_id ? base_id : this.getParent().ownerMenu.callerRowId) + "";
2077 ids = ids.size() != 0 && ids.indexOf(id) != -1 ? ids : [id];
2079 selectionRemoveLabel(this.labelId, ids);
2084 menu.addChild(new dijit.PopupMenuItem({
2085 label: __("Assign label"),
2089 menu.addChild(new dijit.PopupMenuItem({
2090 label: __("Remove label"),
2098 exception_error("headlinesMenuCommon", e);
2102 function initHeadlinesMenu() {
2104 if (dijit.byId("headlinesMenu"))
2105 dijit.byId("headlinesMenu").destroyRecursive();
2110 nodes = $$("#headlines-frame > div[id*=RROW]");
2112 nodes = $$("#headlines-frame span[id*=RTITLE]");
2115 nodes.each(function(node) {
2119 var menu = new dijit.Menu({
2120 id: "headlinesMenu",
2124 var tmph = dojo.connect(menu, '_openMyself', function (event) {
2125 var callerNode = event.target, match = null, tries = 0;
2127 while (match == null && callerNode && tries <= 3) {
2128 match = callerNode.id.match("^[A-Z]+[-]([0-9]+)$");
2129 callerNode = callerNode.parentNode;
2133 if (match) this.callerRowId = parseInt(match[1]);
2137 headlinesMenuCommon(menu, false);
2141 /* vgroup feed title menu */
2143 var nodes = $$("#headlines-frame > div[class='cdmFeedTitle']");
2146 nodes.each(function(node) {
2150 if (ids.length > 0) {
2151 if (dijit.byId("headlinesFeedTitleMenu"))
2152 dijit.byId("headlinesFeedTitleMenu").destroyRecursive();
2154 var menu = new dijit.Menu({
2155 id: "headlinesFeedTitleMenu",
2159 var tmph = dojo.connect(menu, '_openMyself', function (event) {
2160 var callerNode = event.target, match = null, tries = 0;
2162 while (match == null && callerNode && tries <= 3) {
2163 console.log(callerNode.id);
2165 match = callerNode.id.match("^[A-Z]+[-]([0-9]+)$");
2166 callerNode = callerNode.parentNode;
2169 console.log(match[1]);
2172 if (match) this.callerRowId = parseInt(match[1]);
2176 menu.addChild(new dijit.MenuItem({
2177 label: __("Select articles in group"),
2178 onClick: function(event) {
2179 selectArticles("all",
2180 "#headlines-frame > div[id*=RROW]"+
2181 "[orig-feed-id='"+menu.callerRowId+"']");
2185 menu.addChild(new dijit.MenuItem({
2186 label: __("Mark group as read"),
2187 onClick: function(event) {
2188 selectArticles("none");
2189 selectArticles("all",
2190 "#headlines-frame > div[id*=RROW]"+
2191 "[orig-feed-id='"+menu.callerRowId+"']");
2197 menu.addChild(new dijit.MenuItem({
2198 label: __("Mark feed as read"),
2199 onClick: function(event) {
2200 catchupFeedInGroup(menu.callerRowId);
2203 menu.addChild(new dijit.MenuItem({
2204 label: __("Edit feed"),
2205 onClick: function(event) {
2206 editFeed(menu.callerRowId);
2214 exception_error("initHeadlinesMenu", e);
2218 function cache_set(id, obj) {
2219 //console.log("cache_set: " + id);
2222 sessionStorage[id] = obj;
2224 sessionStorage.clear();
2228 function cache_get(id) {
2230 return sessionStorage[id];
2233 function cache_clear() {
2235 sessionStorage.clear();
2238 function cache_delete(id) {
2240 sessionStorage.removeItem(id);
2243 function cancelSearch() {
2248 exception_error("cancelSearch", e);
2252 function setSelectionScore() {
2254 var ids = getSelectedArticleIds2();
2256 if (ids.length > 0) {
2259 var score = prompt(__("Please enter new score for selected articles:"), score);
2261 if (score != undefined) {
2262 var query = "op=article&method=setScore&id=" + param_escape(ids.toString()) +
2263 "&score=" + param_escape(score);
2265 new Ajax.Request("backend.php", {
2267 onComplete: function(transport) {
2268 var reply = JSON.parse(transport.responseText);
2272 ids.each(function(id) {
2273 var row = $("RROW-" + id);
2276 var pic = row.getElementsByClassName("hlScorePic")[0];
2279 pic.src = pic.src.replace(/score_.*?\.png/,
2280 reply["score_pic"]);
2281 pic.setAttribute("score", score);
2290 alert(__("No articles are selected."));
2293 exception_error("setSelectionScore", e);
2297 function updateScore(id) {
2299 var pic = $$("#RROW-" + id + " .hlScorePic")[0];
2303 var query = "op=article&method=getScore&id=" + param_escape(id);
2305 new Ajax.Request("backend.php", {
2307 onComplete: function(transport) {
2308 console.log(transport.responseText);
2310 var reply = JSON.parse(transport.responseText);
2313 pic.src = pic.src.replace(/score_.*?\.png/, reply["score_pic"]);
2314 pic.setAttribute("score", reply["score"]);
2315 pic.setAttribute("title", reply["score"]);
2321 exception_error("updateScore", e);
2325 function changeScore(id, pic) {
2327 var score = pic.getAttribute("score");
2329 var new_score = prompt(__("Please enter new score for this article:"), score);
2331 if (new_score != undefined) {
2333 var query = "op=article&method=setScore&id=" + param_escape(id) +
2334 "&score=" + param_escape(new_score);
2336 new Ajax.Request("backend.php", {
2338 onComplete: function(transport) {
2339 var reply = JSON.parse(transport.responseText);
2342 pic.src = pic.src.replace(/score_.*?\.png/, reply["score_pic"]);
2343 pic.setAttribute("score", new_score);
2344 pic.setAttribute("title", new_score);
2349 exception_error("changeScore", e);
2353 function displayArticleUrl(id) {
2355 var query = "op=rpc&method=getlinktitlebyid&id=" + param_escape(id);
2357 new Ajax.Request("backend.php", {
2359 onComplete: function(transport) {
2360 var reply = JSON.parse(transport.responseText);
2362 if (reply && reply.link) {
2363 prompt(__("Article URL:"), reply.link);
2367 exception_error("changeScore", e);
2371 function scrollToRowId(id) {
2376 $("headlines-frame").scrollTop = row.offsetTop - 4;
2379 exception_error("scrollToRowId", e);
2383 function updateFloatingTitle(unread_only) {
2385 if (!isCdmMode()) return;
2387 var hf = $("headlines-frame");
2389 var elems = $$("#headlines-frame > div[id*=RROW]");
2391 for (var i = 0; i < elems.length; i++) {
2393 var child = elems[i];
2395 if (child && child.offsetTop + child.offsetHeight > hf.scrollTop) {
2397 var header = child.getElementsByClassName("cdmHeader")[0];
2399 if (unread_only || child.id != $("floatingTitle").getAttribute("rowid")) {
2400 if (child.id != $("floatingTitle").getAttribute("rowid")) {
2401 $("floatingTitle").setAttribute("rowid", child.id);
2402 $("floatingTitle").innerHTML = header.innerHTML;
2403 $("floatingTitle").firstChild.innerHTML = "<img class='anchor markedPic' src='images/page_white_go.png' onclick=\"scrollToRowId('"+child.id+"')\">" + $("floatingTitle").firstChild.innerHTML;
2407 var cb = $$("#floatingTitle .dijitCheckBox")[0];
2410 cb.parentNode.removeChild(cb);
2413 if (child.hasClassName("Unread"))
2414 $("floatingTitle").addClassName("Unread");
2416 $("floatingTitle").removeClassName("Unread");
2418 PluginHost.run(PluginHost.HOOK_FLOATING_TITLE, child);
2421 $("floatingTitle").style.marginRight = hf.offsetWidth - child.offsetWidth + "px";
2422 if (header.offsetTop + header.offsetHeight < hf.scrollTop + $("floatingTitle").offsetHeight - 5 &&
2423 child.offsetTop + child.offsetHeight >= hf.scrollTop + $("floatingTitle").offsetHeight - 5)
2424 $("floatingTitle").style.visibility = "visible";
2426 $("floatingTitle").style.visibility = "hidden";
2434 exception_error("updateFloatingTitle", e);
2438 function catchupCurrentBatchIfNeeded() {
2439 if (catchup_id_batch.length > 0) {
2440 window.clearTimeout(catchup_timeout_id);
2441 catchup_timeout_id = window.setTimeout('catchupBatchedArticles()', 1000);
2443 if (catchup_id_batch.length >= 10) {
2444 catchupBatchedArticles();
2449 function cdmFooterClick(event) {
2450 event.stopPropagation();