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 --- plugins/embed_original/init.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'plugins/embed_original') diff --git a/plugins/embed_original/init.js b/plugins/embed_original/init.js index 3c48b507e..d0731d5d1 100644 --- a/plugins/embed_original/init.js +++ b/plugins/embed_original/init.js @@ -9,7 +9,7 @@ function embedOriginalArticle(id) { let c = false; - if (isCombinedMode()) { + if (App.isCombinedMode()) { c = $$("div#RROW-" + id + " div[class=content-inner]")[0]; } else if (id == getActiveArticleId()) { c = $$(".post .content")[0]; @@ -22,7 +22,7 @@ function embedOriginalArticle(id) { Element.show(c); c.parentNode.removeChild(iframe); - if (isCombinedMode()) { + if (App.isCombinedMode()) { cdmScrollToArticleId(id, true); } @@ -47,7 +47,7 @@ function embedOriginalArticle(id) { Element.hide(c); c.parentNode.insertBefore(iframe, c); - if (isCombinedMode()) { + if (App.isCombinedMode()) { cdmScrollToArticleId(id, true); } } -- 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 'plugins/embed_original') 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 'plugins/embed_original') 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 71fc6d45bd761a9d2715faa68f2b8c0271ee7169 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Mon, 3 Dec 2018 13:38:13 +0300 Subject: refactor error reporting to AppBase; keep exception_error() for now as a shim --- include/login_form.php | 41 +++++----------- js/AppBase.js | 70 +++++++++++++++++++++++++-- js/Article.js | 4 +- js/CommonDialogs.js | 2 +- js/CommonFilters.js | 6 +-- js/FeedTree.js | 4 +- js/Feeds.js | 6 +-- js/common.js | 75 ++++------------------------- js/prefs.js | 8 +--- js/tt-rss.js | 8 +--- plugins/embed_original/init.js | 86 ++++++++++++++++------------------ plugins/import_export/import_export.js | 6 +-- plugins/mail/mail.js | 83 +++++++++++++++----------------- plugins/mailto/init.js | 37 +++++++-------- plugins/nsfw/init.js | 11 ++--- plugins/shorten_expanded/init.js | 22 +++------ register.php | 6 +-- 17 files changed, 215 insertions(+), 260 deletions(-) (limited to 'plugins/embed_original') diff --git a/include/login_form.php b/include/login_form.php index 1eb5d26d4..cdf70803b 100644 --- a/include/login_form.php +++ b/include/login_form.php @@ -42,41 +42,26 @@ require(['dojo/parser', "dojo/ready", 'dijit/form/Button','dijit/form/CheckBox', }); function fetchProfiles() { - try { - var query = "op=getProfiles&login=" + encodeURIComponent(document.forms["loginForm"].login.value); - - if (query) { - new Ajax.Request("public.php", { - parameters: query, - onComplete: function(transport) { - if (transport.responseText.match("select")) { - $('profile_box').innerHTML = transport.responseText; - //dojo.parser.parse('profile_box'); - } - } }); - } - - } catch (e) { - exception_error("fetchProfiles", e); - } + const query = "op=getProfiles&login=" + encodeURIComponent(document.forms["loginForm"].login.value); + + new Ajax.Request("public.php", { + parameters: query, + onComplete: function(transport) { + if (transport.responseText.match("select")) { + $('profile_box').innerHTML = transport.responseText; + //dojo.parser.parse('profile_box'); + } + } }); } - function gotoRegForm() { window.location.href = "register.php"; return false; } function bwLimitChange(elem) { - try { - var limit_set = elem.checked; - - setCookie("ttrss_bwlimit", limit_set, - ); - - } catch (e) { - exception_error("bwLimitChange", e); - } + Cookie.set("ttrss_bwlimit", elem.checked, + ); } @@ -139,7 +124,7 @@ function bwLimitChange(elem) {
- +
0) { ?> diff --git a/js/AppBase.js b/js/AppBase.js index ce040e8c9..9ab2f507e 100644 --- a/js/AppBase.js +++ b/js/AppBase.js @@ -7,15 +7,15 @@ define(["dojo/_base/declare"], function (declare) { hotkey_prefix: 0, hotkey_prefix_pressed: false, hotkey_prefix_timeout: 0, + constructor: function() { + window.onerror = this.Error.onWindowError; + }, getInitParam: function(k) { return this._initParams[k]; }, setInitParam: function(k, v) { this._initParams[k] = v; }, - constructor: function(args) { - // - }, enableCsrfSupport: function() { Ajax.Base.prototype.initialize = Ajax.Base.prototype.initialize.wrap( function (callOriginal, options) { @@ -176,7 +176,7 @@ define(["dojo/_base/declare"], function (declare) { if (callback) callback(transport); } catch (e) { - exception_error(e); + this.Error.report(e); } }); @@ -355,5 +355,67 @@ define(["dojo/_base/declare"], function (declare) { explainError: function(code) { return this.displayDlg(__("Error explained"), "explainError", code); }, + Error: { + report: function(error, params) { + params = params || {}; + + if (!error) return; + + console.error("[Error.report]", error, params); + + const message = params.message ? params.message : error.toString(); + + try { + xhrPost("backend.php", + {op: "rpc", method: "log", + file: params.filename ? params.filename : error.fileName, + line: params.lineno ? params.lineno : error.lineNumber, + msg: message, + context: error.stack}, + (transport) => { + console.warn("[Error.report] log response", transport.responseText); + }); + } catch (re) { + console.error("[Error.report] exception while saving logging error on server", re); + } + + try { + if (dijit.byId("exceptionDlg")) + dijit.byId("exceptionDlg").destroyRecursive(); + + let content = "

" + message + "

"; + + if (error.stack) + content += "
Stack trace:
" + + ""; + + content += "
"; + + content += ""; + content += "
"; + + const dialog = new dijit.Dialog({ + id: "exceptionDlg", + title: "Unhandled exception", + style: "width: 600px", + content: content + }); + + dialog.show(); + } catch (de) { + console.error("[Error.report] exception while showing error dialog", de); + + alert(error.stack ? error.stack : message); + } + + }, + onWindowError: function (message, filename, lineno, colno, error) { + // called without context (this) from window.onerror + App.Error.report(error, + {message: message, filename: filename, lineno: lineno, colno: colno}); + }, + } }); }); diff --git a/js/Article.js b/js/Article.js index d3ae8eed7..04cba8ab7 100644 --- a/js/Article.js +++ b/js/Article.js @@ -168,7 +168,7 @@ define(["dojo/_base/declare"], function (declare) { Notify.close(); } catch (e) { - exception_error(e); + App.Error.report(e); } }) } @@ -206,7 +206,7 @@ define(["dojo/_base/declare"], function (declare) { if (tooltip) tooltip.attr('label', data.content_full); } } catch (e) { - exception_error(e); + App.Error.report(e); } }); } diff --git a/js/CommonDialogs.js b/js/CommonDialogs.js index b9cee8873..81ad2ffce 100644 --- a/js/CommonDialogs.js +++ b/js/CommonDialogs.js @@ -152,7 +152,7 @@ define(["dojo/_base/declare"], function (declare) { } catch (e) { console.error(transport.responseText); - exception_error(e); + App.Error.report(e); } }); } diff --git a/js/CommonFilters.js b/js/CommonFilters.js index d2a3e6317..97a676c98 100644 --- a/js/CommonFilters.js +++ b/js/CommonFilters.js @@ -67,7 +67,7 @@ define(["dojo/_base/declare"], function (declare) { parentNode.appendChild(li); } } catch (e) { - exception_error(e); + App.Error.report(e); } }); }, @@ -117,7 +117,7 @@ define(["dojo/_base/declare"], function (declare) { } } catch (e) { - exception_error(e); + App.Error.report(e); } }); }, @@ -238,7 +238,7 @@ define(["dojo/_base/declare"], function (declare) { console.log("getTestResults: dialog closed, bailing out."); } } catch (e) { - exception_error(e); + App.Error.report(e); } }); diff --git a/js/FeedTree.js b/js/FeedTree.js index 37e3de2d1..75d1c901b 100755 --- a/js/FeedTree.js +++ b/js/FeedTree.js @@ -207,7 +207,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "dijit/Tree", "dijit/Menu"], } } } catch (e) { - exception_error(e); + App.Error.report(e); } }, findNodeParentsAndExpandThem: function(feed, is_cat, root, parents) { @@ -242,7 +242,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "dijit/Tree", "dijit/Menu"], this.expandParentNodes(feed, is_cat, parents.slice(0)); } } catch (e) { - exception_error(e); + App.Error.report(e); } }, selectFeed: function(feed, is_cat) { diff --git a/js/Feeds.js b/js/Feeds.js index eb9a468ad..fbcb56150 100644 --- a/js/Feeds.js +++ b/js/Feeds.js @@ -198,13 +198,13 @@ define(["dojo/_base/declare"], function (declare) { Feeds.init(); App.setLoadingProgress(25); } catch (e) { - exception_error(e); + App.Error.report(e); } }); tree.startup(); } catch (e) { - exception_error(e); + App.Error.report(e); } }, init: function() { @@ -380,7 +380,7 @@ define(["dojo/_base/declare"], function (declare) { Headlines.onLoaded(transport, offset); PluginHost.run(PluginHost.HOOK_FEED_LOADED, [feed, is_cat]); } catch (e) { - exception_error(e); + App.Error.report(e); } }); }); diff --git a/js/common.js b/js/common.js index de6d13a78..427e3034c 100755 --- a/js/common.js +++ b/js/common.js @@ -4,6 +4,16 @@ let _label_base_index = -1024; let loading_progress = 0; +/* error reporting shim */ + +// TODO: deprecated; remove +function exception_error(e, e_compat, filename, lineno, colno) { + if (typeof e == "string") + e = e_compat; + + App.Error.report(e, {filename: filename, lineno: lineno, colno: colno}); +} + /* xhr shorthand helpers */ function xhrPost(url, params, complete) { @@ -118,71 +128,6 @@ const Cookie = { } }; -/* error reporting */ - -function report_error(message, filename, lineno, colno, error) { - exception_error(error, null, filename, lineno); -} - -function exception_error(e, e_compat, filename, lineno, colno) { - if (typeof e == "string") e = e_compat; - - if (!e) return; // no exception object, nothing to report. - - try { - console.error(e); - const msg = e.toString(); - - try { - xhrPost("backend.php", - {op: "rpc", method: "log", - file: e.fileName ? e.fileName : filename, - line: e.lineNumber ? e.lineNumber : lineno, - msg: msg, context: e.stack}, - (transport) => { - console.warn(transport.responseText); - }); - - } catch (e) { - console.error("Exception while trying to log the error.", e); - } - - let content = "

" + msg + "

"; - - if (e.stack) { - content += "
Stack trace:
" + - ""; - } - - content += "
"; - - content += "
"; - - content += ""; - content += "
"; - - if (dijit.byId("exceptionDlg")) - dijit.byId("exceptionDlg").destroyRecursive(); - - const dialog = new dijit.Dialog({ - id: "exceptionDlg", - title: "Unhandled exception", - style: "width: 600px", - content: content}); - - dialog.show(); - - } catch (ei) { - console.error("Exception while trying to report an exception:", ei); - console.error("Original exception:", e); - - alert("Exception occured while trying to report an exception.\n" + - ei.stack + "\n\nOriginal exception:\n" + e.stack); - } -} - /* runtime notifications */ const Notify = { diff --git a/js/prefs.js b/js/prefs.js index dafdbcdee..c89c0494f 100755 --- a/js/prefs.js +++ b/js/prefs.js @@ -58,10 +58,6 @@ require(["dojo/_base/kernel", try { const _App = declare("fox.App", AppBase, { constructor: function() { - window.onerror = function (message, filename, lineno, colno, error) { - report_error(message, filename, lineno, colno, error); - }; - parser.parse(); this.setLoadingProgress(50); @@ -73,7 +69,7 @@ require(["dojo/_base/kernel", try { this.backendSanityCallback(transport); } catch (e) { - exception_error(e); + this.Error.report(e); } }); }, @@ -149,7 +145,7 @@ require(["dojo/_base/kernel", App = new _App(); } catch (e) { - exception_error(e); + this.Error.report(e); } }); }); \ No newline at end of file diff --git a/js/tt-rss.js b/js/tt-rss.js index 97d34fbc1..8931e9860 100644 --- a/js/tt-rss.js +++ b/js/tt-rss.js @@ -65,10 +65,6 @@ require(["dojo/_base/kernel", _widescreen_mode: false, hotkey_actions: {}, constructor: function () { - window.onerror = function (message, filename, lineno, colno, error) { - report_error(message, filename, lineno, colno, error); - }; - parser.parse(); this.setLoadingProgress(30); @@ -91,7 +87,7 @@ require(["dojo/_base/kernel", try { App.backendSanityCallback(transport); } catch (e) { - exception_error(e); + App.Error.report(e); } }); }, @@ -555,7 +551,7 @@ require(["dojo/_base/kernel", App = new _App(); } catch (e) { - exception_error(e); + App.Error.report(e); } }); }); diff --git a/plugins/embed_original/init.js b/plugins/embed_original/init.js index 6f797556b..1e9fcb253 100644 --- a/plugins/embed_original/init.js +++ b/plugins/embed_original/init.js @@ -1,60 +1,56 @@ function embedOriginalArticle(id) { - try { - const hasSandbox = "sandbox" in document.createElement("iframe"); + const hasSandbox = "sandbox" in document.createElement("iframe"); - if (!hasSandbox) { - alert(__("Sorry, your browser does not support sandboxed iframes.")); - return; - } + if (!hasSandbox) { + alert(__("Sorry, your browser does not support sandboxed iframes.")); + return; + } - let c = false; + let c = false; + + if (App.isCombinedMode()) { + c = $$("div#RROW-" + id + " div[class=content-inner]")[0]; + } else if (id == Article.getActive()) { + c = $$(".post .content")[0]; + } + + if (c) { + const iframe = c.parentNode.getElementsByClassName("embeddedContent")[0]; + + if (iframe) { + Element.show(c); + c.parentNode.removeChild(iframe); + + if (App.isCombinedMode()) { + Article.cdmScrollToId(id, true); + } - if (App.isCombinedMode()) { - c = $$("div#RROW-" + id + " div[class=content-inner]")[0]; - } else if (id == Article.getActive()) { - c = $$(".post .content")[0]; + return; } + } - if (c) { - const iframe = c.parentNode.getElementsByClassName("embeddedContent")[0]; + const query = { op: "pluginhandler", plugin: "embed_original", method: "getUrl", id: id }; - if (iframe) { - Element.show(c); - c.parentNode.removeChild(iframe); + xhrJson("backend.php", query, (reply) => { + if (reply) { + const iframe = new Element("iframe", { + class: "embeddedContent", + src: reply.url, + width: (c.parentNode.offsetWidth - 5) + 'px', + height: (c.parentNode.parentNode.offsetHeight - c.parentNode.firstChild.offsetHeight - 5) + 'px', + style: "overflow: auto; border: none; min-height: " + (document.body.clientHeight / 2) + "px;", + sandbox: 'allow-scripts', + }); + + if (c) { + Element.hide(c); + c.parentNode.insertBefore(iframe, c); if (App.isCombinedMode()) { Article.cdmScrollToId(id, true); } - - return; } } + }); - const query = { op: "pluginhandler", plugin: "embed_original", method: "getUrl", id: id }; - - xhrJson("backend.php", query, (reply) => { - if (reply) { - const iframe = new Element("iframe", { - class: "embeddedContent", - src: reply.url, - width: (c.parentNode.offsetWidth - 5) + 'px', - height: (c.parentNode.parentNode.offsetHeight - c.parentNode.firstChild.offsetHeight - 5) + 'px', - style: "overflow: auto; border: none; min-height: " + (document.body.clientHeight / 2) + "px;", - sandbox: 'allow-scripts', - }); - - if (c) { - Element.hide(c); - c.parentNode.insertBefore(iframe, c); - - if (App.isCombinedMode()) { - Article.cdmScrollToId(id, true); - } - } - } - }); - - } catch (e) { - exception_error("embedOriginalArticle", e); - } } diff --git a/plugins/import_export/import_export.js b/plugins/import_export/import_export.js index 56a2a5c3e..8dc5f7570 100644 --- a/plugins/import_export/import_export.js +++ b/plugins/import_export/import_export.js @@ -50,7 +50,7 @@ function exportData() { "Error occured, could not export data."; } } catch (e) { - exception_error("exportData", e, transport.responseText); + App.Error.report(e); } Notify.close(); @@ -71,7 +71,7 @@ function exportData() { } catch (e) { - exception_error("exportData", e); + App.Error.report(e); } } @@ -100,7 +100,7 @@ function dataImportComplete(iframe) { dialog.show(); } catch (e) { - exception_error("dataImportComplete", e); + App.Error.report(e); } } diff --git a/plugins/mail/mail.js b/plugins/mail/mail.js index b72289c2a..87e354b42 100644 --- a/plugins/mail/mail.js +++ b/plugins/mail/mail.js @@ -1,57 +1,52 @@ function emailArticle(id) { - try { - if (!id) { - var ids = Headlines.getSelected(); + if (!id) { + let ids = Headlines.getSelected(); - if (ids.length == 0) { - alert(__("No articles selected.")); - return; - } - - id = ids.toString(); + if (ids.length == 0) { + alert(__("No articles selected.")); + return; } - if (dijit.byId("emailArticleDlg")) - dijit.byId("emailArticleDlg").destroyRecursive(); - - var query = "backend.php?op=pluginhandler&plugin=mail&method=emailArticle¶m=" + encodeURIComponent(id); - - dialog = new dijit.Dialog({ - id: "emailArticleDlg", - title: __("Forward article by email"), - style: "width: 600px", - execute: function() { - if (this.validate()) { - xhrJson("backend.php", this.attr('value'), (reply) => { - if (reply) { - const error = reply['error']; - - if (error) { - alert(__('Error sending email:') + ' ' + error); - } else { - Notify.info('Your message has been sent.'); - dialog.hide(); - } + id = ids.toString(); + } + if (dijit.byId("emailArticleDlg")) + dijit.byId("emailArticleDlg").destroyRecursive(); + + const query = "backend.php?op=pluginhandler&plugin=mail&method=emailArticle¶m=" + encodeURIComponent(id); + + const dialog = new dijit.Dialog({ + id: "emailArticleDlg", + title: __("Forward article by email"), + style: "width: 600px", + execute: function() { + if (this.validate()) { + xhrJson("backend.php", this.attr('value'), (reply) => { + if (reply) { + const error = reply['error']; + + if (error) { + alert(__('Error sending email:') + ' ' + error); + } else { + Notify.info('Your message has been sent.'); + dialog.hide(); } - }); - } - }, - href: query}); - /* var tmph = dojo.connect(dialog, 'onLoad', function() { - dojo.disconnect(tmph); + } + }); + } + }, + href: query}); - new Ajax.Autocompleter('emailArticleDlg_destination', 'emailArticleDlg_dst_choices', - "backend.php?op=pluginhandler&plugin=mail&method=completeEmails", - { tokens: '', paramName: "search" }); - }); */ + /* var tmph = dojo.connect(dialog, 'onLoad', function() { + dojo.disconnect(tmph); - dialog.show(); + new Ajax.Autocompleter('emailArticleDlg_destination', 'emailArticleDlg_dst_choices', + "backend.php?op=pluginhandler&plugin=mail&method=completeEmails", + { tokens: '', paramName: "search" }); + }); */ - } catch (e) { - exception_error("emailArticle", e); - } + dialog.show(); } diff --git a/plugins/mailto/init.js b/plugins/mailto/init.js index dacff725e..92a90f8e9 100644 --- a/plugins/mailto/init.js +++ b/plugins/mailto/init.js @@ -1,32 +1,27 @@ function mailtoArticle(id) { - try { - if (!id) { - const ids = Headlines.getSelected(); + if (!id) { + const ids = Headlines.getSelected(); - if (ids.length == 0) { - alert(__("No articles selected.")); - return; - } - - id = ids.toString(); + if (ids.length == 0) { + alert(__("No articles selected.")); + return; } - if (dijit.byId("emailArticleDlg")) - dijit.byId("emailArticleDlg").destroyRecursive(); + id = ids.toString(); + } - const query = "backend.php?op=pluginhandler&plugin=mailto&method=emailArticle¶m=" + encodeURIComponent(id); + if (dijit.byId("emailArticleDlg")) + dijit.byId("emailArticleDlg").destroyRecursive(); - dialog = new dijit.Dialog({ - id: "emailArticleDlg", - title: __("Forward article by email"), - style: "width: 600px", - href: query}); + const query = "backend.php?op=pluginhandler&plugin=mailto&method=emailArticle¶m=" + encodeURIComponent(id); - dialog.show(); + const dialog = new dijit.Dialog({ + id: "emailArticleDlg", + title: __("Forward article by email"), + style: "width: 600px", + href: query}); - } catch (e) { - exception_error("emailArticle", e); - } + dialog.show(); } diff --git a/plugins/nsfw/init.js b/plugins/nsfw/init.js index 40ad2b0ba..adb6d43c0 100644 --- a/plugins/nsfw/init.js +++ b/plugins/nsfw/init.js @@ -1,12 +1,7 @@ function nsfwShow(elem) { - try { - content = elem.parentNode.getElementsBySelector("div.nswf.content")[0]; + let content = elem.parentNode.getElementsBySelector("div.nswf.content")[0]; - if (content) { - Element.toggle(content); - } - - } catch (e) { - exception_error("nswfSHow", e); + if (content) { + Element.toggle(content); } } diff --git a/plugins/shorten_expanded/init.js b/plugins/shorten_expanded/init.js index d9995e8ac..a5424ea38 100644 --- a/plugins/shorten_expanded/init.js +++ b/plugins/shorten_expanded/init.js @@ -1,29 +1,20 @@ var _shorten_expanded_threshold = 1.5; //window heights function expandSizeWrapper(id) { - try { - const row = $(id); + const row = $(id); - console.log(row); + if (row) { + const content = row.select(".contentSizeWrapper")[0]; + const link = row.select(".expandPrompt")[0]; - if (row) { - const content = row.select(".contentSizeWrapper")[0]; - const link = row.select(".expandPrompt")[0]; - - if (content) content.removeClassName("contentSizeWrapper"); - if (link) Element.hide(link); - - } - } catch (e) { - exception_error("expandSizeWrapper", e); + if (content) content.removeClassName("contentSizeWrapper"); + if (link) Element.hide(link); } return false; - } require(['dojo/_base/kernel', 'dojo/ready'], function (dojo, ready) { - ready(function() { PluginHost.register(PluginHost.HOOK_ARTICLE_RENDERED_CDM, function(row) { window.setTimeout(function() { @@ -48,5 +39,4 @@ require(['dojo/_base/kernel', 'dojo/ready'], function (dojo, ready) { return true; }); }); - }); diff --git a/register.php b/register.php index 6c76eed5a..1bd1b2544 100644 --- a/register.php +++ b/register.php @@ -135,13 +135,13 @@ f.sub_btn.disabled = true; } } catch (e) { - exception_error("checkUsername_callback", e); + App.Error.report(e); } } }); } catch (e) { - exception_error("checkUsername", e); + App.Error.report(e); } return false; @@ -171,7 +171,7 @@ return true; } catch (e) { - exception_error("validateRegForm", e); + alert(e.stack); return false; } } -- cgit v1.2.3-54-g00ecf