From 049a37aa0e7d37cafd979e7d470c7649700b5010 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sat, 1 Dec 2018 17:05:28 +0300 Subject: WIP reshuffling of JS global context into separate logical objects --- classes/article.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'classes/article.php') diff --git a/classes/article.php b/classes/article.php index 50a61a019..bc2e76537 100755 --- a/classes/article.php +++ b/classes/article.php @@ -877,7 +877,7 @@ class Article extends Handler_Protected { $tags_str = ""; for ($i = 0; $i < $maxtags; $i++) { - $tags_str .= "" . $tags[$i] . ", "; + $tags_str .= "" . $tags[$i] . ", "; } $tags_str = mb_substr($tags_str, 0, mb_strlen($tags_str)-2); -- cgit v1.2.3-54-g00ecf From 642c37ea6117954fc19e2a800f2fce4c1304d89d Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sat, 1 Dec 2018 21:01:53 +0300 Subject: further effocts to wrap JS stuff into objects --- classes/article.php | 2 +- classes/feeds.php | 26 +- js/feedlist.js | 25 +- js/functions.js | 6 +- js/prefs.js | 2 +- js/tt-rss.js | 46 +- js/viewfeed.js | 1097 ++++++++++++++++++++-------------------- plugins/embed_original/init.js | 6 +- plugins/mail/mail.js | 2 +- plugins/mailto/init.js | 2 +- plugins/mark_button/init.php | 4 +- 11 files changed, 596 insertions(+), 622 deletions(-) (limited to 'classes/article.php') diff --git a/classes/article.php b/classes/article.php index bc2e76537..60a956c8d 100755 --- a/classes/article.php +++ b/classes/article.php @@ -727,7 +727,7 @@ class Article extends Handler_Protected { if (!$zoom_mode) { $rv['content'] .= "$tags_str (+)"; + href=\"#\" onclick=\"Article.editArticleTags($id, $feed_id)\">(+)"; $rv['content'] .= "
"; + $marked_pic = ""; $published_pic_src = $line["published"] ? "pub_set.png" : "pub_unset.png"; $class .= $line["published"] ? " published" : ""; - $published_pic = ""; + $published_pic = ""; $updated_fmt = make_local_datetime($line["updated"], false, false, false, true); $date_entered_fmt = T_sprintf("Imported at %s", @@ -628,7 +628,7 @@ class Feeds extends Handler_Protected { $tmp_content .= "Tags $tags_str (+)"; + href=\"#\" onclick=\"Article.editArticleTags($id)\">(+)"; $num_comments = (int) $line["num_comments"]; $entry_comments = ""; diff --git a/js/feedlist.js b/js/feedlist.js index f2f5e60ba..ad863f94c 100644 --- a/js/feedlist.js +++ b/js/feedlist.js @@ -207,8 +207,8 @@ const Feeds = { Utils.setLoadingProgress(50); document.onkeydown = App.hotkeyHandler; - setInterval(hotkeyPrefixTimeout, 3 * 1000); - setInterval(catchupBatchedArticles, 10 * 1000); + window.setInterval(() => { hotkeyPrefixTimeout() }, 3 * 1000); + window.setInterval(() => { Headlines.catchupBatchedArticles() }, 10 * 1000); if (!this.getActiveFeedId()) { this.viewfeed({feed: -3}); @@ -246,10 +246,7 @@ const Feeds = { } else { setTimeout(() => { this.requestCounters(true); - - setInterval(() => { - this.requestCounters(); - }, 60 * 1000) + setInterval(() => { this.requestCounters(); }, 60 * 1000) }, 250); } }, @@ -271,7 +268,7 @@ const Feeds = { this.selectFeed(id, is_cat); - PluginHost.run(PluginHost.HOOK_FEED_SET_ACTIVE, _active_article_id); + PluginHost.run(PluginHost.HOOK_FEED_SET_ACTIVE, [this._active_feed_id, this._active_feed_is_cat]); }, selectFeed: function(feed, is_cat) { const tree = dijit.byId("feedTree"); @@ -303,7 +300,7 @@ const Feeds = { if (feed != this.getActiveFeedId() || this.activeFeedIsCat() != is_cat) { this._search_query = false; - setActiveArticleId(0); + Article.setActiveArticleId(0); } if (offset != 0) { @@ -330,8 +327,8 @@ const Feeds = { if (method) query.m = method; if (offset > 0) { - if (current_first_id) { - query.fid = current_first_id; + if (Headlines.current_first_id) { + query.fid = Headlines.current_first_id; } } @@ -343,8 +340,8 @@ const Feeds = { query.skip = offset; // to prevent duplicate feed titles when showing grouped vfeeds - if (vgroup_last_feed) { - query.vgrlf = vgroup_last_feed; + if (Headlines.vgroup_last_feed != undefined) { + query.vgrlf = Headlines.vgroup_last_feed; } } else if (!is_cat && feed == this.getActiveFeedId() && !params.method) { query.m = "ForceUpdate"; @@ -370,7 +367,7 @@ const Feeds = { window.clearTimeout(this._viewfeed_wait_timeout); this._viewfeed_wait_timeout = window.setTimeout(() => { - catchupBatchedArticles(() => { + Headlines.catchupBatchedArticles(() => { xhrPost("backend.php", query, (transport) => { try { this.setFeedExpandoIcon(feed, is_cat, 'images/blank_icon.gif'); @@ -492,7 +489,7 @@ const Feeds = { rows.each(function (row) { row.removeClassName("Unread"); - if (row.getAttribute("data-article-id") != getActiveArticleId()) { + if (row.getAttribute("data-article-id") != Article.getActiveArticleId()) { new Effect.Fade(row, {duration: 0.5}); } diff --git a/js/functions.js b/js/functions.js index 0bddbbf0e..1a0fca484 100755 --- a/js/functions.js +++ b/js/functions.js @@ -878,7 +878,7 @@ function toggleSelectRow2(sender, row, is_cdm) { row.removeClassName('Selected'); if (typeof updateSelectedPrompt != undefined) - updateSelectedPrompt(); + Headlines.updateSelectedPrompt(); } @@ -892,7 +892,7 @@ function toggleSelectRow(sender, row) { row.removeClassName('Selected'); if (typeof updateSelectedPrompt != undefined) - updateSelectedPrompt(); + Headlines.updateSelectedPrompt(); } // noinspection JSUnusedGlobalSymbols @@ -1412,7 +1412,7 @@ function quickAddFilter() { } else { - const query = { op: "rpc", method: "getlinktitlebyid", id: getActiveArticleId() }; + const query = { op: "rpc", method: "getlinktitlebyid", id: Article.getActiveArticleId() }; xhrPost("backend.php", query, (transport) => { const reply = JSON.parse(transport.responseText); diff --git a/js/prefs.js b/js/prefs.js index e83e69bd5..a9417cf3c 100755 --- a/js/prefs.js +++ b/js/prefs.js @@ -86,7 +86,7 @@ const App = { }, 100); } - setInterval(hotkeyPrefixTimeout, 5 * 1000); + setInterval(() => { hotkeyPrefixTimeout() }, 5 * 1000); }, hotkeyHandler: function (event) { if (event.target.nodeName == "INPUT" || event.target.nodeName == "TEXTAREA") return; diff --git a/js/tt-rss.js b/js/tt-rss.js index 4c37102e6..02cf1ddb6 100644 --- a/js/tt-rss.js +++ b/js/tt-rss.js @@ -143,7 +143,7 @@ const App = { if (getInitParam("simple_update")) { console.log("scheduling simple feed updater..."); - window.setInterval(Feeds.updateRandomFeed, 30 * 1000); + window.setInterval(() => { Feeds.updateRandomFeed() }, 30 * 1000); } console.log("second stage ok"); @@ -191,7 +191,7 @@ const App = { switchPanelMode: function(wide) { if (App.isCombinedMode()) return; - const article_id = getActiveArticleId(); + const article_id = Article.getActiveArticleId(); if (wide) { dijit.byId("headlines-wrap-inner").attr("design", 'sidebar'); @@ -249,44 +249,44 @@ function init_hotkey_actions() { if (rv) Feeds.viewfeed({feed: rv[0], is_cat: rv[1], delayed: true}) }; hotkey_actions["next_article"] = function () { - moveToPost('next'); + Headlines.moveToPost('next'); }; hotkey_actions["prev_article"] = function () { - moveToPost('prev'); + Headlines.moveToPost('prev'); }; hotkey_actions["next_article_noscroll"] = function () { - moveToPost('next', true); + Headlines.moveToPost('next', true); }; hotkey_actions["prev_article_noscroll"] = function () { - moveToPost('prev', true); + Headlines.moveToPost('prev', true); }; hotkey_actions["next_article_noexpand"] = function () { - moveToPost('next', true, true); + Headlines.moveToPost('next', true, true); }; hotkey_actions["prev_article_noexpand"] = function () { - moveToPost('prev', true, true); + Headlines.moveToPost('prev', true, true); }; hotkey_actions["search_dialog"] = function () { Feeds.search(); }; hotkey_actions["toggle_mark"] = function () { - selectionToggleMarked(); + Headlines.selectionToggleMarked(); }; hotkey_actions["toggle_publ"] = function () { - selectionTogglePublished(); + Headlines.selectionTogglePublished(); }; hotkey_actions["toggle_unread"] = function () { - selectionToggleUnread({no_error: 1}); + Headlines.selectionToggleUnread({no_error: 1}); }; hotkey_actions["edit_tags"] = function () { - const id = getActiveArticleId(); + const id = Article.getActiveArticleId(); if (id) { - editArticleTags(id); + Article.editArticleTags(id); } } hotkey_actions["open_in_new_window"] = function () { - if (getActiveArticleId()) { - Article.openArticleInNewWindow(getActiveArticleId()); + if (Article.getActiveArticleId()) { + Article.openArticleInNewWindow(Article.getActiveArticleId()); } }; hotkey_actions["catchup_below"] = function () { @@ -318,22 +318,22 @@ function init_hotkey_actions() { } }; hotkey_actions["select_all"] = function () { - selectArticles('all'); + Headlines.selectArticles('all'); }; hotkey_actions["select_unread"] = function () { - selectArticles('unread'); + Headlines.selectArticles('unread'); }; hotkey_actions["select_marked"] = function () { - selectArticles('marked'); + Headlines.selectArticles('marked'); }; hotkey_actions["select_published"] = function () { - selectArticles('published'); + Headlines.selectArticles('published'); }; hotkey_actions["select_invert"] = function () { - selectArticles('invert'); + Headlines.selectArticles('invert'); }; hotkey_actions["select_none"] = function () { - selectArticles('none'); + Headlines.selectArticles('none'); }; hotkey_actions["feed_refresh"] = function () { if (Feeds.getActiveFeedId() != undefined) { @@ -434,8 +434,8 @@ function init_hotkey_actions() { }; hotkey_actions["toggle_embed_original"] = function () { if (typeof embedOriginalArticle != "undefined") { - if (getActiveArticleId()) - embedOriginalArticle(getActiveArticleId()); + if (Article.getActiveArticleId()) + embedOriginalArticle(Article.getActiveArticleId()); } else { alert(__("Please enable embed_original plugin first.")); } diff --git a/js/viewfeed.js b/js/viewfeed.js index 45d2efebb..cbbea8a05 100755 --- a/js/viewfeed.js +++ b/js/viewfeed.js @@ -1,16 +1,6 @@ /* global dijit, __, ngettext */ -let _active_article_id = 0; - -let vgroup_last_feed = false; let post_under_pointer = false; - -let catchup_id_batch = []; -//let catchup_timeout_id = false; - -//let cids_requested = []; -let loaded_article_ids = []; -let current_first_id = 0; let last_search_query; const ArticleCache = { @@ -38,8 +28,9 @@ const ArticleCache = { }; const Article = { + _active_article_id: 0, setSelectionScore: function() { - const ids = getSelectedArticleIds2(); + const ids = Headlines.getSelectedArticleIds2(); if (ids.length > 0) { console.log(ids); @@ -127,7 +118,7 @@ const Article = { c.attr('content', article); PluginHost.run(PluginHost.HOOK_ARTICLE_RENDERED, c.domNode); - correctHeadlinesOffset(getActiveArticleId()); + correctHeadlinesOffset(Article.getActiveArticleId()); try { c.focus(); @@ -135,7 +126,7 @@ const Article = { } }, view: function(id, noexpand) { - setActiveArticleId(id); + Article.setActiveArticleId(id); if (!noexpand) { console.log("loading article", id); @@ -164,7 +155,7 @@ const Article = { if (reply) { reply.each(function (article) { - if (getActiveArticleId() == article['id']) { + if (Article.getActiveArticleId() == article['id']) { Article.renderArticle(article['content']); } ArticleCache.set(article['id'], article['content']); @@ -191,7 +182,7 @@ const Article = { return false; }, cdmCollapseActive: function(event) { - const row = $("RROW-" + getActiveArticleId()); + const row = $("RROW-" + Article.getActiveArticleId()); if (row) { row.removeClassName("active"); @@ -200,38 +191,157 @@ const Article = { if (cb && !row.hasClassName("Selected")) cb.attr("checked", false); - setActiveArticleId(0); + Article.setActiveArticleId(0); if (event) event.stopPropagation(); return false; } + }, + editArticleTags: function(id) { + const query = "backend.php?op=article&method=editArticleTags¶m=" + param_escape(id); + + if (dijit.byId("editTagsDlg")) + dijit.byId("editTagsDlg").destroyRecursive(); + + const dialog = new dijit.Dialog({ + id: "editTagsDlg", + title: __("Edit article Tags"), + style: "width: 600px", + execute: function () { + if (this.validate()) { + notify_progress("Saving article tags...", true); + + xhrPost("backend.php", this.attr('value'), (transport) => { + try { + notify(''); + dialog.hide(); + + const data = JSON.parse(transport.responseText); + + if (data) { + const id = data.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); + } + }); + } + }, + href: query + }); + + const tmph = dojo.connect(dialog, 'onLoad', function () { + dojo.disconnect(tmph); + + new Ajax.Autocompleter('tags_str', 'tags_choices', + "backend.php?op=article&method=completeTags", + {tokens: ',', paramName: "search"}); + }); + + dialog.show(); + }, + cdmScrollToArticleId: function(id, force) { + const ctr = $("headlines-frame"); + const e = $("RROW-" + id); + + if (!e || !ctr) return; + + if (force || e.offsetTop + e.offsetHeight > (ctr.scrollTop + ctr.offsetHeight) || + e.offsetTop < ctr.scrollTop) { + + // expanded cdm has a 4px margin now + ctr.scrollTop = parseInt(e.offsetTop) - 4; + + Element.hide("floatingTitle"); + } + }, + setActiveArticleId: function(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); + } + }); + + this._active_article_id = id; + + const row = $("RROW-" + id); + + if (row) { + if (row.hasAttribute("data-content")) { + console.log("unpacking: " + row.id); + + row.select(".content-inner")[0].innerHTML = row.getAttribute("data-content"); + row.removeAttribute("data-content"); + + PluginHost.run(PluginHost.HOOK_ARTICLE_RENDERED_CDM, row); + } + + if (row.hasClassName("Unread")) { + + Headlines.catchupBatchedArticles(() => { + Feeds.decrementFeedCounter(Feeds.getActiveFeedId(), Feeds.activeFeedIsCat()); + Headlines.toggleUnread(id, 0); + Headlines.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, this._active_article_id); + } + + Headlines.updateSelectedPrompt(); + }, + getActiveArticleId: function() { + return this._active_article_id; } }; const Headlines = { + vgroup_last_feed: undefined, _headlines_scroll_timeout: 0, + loaded_article_ids: [], + current_first_id: 0, + catchup_id_batch: [], click: function(event, id, in_body) { in_body = in_body || false; if (App.isCombinedMode()) { - if (!in_body && (event.ctrlKey || id == getActiveArticleId() || getInitParam("cdm_expanded"))) { + if (!in_body && (event.ctrlKey || id == Article.getActiveArticleId() || getInitParam("cdm_expanded"))) { Article.openArticleInNewWindow(id); } - setActiveArticleId(id); + Article.setActiveArticleId(id); if (!getInitParam("cdm_expanded")) - cdmScrollToArticleId(id); + Article.cdmScrollToArticleId(id); return in_body; } else { if (event.ctrlKey) { Article.openArticleInNewWindow(id); - setActiveArticleId(id); + Article.setActiveArticleId(id); } else { Article.view(id); } @@ -293,9 +403,9 @@ const Headlines = { if ($("headlines-frame").scrollTop <= row.offsetTop && row.offsetTop - $("headlines-frame").scrollTop < 100 && - row.getAttribute("data-article-id") != getActiveArticleId()) { + row.getAttribute("data-article-id") != Article.getActiveArticleId()) { - setActiveArticleId(row.getAttribute("data-article-id")); + Article.setActiveArticleId(row.getAttribute("data-article-id")); break; } } @@ -326,8 +436,8 @@ const Headlines = { if ($("headlines-frame").scrollTop > (row.offsetTop + row.offsetHeight / 2)) { const id = row.getAttribute("data-article-id") - if (catchup_id_batch.indexOf(id) == -1) - catchup_id_batch.push(id); + if (this.catchup_id_batch.indexOf(id) == -1) + this.catchup_id_batch.push(id); } else { break; @@ -373,7 +483,7 @@ const Headlines = { ft.setAttribute("data-article-id", id); ft.innerHTML = header.innerHTML; ft.firstChild.innerHTML = "" + ft.firstChild.innerHTML; + "onclick=\"Article.cdmScrollToArticleId(" + id + ", true)\">" + ft.firstChild.innerHTML; initFloatingMenu(); @@ -462,11 +572,11 @@ const Headlines = { console.log('received', headlines_count, 'headlines, infscroll disabled=', Feeds.infscroll_disabled); - vgroup_last_feed = reply['headlines-info']['vgroup_last_feed']; - current_first_id = reply['headlines']['first_id']; + this.vgroup_last_feed = reply['headlines-info']['vgroup_last_feed']; + this.current_first_id = reply['headlines']['first_id']; if (offset == 0) { - loaded_article_ids = []; + this.loaded_article_ids = []; dojo.html.set($("headlines-toolbar"), reply['headlines']['toolbar'], @@ -481,10 +591,10 @@ const Headlines = { while (tmp.hasChildNodes()) { const row = tmp.removeChild(tmp.firstChild); - if (loaded_article_ids.indexOf(row.id) == -1 || row.hasClassName("feed-title")) { + if (this.loaded_article_ids.indexOf(row.id) == -1 || row.hasClassName("feed-title")) { dijit.byId("headlines-frame").domNode.appendChild(row); - loaded_article_ids.push(row.id); + this.loaded_article_ids.push(row.id); } } @@ -506,7 +616,7 @@ const Headlines = { } else if (headlines_count > 0 && feed_id == Feeds.getActiveFeedId() && is_cat == Feeds.activeFeedIsCat()) { const c = dijit.byId("headlines-frame"); - //const ids = getSelectedArticleIds2(); + //const ids = Headlines.getSelectedArticleIds2(); let hsp = $("headlines-spacer"); @@ -520,10 +630,10 @@ const Headlines = { while (tmp.hasChildNodes()) { let row = tmp.removeChild(tmp.firstChild); - if (loaded_article_ids.indexOf(row.id) == -1 || row.hasClassName("feed-title")) { + if (this.loaded_article_ids.indexOf(row.id) == -1 || row.hasClassName("feed-title")) { dijit.byId("headlines-frame").domNode.appendChild(row); - loaded_article_ids.push(row.id); + this.loaded_article_ids.push(row.id); } } @@ -601,238 +711,247 @@ const Headlines = { Feeds.viewCurrentFeed(); }, -}; + selectionToggleUnread: function(params) { + params = params || {}; -function toggleMark(id, client_only) { - const query = { op: "rpc", id: id, method: "mark" }; - const row = $("RROW-" + id); + const cmode = params.cmode || 2; + const callback = params.callback; + const no_error = params.no_error || false; + const ids = params.ids || Headlines.getSelectedArticleIds2(); - if (row) { - const imgs = $$("img[class*=marked-pic][class*=marked-" + id + "]"); + if (ids.length == 0) { + if (!no_error) + alert(__("No articles are selected.")); - imgs.each((img) => { - if (!row.hasClassName("marked")) { - img.src = img.src.replace("mark_unset", "mark_set"); - query.mark = 1; - } else { - img.src = img.src.replace("mark_set", "mark_unset"); - query.mark = 0; + return; + } + + ids.each((id) => { + const row = $("RROW-" + id); + + if (row) { + switch (cmode) { + case 0: + row.removeClassName("Unread"); + break; + case 1: + row.addClassName("Unread"); + break; + case 2: + row.toggleClassName("Unread"); + } } }); - row.toggleClassName("marked"); + const query = { + op: "rpc", method: "catchupSelected", + cmode: cmode, ids: ids.toString() + }; - if (!client_only) - xhrPost("backend.php", query, (transport) => { - Utils.handleRpcJson(transport); - }); - } -} + notify_progress("Loading, please wait..."); -function togglePub(id, client_only) { - const row = $("RROW-" + id); + xhrPost("backend.php", query, (transport) => { + Utils.handleRpcJson(transport); + if (callback) callback(transport); + }); + }, + selectionToggleMarked: function(ids) { + const rows = ids || Headlines.getSelectedArticleIds2(); + + if (rows.length == 0) { + alert(__("No articles are selected.")); + return; + } - if (row) { - const query = { op: "rpc", id: id, method: "publ" }; + for (let i = 0; i < rows.length; i++) { + this.toggleMark(rows[i], true, true); + } - const imgs = $$("img[class*=pub-pic][class*=pub-" + id + "]"); + const query = { + op: "rpc", method: "markSelected", + ids: rows.toString(), cmode: 2 + }; - imgs.each((img) => { - if (!row.hasClassName("published")) { - img.src = img.src.replace("pub_unset", "pub_set"); - query.pub = 1; - } else { - img.src = img.src.replace("pub_set", "pub_unset"); - query.pub = 0; - } + xhrPost("backend.php", query, (transport) => { + Utils.handleRpcJson(transport); }); + }, + selectionTogglePublished: function(ids) { + const rows = ids || Headlines.getSelectedArticleIds2(); - row.toggleClassName("published"); + if (rows.length == 0) { + alert(__("No articles are selected.")); + return; + } + + for (let i = 0; i < rows.length; i++) { + this.togglePub(rows[i], true); + } + + if (rows.length > 0) { + const query = { + op: "rpc", method: "publishSelected", + ids: rows.toString(), cmode: 2 + }; - if (!client_only) xhrPost("backend.php", query, (transport) => { Utils.handleRpcJson(transport); }); + } + }, + toggleMark: function(id, client_only) { + const query = {op: "rpc", id: id, method: "mark"}; + const row = $("RROW-" + id); - } -} + if (row) { + const imgs = $$("img[class*=marked-pic][class*=marked-" + id + "]"); -function moveToPost(mode, noscroll, noexpand) { - const rows = getLoadedArticleIds(); + imgs.each((img) => { + if (!row.hasClassName("marked")) { + img.src = img.src.replace("mark_unset", "mark_set"); + query.mark = 1; + } else { + img.src = img.src.replace("mark_set", "mark_unset"); + query.mark = 0; + } + }); - let prev_id = false; - let next_id = false; + row.toggleClassName("marked"); - if (!$('RROW-' + getActiveArticleId())) { - setActiveArticleId(0); - } + if (!client_only) + xhrPost("backend.php", query, (transport) => { + Utils.handleRpcJson(transport); + }); + } + }, + togglePub: function(id, client_only) { + const row = $("RROW-" + id); - if (!getActiveArticleId()) { - next_id = rows[0]; - prev_id = rows[rows.length-1] - } else { - for (let i = 0; i < rows.length; i++) { - if (rows[i] == getActiveArticleId()) { + if (row) { + const query = {op: "rpc", id: id, method: "publ"}; - // Account for adjacent identical article ids. - if (i > 0) prev_id = rows[i-1]; + const imgs = $$("img[class*=pub-pic][class*=pub-" + id + "]"); - for (let j = i+1; j < rows.length; j++) { - if (rows[j] != getActiveArticleId()) { - next_id = rows[j]; - break; - } + imgs.each((img) => { + if (!row.hasClassName("published")) { + img.src = img.src.replace("pub_unset", "pub_set"); + query.pub = 1; + } else { + img.src = img.src.replace("pub_set", "pub_unset"); + query.pub = 0; } - break; - } - } - } - - console.log("cur: " + getActiveArticleId() + " next: " + next_id); - - if (mode == "next") { - if (next_id || getActiveArticleId()) { - if (App.isCombinedMode()) { + }); - const article = $("RROW-" + getActiveArticleId()); - const ctr = $("headlines-frame"); + row.toggleClassName("published"); - if (!noscroll && article && article.offsetTop + article.offsetHeight > - ctr.scrollTop + ctr.offsetHeight) { + if (!client_only) + xhrPost("backend.php", query, (transport) => { + Utils.handleRpcJson(transport); + }); - scrollArticle(ctr.offsetHeight/4); + } + }, + moveToPost: function(mode, noscroll, noexpand) { + const rows = Headlines.getLoadedArticleIds(); - } else if (next_id) { - setActiveArticleId(next_id); - cdmScrollToArticleId(next_id, true); - } + let prev_id = false; + let next_id = false; - } else if (next_id) { - correctHeadlinesOffset(next_id); - Article.view(next_id, noexpand); - } + if (!$('RROW-' + Article.getActiveArticleId())) { + Article.setActiveArticleId(0); } - } - if (mode == "prev") { - if (prev_id || getActiveArticleId()) { - if (App.isCombinedMode()) { + if (!Article.getActiveArticleId()) { + next_id = rows[0]; + prev_id = rows[rows.length - 1] + } else { + for (let i = 0; i < rows.length; i++) { + if (rows[i] == Article.getActiveArticleId()) { - const article = $("RROW-" + getActiveArticleId()); - const prev_article = $("RROW-" + prev_id); - const ctr = $("headlines-frame"); + // Account for adjacent identical article ids. + if (i > 0) prev_id = rows[i - 1]; - if (!noscroll && article && article.offsetTop < ctr.scrollTop) { - scrollArticle(-ctr.offsetHeight/3); - } else if (!noscroll && prev_article && - prev_article.offsetTop < ctr.scrollTop) { - scrollArticle(-ctr.offsetHeight/4); - } else if (prev_id) { - setActiveArticleId(prev_id); - cdmScrollToArticleId(prev_id, noscroll); + for (let j = i + 1; j < rows.length; j++) { + if (rows[j] != Article.getActiveArticleId()) { + next_id = rows[j]; + break; + } + } + break; } - - } else if (prev_id) { - correctHeadlinesOffset(prev_id); - Article.view(prev_id, noexpand); } } - } -} -function updateSelectedPrompt() { - const count = getSelectedArticleIds2().length; - const elem = $("selected_prompt"); + console.log("cur: " + Article.getActiveArticleId() + " next: " + next_id); - if (elem) { - elem.innerHTML = ngettext("%d article selected", - "%d articles selected", count).replace("%d", count); + if (mode == "next") { + if (next_id || Article.getActiveArticleId()) { + if (App.isCombinedMode()) { - count > 0 ? Element.show(elem) : Element.hide(elem); - } -} + const article = $("RROW-" + Article.getActiveArticleId()); + const ctr = $("headlines-frame"); -function toggleUnread(id, cmode) { - const row = $("RROW-" + id); + if (!noscroll && article && article.offsetTop + article.offsetHeight > + ctr.scrollTop + ctr.offsetHeight) { - if (row) { - const origClassName = row.className; + scrollArticle(ctr.offsetHeight / 4); - if (cmode == undefined) cmode = 2; + } else if (next_id) { + Article.setActiveArticleId(next_id); + Article.cdmScrollToArticleId(next_id, true); + } - switch (cmode) { - case 0: - row.removeClassName("Unread"); - break; - case 1: - row.addClassName("Unread"); - break; - case 2: - row.toggleClassName("Unread"); - break; + } else if (next_id) { + correctHeadlinesOffset(next_id); + Article.view(next_id, noexpand); + } + } } - if (row.className != origClassName) - xhrPost("backend.php", - {op: "rpc", method: "catchupSelected", cmode: cmode, ids: id},(transport) => { - Utils.handleRpcJson(transport); - }); - } -} - -function selectionRemoveLabel(id, ids) { - if (!ids) ids = getSelectedArticleIds2(); - - if (ids.length == 0) { - alert(__("No articles are selected.")); - return; - } - - const query = { op: "article", method: "removeFromLabel", - ids: ids.toString(), lid: id }; - - xhrPost("backend.php", query, (transport) => { - Utils.handleRpcJson(transport); - updateHeadlineLabels(transport); - }); -} - -function selectionAssignLabel(id, ids) { - if (!ids) ids = getSelectedArticleIds2(); - - if (ids.length == 0) { - alert(__("No articles are selected.")); - return; - } + if (mode == "prev") { + if (prev_id || Article.getActiveArticleId()) { + if (App.isCombinedMode()) { - const query = { op: "article", method: "assignToLabel", - ids: ids.toString(), lid: id }; + const article = $("RROW-" + Article.getActiveArticleId()); + const prev_article = $("RROW-" + prev_id); + const ctr = $("headlines-frame"); - xhrPost("backend.php", query, (transport) => { - Utils.handleRpcJson(transport); - updateHeadlineLabels(transport); - }); -} - -function selectionToggleUnread(params) { - params = params || {}; - - const cmode = params.cmode || 2; - const callback = params.callback; - const no_error = params.no_error || false; - const ids = params.ids || getSelectedArticleIds2(); + if (!noscroll && article && article.offsetTop < ctr.scrollTop) { + scrollArticle(-ctr.offsetHeight / 3); + } else if (!noscroll && prev_article && + prev_article.offsetTop < ctr.scrollTop) { + scrollArticle(-ctr.offsetHeight / 4); + } else if (prev_id) { + Article.setActiveArticleId(prev_id); + Article.cdmScrollToArticleId(prev_id, noscroll); + } - if (ids.length == 0) { - if (!no_error) - alert(__("No articles are selected.")); + } else if (prev_id) { + correctHeadlinesOffset(prev_id); + Article.view(prev_id, noexpand); + } + } + } + }, + updateSelectedPrompt: function() { + const count = Headlines.getSelectedArticleIds2().length; + const elem = $("selected_prompt"); - return; - } + if (elem) { + elem.innerHTML = ngettext("%d article selected", + "%d articles selected", count).replace("%d", count); - ids.each((id) => { + count > 0 ? Element.show(elem) : Element.hide(elem); + } + }, + toggleUnread: function(id, cmode) { const row = $("RROW-" + id); if (row) { + const origClassName = row.className; + + if (cmode == undefined) cmode = 2; + switch (cmode) { case 0: row.removeClassName("Unread"); @@ -842,368 +961,259 @@ function selectionToggleUnread(params) { break; case 2: row.toggleClassName("Unread"); + break; } - } - }); - - const query = {op: "rpc", method: "catchupSelected", - cmode: cmode, ids: ids.toString() }; - notify_progress("Loading, please wait..."); - - xhrPost("backend.php", query, (transport) => { - Utils.handleRpcJson(transport); - if (callback) callback(transport); - }); -} - -function selectionToggleMarked(ids) { - const rows = ids || getSelectedArticleIds2(); - - if (rows.length == 0) { - alert(__("No articles are selected.")); - return; - } - - for (let i = 0; i < rows.length; i++) { - toggleMark(rows[i], true, true); - } - - const query = { op: "rpc", method: "markSelected", - ids: rows.toString(), cmode: 2 }; + if (row.className != origClassName) + xhrPost("backend.php", + {op: "rpc", method: "catchupSelected", cmode: cmode, ids: id}, (transport) => { + Utils.handleRpcJson(transport); + }); + } + }, + selectionRemoveLabel: function(id, ids) { + if (!ids) ids = Headlines.getSelectedArticleIds2(); - xhrPost("backend.php", query, (transport) => { - Utils.handleRpcJson(transport); - }); -} + if (ids.length == 0) { + alert(__("No articles are selected.")); + return; + } -// sel_state ignored -function selectionTogglePublished(ids) { - const rows = ids || getSelectedArticleIds2(); + const query = { + op: "article", method: "removeFromLabel", + ids: ids.toString(), lid: id + }; - if (rows.length == 0) { - alert(__("No articles are selected.")); - return; - } + xhrPost("backend.php", query, (transport) => { + Utils.handleRpcJson(transport); + updateHeadlineLabels(transport); + }); + }, + selectionAssignLabel: function(id, ids) { + if (!ids) ids = Headlines.getSelectedArticleIds2(); - for (let i = 0; i < rows.length; i++) { - togglePub(rows[i], true); - } + if (ids.length == 0) { + alert(__("No articles are selected.")); + return; + } - if (rows.length > 0) { - const query = { op: "rpc", method: "publishSelected", - ids: rows.toString(), cmode: 2 }; + const query = { + op: "article", method: "assignToLabel", + ids: ids.toString(), lid: id + }; xhrPost("backend.php", query, (transport) => { Utils.handleRpcJson(transport); + updateHeadlineLabels(transport); }); - } -} + }, + deleteSelection: function() { + const rows = Headlines.getSelectedArticleIds2(); -function getSelectedArticleIds2() { + if (rows.length == 0) { + alert(__("No articles are selected.")); + return; + } - const rv = []; + const fn = Feeds.getFeedName(Feeds.getActiveFeedId(), Feeds.activeFeedIsCat()); + let str; - $$("#headlines-frame > div[id*=RROW][class*=Selected]").each( - function(child) { - rv.push(child.getAttribute("data-article-id")); - }); + if (Feeds.getActiveFeedId() != 0) { + str = ngettext("Delete %d selected article in %s?", "Delete %d selected articles in %s?", rows.length); + } else { + str = ngettext("Delete %d selected article?", "Delete %d selected articles?", rows.length); + } - // consider active article a honorary member of selected articles - if (getActiveArticleId()) - rv.push(getActiveArticleId()); + str = str.replace("%d", rows.length); + str = str.replace("%s", fn); - return rv.uniq(); -} + if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) { + return; + } -function getLoadedArticleIds() { - const rv = []; + const query = {op: "rpc", method: "delete", ids: rows.toString()}; - const children = $$("#headlines-frame > div[id*=RROW-]"); + xhrPost("backend.php", query, (transport) => { + Utils.handleRpcJson(transport); + Feeds.viewCurrentFeed(); + }); + }, + getSelectedArticleIds2: function() { + const rv = []; - children.each(function(child) { - if (Element.visible(child)) { - rv.push(child.getAttribute("data-article-id")); - } - }); + $$("#headlines-frame > div[id*=RROW][class*=Selected]").each( + function (child) { + rv.push(child.getAttribute("data-article-id")); + }); - return rv; -} + // consider active article a honorary member of selected articles + if (Article.getActiveArticleId()) + rv.push(Article.getActiveArticleId()); -// mode = all,none,unread,invert,marked,published -function selectArticles(mode) { - let query = "#headlines-frame > div[id*=RROW]"; + return rv.uniq(); + }, + getLoadedArticleIds: function() { + const rv = []; - 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 children = $$("#headlines-frame > div[id*=RROW-]"); - const rows = $$(query); + children.each(function (child) { + if (Element.visible(child)) { + rv.push(child.getAttribute("data-article-id")); + } + }); - for (let i = 0; i < rows.length; i++) { - const row = rows[i]; - const cb = dijit.getEnclosingWidget(row.select(".rchk")[0]); + return rv; + }, + selectArticles: function(mode) { + // mode = all,none,unread,invert,marked,published + let query = "#headlines-frame > div[id*=RROW]"; switch (mode) { case "none": - row.removeClassName("Selected"); - - if (!row.hasClassName("active")) - cb.attr("checked", false); - break; + case "all": 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; + case "marked": + query += "[class*=marked]"; + break; + case "published": + query += "[class*=published]"; + break; + case "unread": + query += "[class*=Unread]"; break; default: - row.addClassName("Selected"); - cb.attr("checked", true); + console.warn("selectArticles: unknown mode", mode); } - updateSelectedPrompt(); - } -} - -// noinspection JSUnusedGlobalSymbols -function deleteSelection() { - - const rows = getSelectedArticleIds2(); - - if (rows.length == 0) { - alert(__("No articles are selected.")); - return; - } - - const fn = Feeds.getFeedName(Feeds.getActiveFeedId(), Feeds.activeFeedIsCat()); - let str; - - if (Feeds.getActiveFeedId() != 0) { - str = ngettext("Delete %d selected article in %s?", "Delete %d selected articles in %s?", rows.length); - } else { - str = ngettext("Delete %d selected article?", "Delete %d selected articles?", rows.length); - } - - str = str.replace("%d", rows.length); - str = str.replace("%s", fn); - - if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) { - return; - } - - const query = { op: "rpc", method: "delete", ids: rows.toString() }; - - xhrPost("backend.php", query, (transport) => { - Utils.handleRpcJson(transport); - Feeds.viewCurrentFeed(); - }); -} - -// noinspection JSUnusedGlobalSymbols -function archiveSelection() { - - const rows = getSelectedArticleIds2(); - - if (rows.length == 0) { - alert(__("No articles are selected.")); - return; - } - - const fn = Feeds.getFeedName(Feeds.getActiveFeedId(), Feeds.activeFeedIsCat()); - let str; - let op; - - if (Feeds.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."); - - op = "unarchive"; - } - - str = str.replace("%d", rows.length); - str = str.replace("%s", fn); - - if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) { - return; - } - - for (let i = 0; i < rows.length; i++) { - ArticleCache.del(rows[i]); - } - - const query = {op: "rpc", method: op, ids: rows.toString()}; - - xhrPost("backend.php", query, (transport) => { - Utils.handleRpcJson(transport); - Feeds.viewCurrentFeed(); - }); -} - -function catchupSelection() { - - const rows = getSelectedArticleIds2(); - - if (rows.length == 0) { - alert(__("No articles are selected.")); - return; - } - - const fn = Feeds.getFeedName(Feeds.getActiveFeedId(), Feeds.activeFeedIsCat()); - - let str = ngettext("Mark %d selected article in %s as read?", "Mark %d selected articles in %s as read?", rows.length); - - str = str.replace("%d", rows.length); - str = str.replace("%s", fn); - - if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) { - return; - } - - selectionToggleUnread({callback: viewCurrentFeed, no_error: 1}); -} - -function editArticleTags(id) { - const query = "backend.php?op=article&method=editArticleTags¶m=" + param_escape(id); - - if (dijit.byId("editTagsDlg")) - dijit.byId("editTagsDlg").destroyRecursive(); - - const dialog = new dijit.Dialog({ - id: "editTagsDlg", - title: __("Edit article Tags"), - style: "width: 600px", - execute: function() { - if (this.validate()) { - notify_progress("Saving article tags...", true); + const rows = $$(query); - xhrPost("backend.php", this.attr('value'), (transport) => { - try { - notify(''); - dialog.hide(); - - const data = JSON.parse(transport.responseText); + for (let i = 0; i < rows.length; i++) { + const row = rows[i]; + const cb = dijit.getEnclosingWidget(row.select(".rchk")[0]); - if (data) { - const id = data.id; + switch (mode) { + case "none": + row.removeClassName("Selected"); - const tags = $("ATSTR-" + id); - const tooltip = dijit.byId("ATSTRTIP-" + id); + if (!row.hasClassName("active")) + cb.attr("checked", false); + break; + case "invert": + if (row.hasClassName("Selected")) { + row.removeClassName("Selected"); - if (tags) tags.innerHTML = data.content; - if (tooltip) tooltip.attr('label', data.content_full); - } - } catch (e) { - exception_error(e); + 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); } - }, - href: query - }); - - const tmph = dojo.connect(dialog, 'onLoad', function() { - dojo.disconnect(tmph); - new Ajax.Autocompleter('tags_str', 'tags_choices', - "backend.php?op=article&method=completeTags", - { tokens: ',', paramName: "search" }); - }); + Headlines.updateSelectedPrompt(); + } + }, + archiveSelection: function() { + const rows = Headlines.getSelectedArticleIds2(); - dialog.show(); + if (rows.length == 0) { + alert(__("No articles are selected.")); + return; + } -} + const fn = Feeds.getFeedName(Feeds.getActiveFeedId(), Feeds.activeFeedIsCat()); + let str; + let op; -function cdmScrollToArticleId(id, force) { - const ctr = $("headlines-frame"); - const e = $("RROW-" + id); + if (Feeds.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."); - if (!e || !ctr) return; + op = "unarchive"; + } - if (force || e.offsetTop+e.offsetHeight > (ctr.scrollTop+ctr.offsetHeight) || - e.offsetTop < ctr.scrollTop) { + str = str.replace("%d", rows.length); + str = str.replace("%s", fn); - // expanded cdm has a 4px margin now - ctr.scrollTop = parseInt(e.offsetTop) - 4; + if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) { + return; + } - Element.hide("floatingTitle"); - } -} + for (let i = 0; i < rows.length; i++) { + ArticleCache.del(rows[i]); + } -function setActiveArticleId(id) { - console.log("setActiveArticleId", id); + const query = {op: "rpc", method: op, ids: rows.toString()}; - $$("div[id*=RROW][class*=active]").each((e) => { - e.removeClassName("active"); + xhrPost("backend.php", query, (transport) => { + Utils.handleRpcJson(transport); + Feeds.viewCurrentFeed(); + }); + }, + catchupSelection: function() { + const rows = Headlines.getSelectedArticleIds2(); - if (!e.hasClassName("Selected")) { - const cb = dijit.getEnclosingWidget(e.select(".rchk")[0]); - if (cb) cb.attr("checked", false); + if (rows.length == 0) { + alert(__("No articles are selected.")); + return; } - }); - - _active_article_id = id; - const row = $("RROW-" + id); + const fn = Feeds.getFeedName(Feeds.getActiveFeedId(), Feeds.activeFeedIsCat()); - if (row) { - if (row.hasAttribute("data-content")) { - console.log("unpacking: " + row.id); + let str = ngettext("Mark %d selected article in %s as read?", "Mark %d selected articles in %s as read?", rows.length); - row.select(".content-inner")[0].innerHTML = row.getAttribute("data-content"); - row.removeAttribute("data-content"); + str = str.replace("%d", rows.length); + str = str.replace("%s", fn); - PluginHost.run(PluginHost.HOOK_ARTICLE_RENDERED_CDM, row); + if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) { + return; } - if (row.hasClassName("Unread")) { + Headlines.selectionToggleUnread({callback: Feeds.viewCurrentFeed, no_error: 1}); + }, + catchupBatchedArticles: function(callback) { + console.log("catchupBatchedArticles, size=", this.catchup_id_batch.length); - catchupBatchedArticles(() => { - Feeds.decrementFeedCounter(Feeds.getActiveFeedId(), Feeds.activeFeedIsCat()); - toggleUnread(id, 0); - Headlines.updateFloatingTitle(true); - }); + if (this.catchup_id_batch.length > 0) { - } + // make a copy of the array + const batch = this.catchup_id_batch.slice(); + const query = { + op: "rpc", method: "catchupSelected", + cmode: 0, ids: batch.toString() + }; - row.addClassName("active"); + xhrPost("backend.php", query, (transport) => { + const reply = Utils.handleRpcJson(transport); - if (!row.hasClassName("Selected")) { - const cb = dijit.getEnclosingWidget(row.select(".rchk")[0]); - if (cb) cb.attr("checked", true); - } + if (reply) { + const batch = reply.ids; - PluginHost.run(PluginHost.HOOK_ARTICLE_SET_ACTIVE, _active_article_id); - } + batch.each(function (id) { + const elem = $("RROW-" + id); + if (elem) elem.removeClassName("Unread"); + Headlines.catchup_id_batch.remove(id); + }); + } - updateSelectedPrompt(); -} + Headlines.updateFloatingTitle(true); -function getActiveArticleId() { - return _active_article_id; -} + if (callback) callback(); + }); + } else { + if (callback) callback(); + } + } +}; function postMouseIn(e, id) { post_under_pointer = id; @@ -1213,48 +1223,16 @@ function postMouseOut(id) { post_under_pointer = false; } -function catchupBatchedArticles(callback) { - console.log("catchupBatchedArticles, size=", catchup_id_batch.length); - - if (catchup_id_batch.length > 0) { - - // make a copy of the array - const batch = catchup_id_batch.slice(); - const query = { op: "rpc", method: "catchupSelected", - cmode: 0, ids: batch.toString() }; - - xhrPost("backend.php", query, (transport) => { - const reply = Utils.handleRpcJson(transport); - - if (reply) { - const batch = reply.ids; - - batch.each(function (id) { - const elem = $("RROW-" + id); - if (elem) elem.removeClassName("Unread"); - catchup_id_batch.remove(id); - }); - } - - Headlines.updateFloatingTitle(true); - - if (callback) callback(); - }); - } else { - if (callback) callback(); - } -} - function catchupRelativeToArticle(below, id) { - if (!id) id = getActiveArticleId(); + if (!id) id = Article.getActiveArticleId(); if (!id) { alert(__("No article is selected.")); return; } - const visible_ids = getLoadedArticleIds(); + const visible_ids = Headlines.getLoadedArticleIds(); const ids_to_mark = []; @@ -1343,7 +1321,7 @@ function getRelativePostIds(id, limit) { if (!limit) limit = 6; //3 - const ids = getLoadedArticleIds(); + const ids = Headlines.getLoadedArticleIds(); for (let i = 0; i < ids.length; i++) { if (ids[i] == id) { @@ -1379,7 +1357,6 @@ function correctHeadlinesOffset(id) { } } -// noinspection JSUnusedGlobalSymbols function headlineActionsChange(elem) { eval(elem.value); elem.attr('value', 'false'); @@ -1421,36 +1398,36 @@ function headlinesMenuCommon(menu) { label: __("Toggle unread"), onClick: function () { - let ids = getSelectedArticleIds2(); + let ids = Headlines.getSelectedArticleIds2(); // cast to string const id = (this.getParent().currentTarget.getAttribute("data-article-id")) + ""; ids = ids.length != 0 && ids.indexOf(id) != -1 ? ids : [id]; - selectionToggleUnread({ids: ids, no_error: 1}); + Headlines.selectionToggleUnread({ids: ids, no_error: 1}); } })); menu.addChild(new dijit.MenuItem({ label: __("Toggle starred"), onClick: function () { - let ids = getSelectedArticleIds2(); + let ids = Headlines.getSelectedArticleIds2(); // cast to string const id = (this.getParent().currentTarget.getAttribute("data-article-id")) + ""; ids = ids.length != 0 && ids.indexOf(id) != -1 ? ids : [id]; - selectionToggleMarked(ids); + Headlines.selectionToggleMarked(ids); } })); menu.addChild(new dijit.MenuItem({ label: __("Toggle published"), onClick: function () { - let ids = getSelectedArticleIds2(); + let ids = Headlines.getSelectedArticleIds2(); // cast to string const id = (this.getParent().currentTarget.getAttribute("data-article-id")) + ""; ids = ids.length != 0 && ids.indexOf(id) != -1 ? ids : [id]; - selectionTogglePublished(ids); + Headlines.selectionTogglePublished(ids); } })); @@ -1489,13 +1466,13 @@ function headlinesMenuCommon(menu) { labelId: bare_id, onClick: function () { - let ids = getSelectedArticleIds2(); + let ids = Headlines.getSelectedArticleIds2(); // cast to string const id = (this.getParent().ownerMenu.currentTarget.getAttribute("data-article-id")) + ""; ids = ids.length != 0 && ids.indexOf(id) != -1 ? ids : [id]; - selectionAssignLabel(this.labelId, ids); + Headlines.selectionAssignLabel(this.labelId, ids); } })); @@ -1503,13 +1480,13 @@ function headlinesMenuCommon(menu) { label: name, labelId: bare_id, onClick: function () { - let ids = getSelectedArticleIds2(); + let ids = Headlines.getSelectedArticleIds2(); // cast to string const id = (this.getParent().ownerMenu.currentTarget.getAttribute("data-article-id")) + ""; ids = ids.length != 0 && ids.indexOf(id) != -1 ? ids : [id]; - selectionRemoveLabel(this.labelId, ids); + Headlines.selectionRemoveLabel(this.labelId, ids); } })); @@ -1555,7 +1532,7 @@ function initHeadlinesMenu() { menu.addChild(new dijit.MenuItem({ label: __("Select articles in group"), onClick: function (event) { - selectArticles("all", + Headlines.selectArticles("all", "#headlines-frame > div[id*=RROW]" + "[data-orig-feed-id='" + this.getParent().currentTarget.getAttribute("data-feed-id") + "']"); @@ -1565,12 +1542,12 @@ function initHeadlinesMenu() { menu.addChild(new dijit.MenuItem({ label: __("Mark group as read"), onClick: function () { - selectArticles("none"); - selectArticles("all", + Headlines.selectArticles("none"); + Headlines.selectArticles("all", "#headlines-frame > div[id*=RROW]" + "[data-orig-feed-id='" + this.getParent().currentTarget.getAttribute("data-feed-id") + "']"); - catchupSelection(); + Headlines.catchupSelection(); } })); diff --git a/plugins/embed_original/init.js b/plugins/embed_original/init.js index d0731d5d1..95a5ef9e5 100644 --- a/plugins/embed_original/init.js +++ b/plugins/embed_original/init.js @@ -11,7 +11,7 @@ function embedOriginalArticle(id) { if (App.isCombinedMode()) { c = $$("div#RROW-" + id + " div[class=content-inner]")[0]; - } else if (id == getActiveArticleId()) { + } else if (id == Article.getActiveArticleId()) { c = $$(".post .content")[0]; } @@ -23,7 +23,7 @@ function embedOriginalArticle(id) { c.parentNode.removeChild(iframe); if (App.isCombinedMode()) { - cdmScrollToArticleId(id, true); + Article.cdmScrollToArticleId(id, true); } return; @@ -48,7 +48,7 @@ function embedOriginalArticle(id) { c.parentNode.insertBefore(iframe, c); if (App.isCombinedMode()) { - cdmScrollToArticleId(id, true); + Article.cdmScrollToArticleId(id, true); } } } diff --git a/plugins/mail/mail.js b/plugins/mail/mail.js index 929b35243..1dc383b00 100644 --- a/plugins/mail/mail.js +++ b/plugins/mail/mail.js @@ -1,7 +1,7 @@ function emailArticle(id) { try { if (!id) { - var ids = getSelectedArticleIds2(); + var ids = Headlines.getSelectedArticleIds2(); if (ids.length == 0) { alert(__("No articles are selected.")); diff --git a/plugins/mailto/init.js b/plugins/mailto/init.js index 272b8cea7..a3be90e95 100644 --- a/plugins/mailto/init.js +++ b/plugins/mailto/init.js @@ -1,7 +1,7 @@ function mailtoArticle(id) { try { if (!id) { - const ids = getSelectedArticleIds2(); + const ids = Headlines.getSelectedArticleIds2(); if (ids.length == 0) { alert(__("No articles are selected.")); diff --git a/plugins/mark_button/init.php b/plugins/mark_button/init.php index 2b8fa9242..8f05d1ada 100644 --- a/plugins/mark_button/init.php +++ b/plugins/mark_button/init.php @@ -23,12 +23,12 @@ class Mark_Button extends Plugin { $marked_pic = "\"Unstar"; + onclick='Headlines.toggleMark($id)'>"; } else { $marked_pic = "\"Star"; + onclick='Headlines.toggleMark($id)'>"; } } -- cgit v1.2.3-54-g00ecf From 3678315bead3f7264dc2aa9c7feb6e0a0f20ea63 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sun, 2 Dec 2018 08:32:13 +0300 Subject: Article, Headlines: shorten several method names --- classes/article.php | 2 +- classes/feeds.php | 4 +- js/feedlist.js | 8 +- js/functions.js | 2 +- js/tt-rss.js | 48 +++++----- js/viewfeed.js | 212 ++++++++++++++++++++--------------------- plugins/close_button/init.php | 2 +- plugins/embed_original/init.js | 6 +- plugins/mail/mail.js | 2 +- plugins/mailto/init.js | 2 +- 10 files changed, 144 insertions(+), 144 deletions(-) (limited to 'classes/article.php') diff --git a/classes/article.php b/classes/article.php index 60a956c8d..20febdf3b 100755 --- a/classes/article.php +++ b/classes/article.php @@ -727,7 +727,7 @@ class Article extends Handler_Protected { if (!$zoom_mode) { $rv['content'] .= "$tags_str (+)"; + href=\"#\" onclick=\"Article.editTags($id)\">(+)"; $rv['content'] .= "
"; if ($score > 500) { diff --git a/js/feedlist.js b/js/feedlist.js index 53274b8ba..400328317 100644 --- a/js/feedlist.js +++ b/js/feedlist.js @@ -212,7 +212,7 @@ const Feeds = { Utils.setLoadingProgress(50); document.onkeydown = () => { App.hotkeyHandler(event) }; - window.setInterval(() => { Headlines.catchupBatchedArticles() }, 10 * 1000); + window.setInterval(() => { Headlines.catchupBatched() }, 10 * 1000); if (!this.getActiveFeedId()) { this.viewfeed({feed: -3}); @@ -304,7 +304,7 @@ const Feeds = { if (feed != this.getActiveFeedId() || this.activeFeedIsCat() != is_cat) { this._search_query = false; - Article.setActiveArticleId(0); + Article.setActive(0); } if (offset != 0) { @@ -371,7 +371,7 @@ const Feeds = { window.clearTimeout(this._viewfeed_wait_timeout); this._viewfeed_wait_timeout = window.setTimeout(() => { - Headlines.catchupBatchedArticles(() => { + Headlines.catchupBatched(() => { xhrPost("backend.php", query, (transport) => { try { window.clearTimeout(this._infscroll_timeout); @@ -494,7 +494,7 @@ const Feeds = { rows.each(function (row) { row.removeClassName("Unread"); - if (row.getAttribute("data-article-id") != Article.getActiveArticleId()) { + if (row.getAttribute("data-article-id") != Article.getActive()) { new Effect.Fade(row, {duration: 0.5}); } diff --git a/js/functions.js b/js/functions.js index a4d9893d4..a3b257979 100755 --- a/js/functions.js +++ b/js/functions.js @@ -1454,7 +1454,7 @@ const Filters = { } else { - const query = {op: "rpc", method: "getlinktitlebyid", id: Article.getActiveArticleId()}; + const query = {op: "rpc", method: "getlinktitlebyid", id: Article.getActive()}; xhrPost("backend.php", query, (transport) => { const reply = JSON.parse(transport.responseText); diff --git a/js/tt-rss.js b/js/tt-rss.js index e6dbd1107..8750dcdd2 100644 --- a/js/tt-rss.js +++ b/js/tt-rss.js @@ -90,7 +90,7 @@ const App = { }, initSecondStage: function () { Feeds.reload(); - Article.closeArticlePanel(); + Article.close(); if (parseInt(getCookie("ttrss_fh_width")) > 0) { dijit.byId("feeds-holder").domNode.setStyle( @@ -190,7 +190,7 @@ const App = { switchPanelMode: function(wide) { if (App.isCombinedMode()) return; - const article_id = Article.getActiveArticleId(); + const article_id = Article.getActive(); if (wide) { dijit.byId("headlines-wrap-inner").attr("design", 'sidebar'); @@ -226,7 +226,7 @@ const App = { } - Article.closeArticlePanel(); + Article.close(); if (article_id) Article.view(article_id); @@ -246,22 +246,22 @@ const App = { if (rv) Feeds.viewfeed({feed: rv[0], is_cat: rv[1], delayed: true}) }; this.hotkey_actions["next_article"] = function () { - Headlines.moveToPost('next'); + Headlines.move('next'); }; this.hotkey_actions["prev_article"] = function () { - Headlines.moveToPost('prev'); + Headlines.move('prev'); }; this.hotkey_actions["next_article_noscroll"] = function () { - Headlines.moveToPost('next', true); + Headlines.move('next', true); }; this.hotkey_actions["prev_article_noscroll"] = function () { - Headlines.moveToPost('prev', true); + Headlines.move('prev', true); }; this.hotkey_actions["next_article_noexpand"] = function () { - Headlines.moveToPost('next', true, true); + Headlines.move('next', true, true); }; this.hotkey_actions["prev_article_noexpand"] = function () { - Headlines.moveToPost('prev', true, true); + Headlines.move('prev', true, true); }; this.hotkey_actions["search_dialog"] = function () { Feeds.search(); @@ -276,33 +276,33 @@ const App = { Headlines.selectionToggleUnread({no_error: 1}); }; this.hotkey_actions["edit_tags"] = function () { - const id = Article.getActiveArticleId(); + const id = Article.getActive(); if (id) { - Article.editArticleTags(id); + Article.editTags(id); } }; this.hotkey_actions["open_in_new_window"] = function () { - if (Article.getActiveArticleId()) { - Article.openArticleInNewWindow(Article.getActiveArticleId()); + if (Article.getActive()) { + Article.openInNewWindow(Article.getActive()); } }; this.hotkey_actions["catchup_below"] = function () { - Headlines.catchupRelativeToArticle(1); + Headlines.catchupRelativeTo(1); }; this.hotkey_actions["catchup_above"] = function () { - Headlines.catchupRelativeToArticle(0); + Headlines.catchupRelativeTo(0); }; this.hotkey_actions["article_scroll_down"] = function () { - Article.scrollArticle(40); + Article.scroll(40); }; this.hotkey_actions["article_scroll_up"] = function () { - Article.scrollArticle(-40); + Article.scroll(-40); }; this.hotkey_actions["close_article"] = function () { if (App.isCombinedMode()) { - Article.cdmCollapseActive(); + Article.cdmUnsetActive(); } else { - Article.closeArticlePanel(); + Article.close(); } }; this.hotkey_actions["email_article"] = function () { @@ -368,7 +368,7 @@ const App = { } }; this.hotkey_actions["feed_reverse"] = function () { - Headlines.reverseHeadlineOrder(); + Headlines.reverse(); }; this.hotkey_actions["feed_toggle_vgroup"] = function () { xhrPost("backend.php", {op: "rpc", method: "togglepref", key: "VFEED_GROUP_BY_FEED"}, () => { @@ -402,7 +402,7 @@ const App = { document.location.href = "prefs.php"; }; this.hotkey_actions["select_article_cursor"] = function () { - const id = Article.getArticleUnderPointer(); + const id = Article.getUnderPointer(); if (id) { const row = $("RROW-" + id); @@ -431,8 +431,8 @@ const App = { }; this.hotkey_actions["toggle_embed_original"] = function () { if (typeof embedOriginalArticle != "undefined") { - if (Article.getActiveArticleId()) - embedOriginalArticle(Article.getActiveArticleId()); + if (Article.getActive()) + embedOriginalArticle(Article.getActive()); } else { alert(__("Please enable embed_original plugin first.")); } @@ -462,7 +462,7 @@ const App = { setInitParam("combined_display_mode", !getInitParam("combined_display_mode")); - Article.closeArticlePanel(); + Article.close(); Feeds.viewCurrentFeed(); }) }; diff --git a/js/viewfeed.js b/js/viewfeed.js index a609a65d1..83e943696 100755 --- a/js/viewfeed.js +++ b/js/viewfeed.js @@ -26,8 +26,8 @@ const ArticleCache = { const Article = { _active_article_id: 0, - setSelectionScore: function() { - const ids = Headlines.getSelectedArticleIds2(); + selectionSetScore: function() { + const ids = Headlines.getSelected(); if (ids.length > 0) { console.log(ids); @@ -63,7 +63,7 @@ const Article = { alert(__("No articles are selected.")); } }, - changeScore: function(id, pic) { + setScore: function(id, pic) { const score = pic.getAttribute("score"); const new_score = prompt(__("Please enter new score for this article:"), score); @@ -80,12 +80,30 @@ const Article = { }); } }, - closeArticlePanel: function () { + cdmUnsetActive: function(event) { + const row = $("RROW-" + Article.getActive()); + + if (row) { + row.removeClassName("active"); + const cb = dijit.getEnclosingWidget(row.select(".rchk")[0]); + + if (cb && !row.hasClassName("Selected")) + cb.attr("checked", false); + + Article.setActive(0); + + if (event) + event.stopPropagation(); + + return false; + } + }, + close: function () { if (dijit.byId("content-insert")) dijit.byId("headlines-wrap-inner").removeChild( dijit.byId("content-insert")); }, - displayArticleUrl: function (id) { + displayUrl: function (id) { const query = {op: "rpc", method: "getlinktitlebyid", id: id}; xhrJson("backend.php", query, (reply) => { @@ -94,14 +112,14 @@ const Article = { } }); }, - openArticleInNewWindow: function (id) { + openInNewWindow: function (id) { const w = window.open(""); w.opener = null; w.location = "backend.php?op=article&method=redirect&id=" + id; - Article.setActiveArticleId(id); + Article.setActive(id); }, - renderArticle: function (article) { + render: function (article) { Utils.cleanupMemory("content-insert"); dijit.byId("headlines-wrap-inner").addChild( @@ -117,7 +135,7 @@ const Article = { c.attr('content', article); PluginHost.run(PluginHost.HOOK_ARTICLE_RENDERED, c.domNode); - Headlines.correctHeadlinesOffset(Article.getActiveArticleId()); + Headlines.correctHeadlinesOffset(Article.getActive()); try { c.focus(); @@ -125,7 +143,7 @@ const Article = { } }, view: function(id, noexpand) { - this.setActiveArticleId(id); + this.setActive(id); if (!noexpand) { console.log("loading article", id); @@ -134,7 +152,7 @@ const Article = { /* only request uncached articles */ - this.getRelativePostIds(id).each((n) => { + this.getRelativeIds(id).each((n) => { if (!ArticleCache.get(n)) cids.push(n); }); @@ -143,7 +161,7 @@ const Article = { if (cached_article) { console.log('rendering cached', id); - this.renderArticle(cached_article); + this.render(cached_article); return false; } @@ -154,8 +172,8 @@ const Article = { if (reply) { reply.each(function (article) { - if (Article.getActiveArticleId() == article['id']) { - Article.renderArticle(article['content']); + if (Article.getActive() == article['id']) { + Article.render(article['content']); } ArticleCache.set(article['id'], article['content']); }); @@ -163,7 +181,7 @@ const Article = { } else { console.error("Invalid object received: " + transport.responseText); - Article.renderArticle("
" + + Article.render("
" + __('Could not display article (invalid object received - see error console for details)') + "
"); } @@ -180,25 +198,7 @@ const Article = { return false; }, - cdmCollapseActive: function(event) { - const row = $("RROW-" + Article.getActiveArticleId()); - - if (row) { - row.removeClassName("active"); - const cb = dijit.getEnclosingWidget(row.select(".rchk")[0]); - - if (cb && !row.hasClassName("Selected")) - cb.attr("checked", false); - - Article.setActiveArticleId(0); - - if (event) - event.stopPropagation(); - - return false; - } - }, - editArticleTags: function(id) { + editTags: function(id) { const query = "backend.php?op=article&method=editArticleTags¶m=" + param_escape(id); if (dijit.byId("editTagsDlg")) @@ -247,7 +247,7 @@ const Article = { dialog.show(); }, - cdmScrollToArticleId: function(id, force) { + cdmScrollToId: function(id, force) { const ctr = $("headlines-frame"); const e = $("RROW-" + id); @@ -262,8 +262,8 @@ const Article = { Element.hide("floatingTitle"); } }, - setActiveArticleId: function(id) { - console.log("setActiveArticleId", id); + setActive: function(id) { + console.log("setActive", id); $$("div[id*=RROW][class*=active]").each((e) => { e.removeClassName("active"); @@ -290,7 +290,7 @@ const Article = { if (row.hasClassName("Unread")) { - Headlines.catchupBatchedArticles(() => { + Headlines.catchupBatched(() => { Feeds.decrementFeedCounter(Feeds.getActiveFeedId(), Feeds.activeFeedIsCat()); Headlines.toggleUnread(id, 0); Headlines.updateFloatingTitle(true); @@ -310,10 +310,10 @@ const Article = { Headlines.updateSelectedPrompt(); }, - getActiveArticleId: function() { + getActive: function() { return this._active_article_id; }, - scrollArticle: function(offset) { + scroll: function(offset) { if (!App.isCombinedMode()) { const ci = $("content-insert"); if (ci) { @@ -327,13 +327,13 @@ const Article = { } }, - getRelativePostIds: function(id, limit) { + getRelativeIds: function(id, limit) { const tmp = []; if (!limit) limit = 6; //3 - const ids = Headlines.getLoadedArticleIds(); + const ids = Headlines.getLoaded(); for (let i = 0; i < ids.length; i++) { if (ids[i] == id) { @@ -353,7 +353,7 @@ const Article = { mouseOut: function(id) { this.post_under_pointer = false; }, - getArticleUnderPointer: function() { + getUnderPointer: function() { return this.post_under_pointer; } }; @@ -369,21 +369,21 @@ const Headlines = { if (App.isCombinedMode()) { - if (!in_body && (event.ctrlKey || id == Article.getActiveArticleId() || getInitParam("cdm_expanded"))) { - Article.openArticleInNewWindow(id); + if (!in_body && (event.ctrlKey || id == Article.getActive() || getInitParam("cdm_expanded"))) { + Article.openInNewWindow(id); } - Article.setActiveArticleId(id); + Article.setActive(id); if (!getInitParam("cdm_expanded")) - Article.cdmScrollToArticleId(id); + Article.cdmScrollToId(id); return in_body; } else { if (event.ctrlKey) { - Article.openArticleInNewWindow(id); - Article.setActiveArticleId(id); + Article.openInNewWindow(id); + Article.setActive(id); } else { Article.view(id); } @@ -400,7 +400,7 @@ const Headlines = { }, 50); } }, - loadMoreHeadlines: function() { + loadMore: function() { const view_mode = document.forms["main_toolbar_form"].view_mode.value; const unread_in_buffer = $$("#headlines-frame > div[id*=RROW][class*=Unread]").length; const num_all = $$("#headlines-frame > div[id*=RROW]").length; @@ -413,7 +413,7 @@ const Headlines = { switch (view_mode) { case "marked": case "published": - console.warn("loadMoreHeadlines: ", view_mode, "not implemented"); + console.warn("loadMore: ", view_mode, "not implemented"); break; case "unread": offset = unread_in_buffer; @@ -424,13 +424,13 @@ const Headlines = { break; } - console.log("loadMoreHeadlines, offset=", offset); + console.log("loadMore, offset=", offset); Feeds.viewfeed({feed: Feeds.getActiveFeedId(), is_cat: Feeds.activeFeedIsCat(), offset: offset}); }, scrollHandler: function() { try { - Headlines.unpackVisibleArticles(); + Headlines.unpackVisible(); if (App.isCombinedMode()) { Headlines.updateFloatingTitle(); @@ -447,9 +447,9 @@ const Headlines = { if ($("headlines-frame").scrollTop <= row.offsetTop && row.offsetTop - $("headlines-frame").scrollTop < 100 && - row.getAttribute("data-article-id") != Article.getActiveArticleId()) { + row.getAttribute("data-article-id") != Article.getActive()) { - Article.setActiveArticleId(row.getAttribute("data-article-id")); + Article.setActive(row.getAttribute("data-article-id")); break; } } @@ -465,7 +465,7 @@ const Headlines = { hsp.innerHTML = " " + __("Loading, please wait...") + ""; - Headlines.loadMoreHeadlines(); + Headlines.loadMore(); return; } } @@ -527,7 +527,7 @@ const Headlines = { ft.setAttribute("data-article-id", id); ft.innerHTML = header.innerHTML; ft.firstChild.innerHTML = "" + ft.firstChild.innerHTML; + "onclick=\"Article.cdmScrollToId(" + id + ", true)\">" + ft.firstChild.innerHTML; this.initFloatingMenu(); @@ -557,7 +557,7 @@ const Headlines = { } } }, - unpackVisibleArticles: function() { + unpackVisible: function() { if (!App.isCombinedMode() || !getInitParam("cdm_expanded")) return; const rows = $$("#headlines-frame div[id*=RROW][data-content]"); @@ -665,7 +665,7 @@ const Headlines = { } else if (headlines_count > 0 && feed_id == Feeds.getActiveFeedId() && is_cat == Feeds.activeFeedIsCat()) { const c = dijit.byId("headlines-frame"); - //const ids = Headlines.getSelectedArticleIds2(); + //const ids = Headlines.getSelected(); let hsp = $("headlines-spacer"); @@ -740,7 +740,7 @@ const Headlines = { notify(""); }, - reverseHeadlineOrder: function() { + reverse: function() { const toolbar = document.forms["main_toolbar_form"]; const order_by = dijit.getEnclosingWidget(toolbar.order_by); @@ -761,7 +761,7 @@ const Headlines = { const cmode = params.cmode || 2; const callback = params.callback; const no_error = params.no_error || false; - const ids = params.ids || Headlines.getSelectedArticleIds2(); + const ids = params.ids || Headlines.getSelected(); if (ids.length == 0) { if (!no_error) @@ -800,7 +800,7 @@ const Headlines = { }); }, selectionToggleMarked: function(ids) { - const rows = ids || Headlines.getSelectedArticleIds2(); + const rows = ids || Headlines.getSelected(); if (rows.length == 0) { alert(__("No articles are selected.")); @@ -821,7 +821,7 @@ const Headlines = { }); }, selectionTogglePublished: function(ids) { - const rows = ids || Headlines.getSelectedArticleIds2(); + const rows = ids || Headlines.getSelected(); if (rows.length == 0) { alert(__("No articles are selected.")); @@ -895,28 +895,28 @@ const Headlines = { } }, - moveToPost: function(mode, noscroll, noexpand) { - const rows = Headlines.getLoadedArticleIds(); + move: function(mode, noscroll, noexpand) { + const rows = Headlines.getLoaded(); let prev_id = false; let next_id = false; - if (!$('RROW-' + Article.getActiveArticleId())) { - Article.setActiveArticleId(0); + if (!$('RROW-' + Article.getActive())) { + Article.setActive(0); } - if (!Article.getActiveArticleId()) { + if (!Article.getActive()) { next_id = rows[0]; prev_id = rows[rows.length - 1] } else { for (let i = 0; i < rows.length; i++) { - if (rows[i] == Article.getActiveArticleId()) { + if (rows[i] == Article.getActive()) { // Account for adjacent identical article ids. if (i > 0) prev_id = rows[i - 1]; for (let j = i + 1; j < rows.length; j++) { - if (rows[j] != Article.getActiveArticleId()) { + if (rows[j] != Article.getActive()) { next_id = rows[j]; break; } @@ -926,23 +926,23 @@ const Headlines = { } } - console.log("cur: " + Article.getActiveArticleId() + " next: " + next_id); + console.log("cur: " + Article.getActive() + " next: " + next_id); if (mode == "next") { - if (next_id || Article.getActiveArticleId()) { + if (next_id || Article.getActive()) { if (App.isCombinedMode()) { - const article = $("RROW-" + Article.getActiveArticleId()); + const article = $("RROW-" + Article.getActive()); const ctr = $("headlines-frame"); if (!noscroll && article && article.offsetTop + article.offsetHeight > ctr.scrollTop + ctr.offsetHeight) { - Article.scrollArticle(ctr.offsetHeight / 4); + Article.scroll(ctr.offsetHeight / 4); } else if (next_id) { - Article.setActiveArticleId(next_id); - Article.cdmScrollToArticleId(next_id, true); + Article.setActive(next_id); + Article.cdmScrollToId(next_id, true); } } else if (next_id) { @@ -953,21 +953,21 @@ const Headlines = { } if (mode == "prev") { - if (prev_id || Article.getActiveArticleId()) { + if (prev_id || Article.getActive()) { if (App.isCombinedMode()) { - const article = $("RROW-" + Article.getActiveArticleId()); + const article = $("RROW-" + Article.getActive()); const prev_article = $("RROW-" + prev_id); const ctr = $("headlines-frame"); if (!noscroll && article && article.offsetTop < ctr.scrollTop) { - Article.scrollArticle(-ctr.offsetHeight / 3); + Article.scroll(-ctr.offsetHeight / 3); } else if (!noscroll && prev_article && prev_article.offsetTop < ctr.scrollTop) { - Article.scrollArticle(-ctr.offsetHeight / 4); + Article.scroll(-ctr.offsetHeight / 4); } else if (prev_id) { - Article.setActiveArticleId(prev_id); - Article.cdmScrollToArticleId(prev_id, noscroll); + Article.setActive(prev_id); + Article.cdmScrollToId(prev_id, noscroll); } } else if (prev_id) { @@ -978,7 +978,7 @@ const Headlines = { } }, updateSelectedPrompt: function() { - const count = Headlines.getSelectedArticleIds2().length; + const count = Headlines.getSelected().length; const elem = $("selected_prompt"); if (elem) { @@ -1016,7 +1016,7 @@ const Headlines = { } }, selectionRemoveLabel: function(id, ids) { - if (!ids) ids = Headlines.getSelectedArticleIds2(); + if (!ids) ids = Headlines.getSelected(); if (ids.length == 0) { alert(__("No articles are selected.")); @@ -1034,7 +1034,7 @@ const Headlines = { }); }, selectionAssignLabel: function(id, ids) { - if (!ids) ids = Headlines.getSelectedArticleIds2(); + if (!ids) ids = Headlines.getSelected(); if (ids.length == 0) { alert(__("No articles are selected.")); @@ -1052,7 +1052,7 @@ const Headlines = { }); }, deleteSelection: function() { - const rows = Headlines.getSelectedArticleIds2(); + const rows = Headlines.getSelected(); if (rows.length == 0) { alert(__("No articles are selected.")); @@ -1082,7 +1082,7 @@ const Headlines = { Feeds.viewCurrentFeed(); }); }, - getSelectedArticleIds2: function() { + getSelected: function() { const rv = []; $$("#headlines-frame > div[id*=RROW][class*=Selected]").each( @@ -1091,12 +1091,12 @@ const Headlines = { }); // consider active article a honorary member of selected articles - if (Article.getActiveArticleId()) - rv.push(Article.getActiveArticleId()); + if (Article.getActive()) + rv.push(Article.getActive()); return rv.uniq(); }, - getLoadedArticleIds: function() { + getLoaded: function() { const rv = []; const children = $$("#headlines-frame > div[id*=RROW-]"); @@ -1164,7 +1164,7 @@ const Headlines = { } }, archiveSelection: function() { - const rows = Headlines.getSelectedArticleIds2(); + const rows = Headlines.getSelected(); if (rows.length == 0) { alert(__("No articles are selected.")); @@ -1204,7 +1204,7 @@ const Headlines = { }); }, catchupSelection: function() { - const rows = Headlines.getSelectedArticleIds2(); + const rows = Headlines.getSelected(); if (rows.length == 0) { alert(__("No articles are selected.")); @@ -1224,8 +1224,8 @@ const Headlines = { Headlines.selectionToggleUnread({callback: Feeds.viewCurrentFeed, no_error: 1}); }, - catchupBatchedArticles: function(callback) { - console.log("catchupBatchedArticles, size=", this.catchup_id_batch.length); + catchupBatched: function(callback) { + console.log("catchupBatched, size=", this.catchup_id_batch.length); if (this.catchup_id_batch.length > 0) { @@ -1257,16 +1257,16 @@ const Headlines = { if (callback) callback(); } }, - catchupRelativeToArticle: function(below, id) { + catchupRelativeTo: function(below, id) { - if (!id) id = Article.getActiveArticleId(); + if (!id) id = Article.getActive(); if (!id) { alert(__("No article is selected.")); return; } - const visible_ids = this.getLoadedArticleIds(); + const visible_ids = this.getLoaded(); const ids_to_mark = []; @@ -1372,14 +1372,14 @@ const Headlines = { menu.addChild(new dijit.MenuItem({ label: __("Open original article"), onClick: function (event) { - Article.openArticleInNewWindow(this.getParent().currentTarget.getAttribute("data-article-id")); + Article.openInNewWindow(this.getParent().currentTarget.getAttribute("data-article-id")); } })); menu.addChild(new dijit.MenuItem({ label: __("Display article URL"), onClick: function (event) { - Article.displayArticleUrl(this.getParent().currentTarget.getAttribute("data-article-id")); + Article.displayUrl(this.getParent().currentTarget.getAttribute("data-article-id")); } })); @@ -1389,7 +1389,7 @@ const Headlines = { label: __("Toggle unread"), onClick: function () { - let ids = Headlines.getSelectedArticleIds2(); + let ids = Headlines.getSelected(); // cast to string const id = (this.getParent().currentTarget.getAttribute("data-article-id")) + ""; ids = ids.length != 0 && ids.indexOf(id) != -1 ? ids : [id]; @@ -1401,7 +1401,7 @@ const Headlines = { menu.addChild(new dijit.MenuItem({ label: __("Toggle starred"), onClick: function () { - let ids = Headlines.getSelectedArticleIds2(); + let ids = Headlines.getSelected(); // cast to string const id = (this.getParent().currentTarget.getAttribute("data-article-id")) + ""; ids = ids.length != 0 && ids.indexOf(id) != -1 ? ids : [id]; @@ -1413,7 +1413,7 @@ const Headlines = { menu.addChild(new dijit.MenuItem({ label: __("Toggle published"), onClick: function () { - let ids = Headlines.getSelectedArticleIds2(); + let ids = Headlines.getSelected(); // cast to string const id = (this.getParent().currentTarget.getAttribute("data-article-id")) + ""; ids = ids.length != 0 && ids.indexOf(id) != -1 ? ids : [id]; @@ -1427,14 +1427,14 @@ const Headlines = { menu.addChild(new dijit.MenuItem({ label: __("Mark above as read"), onClick: function () { - Headlines.catchupRelativeToArticle(0, this.getParent().currentTarget.getAttribute("data-article-id")); + Headlines.catchupRelativeTo(0, this.getParent().currentTarget.getAttribute("data-article-id")); } })); menu.addChild(new dijit.MenuItem({ label: __("Mark below as read"), onClick: function () { - Headlines.catchupRelativeToArticle(1, this.getParent().currentTarget.getAttribute("data-article-id")); + Headlines.catchupRelativeTo(1, this.getParent().currentTarget.getAttribute("data-article-id")); } })); @@ -1457,7 +1457,7 @@ const Headlines = { labelId: bare_id, onClick: function () { - let ids = Headlines.getSelectedArticleIds2(); + let ids = Headlines.getSelected(); // cast to string const id = (this.getParent().ownerMenu.currentTarget.getAttribute("data-article-id")) + ""; @@ -1471,7 +1471,7 @@ const Headlines = { label: name, labelId: bare_id, onClick: function () { - let ids = Headlines.getSelectedArticleIds2(); + let ids = Headlines.getSelected(); // cast to string const id = (this.getParent().ownerMenu.currentTarget.getAttribute("data-article-id")) + ""; diff --git a/plugins/close_button/init.php b/plugins/close_button/init.php index 62f8780c4..8678d577c 100644 --- a/plugins/close_button/init.php +++ b/plugins/close_button/init.php @@ -21,7 +21,7 @@ class Close_Button extends Plugin { if (!get_pref("COMBINED_DISPLAY_MODE")) { $rv = ""; } diff --git a/plugins/embed_original/init.js b/plugins/embed_original/init.js index 95a5ef9e5..6f797556b 100644 --- a/plugins/embed_original/init.js +++ b/plugins/embed_original/init.js @@ -11,7 +11,7 @@ function embedOriginalArticle(id) { if (App.isCombinedMode()) { c = $$("div#RROW-" + id + " div[class=content-inner]")[0]; - } else if (id == Article.getActiveArticleId()) { + } else if (id == Article.getActive()) { c = $$(".post .content")[0]; } @@ -23,7 +23,7 @@ function embedOriginalArticle(id) { c.parentNode.removeChild(iframe); if (App.isCombinedMode()) { - Article.cdmScrollToArticleId(id, true); + Article.cdmScrollToId(id, true); } return; @@ -48,7 +48,7 @@ function embedOriginalArticle(id) { c.parentNode.insertBefore(iframe, c); if (App.isCombinedMode()) { - Article.cdmScrollToArticleId(id, true); + Article.cdmScrollToId(id, true); } } } diff --git a/plugins/mail/mail.js b/plugins/mail/mail.js index 1dc383b00..538970fc3 100644 --- a/plugins/mail/mail.js +++ b/plugins/mail/mail.js @@ -1,7 +1,7 @@ function emailArticle(id) { try { if (!id) { - var ids = Headlines.getSelectedArticleIds2(); + var ids = Headlines.getSelected(); if (ids.length == 0) { alert(__("No articles are selected.")); diff --git a/plugins/mailto/init.js b/plugins/mailto/init.js index a3be90e95..6b8520928 100644 --- a/plugins/mailto/init.js +++ b/plugins/mailto/init.js @@ -1,7 +1,7 @@ function mailtoArticle(id) { try { if (!id) { - const ids = Headlines.getSelectedArticleIds2(); + const ids = Headlines.getSelected(); if (ids.length == 0) { alert(__("No articles are selected.")); -- cgit v1.2.3-54-g00ecf From 0a18d0b1edb208e5811c419a1119d131b7041173 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sun, 2 Dec 2018 08:57:22 +0300 Subject: Feeds: shorten some method names finally rename "view as rss" --- classes/article.php | 2 +- classes/dlg.php | 2 +- classes/feeds.php | 19 ++++--- classes/pref/feeds.php | 2 +- index.php | 8 +-- js/feedlist.js | 122 ++++++++++++++++++++-------------------- js/functions.js | 18 +++--- js/tt-rss.js | 70 +++++++++++------------ js/viewfeed.js | 40 ++++++------- plugins/af_psql_trgm/init.php | 2 +- plugins/toggle_sidebar/init.php | 2 +- 11 files changed, 144 insertions(+), 143 deletions(-) (limited to 'classes/article.php') diff --git a/classes/article.php b/classes/article.php index 20febdf3b..282748ed1 100755 --- a/classes/article.php +++ b/classes/article.php @@ -877,7 +877,7 @@ class Article extends Handler_Protected { $tags_str = ""; for ($i = 0; $i < $maxtags; $i++) { - $tags_str .= "" . $tags[$i] . ", "; + $tags_str .= "" . $tags[$i] . ", "; } $tags_str = mb_substr($tags_str, 0, mb_strlen($tags_str)-2); diff --git a/classes/dlg.php b/classes/dlg.php index 02249ea96..aa695ee18 100644 --- a/classes/dlg.php +++ b/classes/dlg.php @@ -139,7 +139,7 @@ class Dlg extends Handler_Protected { $key_escaped = str_replace("'", "\\'", $key); - echo "' . $key . ' '; } diff --git a/classes/feeds.php b/classes/feeds.php index 647414609..c9e5ca496 100755 --- a/classes/feeds.php +++ b/classes/feeds.php @@ -50,8 +50,8 @@ class Feeds extends Handler_Protected { $reply .= " + title=\"".__("Show as feed")."\" + onclick=\"Utils.displayDlg('".__("Show as feed")."','generatedFeed', '$feed_id:$is_cat:$rss_link')\"> "; @@ -137,7 +137,8 @@ class Feeds extends Handler_Protected { //$reply .= ""; - $reply .= ""; + $reply .= ""; $reply .= ""; @@ -392,7 +393,7 @@ class Feeds extends Handler_Protected { $reply['content'] .= "
". "
$feed_icon_img
". - "". + "". $line["feed_title"]." $vf_catchup_link
"; @@ -434,7 +435,7 @@ class Feeds extends Handler_Protected { if (@$line["feed_title"]) { $rgba = @$rgba_cache[$feed_id]; - $reply['content'] .= "". + $reply['content'] .= "". truncate_string($line["feed_title"],30).""; } } @@ -451,7 +452,7 @@ class Feeds extends Handler_Protected { if ($line["feed_title"] && !$vfeed_group_enabled) { - $reply['content'] .= " $feed_icon_img"; @@ -488,7 +489,7 @@ class Feeds extends Handler_Protected { $reply['content'] .= "
". "
$feed_icon_img
". - "". + "". $line["feed_title"]." $vf_catchup_link
"; } @@ -547,7 +548,7 @@ class Feeds extends Handler_Protected { $tmp_content .= ""; } @@ -561,7 +562,7 @@ class Feeds extends Handler_Protected { if (!get_pref("VFEED_GROUP_BY_FEED") && $line["feed_title"]) { $tmp_content .= "$feed_icon_img"; + onclick=\"Feeds.open({feed:$feed_id})\">$feed_icon_img
"; } $tmp_content .= "
"; //score wrapper2 diff --git a/classes/pref/feeds.php b/classes/pref/feeds.php index 2184a0b42..f47d24501 100755 --- a/classes/pref/feeds.php +++ b/classes/pref/feeds.php @@ -1323,7 +1323,7 @@ class Pref_Feeds extends Handler_Protected { print "

"; - print " "; print " -- cgit v1.2.3-54-g00ecf From 78cc470193448048759b3f315ee630e50acb064b Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Mon, 3 Dec 2018 10:51:14 +0300 Subject: remove some plugin JS code out of global context --- classes/article.php | 4 ++-- js/prefs.js | 2 ++ js/tt-rss.js | 2 ++ plugins/af_psql_trgm/init.js | 12 ++++-------- plugins/af_psql_trgm/init.php | 2 +- plugins/note/init.php | 2 +- plugins/note/note.js | 43 +++++++++++++++++++------------------------ plugins/share/init.php | 4 ++-- plugins/share/share.js | 25 ++++++++++++------------- plugins/share/share_prefs.js | 25 ++++++++++++------------- 10 files changed, 57 insertions(+), 64 deletions(-) (limited to 'classes/article.php') diff --git a/classes/article.php b/classes/article.php index 282748ed1..248dcdb9e 100755 --- a/classes/article.php +++ b/classes/article.php @@ -907,8 +907,8 @@ class Article extends Handler_Protected { static function format_article_note($id, $note, $allow_edit = true) { - $str = "

-
". + $str = "
+
". ($allow_edit ? __('(edit note)') : "")."
$note
"; return $str; diff --git a/js/prefs.js b/js/prefs.js index ea5d847a9..edb11bc7d 100755 --- a/js/prefs.js +++ b/js/prefs.js @@ -7,6 +7,8 @@ let Filters; let Users; let Prefs; +const Plugins = {}; + require(["dojo/_base/kernel", "dojo/_base/declare", "dojo/ready", diff --git a/js/tt-rss.js b/js/tt-rss.js index 78ef10067..3c6fd88dc 100644 --- a/js/tt-rss.js +++ b/js/tt-rss.js @@ -10,6 +10,8 @@ let Article; let ArticleCache; let PluginHost; +const Plugins = {}; + require(["dojo/_base/kernel", "dojo/_base/declare", "dojo/ready", diff --git a/plugins/af_psql_trgm/init.js b/plugins/af_psql_trgm/init.js index af2facfc1..af337ca6b 100644 --- a/plugins/af_psql_trgm/init.js +++ b/plugins/af_psql_trgm/init.js @@ -1,6 +1,5 @@ -function showTrgmRelated(id) { - try { - +Plugins.Psql_Trgm = { + showRelated: function (id) { const query = "backend.php?op=pluginhandler&plugin=af_psql_trgm&method=showrelated¶m=" + encodeURIComponent(id); if (dijit.byId("trgmRelatedDlg")) @@ -10,16 +9,13 @@ function showTrgmRelated(id) { id: "trgmRelatedDlg", title: __("Related articles"), style: "width: 600px", - execute: function() { + execute: function () { }, href: query, }); dialog.show(); - - } catch (e) { - exception_error("showTrgmRelated", e); } -} +}; diff --git a/plugins/af_psql_trgm/init.php b/plugins/af_psql_trgm/init.php index 514f5731a..57ad355f9 100644 --- a/plugins/af_psql_trgm/init.php +++ b/plugins/af_psql_trgm/init.php @@ -115,7 +115,7 @@ class Af_Psql_Trgm extends Plugin { function hook_article_button($line) { return ""; } diff --git a/plugins/note/init.php b/plugins/note/init.php index 354591b75..ac908a5ba 100644 --- a/plugins/note/init.php +++ b/plugins/note/init.php @@ -24,7 +24,7 @@ class Note extends Plugin { function hook_article_button($line) { return ""; } diff --git a/plugins/note/note.js b/plugins/note/note.js index 836481c40..21c1ae51e 100644 --- a/plugins/note/note.js +++ b/plugins/note/note.js @@ -1,46 +1,41 @@ -function editArticleNote(id) { - try { - - var query = "backend.php?op=pluginhandler&plugin=note&method=edit¶m=" + encodeURIComponent(id); +Plugins.Note = { + edit: function(id) { + const query = "backend.php?op=pluginhandler&plugin=note&method=edit¶m=" + encodeURIComponent(id); if (dijit.byId("editNoteDlg")) dijit.byId("editNoteDlg").destroyRecursive(); - dialog = new dijit.Dialog({ + const dialog = new dijit.Dialog({ id: "editNoteDlg", title: __("Edit article note"), style: "width: 600px", - execute: function() { + execute: function () { if (this.validate()) { Notify.progress("Saving article note...", true); xhrJson("backend.php", this.attr('value'), (reply) => { - Notify.close(); - dialog.hide(); + Notify.close(); + dialog.hide(); - if (reply) { - ArticleCache.del(id); + if (reply) { + ArticleCache.del(id); - var elem = $("POSTNOTE-" + id); + var elem = $("POSTNOTE-" + id); - if (elem) { - Element.hide(elem); - elem.innerHTML = reply.note; + if (elem) { + Element.hide(elem); + elem.innerHTML = reply.note; - if (reply.raw_length != 0) - new Effect.Appear(elem); - } - } - }); + if (reply.raw_length != 0) + new Effect.Appear(elem); + } + } + }); } }, href: query, }); dialog.show(); - - } catch (e) { - exception_error("editArticleNote", e); } -} - +}; \ No newline at end of file diff --git a/plugins/share/init.php b/plugins/share/init.php index 94571bb1b..6ac08b751 100644 --- a/plugins/share/init.php +++ b/plugins/share/init.php @@ -40,7 +40,7 @@ class Share extends Plugin { print "

" . __("You can disable all articles shared by unique URLs here.") . "

"; - print " "; print "

"; @@ -74,7 +74,7 @@ class Share extends Plugin { return ""; } diff --git a/plugins/share/share.js b/plugins/share/share.js index a22e01715..7366c2aff 100644 --- a/plugins/share/share.js +++ b/plugins/share/share.js @@ -1,20 +1,20 @@ -function shareArticle(id) { - try { +Plugins.Share = { + shareArticle: function(id) { if (dijit.byId("shareArticleDlg")) dijit.byId("shareArticleDlg").destroyRecursive(); - var query = "backend.php?op=pluginhandler&plugin=share&method=shareArticle¶m=" + encodeURIComponent(id); + const query = "backend.php?op=pluginhandler&plugin=share&method=shareArticle¶m=" + encodeURIComponent(id); - dialog = new dijit.Dialog({ + const dialog = new dijit.Dialog({ id: "shareArticleDlg", title: __("Share article by URL"), style: "width: 600px", - newurl: function() { + newurl: function () { if (confirm(__("Generate new share URL for this article?"))) { Notify.progress("Trying to change URL...", true); - const query = { op: "pluginhandler", plugin: "share", method: "newkey", id: id }; + const query = {op: "pluginhandler", plugin: "share", method: "newkey", id: id}; xhrJson("backend.php", query, (reply) => { if (reply) { @@ -44,12 +44,12 @@ function shareArticle(id) { } }, - unshare: function() { + unshare: function () { if (confirm(__("Remove sharing for this article?"))) { Notify.progress("Trying to unshare...", true); - const query = { op: "pluginhandler", plugin: "share", method: "unshare", id: id }; + const query = {op: "pluginhandler", plugin: "share", method: "unshare", id: id}; xhrPost("backend.php", query, () => { notify("Article unshared."); @@ -62,16 +62,15 @@ function shareArticle(id) { } }, - href: query}); + href: query + }); dialog.show(); const img = $("SHARE-IMG-" + id); if (img) img.src = img.src.replace("notshared.png", "share.png"); - - } catch (e) { - exception_error("shareArticle", e); } -} +}; + diff --git a/plugins/share/share_prefs.js b/plugins/share/share_prefs.js index 92975f8f4..071a6667c 100644 --- a/plugins/share/share_prefs.js +++ b/plugins/share/share_prefs.js @@ -1,16 +1,15 @@ -function clearArticleAccessKeys() { - if (confirm(__("This will invalidate all previously shared article URLs. Continue?"))) { - Notify.progress("Clearing URLs..."); - - const query = { op: "pluginhandler", plugin: "share", method: "clearArticleKeys" }; - - xhrPost("backend.php", query, () => { - Notify.info("Shared URLs cleared."); - }); - } - - return false; -} +Plugins.Share = { + clearKeys: function() { + if (confirm(__("This will invalidate all previously shared article URLs. Continue?"))) { + Notify.progress("Clearing URLs..."); + const query = {op: "pluginhandler", plugin: "share", method: "clearArticleKeys"}; + xhrPost("backend.php", query, () => { + Notify.info("Shared URLs cleared."); + }); + } + return false; + } +}; -- cgit v1.2.3-54-g00ecf