migrate tt-rss.js contents to App

This commit is contained in:
Andrew Dolgov 2018-12-01 21:51:00 +03:00
parent ab0fadf60d
commit cc26be0793
8 changed files with 654 additions and 678 deletions

View File

@ -190,7 +190,7 @@ class Dlg extends Handler_Protected {
print_warning(__("You are using default tt-rss password. Please change it in the Preferences (Personal data / Authentication).")); print_warning(__("You are using default tt-rss password. Please change it in the Preferences (Personal data / Authentication)."));
print "<div align='center'>"; print "<div align='center'>";
print "<button dojoType=\"dijit.form.Button\" onclick=\"gotoPreferences()\">". print "<button dojoType=\"dijit.form.Button\" onclick=\"document.location.href = 'prefs.php'\">".
__('Open Preferences')."</button> "; __('Open Preferences')."</button> ";
print "<button dojoType=\"dijit.form.Button\" print "<button dojoType=\"dijit.form.Button\"
onclick=\"return closeInfoBox()\">". onclick=\"return closeInfoBox()\">".

View File

@ -95,7 +95,7 @@ class Feeds extends Handler_Protected {
$reply .= "</span> "; */ $reply .= "</span> "; */
$reply .= "<select dojoType=\"dijit.form.Select\" $reply .= "<select dojoType=\"dijit.form.Select\"
onchange=\"headlineActionsChange(this)\">"; onchange=\"Headlines.onActionChanged(this)\">";
$reply .= "<option value=\"0\" disabled='1'>".__('Select...')."</option>"; $reply .= "<option value=\"0\" disabled='1'>".__('Select...')."</option>";
@ -299,7 +299,7 @@ class Feeds extends Handler_Protected {
$label_cache = $line["label_cache"]; $label_cache = $line["label_cache"];
$labels = false; $labels = false;
$mouseover_attrs = "onmouseover='postMouseIn(event, $id)' onmouseout='postMouseOut($id)'"; $mouseover_attrs = "onmouseover='Article.mouseIn($id)' onmouseout='Article.mouseOut($id)'";
if ($label_cache) { if ($label_cache) {
$label_cache = json_decode($label_cache, true); $label_cache = json_decode($label_cache, true);

View File

@ -240,18 +240,18 @@
<div dojoType="dijit.form.DropDownButton"> <div dojoType="dijit.form.DropDownButton">
<span><?php echo __('Actions...') ?></span> <span><?php echo __('Actions...') ?></span>
<div dojoType="dijit.Menu" style="display: none"> <div dojoType="dijit.Menu" style="display: none">
<div dojoType="dijit.MenuItem" onclick="quickMenuGo('qmcPrefs')"><?php echo __('Preferences...') ?></div> <div dojoType="dijit.MenuItem" onclick="App.onActionSelected('qmcPrefs')"><?php echo __('Preferences...') ?></div>
<div dojoType="dijit.MenuItem" onclick="quickMenuGo('qmcSearch')"><?php echo __('Search...') ?></div> <div dojoType="dijit.MenuItem" onclick="App.onActionSelected('qmcSearch')"><?php echo __('Search...') ?></div>
<div dojoType="dijit.MenuItem" disabled="1"><?php echo __('Feed actions:') ?></div> <div dojoType="dijit.MenuItem" disabled="1"><?php echo __('Feed actions:') ?></div>
<div dojoType="dijit.MenuItem" onclick="quickMenuGo('qmcAddFeed')"><?php echo __('Subscribe to feed...') ?></div> <div dojoType="dijit.MenuItem" onclick="App.onActionSelected('qmcAddFeed')"><?php echo __('Subscribe to feed...') ?></div>
<div dojoType="dijit.MenuItem" onclick="quickMenuGo('qmcEditFeed')"><?php echo __('Edit this feed...') ?></div> <div dojoType="dijit.MenuItem" onclick="App.onActionSelected('qmcEditFeed')"><?php echo __('Edit this feed...') ?></div>
<div dojoType="dijit.MenuItem" onclick="quickMenuGo('qmcRemoveFeed')"><?php echo __('Unsubscribe') ?></div> <div dojoType="dijit.MenuItem" onclick="App.onActionSelected('qmcRemoveFeed')"><?php echo __('Unsubscribe') ?></div>
<div dojoType="dijit.MenuItem" disabled="1"><?php echo __('All feeds:') ?></div> <div dojoType="dijit.MenuItem" disabled="1"><?php echo __('All feeds:') ?></div>
<div dojoType="dijit.MenuItem" onclick="quickMenuGo('qmcCatchupAll')"><?php echo __('Mark as read') ?></div> <div dojoType="dijit.MenuItem" onclick="App.onActionSelected('qmcCatchupAll')"><?php echo __('Mark as read') ?></div>
<div dojoType="dijit.MenuItem" onclick="quickMenuGo('qmcShowOnlyUnread')"><?php echo __('(Un)hide read feeds') ?></div> <div dojoType="dijit.MenuItem" onclick="App.onActionSelected('qmcShowOnlyUnread')"><?php echo __('(Un)hide read feeds') ?></div>
<div dojoType="dijit.MenuItem" disabled="1"><?php echo __('Other actions:') ?></div> <div dojoType="dijit.MenuItem" disabled="1"><?php echo __('Other actions:') ?></div>
<div dojoType="dijit.MenuItem" onclick="quickMenuGo('qmcToggleWidescreen')"><?php echo __('Toggle widescreen mode') ?></div> <div dojoType="dijit.MenuItem" onclick="App.onActionSelected('qmcToggleWidescreen')"><?php echo __('Toggle widescreen mode') ?></div>
<div dojoType="dijit.MenuItem" onclick="quickMenuGo('qmcHKhelp')"><?php echo __('Keyboard shortcuts help') ?></div> <div dojoType="dijit.MenuItem" onclick="App.onActionSelected('qmcHKhelp')"><?php echo __('Keyboard shortcuts help') ?></div>
<?php <?php
foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_ACTION_ITEM) as $p) { foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_ACTION_ITEM) as $p) {
@ -260,7 +260,7 @@
?> ?>
<?php if (!$_SESSION["hide_logout"]) { ?> <?php if (!$_SESSION["hide_logout"]) { ?>
<div dojoType="dijit.MenuItem" onclick="quickMenuGo('qmcLogout')"><?php echo __('Logout') ?></div> <div dojoType="dijit.MenuItem" onclick="App.onActionSelected('qmcLogout')"><?php echo __('Logout') ?></div>
<?php } ?> <?php } ?>
</div> </div>
</div> </div>

View File

@ -6,6 +6,7 @@ const Feeds = {
infscroll_disabled: 0, infscroll_disabled: 0,
_infscroll_timeout: false, _infscroll_timeout: false,
_search_query: false, _search_query: false,
last_search_query: [],
_viewfeed_wait_timeout: false, _viewfeed_wait_timeout: false,
_counters_prev: [], _counters_prev: [],
// NOTE: this implementation is incomplete // NOTE: this implementation is incomplete
@ -206,7 +207,7 @@ const Feeds = {
Utils.setLoadingProgress(50); Utils.setLoadingProgress(50);
document.onkeydown = App.hotkeyHandler; document.onkeydown = () => { App.hotkeyHandler(event) };
window.setInterval(() => { hotkeyPrefixTimeout() }, 3 * 1000); window.setInterval(() => { hotkeyPrefixTimeout() }, 3 * 1000);
window.setInterval(() => { Headlines.catchupBatchedArticles() }, 10 * 1000); window.setInterval(() => { Headlines.catchupBatchedArticles() }, 10 * 1000);
@ -436,7 +437,7 @@ const Feeds = {
str = __("Mark %w in %s as read?"); str = __("Mark %w in %s as read?");
} }
const mark_what = last_search_query && last_search_query[0] ? __("search results") : __("all articles"); const mark_what = this.last_search_query && this.last_search_query[0] ? __("search results") : __("all articles");
const fn = this.getFeedName(feed, is_cat); const fn = this.getFeedName(feed, is_cat);
str = str.replace("%s", fn) str = str.replace("%s", fn)
@ -448,8 +449,8 @@ const Feeds = {
const catchup_query = { const catchup_query = {
op: 'rpc', method: 'catchupFeed', feed_id: feed, op: 'rpc', method: 'catchupFeed', feed_id: feed,
is_cat: is_cat, mode: mode, search_query: last_search_query[0], is_cat: is_cat, mode: mode, search_query: this.last_search_query[0],
search_lang: last_search_query[1] search_lang: this.last_search_query[1]
}; };
notify_progress("Loading, please wait...", true); notify_progress("Loading, please wait...", true);

View File

@ -1025,7 +1025,7 @@ function uploadIconHandler(rc) {
switch (rc) { switch (rc) {
case 0: case 0:
notify_info("Upload complete."); notify_info("Upload complete.");
if (inPreferences()) { if (App.isPrefs()) {
Feeds.reload(); Feeds.reload();
} else { } else {
setTimeout('Feeds.reload(false, false)', 50); setTimeout('Feeds.reload(false, false)', 50);
@ -1050,7 +1050,7 @@ function removeFeedIcon(id) {
xhrPost("backend.php", query, (transport) => { xhrPost("backend.php", query, (transport) => {
notify_info("Feed icon removed."); notify_info("Feed icon removed.");
if (inPreferences()) { if (App.isPrefs()) {
Feeds.reload(); Feeds.reload();
} else { } else {
setTimeout('Feeds.reload(false, false)', 50); setTimeout('Feeds.reload(false, false)', 50);
@ -1090,7 +1090,7 @@ function addLabel(select, callback) {
xhrPost("backend.php", query, (transport) => { xhrPost("backend.php", query, (transport) => {
if (callback) { if (callback) {
callback(transport); callback(transport);
} else if (inPreferences()) { } else if (App.isPrefs()) {
updateLabelList(); updateLabelList();
} else { } else {
Feeds.reload(); Feeds.reload();
@ -1317,7 +1317,7 @@ function editFilterTest(query) {
function quickAddFilter() { function quickAddFilter() {
let query; let query;
if (!inPreferences()) { if (!App.isPrefs()) {
query = { op: "pref-filters", method: "newfilter", query = { op: "pref-filters", method: "newfilter",
feed: Feeds.getActiveFeedId(), is_cat: Feeds.activeFeedIsCat() }; feed: Feeds.getActiveFeedId(), is_cat: Feeds.activeFeedIsCat() };
} else { } else {
@ -1385,7 +1385,7 @@ function quickAddFilter() {
const query = dojo.formToQuery("filter_new_form"); const query = dojo.formToQuery("filter_new_form");
xhrPost("backend.php", query, (transport) => { xhrPost("backend.php", query, (transport) => {
if (inPreferences()) { if (App.isPrefs()) {
updateFilterList(); updateFilterList();
} }
@ -1395,7 +1395,7 @@ function quickAddFilter() {
}, },
href: "backend.php?" + dojo.objectToQuery(query)}); href: "backend.php?" + dojo.objectToQuery(query)});
if (!inPreferences()) { if (!App.isPrefs()) {
const selectedText = getSelectionText(); const selectedText = getSelectionText();
const lh = dojo.connect(dialog, "onLoad", function(){ const lh = dojo.connect(dialog, "onLoad", function(){
@ -1453,7 +1453,7 @@ function unsubscribeFeed(feed_id, title) {
xhrPost("backend.php", query, (transport) => { xhrPost("backend.php", query, (transport) => {
if (dijit.byId("feedEditDlg")) dijit.byId("feedEditDlg").hide(); if (dijit.byId("feedEditDlg")) dijit.byId("feedEditDlg").hide();
if (inPreferences()) { if (App.isPrefs()) {
Feeds.reload(); Feeds.reload();
} else { } else {
if (feed_id == Feeds.getActiveFeedId()) if (feed_id == Feeds.getActiveFeedId())

View File

@ -65,7 +65,7 @@ const App = {
}); });
}, },
initSecondStage: function() { initSecondStage: function() {
document.onkeydown = this.hotkeyHandler; document.onkeydown = () => { App.hotkeyHandler(event) };
Utils.setLoadingProgress(50); Utils.setLoadingProgress(50);
notify(""); notify("");
@ -111,8 +111,11 @@ const App = {
console.log("unhandled action: " + action_name + "; keycode: " + event.which); console.log("unhandled action: " + action_name + "; keycode: " + event.which);
} }
} }
},
isPrefs: function() {
return true;
} }
} };
function notify_callback2(transport, sticky) { function notify_callback2(transport, sticky) {
notify_info(transport.responseText, sticky); notify_info(transport.responseText, sticky);
@ -909,10 +912,6 @@ function labelColorReset() {
} }
} }
function inPreferences() {
return true;
}
function editProfiles() { function editProfiles() {
if (dijit.byId("profileEditDlg")) if (dijit.byId("profileEditDlg"))

View File

@ -1,10 +1,9 @@
/* global dijit, __ */ /* global dijit, __ */
let hotkey_actions = {};
const App = { const App = {
global_unread: -1, global_unread: -1,
_widescreen_mode: false, _widescreen_mode: false,
hotkey_actions: {},
init: function() { init: function() {
window.onerror = function (message, filename, lineno, colno, error) { window.onerror = function (message, filename, lineno, colno, error) {
@ -57,7 +56,7 @@ const App = {
return false; return false;
Utils.setLoadingProgress(30); Utils.setLoadingProgress(30);
init_hotkey_actions(); App.initHotkeyActions();
const a = document.createElement('audio'); const a = document.createElement('audio');
const hasAudio = !!a.canPlayType; const hasAudio = !!a.canPlayType;
@ -179,7 +178,7 @@ const App = {
const action_name = Utils.keyeventToAction(event); const action_name = Utils.keyeventToAction(event);
if (action_name) { if (action_name) {
const action_func = hotkey_actions[action_name]; const action_func = this.hotkey_actions[action_name];
if (action_func != null) { if (action_func != null) {
action_func(); action_func();
@ -233,82 +232,80 @@ const App = {
xhrPost("backend.php", {op: "rpc", method: "setpanelmode", wide: wide ? 1 : 0}); xhrPost("backend.php", {op: "rpc", method: "setpanelmode", wide: wide ? 1 : 0});
}, },
}; initHotkeyActions: function() {
this.hotkey_actions["next_feed"] = function () {
function init_hotkey_actions() {
hotkey_actions["next_feed"] = function () {
const rv = dijit.byId("feedTree").getNextFeed( const rv = dijit.byId("feedTree").getNextFeed(
Feeds.getActiveFeedId(), Feeds.activeFeedIsCat()); Feeds.getActiveFeedId(), Feeds.activeFeedIsCat());
if (rv) Feeds.viewfeed({feed: rv[0], is_cat: rv[1], delayed: true}) if (rv) Feeds.viewfeed({feed: rv[0], is_cat: rv[1], delayed: true})
}; };
hotkey_actions["prev_feed"] = function () { this.hotkey_actions["prev_feed"] = function () {
const rv = dijit.byId("feedTree").getPreviousFeed( const rv = dijit.byId("feedTree").getPreviousFeed(
Feeds.getActiveFeedId(), Feeds.activeFeedIsCat()); Feeds.getActiveFeedId(), Feeds.activeFeedIsCat());
if (rv) Feeds.viewfeed({feed: rv[0], is_cat: rv[1], delayed: true}) if (rv) Feeds.viewfeed({feed: rv[0], is_cat: rv[1], delayed: true})
}; };
hotkey_actions["next_article"] = function () { this.hotkey_actions["next_article"] = function () {
Headlines.moveToPost('next'); Headlines.moveToPost('next');
}; };
hotkey_actions["prev_article"] = function () { this.hotkey_actions["prev_article"] = function () {
Headlines.moveToPost('prev'); Headlines.moveToPost('prev');
}; };
hotkey_actions["next_article_noscroll"] = function () { this.hotkey_actions["next_article_noscroll"] = function () {
Headlines.moveToPost('next', true); Headlines.moveToPost('next', true);
}; };
hotkey_actions["prev_article_noscroll"] = function () { this.hotkey_actions["prev_article_noscroll"] = function () {
Headlines.moveToPost('prev', true); Headlines.moveToPost('prev', true);
}; };
hotkey_actions["next_article_noexpand"] = function () { this.hotkey_actions["next_article_noexpand"] = function () {
Headlines.moveToPost('next', true, true); Headlines.moveToPost('next', true, true);
}; };
hotkey_actions["prev_article_noexpand"] = function () { this.hotkey_actions["prev_article_noexpand"] = function () {
Headlines.moveToPost('prev', true, true); Headlines.moveToPost('prev', true, true);
}; };
hotkey_actions["search_dialog"] = function () { this.hotkey_actions["search_dialog"] = function () {
Feeds.search(); Feeds.search();
}; };
hotkey_actions["toggle_mark"] = function () { this.hotkey_actions["toggle_mark"] = function () {
Headlines.selectionToggleMarked(); Headlines.selectionToggleMarked();
}; };
hotkey_actions["toggle_publ"] = function () { this.hotkey_actions["toggle_publ"] = function () {
Headlines.selectionTogglePublished(); Headlines.selectionTogglePublished();
}; };
hotkey_actions["toggle_unread"] = function () { this.hotkey_actions["toggle_unread"] = function () {
Headlines.selectionToggleUnread({no_error: 1}); Headlines.selectionToggleUnread({no_error: 1});
}; };
hotkey_actions["edit_tags"] = function () { this.hotkey_actions["edit_tags"] = function () {
const id = Article.getActiveArticleId(); const id = Article.getActiveArticleId();
if (id) { if (id) {
Article.editArticleTags(id); Article.editArticleTags(id);
} }
} }
hotkey_actions["open_in_new_window"] = function () { this.hotkey_actions["open_in_new_window"] = function () {
if (Article.getActiveArticleId()) { if (Article.getActiveArticleId()) {
Article.openArticleInNewWindow(Article.getActiveArticleId()); Article.openArticleInNewWindow(Article.getActiveArticleId());
} }
}; };
hotkey_actions["catchup_below"] = function () { this.hotkey_actions["catchup_below"] = function () {
catchupRelativeToArticle(1); Headlines.catchupRelativeToArticle(1);
}; };
hotkey_actions["catchup_above"] = function () { this.hotkey_actions["catchup_above"] = function () {
catchupRelativeToArticle(0); Headlines.catchupRelativeToArticle(0);
}; };
hotkey_actions["article_scroll_down"] = function () { this.hotkey_actions["article_scroll_down"] = function () {
scrollArticle(40); Article.scrollArticle(40);
}; };
hotkey_actions["article_scroll_up"] = function () { this.hotkey_actions["article_scroll_up"] = function () {
scrollArticle(-40); Article.scrollArticle(-40);
}; };
hotkey_actions["close_article"] = function () { this.hotkey_actions["close_article"] = function () {
if (App.isCombinedMode()) { if (App.isCombinedMode()) {
Article.cdmCollapseActive(); Article.cdmCollapseActive();
} else { } else {
Article.closeArticlePanel(); Article.closeArticlePanel();
} }
}; };
hotkey_actions["email_article"] = function () { this.hotkey_actions["email_article"] = function () {
if (typeof emailArticle != "undefined") { if (typeof emailArticle != "undefined") {
emailArticle(); emailArticle();
} else if (typeof mailtoArticle != "undefined") { } else if (typeof mailtoArticle != "undefined") {
@ -317,36 +314,36 @@ function init_hotkey_actions() {
alert(__("Please enable mail plugin first.")); alert(__("Please enable mail plugin first."));
} }
}; };
hotkey_actions["select_all"] = function () { this.hotkey_actions["select_all"] = function () {
Headlines.selectArticles('all'); Headlines.selectArticles('all');
}; };
hotkey_actions["select_unread"] = function () { this.hotkey_actions["select_unread"] = function () {
Headlines.selectArticles('unread'); Headlines.selectArticles('unread');
}; };
hotkey_actions["select_marked"] = function () { this.hotkey_actions["select_marked"] = function () {
Headlines.selectArticles('marked'); Headlines.selectArticles('marked');
}; };
hotkey_actions["select_published"] = function () { this.hotkey_actions["select_published"] = function () {
Headlines.selectArticles('published'); Headlines.selectArticles('published');
}; };
hotkey_actions["select_invert"] = function () { this.hotkey_actions["select_invert"] = function () {
Headlines.selectArticles('invert'); Headlines.selectArticles('invert');
}; };
hotkey_actions["select_none"] = function () { this.hotkey_actions["select_none"] = function () {
Headlines.selectArticles('none'); Headlines.selectArticles('none');
}; };
hotkey_actions["feed_refresh"] = function () { this.hotkey_actions["feed_refresh"] = function () {
if (Feeds.getActiveFeedId() != undefined) { if (Feeds.getActiveFeedId() != undefined) {
Feeds.viewfeed({feed: Feeds.getActiveFeedId(), is_cat: Feeds.activeFeedIsCat()}); Feeds.viewfeed({feed: Feeds.getActiveFeedId(), is_cat: Feeds.activeFeedIsCat()});
} }
}; };
hotkey_actions["feed_unhide_read"] = function () { this.hotkey_actions["feed_unhide_read"] = function () {
Feeds.toggleDispRead(); Feeds.toggleDispRead();
}; };
hotkey_actions["feed_subscribe"] = function () { this.hotkey_actions["feed_subscribe"] = function () {
CommonDialogs.quickAddFeed(); CommonDialogs.quickAddFeed();
}; };
hotkey_actions["feed_debug_update"] = function () { this.hotkey_actions["feed_debug_update"] = function () {
if (!Feeds.activeFeedIsCat() && parseInt(Feeds.getActiveFeedId()) > 0) { if (!Feeds.activeFeedIsCat() && parseInt(Feeds.getActiveFeedId()) > 0) {
window.open("backend.php?op=feeds&method=update_debugger&feed_id=" + Feeds.getActiveFeedId() + window.open("backend.php?op=feeds&method=update_debugger&feed_id=" + Feeds.getActiveFeedId() +
"&csrf_token=" + getInitParam("csrf_token")); "&csrf_token=" + getInitParam("csrf_token"));
@ -355,57 +352,57 @@ function init_hotkey_actions() {
} }
}; };
hotkey_actions["feed_debug_viewfeed"] = function () { this.hotkey_actions["feed_debug_viewfeed"] = function () {
Feeds.viewfeed({feed: Feeds.getActiveFeedId(), is_cat: Feeds.activeFeedIsCat(), viewfeed_debug: true}); Feeds.viewfeed({feed: Feeds.getActiveFeedId(), is_cat: Feeds.activeFeedIsCat(), viewfeed_debug: true});
}; };
hotkey_actions["feed_edit"] = function () { this.hotkey_actions["feed_edit"] = function () {
if (Feeds.activeFeedIsCat()) if (Feeds.activeFeedIsCat())
alert(__("You can't edit this kind of feed.")); alert(__("You can't edit this kind of feed."));
else else
editFeed(Feeds.getActiveFeedId()); editFeed(Feeds.getActiveFeedId());
}; };
hotkey_actions["feed_catchup"] = function () { this.hotkey_actions["feed_catchup"] = function () {
if (Feeds.getActiveFeedId() != undefined) { if (Feeds.getActiveFeedId() != undefined) {
Feeds.catchupCurrentFeed(); Feeds.catchupCurrentFeed();
} }
}; };
hotkey_actions["feed_reverse"] = function () { this.hotkey_actions["feed_reverse"] = function () {
Headlines.reverseHeadlineOrder(); Headlines.reverseHeadlineOrder();
}; };
hotkey_actions["feed_toggle_vgroup"] = function () { this.hotkey_actions["feed_toggle_vgroup"] = function () {
xhrPost("backend.php", {op: "rpc", method: "togglepref", key: "VFEED_GROUP_BY_FEED"}, () => { xhrPost("backend.php", {op: "rpc", method: "togglepref", key: "VFEED_GROUP_BY_FEED"}, () => {
Feeds.viewCurrentFeed(); Feeds.viewCurrentFeed();
}) })
}; };
hotkey_actions["catchup_all"] = function () { this.hotkey_actions["catchup_all"] = function () {
Feeds.catchupAllFeeds(); Feeds.catchupAllFeeds();
}; };
hotkey_actions["cat_toggle_collapse"] = function () { this.hotkey_actions["cat_toggle_collapse"] = function () {
if (Feeds.activeFeedIsCat()) { if (Feeds.activeFeedIsCat()) {
dijit.byId("feedTree").collapseCat(Feeds.getActiveFeedId()); dijit.byId("feedTree").collapseCat(Feeds.getActiveFeedId());
} }
}; };
hotkey_actions["goto_all"] = function () { this.hotkey_actions["goto_all"] = function () {
Feeds.viewfeed({feed: -4}); Feeds.viewfeed({feed: -4});
}; };
hotkey_actions["goto_fresh"] = function () { this.hotkey_actions["goto_fresh"] = function () {
Feeds.viewfeed({feed: -3}); Feeds.viewfeed({feed: -3});
}; };
hotkey_actions["goto_marked"] = function () { this.hotkey_actions["goto_marked"] = function () {
Feeds.viewfeed({feed: -1}); Feeds.viewfeed({feed: -1});
}; };
hotkey_actions["goto_published"] = function () { this.hotkey_actions["goto_published"] = function () {
Feeds.viewfeed({feed: -2}); Feeds.viewfeed({feed: -2});
}; };
hotkey_actions["goto_tagcloud"] = function () { this.hotkey_actions["goto_tagcloud"] = function () {
Utils.displayDlg(__("Tag cloud"), "printTagCloud"); Utils.displayDlg(__("Tag cloud"), "printTagCloud");
}; };
hotkey_actions["goto_prefs"] = function () { this.hotkey_actions["goto_prefs"] = function () {
gotoPreferences(); document.location.href = "prefs.php";
}; };
hotkey_actions["select_article_cursor"] = function () { this.hotkey_actions["select_article_cursor"] = function () {
const id = getArticleUnderPointer(); const id = Article.getArticleUnderPointer();
if (id) { if (id) {
const row = $("RROW-" + id); const row = $("RROW-" + id);
@ -423,16 +420,16 @@ function init_hotkey_actions() {
} }
} }
}; };
hotkey_actions["create_label"] = function () { this.hotkey_actions["create_label"] = function () {
addLabel(); addLabel();
}; };
hotkey_actions["create_filter"] = function () { this.hotkey_actions["create_filter"] = function () {
quickAddFilter(); quickAddFilter();
}; };
hotkey_actions["collapse_sidebar"] = function () { this.hotkey_actions["collapse_sidebar"] = function () {
Feeds.viewCurrentFeed(); Feeds.viewCurrentFeed();
}; };
hotkey_actions["toggle_embed_original"] = function () { this.hotkey_actions["toggle_embed_original"] = function () {
if (typeof embedOriginalArticle != "undefined") { if (typeof embedOriginalArticle != "undefined") {
if (Article.getActiveArticleId()) if (Article.getActiveArticleId())
embedOriginalArticle(Article.getActiveArticleId()); embedOriginalArticle(Article.getActiveArticleId());
@ -440,7 +437,7 @@ function init_hotkey_actions() {
alert(__("Please enable embed_original plugin first.")); alert(__("Please enable embed_original plugin first."));
} }
}; };
hotkey_actions["toggle_widescreen"] = function () { this.hotkey_actions["toggle_widescreen"] = function () {
if (!App.isCombinedMode()) { if (!App.isCombinedMode()) {
App._widescreen_mode = !App._widescreen_mode; App._widescreen_mode = !App._widescreen_mode;
@ -453,10 +450,10 @@ function init_hotkey_actions() {
alert(__("Widescreen is not available in combined mode.")); alert(__("Widescreen is not available in combined mode."));
} }
}; };
hotkey_actions["help_dialog"] = function () { this.hotkey_actions["help_dialog"] = function () {
Utils.helpDialog("main"); Utils.helpDialog("main");
}; };
hotkey_actions["toggle_combined_mode"] = function () { this.hotkey_actions["toggle_combined_mode"] = function () {
notify_progress("Loading, please wait..."); notify_progress("Loading, please wait...");
const value = App.isCombinedMode() ? "false" : "true"; const value = App.isCombinedMode() ? "false" : "true";
@ -469,7 +466,7 @@ function init_hotkey_actions() {
Feeds.viewCurrentFeed(); Feeds.viewCurrentFeed();
}) })
}; };
hotkey_actions["toggle_cdm_expanded"] = function () { this.hotkey_actions["toggle_cdm_expanded"] = function () {
notify_progress("Loading, please wait..."); notify_progress("Loading, please wait...");
const value = getInitParam("cdm_expanded") ? "false" : "true"; const value = getInitParam("cdm_expanded") ? "false" : "true";
@ -479,9 +476,8 @@ function init_hotkey_actions() {
Feeds.viewCurrentFeed(); Feeds.viewCurrentFeed();
}); });
}; };
} },
onActionSelected: function(opid) {
function quickMenuGo(opid) {
switch (opid) { switch (opid) {
case "qmcPrefs": case "qmcPrefs":
gotoPreferences(); gotoPreferences();
@ -553,11 +549,11 @@ function quickMenuGo(opid) {
default: default:
console.log("quickMenuGo: unknown action: " + opid); console.log("quickMenuGo: unknown action: " + opid);
} }
} },
isPrefs: function() {
function inPreferences() {
return false; return false;
} }
};
function hash_get(key) { function hash_get(key) {
const kv = window.location.hash.substring(1).toQueryParams(); const kv = window.location.hash.substring(1).toQueryParams();
@ -569,7 +565,3 @@ function hash_set(key, value) {
kv[key] = value; kv[key] = value;
window.location.hash = $H(kv).toQueryString(); window.location.hash = $H(kv).toQueryString();
} }
function gotoPreferences() {
document.location.href = "prefs.php";
}

View File

@ -1,8 +1,5 @@
/* global dijit, __, ngettext */ /* global dijit, __, ngettext */
let post_under_pointer = false;
let last_search_query;
const ArticleCache = { const ArticleCache = {
has_storage: 'sessionStorage' in window && window['sessionStorage'] !== null, has_storage: 'sessionStorage' in window && window['sessionStorage'] !== null,
set: function(id, obj) { set: function(id, obj) {
@ -118,7 +115,7 @@ const Article = {
c.attr('content', article); c.attr('content', article);
PluginHost.run(PluginHost.HOOK_ARTICLE_RENDERED, c.domNode); PluginHost.run(PluginHost.HOOK_ARTICLE_RENDERED, c.domNode);
correctHeadlinesOffset(Article.getActiveArticleId()); Headlines.correctHeadlinesOffset(Article.getActiveArticleId());
try { try {
c.focus(); c.focus();
@ -126,7 +123,7 @@ const Article = {
} }
}, },
view: function(id, noexpand) { view: function(id, noexpand) {
Article.setActiveArticleId(id); this.setActiveArticleId(id);
if (!noexpand) { if (!noexpand) {
console.log("loading article", id); console.log("loading article", id);
@ -135,7 +132,7 @@ const Article = {
/* only request uncached articles */ /* only request uncached articles */
getRelativePostIds(id).each((n) => { this.getRelativePostIds(id).each((n) => {
if (!ArticleCache.get(n)) if (!ArticleCache.get(n))
cids.push(n); cids.push(n);
}); });
@ -313,6 +310,49 @@ const Article = {
}, },
getActiveArticleId: function() { getActiveArticleId: function() {
return this._active_article_id; return this._active_article_id;
},
scrollArticle: function(offset) {
if (!App.isCombinedMode()) {
const ci = $("content-insert");
if (ci) {
ci.scrollTop += offset;
}
} else {
const hi = $("headlines-frame");
if (hi) {
hi.scrollTop += offset;
}
}
},
getRelativePostIds: function(id, limit) {
const tmp = [];
if (!limit) limit = 6; //3
const ids = Headlines.getLoadedArticleIds();
for (let i = 0; i < ids.length; i++) {
if (ids[i] == id) {
for (let k = 1; k <= limit; k++) {
//if (i > k-1) tmp.push(ids[i-k]);
if (i < ids.length - k) tmp.push(ids[i + k]);
}
break;
}
}
return tmp;
},
mouseIn: function(id) {
this.post_under_pointer = id;
},
mouseOut: function(id) {
this.post_under_pointer = false;
},
getArticleUnderPointer: function() {
return this.post_under_pointer;
} }
}; };
@ -485,7 +525,7 @@ const Headlines = {
ft.firstChild.innerHTML = "<img class='anchor marked-pic' src='images/page_white_go.png' " + ft.firstChild.innerHTML = "<img class='anchor marked-pic' src='images/page_white_go.png' " +
"onclick=\"Article.cdmScrollToArticleId(" + id + ", true)\">" + ft.firstChild.innerHTML; "onclick=\"Article.cdmScrollToArticleId(" + id + ", true)\">" + ft.firstChild.innerHTML;
initFloatingMenu(); this.initFloatingMenu();
const cb = ft.select(".rchk")[0]; const cb = ft.select(".rchk")[0];
@ -546,7 +586,7 @@ const Headlines = {
is_cat = reply['headlines']['is_cat']; is_cat = reply['headlines']['is_cat'];
feed_id = reply['headlines']['id']; feed_id = reply['headlines']['id'];
last_search_query = reply['headlines']['search_query']; Feeds.last_search_query = reply['headlines']['search_query'];
if (feed_id != -7 && (feed_id != Feeds.getActiveFeedId() || is_cat != Feeds.activeFeedIsCat())) if (feed_id != -7 && (feed_id != Feeds.getActiveFeedId() || is_cat != Feeds.activeFeedIsCat()))
return; return;
@ -602,7 +642,7 @@ const Headlines = {
if (!hsp) hsp = new Element("DIV", {"id": "headlines-spacer"}); if (!hsp) hsp = new Element("DIV", {"id": "headlines-spacer"});
dijit.byId('headlines-frame').domNode.appendChild(hsp); dijit.byId('headlines-frame').domNode.appendChild(hsp);
initHeadlinesMenu(); this.initHeadlinesMenu();
if (Feeds.infscroll_disabled) if (Feeds.infscroll_disabled)
hsp.innerHTML = "<a href='#' onclick='Feeds.openNextUnreadFeed()'>" + hsp.innerHTML = "<a href='#' onclick='Feeds.openNextUnreadFeed()'>" +
@ -646,7 +686,7 @@ const Headlines = {
markHeadline(ids[i]); markHeadline(ids[i]);
} */ } */
initHeadlinesMenu(); this.initHeadlinesMenu();
if (Feeds.infscroll_disabled) { if (Feeds.infscroll_disabled) {
hsp.innerHTML = "<a href='#' onclick='Feeds.openNextUnreadFeed()'>" + hsp.innerHTML = "<a href='#' onclick='Feeds.openNextUnreadFeed()'>" +
@ -894,7 +934,7 @@ const Headlines = {
if (!noscroll && article && article.offsetTop + article.offsetHeight > if (!noscroll && article && article.offsetTop + article.offsetHeight >
ctr.scrollTop + ctr.offsetHeight) { ctr.scrollTop + ctr.offsetHeight) {
scrollArticle(ctr.offsetHeight / 4); Article.scrollArticle(ctr.offsetHeight / 4);
} else if (next_id) { } else if (next_id) {
Article.setActiveArticleId(next_id); Article.setActiveArticleId(next_id);
@ -902,7 +942,7 @@ const Headlines = {
} }
} else if (next_id) { } else if (next_id) {
correctHeadlinesOffset(next_id); Headlines.correctHeadlinesOffset(next_id);
Article.view(next_id, noexpand); Article.view(next_id, noexpand);
} }
} }
@ -917,17 +957,17 @@ const Headlines = {
const ctr = $("headlines-frame"); const ctr = $("headlines-frame");
if (!noscroll && article && article.offsetTop < ctr.scrollTop) { if (!noscroll && article && article.offsetTop < ctr.scrollTop) {
scrollArticle(-ctr.offsetHeight / 3); Article.scrollArticle(-ctr.offsetHeight / 3);
} else if (!noscroll && prev_article && } else if (!noscroll && prev_article &&
prev_article.offsetTop < ctr.scrollTop) { prev_article.offsetTop < ctr.scrollTop) {
scrollArticle(-ctr.offsetHeight / 4); Article.scrollArticle(-ctr.offsetHeight / 4);
} else if (prev_id) { } else if (prev_id) {
Article.setActiveArticleId(prev_id); Article.setActiveArticleId(prev_id);
Article.cdmScrollToArticleId(prev_id, noscroll); Article.cdmScrollToArticleId(prev_id, noscroll);
} }
} else if (prev_id) { } else if (prev_id) {
correctHeadlinesOffset(prev_id); Headlines.correctHeadlinesOffset(prev_id);
Article.view(prev_id, noexpand); Article.view(prev_id, noexpand);
} }
} }
@ -986,7 +1026,7 @@ const Headlines = {
xhrPost("backend.php", query, (transport) => { xhrPost("backend.php", query, (transport) => {
Utils.handleRpcJson(transport); Utils.handleRpcJson(transport);
updateHeadlineLabels(transport); this.onLabelsUpdated(transport);
}); });
}, },
selectionAssignLabel: function(id, ids) { selectionAssignLabel: function(id, ids) {
@ -1004,7 +1044,7 @@ const Headlines = {
xhrPost("backend.php", query, (transport) => { xhrPost("backend.php", query, (transport) => {
Utils.handleRpcJson(transport); Utils.handleRpcJson(transport);
updateHeadlineLabels(transport); this.onLabelsUpdated(transport);
}); });
}, },
deleteSelection: function() { deleteSelection: function() {
@ -1212,18 +1252,8 @@ const Headlines = {
} else { } else {
if (callback) callback(); if (callback) callback();
} }
} },
}; catchupRelativeToArticle: function(below, id) {
function postMouseIn(e, id) {
post_under_pointer = id;
}
function postMouseOut(id) {
post_under_pointer = false;
}
function catchupRelativeToArticle(below, id) {
if (!id) id = Article.getActiveArticleId(); if (!id) id = Article.getActiveArticleId();
@ -1232,7 +1262,7 @@ function catchupRelativeToArticle(below, id) {
return; return;
} }
const visible_ids = Headlines.getLoadedArticleIds(); const visible_ids = this.getLoadedArticleIds();
const ids_to_mark = []; const ids_to_mark = [];
@ -1274,36 +1304,18 @@ function catchupRelativeToArticle(below, id) {
e.removeClassName("Unread"); e.removeClassName("Unread");
} }
const query = { op: "rpc", method: "catchupSelected", const query = {
cmode: 0, ids: ids_to_mark.toString() }; op: "rpc", method: "catchupSelected",
cmode: 0, ids: ids_to_mark.toString()
};
xhrPost("backend.php", query, (transport) => { xhrPost("backend.php", query, (transport) => {
Utils.handleRpcJson(transport); Utils.handleRpcJson(transport);
}); });
} }
} }
} },
onLabelsUpdated: function(transport) {
function getArticleUnderPointer() {
return post_under_pointer;
}
function scrollArticle(offset) {
if (!App.isCombinedMode()) {
const ci = $("content-insert");
if (ci) {
ci.scrollTop += offset;
}
} else {
const hi = $("headlines-frame");
if (hi) {
hi.scrollTop += offset;
}
}
}
function updateHeadlineLabels(transport) {
const data = JSON.parse(transport.responseText); const data = JSON.parse(transport.responseText);
if (data) { if (data) {
@ -1313,30 +1325,12 @@ function updateHeadlineLabels(transport) {
}); });
}); });
} }
} },
onActionChanged: function(elem) {
function getRelativePostIds(id, limit) { eval(elem.value);
elem.attr('value', 'false');
const tmp = []; },
correctHeadlinesOffset: function(id) {
if (!limit) limit = 6; //3
const ids = Headlines.getLoadedArticleIds();
for (let i = 0; i < ids.length; i++) {
if (ids[i] == id) {
for (let k = 1; k <= limit; k++) {
//if (i > k-1) tmp.push(ids[i-k]);
if (i < ids.length - k) tmp.push(ids[i + k]);
}
break;
}
}
return tmp;
}
function correctHeadlinesOffset(id) {
const container = $("headlines-frame"); const container = $("headlines-frame");
const row = $("RROW-" + id); const row = $("RROW-" + id);
@ -1355,14 +1349,8 @@ function correctHeadlinesOffset(id) {
} else if (rel_offset_bottom > viewport) { } else if (rel_offset_bottom > viewport) {
container.scrollTop = row.offsetTop + row.offsetHeight - viewport; container.scrollTop = row.offsetTop + row.offsetHeight - viewport;
} }
} },
initFloatingMenu: function() {
function headlineActionsChange(elem) {
eval(elem.value);
elem.attr('value', 'false');
}
function initFloatingMenu() {
if (!dijit.byId("floatingMenu")) { if (!dijit.byId("floatingMenu")) {
const menu = new dijit.Menu({ const menu = new dijit.Menu({
@ -1370,13 +1358,12 @@ function initFloatingMenu() {
targetNodeIds: ["floatingTitle"] targetNodeIds: ["floatingTitle"]
}); });
headlinesMenuCommon(menu); this.headlinesMenuCommon(menu);
menu.startup(); menu.startup();
} }
} },
headlinesMenuCommon: function(menu) {
function headlinesMenuCommon(menu) {
menu.addChild(new dijit.MenuItem({ menu.addChild(new dijit.MenuItem({
label: __("Open original article"), label: __("Open original article"),
@ -1436,14 +1423,14 @@ function headlinesMenuCommon(menu) {
menu.addChild(new dijit.MenuItem({ menu.addChild(new dijit.MenuItem({
label: __("Mark above as read"), label: __("Mark above as read"),
onClick: function () { onClick: function () {
catchupRelativeToArticle(0, this.getParent().currentTarget.getAttribute("data-article-id")); Headlines.catchupRelativeToArticle(0, this.getParent().currentTarget.getAttribute("data-article-id"));
} }
})); }));
menu.addChild(new dijit.MenuItem({ menu.addChild(new dijit.MenuItem({
label: __("Mark below as read"), label: __("Mark below as read"),
onClick: function () { onClick: function () {
catchupRelativeToArticle(1, this.getParent().currentTarget.getAttribute("data-article-id")); Headlines.catchupRelativeToArticle(1, this.getParent().currentTarget.getAttribute("data-article-id"));
} }
})); }));
@ -1503,9 +1490,8 @@ function headlinesMenuCommon(menu) {
})); }));
} }
} },
initHeadlinesMenu: function() {
function initHeadlinesMenu() {
if (!dijit.byId("headlinesMenu")) { if (!dijit.byId("headlinesMenu")) {
const menu = new dijit.Menu({ const menu = new dijit.Menu({
@ -1514,7 +1500,7 @@ function initHeadlinesMenu() {
selector: ".hlMenuAttach" selector: ".hlMenuAttach"
}); });
headlinesMenuCommon(menu); this.headlinesMenuCommon(menu);
menu.startup(); menu.startup();
} }
@ -1567,7 +1553,5 @@ function initHeadlinesMenu() {
menu.startup(); menu.startup();
} }
} }
};