X-Git-Url: https://git.wh0rd.org/?a=blobdiff_plain;f=js%2Fviewfeed.js;h=95e55050d9ce4b2441eba0036e2f6caa26267e7b;hb=e2b8c9273e09091c235959c25d8e4d8122aa6ca8;hp=6ae9cdd8a503fe42cd51c65775de293d81e41d2c;hpb=0c06bb5fe1278b7d92926b21b000e9c966e19ee6;p=tt-rss.git diff --git a/js/viewfeed.js b/js/viewfeed.js index 6ae9cdd8..95e55050 100755 --- a/js/viewfeed.js +++ b/js/viewfeed.js @@ -8,9 +8,9 @@ let post_under_pointer = false; let last_requested_article = 0; let catchup_id_batch = []; -let catchup_timeout_id = false; +//let catchup_timeout_id = false; -let cids_requested = []; +//let cids_requested = []; let loaded_article_ids = []; let _last_headlines_update = 0; let _headlines_scroll_offset = 0; @@ -29,8 +29,8 @@ function headlines_callback2(transport, offset, background, infscroll_req) { if (background) return; - var is_cat = false; - var feed_id = false; + let is_cat = false; + let feed_id = false; if (reply) { @@ -86,7 +86,7 @@ function headlines_callback2(transport, offset, background, infscroll_req) { while (tmp.hasChildNodes()) { var row = tmp.removeChild(tmp.firstChild); - if (loaded_article_ids.indexOf(row.id) == -1 || row.hasClassName("cdmFeedTitle")) { + if (loaded_article_ids.indexOf(row.id) == -1 || row.hasClassName("feed-title")) { dijit.byId("headlines-frame").domNode.appendChild(row); loaded_article_ids.push(row.id); @@ -110,83 +110,69 @@ function headlines_callback2(transport, offset, background, infscroll_req) { } } else if (headlines_count > 0 && feed_id == getActiveFeedId() && is_cat == activeFeedIsCat()) { - console.log("adding some more headlines: " + headlines_count); + console.log("adding some more headlines: " + headlines_count); - const c = dijit.byId("headlines-frame"); - const ids = getSelectedArticleIds2(); + const c = dijit.byId("headlines-frame"); + //const ids = getSelectedArticleIds2(); - let hsp = $("headlines-spacer"); + let hsp = $("headlines-spacer"); - if (hsp) - c.domNode.removeChild(hsp); + if (hsp) + c.domNode.removeChild(hsp); - let tmp = document.createElement("div"); - tmp.innerHTML = reply['headlines']['content']; - dojo.parser.parse(tmp); + let tmp = document.createElement("div"); + tmp.innerHTML = reply['headlines']['content']; + dojo.parser.parse(tmp); - while (tmp.hasChildNodes()) { - let row = tmp.removeChild(tmp.firstChild); + while (tmp.hasChildNodes()) { + let row = tmp.removeChild(tmp.firstChild); - if (loaded_article_ids.indexOf(row.id) == -1 || row.hasClassName("cdmFeedTitle")) { - dijit.byId("headlines-frame").domNode.appendChild(row); + if (loaded_article_ids.indexOf(row.id) == -1 || row.hasClassName("feed-title")) { + dijit.byId("headlines-frame").domNode.appendChild(row); - loaded_article_ids.push(row.id); - } + loaded_article_ids.push(row.id); } + } - if (!hsp) hsp = new Element("DIV", {"id": "headlines-spacer"}); - c.domNode.appendChild(hsp); - - if (headlines_count < 30) _infscroll_disable = true; + if (!hsp) hsp = new Element("DIV", {"id": "headlines-spacer"}); + c.domNode.appendChild(hsp); - console.log("restore selected ids: " + ids); + if (headlines_count < 30) _infscroll_disable = true; - for (let i = 0; i < ids.length; i++) { - markHeadline(ids[i]); - } + /* console.log("restore selected ids: " + ids); - initHeadlinesMenu(); + for (let i = 0; i < ids.length; i++) { + markHeadline(ids[i]); + } */ - if (_infscroll_disable) { - hsp.innerHTML = "" + - __("Click to open next unread feed.") + ""; - } + initHeadlinesMenu(); - } else { - console.log("no new headlines received"); + if (_infscroll_disable) { + hsp.innerHTML = "" + + __("Click to open next unread feed.") + ""; + } - const first_id_changed = reply['headlines']['first_id_changed']; - console.log("first id changed:" + first_id_changed); + } else { + console.log("no new headlines received"); - let hsp = $("headlines-spacer"); + const first_id_changed = reply['headlines']['first_id_changed']; + console.log("first id changed:" + first_id_changed); - if (hsp) { - if (first_id_changed) { - hsp.innerHTML = "" + - __("New articles found, reload feed to continue.") + ""; - } else { - hsp.innerHTML = "" + - __("Click to open next unread feed.") + ""; - } + let hsp = $("headlines-spacer"); + if (hsp) { + if (first_id_changed) { + hsp.innerHTML = "" + + __("New articles found, reload feed to continue.") + ""; + } else { + hsp.innerHTML = "" + + __("Click to open next unread feed.") + ""; } } - if (articles) { - for (let i = 0; i < articles.length; i++) { - const a_id = articles[i]['id']; - cache_set("article:" + a_id, articles[i]['content']); - } - } else { - console.log("no cached articles received"); } - if (counters) - parse_counters(counters); - else - request_counters(); - } else { console.error("Invalid object received: " + transport.responseText); dijit.byId("headlines-frame").attr('content', "
" + @@ -234,6 +220,7 @@ function render_article(article) { } catch (e) { } } +/* function showArticleInHeadlines(id, noexpand) { const row = $("RROW-" + id); if (!row) return; @@ -276,9 +263,67 @@ function article_callback2(transport, id) { notify(""); } +*/ +function view(id, noexpand) { + setActiveArticleId(id); + + if (!noexpand) { + console.log("loading article", id); + + const neighbor_ids = getRelativePostIds(id); + const cids = []; + + /* only request uncached articles */ + + neighbor_ids.each((n) => { + if (!cache_get("article:" + n)) + cids.push(n); + }); + + const cached_article = cache_get("article:" + id); + + if (cached_article) { + console.log('rendering cached', id); + render_article(cached_article); + return false; + } + + xhrPost("backend.php", {op: "article", method: "view", id: id, cids: cids.toString()}, (transport) => { + try { + const reply = handle_rpc_json(transport); + + if (reply) { + + reply.each(function(article) { + if (getActiveArticleId() == article['id']) { + render_article(article['content']); + } + //cids_requested.remove(article['id']); + + cache_set("article:" + article['id'], article['content']); + }); + + } else { + console.error("Invalid object received: " + transport.responseText); + + render_article("
" + + __('Could not display article (invalid object received - see error console for details)') + "
"); + } + + //const unread_in_buffer = $$("#headlines-frame > div[id*=RROW][class*=Unread]").length; + //request_counters(unread_in_buffer == 0); -function view(id, activefeed, noexpand) { - const oldrow = $("RROW-" + getActiveArticleId()); + notify(""); + + } catch (e) { + exception_error(e); + } + }) + } + + return false; + +/* const oldrow = $("RROW-" + getActiveArticleId()); if (oldrow) oldrow.removeClassName("active"); const crow = $("RROW-" + id); @@ -302,7 +347,7 @@ function view(id, activefeed, noexpand) { /* only request uncached articles */ - const cids_to_request = []; +/* const cids_to_request = []; for (let i = 0; i < neighbor_ids.length; i++) { if (cids_requested.indexOf(neighbor_ids[i]) == -1) @@ -325,7 +370,7 @@ function view(id, activefeed, noexpand) { query.mode = "prefetch"; render_article(cached_article); } else if (cached_article) { - query.mode = "prefetch_old"; + query.mode = "prefetch_old"; render_article(cached_article); // if we don't need to request any relative ids, we might as well skip @@ -344,11 +389,11 @@ function view(id, activefeed, noexpand) { } xhrPost("backend.php", query, (transport) => { - article_callback2(transport, id); + article_callback2(transport, id); }) return false; - +*/ } function toggleMark(id, client_only) { @@ -394,7 +439,7 @@ function toggleMark(id, client_only) { } function togglePub(id, client_only, no_effects, note) { - const query = { op: "rpc", id: id, method: "publ" }; + const query = { op: "rpc", id: id, method: "publ" }; if (note != undefined) { query.note = note; @@ -481,8 +526,8 @@ function moveToPost(mode, noscroll, noexpand) { if (next_id || getActiveArticleId()) { if (isCdmMode()) { - var article = $("RROW-" + getActiveArticleId()); - var ctr = $("headlines-frame"); + const article = $("RROW-" + getActiveArticleId()); + const ctr = $("headlines-frame"); if (!noscroll && article && article.offsetTop + article.offsetHeight > ctr.scrollTop + ctr.offsetHeight) { @@ -491,11 +536,12 @@ function moveToPost(mode, noscroll, noexpand) { } else if (next_id) { cdmScrollToArticleId(next_id, true); + setActiveArticleId(next_id); } } else if (next_id) { correctHeadlinesOffset(next_id); - view(next_id, getActiveFeedId(), noexpand); + view(next_id, noexpand); } } } @@ -504,9 +550,9 @@ function moveToPost(mode, noscroll, noexpand) { if (prev_id || getActiveArticleId()) { if (isCdmMode()) { - var article = $("RROW-" + getActiveArticleId()); + const article = $("RROW-" + getActiveArticleId()); const prev_article = $("RROW-" + prev_id); - var ctr = $("headlines-frame"); + const ctr = $("headlines-frame"); if (!noscroll && article && article.offsetTop < ctr.scrollTop) { scrollArticle(-ctr.offsetHeight/3); @@ -515,18 +561,19 @@ function moveToPost(mode, noscroll, noexpand) { scrollArticle(-ctr.offsetHeight/4); } else if (prev_id) { cdmScrollToArticleId(prev_id, noscroll); + setActiveArticleId(prev_id); } } else if (prev_id) { correctHeadlinesOffset(prev_id); - view(prev_id, getActiveFeedId(), noexpand); + view(prev_id, noexpand); } } } } -function toggleSelected(id, force_on) { +/* function toggleSelected(id, force_on) { const row = $("RROW-" + id); if (row) { @@ -543,7 +590,7 @@ function toggleSelected(id, force_on) { } updateSelectedPrompt(); -} +} */ function updateSelectedPrompt() { const count = getSelectedArticleIds2().length; @@ -563,6 +610,7 @@ function updateSelectedPrompt() { function toggleUnread(id, cmode) { const row = $("RROW-" + id); + if (row) { const tmpClassName = row.className; @@ -575,22 +623,19 @@ function toggleUnread(id, cmode) { } } else if (cmode == 0) { - row.removeClassName("Unread"); - } else if (cmode == 1) { row.addClassName("Unread"); } if (tmpClassName != row.className) { - if (cmode == undefined) cmode = 2; - - const query = {op: "rpc", method: "catchupSelected", - cmode: cmode, ids: id}; + if (cmode == undefined) cmode = 2; - xhrPost("backend.php", query, (transport) => { - handle_rpc_json(transport); + const query = {op: "rpc", method: "catchupSelected", + cmode: cmode, ids: id}; + xhrPost("backend.php", query, (transport) => { + handle_rpc_json(transport); }); } } @@ -608,8 +653,8 @@ function selectionRemoveLabel(id, ids) { ids: ids.toString(), lid: id }; xhrPost("backend.php", query, (transport) => { - handle_rpc_json(transport); - show_labels_in_headlines(transport); + handle_rpc_json(transport); + show_labels_in_headlines(transport); }); } @@ -624,10 +669,10 @@ function selectionAssignLabel(id, ids) { const query = { op: "article", method: "assignToLabel", ids: ids.toString(), lid: id }; - xhrPost("backend.php", query, (transport) => { - handle_rpc_json(transport); - show_labels_in_headlines(transport); - }); + xhrPost("backend.php", query, (transport) => { + handle_rpc_json(transport); + show_labels_in_headlines(transport); + }); } function selectionToggleUnread(set_state, callback, no_error, ids) { @@ -678,10 +723,10 @@ function selectionToggleUnread(set_state, callback, no_error, ids) { notify_progress("Loading, please wait..."); - xhrPost("backend.php", query, (transport) => { - handle_rpc_json(transport); - if (callback) callback(transport); - }); + xhrPost("backend.php", query, (transport) => { + handle_rpc_json(transport); + if (callback) callback(transport); + }); } } @@ -703,10 +748,10 @@ function selectionToggleMarked(sel_state, callback, no_error, ids) { const query = { op: "rpc", method: "markSelected", ids: rows.toString(), cmode: 2 }; - xhrPost("backend.php", query, (transport) => { - handle_rpc_json(transport); - if (callback) callback(transport); - }); + xhrPost("backend.php", query, (transport) => { + handle_rpc_json(transport); + if (callback) callback(transport); + }); } } @@ -724,13 +769,13 @@ function selectionTogglePublished(sel_state, callback, no_error, ids) { } if (rows.length > 0) { - const query = { op: "rpc", method: "publishSelected", - ids: rows.toString(), cmode: 2 }; + const query = { op: "rpc", method: "publishSelected", + ids: rows.toString(), cmode: 2 }; - xhrPost("backend.php", query, (transport) => { - handle_rpc_json(transport); - if (callback) callback(transport); - }); + xhrPost("backend.php", query, (transport) => { + handle_rpc_json(transport); + if (callback) callback(transport); + }); } } @@ -743,6 +788,11 @@ function getSelectedArticleIds2() { rv.push(child.getAttribute("data-article-id")); }); + // i wonder if this is a good idea: consider active article a honorary member + // of selected articles + if (getActiveArticleId()) + rv.push(getActiveArticleId()); + return rv; } @@ -762,7 +812,62 @@ function getLoadedArticleIds() { } // mode = all,none,unread,invert,marked,published -function selectArticles(mode, query) { +function selectArticles(mode) { + let query = "#headlines-frame > div[id*=RROW]"; + + switch (mode) { + case "none": + case "all": + case "invert": + break; + case "marked": + query += "[class*=marked]"; + break; + case "published": + query += "[class*=published]"; + break; + case "unread": + query += "[class*=Unread]"; + break; + default: + console.warn("selectArticles: unknown mode", mode); + } + + const rows = $$(query); + + for (let i = 0; i < rows.length; i++) { + const row = rows[i]; + const cb = dijit.getEnclosingWidget(row.select(".rchk")[0]); + + switch (mode) { + case "none": + row.removeClassName("Selected"); + + if (!row.hasClassName("active")) + cb.attr("checked", false); + break; + case "invert": + if (row.hasClassName("Selected")) { + row.removeClassName("Selected"); + + if (!row.hasClassName("active")) + cb.attr("checked", false); + } else { + row.addClassName("Selected"); + cb.attr("checked", true); + } + break; + default: + row.addClassName("Selected"); + cb.attr("checked", true); + } + + updateSelectedPrompt(); + } +} + +// mode = all,none,unread,invert,marked,published +/* function selectArticles(mode, query) { if (!query) query = "#headlines-frame > div[id*=RROW]"; const children = $$(query); @@ -817,7 +922,7 @@ function selectArticles(mode, query) { }); updateSelectedPrompt(); -} +} */ function deleteSelection() { @@ -847,52 +952,52 @@ function deleteSelection() { const query = { op: "rpc", method: "delete", ids: rows.toString() }; xhrPost("backend.php", query, (transport) => { - handle_rpc_json(transport); - viewCurrentFeed(); + handle_rpc_json(transport); + viewCurrentFeed(); }); } function archiveSelection() { - const rows = getSelectedArticleIds2(); + const rows = getSelectedArticleIds2(); - if (rows.length == 0) { - alert(__("No articles are selected.")); - return; - } + if (rows.length == 0) { + alert(__("No articles are selected.")); + return; + } - const fn = getFeedName(getActiveFeedId(), activeFeedIsCat()); - let str; - let op; + const fn = getFeedName(getActiveFeedId(), activeFeedIsCat()); + let str; + let op; - if (getActiveFeedId() != 0) { - str = ngettext("Archive %d selected article in %s?", "Archive %d selected articles in %s?", rows.length); - op = "archive"; - } else { - str = ngettext("Move %d archived article back?", "Move %d archived articles back?", rows.length); + if (getActiveFeedId() != 0) { + str = ngettext("Archive %d selected article in %s?", "Archive %d selected articles in %s?", rows.length); + op = "archive"; + } else { + str = ngettext("Move %d archived article back?", "Move %d archived articles back?", rows.length); - str += " " + __("Please note that unstarred articles might get purged on next feed update."); + str += " " + __("Please note that unstarred articles might get purged on next feed update."); - op = "unarchive"; - } + op = "unarchive"; + } - str = str.replace("%d", rows.length); - str = str.replace("%s", fn); + str = str.replace("%d", rows.length); + str = str.replace("%s", fn); - if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) { - return; - } + if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) { + return; + } - for (let i = 0; i < rows.length; i++) { - cache_delete("article:" + rows[i]); - } + for (let i = 0; i < rows.length; i++) { + cache_delete("article:" + rows[i]); + } - const query = {op: "rpc", method: op, ids: rows.toString()}; + const query = {op: "rpc", method: op, ids: rows.toString()}; - xhrPost("backend.php", query, (transport) => { - handle_rpc_json(transport); - viewCurrentFeed(); - }); + xhrPost("backend.php", query, (transport) => { + handle_rpc_json(transport); + viewCurrentFeed(); + }); } function catchupSelection() { @@ -935,24 +1040,24 @@ function editArticleTags(id) { notify_progress("Saving article tags...", true); xhrPost("backend.php", this.attr('value'), (transport) => { - try { - notify(''); - dialog.hide(); + try { + notify(''); + dialog.hide(); - const data = JSON.parse(transport.responseText); + const data = JSON.parse(transport.responseText); - if (data) { - const id = data.id; + if (data) { + const id = data.id; - const tags = $("ATSTR-" + id); - const tooltip = dijit.byId("ATSTRTIP-" + id); + const tags = $("ATSTR-" + id); + const tooltip = dijit.byId("ATSTRTIP-" + id); - if (tags) tags.innerHTML = data.content; - if (tooltip) tooltip.attr('label', data.content_full); - } - } catch (e) { - exception_error(e); - } + if (tags) tags.innerHTML = data.content; + if (tooltip) tooltip.attr('label', data.content_full); + } + } catch (e) { + exception_error(e); + } }); } }, @@ -982,14 +1087,49 @@ function cdmScrollToArticleId(id, force) { // expanded cdm has a 4px margin now ctr.scrollTop = parseInt(e.offsetTop) - 4; + + /*setActiveArticleId(id); + + // article is selected manually, set it read + toggleUnread(id, 0); */ } } +// for the time being active article does not affect buffer selection (we still re/set the checkbox +// because of getSelectedArticleIds2() hack function setActiveArticleId(id) { - console.log("setActiveArticleId:" + id); + console.log("setActiveArticleId", id); + + $$("div[id*=RROW][class*=active]").each((e) => { + e.removeClassName("active"); + + if (!e.hasClassName("Selected")) { + const cb = dijit.getEnclosingWidget(e.select(".rchk")[0]); + if (cb) cb.attr("checked", false); + } + }) _active_article_id = id; - PluginHost.run(PluginHost.HOOK_ARTICLE_SET_ACTIVE, _active_article_id); + + const row = $("RROW-" + id); + + if (row) { + if (row.hasClassName("Unread")) { + toggleUnread(id, 0); + + decrementFeedCounter(getActiveFeedId(), activeFeedIsCat()); + updateFloatingTitle(true); + } + + row.addClassName("active"); + + if (!row.hasClassName("Selected")) { + const cb = dijit.getEnclosingWidget(row.select(".rchk")[0]); + if (cb) cb.attr("checked", true); + } + + PluginHost.run(PluginHost.HOOK_ARTICLE_SET_ACTIVE, _active_article_id); + } } function getActiveArticleId() { @@ -1007,24 +1147,28 @@ function postMouseOut(id) { function unpackVisibleHeadlines() { if (!isCdmMode()) return; - const rows = $$("#headlines-frame div[id*=RROW][data-content]"); + const rows = $$("#headlines-frame div[id*=RROW][data-content]"); + const threshold = $("headlines-frame").scrollTop + $("headlines-frame").offsetHeight + 300; + + for (let i = 0; i < rows.length; i++) { + const row = rows[i]; - for (let i = 0; i < rows.length; i++) { - const row = rows[i]; + if (row.offsetTop <= threshold) { + console.log("unpacking: " + row.id); - if (row.offsetTop <= $("headlines-frame").scrollTop + $("headlines-frame").offsetHeight) { - console.log("unpacking: " + row.id); + row.select(".content-inner")[0].innerHTML = row.getAttribute("data-content"); + row.removeAttribute("data-content"); - const content = row.getAttribute("data-content"); + PluginHost.run(PluginHost.HOOK_ARTICLE_RENDERED_CDM, row); - row.select(".cdmContentInner")[0].innerHTML = content; - row.removeAttribute("data-content"); + // i wonder if this is a good idea? + if (!getActiveArticleId() && !row.hasClassName("Unread")) + setActiveArticleId(row.getAttribute("data-article-id")); - PluginHost.run(PluginHost.HOOK_ARTICLE_RENDERED_CDM, row); - } else { - break; - } - } + } else { + break; + } + } } function headlines_scroll_handler(e) { @@ -1040,8 +1184,7 @@ function headlines_scroll_handler(e) { unpackVisibleHeadlines(); // set topmost child in the buffer as active - if (isCdmMode() && getInitParam("cdm_auto_catchup") == 1 && - getSelectedArticleIds2().length <= 1) { + if (isCdmMode() && getInitParam("cdm_auto_catchup") == 1) { const rows = $$("#headlines-frame > div[id*=RROW]"); @@ -1050,23 +1193,26 @@ function headlines_scroll_handler(e) { if ($("headlines-frame").scrollTop <= row.offsetTop && row.offsetTop - $("headlines-frame").scrollTop < 100 && - row.getAttribute("data-article-id") != _active_article_id) { + row.getAttribute("data-article-id") != getActiveArticleId()) { - if (_active_article_id) { + /* if (_active_article_id) { const row = $("RROW-" + _active_article_id); if (row) row.removeClassName("active"); } _active_article_id = row.getAttribute("data-article-id"); showArticleInHeadlines(_active_article_id, true); - updateSelectedPrompt(); + updateSelectedPrompt(); */ + + setActiveArticleId(row.getAttribute("data-article-id")); + break; } } } if (!_infscroll_disable) { - const hsp = $("headlines-spacer"); + const hsp = $("headlines-spacer"); if (hsp && hsp.offsetTop - 250 <= e.scrollTop + e.offsetHeight) { @@ -1088,20 +1234,20 @@ function headlines_scroll_handler(e) { let rows = $$("#headlines-frame > div[id*=RROW][class*=Unread]"); for (let i = 0; i < rows.length; i++) { - const row = rows[i]; + const row = rows[i]; if ($("headlines-frame").scrollTop > (row.offsetTop + row.offsetHeight/2)) { - const id = row.getAttribute("data-article-id") + const id = row.getAttribute("data-article-id") - if (catchup_id_batch.indexOf(id) == -1) - catchup_id_batch.push(id); + if (catchup_id_batch.indexOf(id) == -1) + catchup_id_batch.push(id); - //console.log("auto_catchup_batch: " + catchup_id_batch.toString()); - } else { + //console.log("auto_catchup_batch: " + catchup_id_batch.toString()); + } else { break; } - } + } if (_infscroll_disable) { const row = $$("#headlines-frame div[id*=RROW]").last(); @@ -1142,21 +1288,21 @@ function catchupBatchedArticles() { _catchup_request_sent = true; xhrPost("backend.php", query, (transport) => { - const reply = handle_rpc_json(transport); + const reply = handle_rpc_json(transport); - _catchup_request_sent = false; + _catchup_request_sent = false; - if (reply) { - const batch = reply.ids; + if (reply) { + const batch = reply.ids; - batch.each(function (id) { - const elem = $("RROW-" + id); - if (elem) elem.removeClassName("Unread"); - catchup_id_batch.remove(id); - }); - } + batch.each(function (id) { + const elem = $("RROW-" + id); + if (elem) elem.removeClassName("Unread"); + catchup_id_batch.remove(id); + }); + } - updateFloatingTitle(true); + updateFloatingTitle(true); }); } } @@ -1175,9 +1321,9 @@ function catchupRelativeToArticle(below, id) { const ids_to_mark = []; if (!below) { - for (var i = 0; i < visible_ids.length; i++) { + for (let i = 0; i < visible_ids.length; i++) { if (visible_ids[i] != id) { - var e = $("RROW-" + visible_ids[i]); + const e = $("RROW-" + visible_ids[i]); if (e && e.hasClassName("Unread")) { ids_to_mark.push(visible_ids[i]); @@ -1187,9 +1333,9 @@ function catchupRelativeToArticle(below, id) { } } } else { - for (var i = visible_ids.length - 1; i >= 0; i--) { + for (let i = visible_ids.length - 1; i >= 0; i--) { if (visible_ids[i] != id) { - var e = $("RROW-" + visible_ids[i]); + const e = $("RROW-" + visible_ids[i]); if (e && e.hasClassName("Unread")) { ids_to_mark.push(visible_ids[i]); @@ -1216,7 +1362,7 @@ function catchupRelativeToArticle(below, id) { cmode: 0, ids: ids_to_mark.toString() }; xhrPost("backend.php", query, (transport) => { - handle_rpc_json(transport); + handle_rpc_json(transport); }); } } @@ -1254,9 +1400,15 @@ function show_labels_in_headlines(transport) { } function cdmClicked(event, id, in_body) { + if (event.ctrlKey && !in_body) { + openArticleInNewWindow(id); + } + + setActiveArticleId(id); + //var shift_key = event.shiftKey; - if (!event.ctrlKey && !event.metaKey) { + /* if (!event.ctrlKey && !event.metaKey) { let elem = $("RROW-" + getActiveArticleId()); @@ -1308,13 +1460,22 @@ function cdmClicked(event, id, in_body) { } const unread_in_buffer = $$("#headlines-frame > div[id*=RROW][class*=Unread]").length - request_counters(unread_in_buffer == 0); + request_counters(unread_in_buffer == 0); */ return false; } function hlClicked(event, id) { - if (event.which == 2) { + if (event.ctrlKey) { + openArticleInNewWindow(id); + setActiveArticleId(id); + } else { + view(id); + } + + return false; + + /* if (event.which == 2) { view(id); return true; } else if (event.ctrlKey || event.metaKey) { @@ -1323,12 +1484,10 @@ function hlClicked(event, id) { } else { view(id); return false; - } + } */ } function openArticleInNewWindow(id) { - toggleUnread(id, 0, false); - const w = window.open(""); w.opener = null; w.location = "backend.php?op=article&method=redirect&id=" + id; @@ -1338,7 +1497,7 @@ function isCdmMode() { return getInitParam("combined_display_mode"); } -function markHeadline(id, marked) { +/* function markHeadline(id, marked) { if (marked == undefined) marked = true; const row = $("RROW-" + id); @@ -1355,7 +1514,7 @@ function markHeadline(id, marked) { else row.removeClassName("Selected"); } -} +} */ function getRelativePostIds(id, limit) { @@ -1379,7 +1538,6 @@ function getRelativePostIds(id, limit) { } function correctHeadlinesOffset(id) { - const container = $("headlines-frame"); const row = $("RROW-" + id); @@ -1396,10 +1554,6 @@ function correctHeadlinesOffset(id) { if (rel_offset_top <= 0 || rel_offset_top > viewport) { container.scrollTop = row.offsetTop; } else if (rel_offset_bottom > viewport) { - - /* doesn't properly work with Opera in some cases because - Opera fucks up element scrolling */ - container.scrollTop = row.offsetTop + row.offsetHeight - viewport; } } @@ -1410,7 +1564,6 @@ function headlineActionsChange(elem) { } function closeArticlePanel() { - if (dijit.byId("content-insert")) dijit.byId("headlines-wrap-inner").removeChild( dijit.byId("content-insert")); @@ -1667,20 +1820,20 @@ function setSelectionScore() { xhrJson("backend.php", query, (reply) => { if (reply) { - reply.id.each((id) => { - const row = $("RROW-" + id); - - if (row) { - const pic = row.getElementsByClassName("hlScorePic")[0]; - - if (pic) { - pic.src = pic.src.replace(/score_.*?\.png/, - reply["score_pic"]); - pic.setAttribute("score", reply["score"]); - } - } - }); - } + reply.id.each((id) => { + const row = $("RROW-" + id); + + if (row) { + const pic = row.getElementsByClassName("score-pic")[0]; + + if (pic) { + pic.src = pic.src.replace(/score_.*?\.png/, + reply["score_pic"]); + pic.setAttribute("score", reply["score"]); + } + } + }); + } }); } @@ -1689,31 +1842,6 @@ function setSelectionScore() { } } -/* -function updateScore(id) { - const pic = $$("#RROW-" + id + " .hlScorePic")[0]; - - if (pic) { - - const query = "op=article&method=getScore&id=" + param_escape(id); - - new Ajax.Request("backend.php", { - parameters: query, - onComplete: function (transport) { - console.log(transport.responseText); - - const reply = JSON.parse(transport.responseText); - - if (reply) { - pic.src = pic.src.replace(/score_.*?\.png/, reply["score_pic"]); - pic.setAttribute("score", reply["score"]); - pic.setAttribute("title", reply["score"]); - } - } - }); - } -} */ - function changeScore(id, pic) { const score = pic.getAttribute("score"); @@ -1723,11 +1851,11 @@ function changeScore(id, pic) { const query = { op: "article", method: "setScore", id: id, score: new_score }; xhrJson("backend.php", query, (reply) => { - if (reply) { - pic.src = pic.src.replace(/score_.*?\.png/, reply["score_pic"]); - pic.setAttribute("score", new_score); - pic.setAttribute("title", new_score); - } + if (reply) { + pic.src = pic.src.replace(/score_.*?\.png/, reply["score_pic"]); + pic.setAttribute("score", new_score); + pic.setAttribute("title", new_score); + } }); } } @@ -1736,13 +1864,14 @@ function displayArticleUrl(id) { const query = { op: "rpc", method: "getlinktitlebyid", id: id }; xhrJson("backend.php", query, (reply) => { - if (reply && reply.link) { - prompt(__("Article URL:"), reply.link); - } + if (reply && reply.link) { + prompt(__("Article URL:"), reply.link); + } }); } +// floatingTitle goto button uses this function scrollToRowId(id) { const row = $(id); @@ -1754,7 +1883,6 @@ function updateFloatingTitle(unread_only) { if (!isCdmMode()) return; const hf = $("headlines-frame"); - const elems = $$("#headlines-frame > div[id*=RROW]"); for (let i = 0; i < elems.length; i++) { @@ -1763,7 +1891,7 @@ function updateFloatingTitle(unread_only) { if (child && child.offsetTop + child.offsetHeight > hf.scrollTop) { - const header = child.getElementsByClassName("cdmHeader")[0]; + const header = child.select(".header")[0]; if (unread_only || child.getAttribute("data-article-id") != $("floatingTitle").getAttribute("data-article-id")) { if (child.getAttribute("data-article-id") != $("floatingTitle").getAttribute("data-article-id")) {