WIP reshuffling of JS global context into separate logical objects
This commit is contained in:
parent
78780c9c08
commit
049a37aa0e
|
@ -877,7 +877,7 @@ class Article extends Handler_Protected {
|
|||
$tags_str = "";
|
||||
|
||||
for ($i = 0; $i < $maxtags; $i++) {
|
||||
$tags_str .= "<a class=\"tag\" href=\"#\" onclick=\"viewfeed({feed:'".$tags[$i]."'})\">" . $tags[$i] . "</a>, ";
|
||||
$tags_str .= "<a class=\"tag\" href=\"#\" onclick=\"Feeds.viewfeed({feed:'".$tags[$i]."'})\">" . $tags[$i] . "</a>, ";
|
||||
}
|
||||
|
||||
$tags_str = mb_substr($tags_str, 0, mb_strlen($tags_str)-2);
|
||||
|
|
|
@ -139,7 +139,7 @@ class Dlg extends Handler_Protected {
|
|||
|
||||
$key_escaped = str_replace("'", "\\'", $key);
|
||||
|
||||
echo "<a href=\"javascript:viewfeed({feed:'$key_escaped'}) \" style=\"font-size: " .
|
||||
echo "<a href=\"#\" onclick=\"Feeds.viewfeed({feed:'$key_escaped'}) \" style=\"font-size: " .
|
||||
$size . "px\" title=\"$value articles tagged with " .
|
||||
$key . '">' . $key . '</a> ';
|
||||
}
|
||||
|
|
|
@ -51,7 +51,7 @@ class Feeds extends Handler_Protected {
|
|||
$reply .= "<span class='r'>
|
||||
<a href=\"#\"
|
||||
title=\"".__("View as RSS feed")."\"
|
||||
onclick=\"displayDlg('".__("View as RSS")."','generatedFeed', '$feed_id:$is_cat:$rss_link')\">
|
||||
onclick=\"Utils.displayDlg('".__("View as RSS")."','generatedFeed', '$feed_id:$is_cat:$rss_link')\">
|
||||
<img class=\"noborder\" src=\"images/pub_set.png\"></a>";
|
||||
|
||||
|
||||
|
@ -137,7 +137,7 @@ class Feeds extends Handler_Protected {
|
|||
|
||||
//$reply .= "<option value=\"catchupPage()\">".__('Mark as read')."</option>";
|
||||
|
||||
$reply .= "<option value=\"displayDlg('".__("View as RSS")."','generatedFeed', '$feed_id:$is_cat:$rss_link')\">".__('View as RSS')."</option>";
|
||||
$reply .= "<option value=\"Utils.displayDlg('".__("View as RSS")."','generatedFeed', '$feed_id:$is_cat:$rss_link')\">".__('View as RSS')."</option>";
|
||||
|
||||
$reply .= "</select>";
|
||||
|
||||
|
@ -392,7 +392,7 @@ class Feeds extends Handler_Protected {
|
|||
|
||||
$reply['content'] .= "<div data-feed-id='$feed_id' class='feed-titl'>".
|
||||
"<div style='float : right'>$feed_icon_img</div>".
|
||||
"<a class='title' href=\"#\" onclick=\"viewfeed({feed:$feed_id})\">".
|
||||
"<a class='title' href=\"#\" onclick=\"Feeds.viewfeed({feed:$feed_id})\">".
|
||||
$line["feed_title"]."</a>
|
||||
$vf_catchup_link</div>";
|
||||
|
||||
|
@ -434,7 +434,7 @@ class Feeds extends Handler_Protected {
|
|||
if (@$line["feed_title"]) {
|
||||
$rgba = @$rgba_cache[$feed_id];
|
||||
|
||||
$reply['content'] .= "<span class=\"feed\"><a style=\"background : rgba($rgba, 0.3)\" href=\"#\" onclick=\"viewfeed({feed:$feed_id})\">".
|
||||
$reply['content'] .= "<span class=\"feed\"><a style=\"background : rgba($rgba, 0.3)\" href=\"#\" onclick=\"Feeds.viewfeed({feed:$feed_id})\">".
|
||||
truncate_string($line["feed_title"],30)."</a></span>";
|
||||
}
|
||||
}
|
||||
|
@ -451,7 +451,7 @@ class Feeds extends Handler_Protected {
|
|||
|
||||
if ($line["feed_title"] && !$vfeed_group_enabled) {
|
||||
|
||||
$reply['content'] .= "<span onclick=\"viewfeed({feed:$feed_id})\"
|
||||
$reply['content'] .= "<span onclick=\"Feeds.viewfeed({feed:$feed_id})\"
|
||||
style=\"cursor : pointer\"
|
||||
title=\"".htmlspecialchars($line['feed_title'])."\">
|
||||
$feed_icon_img</span>";
|
||||
|
@ -488,7 +488,7 @@ class Feeds extends Handler_Protected {
|
|||
|
||||
$reply['content'] .= "<div data-feed-id='$feed_id' class='feed-title'>".
|
||||
"<div style=\"float : right\">$feed_icon_img</div>".
|
||||
"<a href=\"#\" class='title' onclick=\"viewfeed({feed:$feed_id})\">".
|
||||
"<a href=\"#\" class='title' onclick=\"Feeds.viewfeed({feed:$feed_id})\">".
|
||||
$line["feed_title"]."</a> $vf_catchup_link</div>";
|
||||
|
||||
}
|
||||
|
@ -547,7 +547,7 @@ class Feeds extends Handler_Protected {
|
|||
|
||||
$tmp_content .= "<div class=\"feed\">
|
||||
<a href=\"#\" style=\"background-color: rgba($rgba,0.3)\"
|
||||
onclick=\"viewfeed({feed:$feed_id})\">".
|
||||
onclick=\"Feeds.viewfeed({feed:$feed_id})\">".
|
||||
truncate_string($line["feed_title"],30)."</a>
|
||||
</div>";
|
||||
}
|
||||
|
@ -561,7 +561,7 @@ class Feeds extends Handler_Protected {
|
|||
if (!get_pref("VFEED_GROUP_BY_FEED") && $line["feed_title"]) {
|
||||
$tmp_content .= "<span style=\"cursor : pointer\"
|
||||
title=\"".htmlspecialchars($line["feed_title"])."\"
|
||||
onclick=\"viewfeed({feed:$feed_id})\">$feed_icon_img</span>";
|
||||
onclick=\"Feeds.viewfeed({feed:$feed_id})\">$feed_icon_img</span>";
|
||||
}
|
||||
$tmp_content .= "</div>"; //score wrapper2
|
||||
|
||||
|
|
|
@ -1174,7 +1174,7 @@ class Pref_Feeds extends Handler_Protected {
|
|||
print "<div style='float : right; padding-right : 4px;'>
|
||||
<input dojoType=\"dijit.form.TextBox\" id=\"feed_search\" size=\"20\" type=\"search\"
|
||||
value=\"$feed_search\">
|
||||
<button dojoType=\"dijit.form.Button\" onclick=\"updateFeedList()\">".
|
||||
<button dojoType=\"dijit.form.Button\" onclick=\"Feeds.reload()\">".
|
||||
__('Search')."</button>
|
||||
</div>";
|
||||
|
||||
|
@ -1306,7 +1306,7 @@ class Pref_Feeds extends Handler_Protected {
|
|||
|
||||
print_warning("Published OPML does not include your Tiny Tiny RSS settings, feeds that require authentication or feeds hidden from Popular feeds.");
|
||||
|
||||
print "<button dojoType=\"dijit.form.Button\" onclick=\"return displayDlg('".__("Public OPML URL")."','pubOPMLUrl')\">".
|
||||
print "<button dojoType=\"dijit.form.Button\" onclick=\"return Utils.displayDlg('".__("Public OPML URL")."','pubOPMLUrl')\">".
|
||||
__('Display published OPML URL')."</button> ";
|
||||
|
||||
PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB_SECTION,
|
||||
|
@ -1323,7 +1323,7 @@ class Pref_Feeds extends Handler_Protected {
|
|||
|
||||
print "<p>";
|
||||
|
||||
print "<button dojoType=\"dijit.form.Button\" onclick=\"return displayDlg('".__("View as RSS")."','generatedFeed', '$rss_url')\">".
|
||||
print "<button dojoType=\"dijit.form.Button\" onclick=\"return Utils.displayDlg('".__("View as RSS")."','generatedFeed', '$rss_url')\">".
|
||||
__('Display URL')."</button> ";
|
||||
|
||||
print "<button class=\"warning\" dojoType=\"dijit.form.Button\" onclick=\"return clearFeedAccessKeys()\">".
|
||||
|
|
|
@ -97,7 +97,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "dijit/Tree", "dijit/Menu"],
|
|||
menu.addChild(new dijit.MenuItem({
|
||||
label: __("Mark all feeds as read"),
|
||||
onClick: function() {
|
||||
catchupAllFeeds();
|
||||
Feeds.catchupAllFeeds();
|
||||
}}));
|
||||
|
||||
menu.bindDomNode(tnode.domNode);
|
||||
|
|
697
js/feedlist.js
697
js/feedlist.js
|
@ -1,302 +1,430 @@
|
|||
let infscroll_in_progress = 0;
|
||||
let infscroll_disabled = 0;
|
||||
|
||||
let _infscroll_timeout = false;
|
||||
let _search_query = false;
|
||||
let _viewfeed_wait_timeout = false;
|
||||
|
||||
let counters_last_request = 0;
|
||||
let _counters_prev = [];
|
||||
|
||||
function resetCounterCache() {
|
||||
_counters_prev = [];
|
||||
}
|
||||
const Counters = {
|
||||
};
|
||||
|
||||
function loadMoreHeadlines() {
|
||||
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;
|
||||
const num_unread = getFeedUnread(getActiveFeedId(), activeFeedIsCat());
|
||||
const Feeds = {
|
||||
_active_feed_id: 0,
|
||||
_active_feed_is_cat: false,
|
||||
infscroll_in_progress: 0,
|
||||
infscroll_disabled: 0,
|
||||
_infscroll_timeout: false,
|
||||
_search_query: false,
|
||||
_viewfeed_wait_timeout: false,
|
||||
_counters_prev: [],
|
||||
// NOTE: this implementation is incomplete
|
||||
// for general objects but good enough for counters
|
||||
// http://adripofjavascript.com/blog/drips/object-equality-in-javascript.html
|
||||
counterEquals: function(a, b) {
|
||||
// Create arrays of property names
|
||||
const aProps = Object.getOwnPropertyNames(a);
|
||||
const bProps = Object.getOwnPropertyNames(b);
|
||||
|
||||
// TODO implement marked & published
|
||||
|
||||
let offset = num_all;
|
||||
|
||||
switch (view_mode) {
|
||||
case "marked":
|
||||
case "published":
|
||||
console.warn("loadMoreHeadlines: ", view_mode, "not implemented");
|
||||
break;
|
||||
case "unread":
|
||||
offset = unread_in_buffer;
|
||||
break;
|
||||
case "adaptive":
|
||||
if (!(getActiveFeedId() == -1 && !activeFeedIsCat()))
|
||||
offset = num_unread > 0 ? unread_in_buffer : num_all;
|
||||
break;
|
||||
}
|
||||
|
||||
console.log("loadMoreHeadlines, offset=", offset);
|
||||
|
||||
viewfeed({feed: getActiveFeedId(), is_cat: activeFeedIsCat(), offset: offset, infscroll_req: true});
|
||||
}
|
||||
|
||||
function cleanup_memory(root) {
|
||||
const dijits = dojo.query("[widgetid]", dijit.byId(root).domNode).map(dijit.byNode);
|
||||
|
||||
dijits.each(function (d) {
|
||||
dojo.destroy(d.domNode);
|
||||
});
|
||||
|
||||
$$("#" + root + " *").each(function (i) {
|
||||
i.parentNode ? i.parentNode.removeChild(i) : true;
|
||||
});
|
||||
}
|
||||
|
||||
function viewfeed(params) {
|
||||
const feed = params.feed;
|
||||
const is_cat = !!params.is_cat || false;
|
||||
const offset = params.offset || 0;
|
||||
const viewfeed_debug = params.viewfeed_debug;
|
||||
const method = params.method;
|
||||
// this is used to quickly switch between feeds, sets active but xhr is on a timeout
|
||||
const delayed = params.delayed || false;
|
||||
|
||||
if (feed != getActiveFeedId() || activeFeedIsCat() != is_cat) {
|
||||
_search_query = false;
|
||||
}
|
||||
|
||||
if (offset != 0) {
|
||||
if (infscroll_in_progress)
|
||||
return;
|
||||
|
||||
infscroll_in_progress = 1;
|
||||
|
||||
window.clearTimeout(_infscroll_timeout);
|
||||
_infscroll_timeout = window.setTimeout(() => {
|
||||
console.log('infscroll request timed out, aborting');
|
||||
infscroll_in_progress = 0;
|
||||
|
||||
// call scroll handler to maybe repeat infscroll request
|
||||
headlinesScrollHandler();
|
||||
}, 10 * 1000);
|
||||
}
|
||||
|
||||
Form.enable("main_toolbar_form");
|
||||
|
||||
let query = Object.assign({op: "feeds", method: "view", feed: feed},
|
||||
dojo.formToObject("main_toolbar_form"));
|
||||
|
||||
if (method) query.m = method;
|
||||
|
||||
if (offset > 0) {
|
||||
if (current_first_id) {
|
||||
query.fid = current_first_id;
|
||||
}
|
||||
}
|
||||
|
||||
if (_search_query) {
|
||||
query = Object.assign(query, _search_query);
|
||||
}
|
||||
|
||||
if (offset != 0) {
|
||||
query.skip = offset;
|
||||
|
||||
// to prevent duplicate feed titles when showing grouped vfeeds
|
||||
if (vgroup_last_feed) {
|
||||
query.vgrlf = vgroup_last_feed;
|
||||
}
|
||||
} else if (!is_cat && feed == getActiveFeedId() && !params.method) {
|
||||
query.m = "ForceUpdate";
|
||||
// If number of properties is different,
|
||||
// objects are not equivalent
|
||||
if (aProps.length != bProps.length) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Form.enable("main_toolbar_form");
|
||||
for (let i = 0; i < aProps.length; i++) {
|
||||
const propName = aProps[i];
|
||||
|
||||
if (!delayed)
|
||||
if (!setFeedExpandoIcon(feed, is_cat,
|
||||
(is_cat) ? 'images/indicator_tiny.gif' : 'images/indicator_white.gif'))
|
||||
notify_progress("Loading, please wait...", true);
|
||||
// If values of same property are not equal,
|
||||
// objects are not equivalent
|
||||
if (a[propName] !== b[propName]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
query.cat = is_cat;
|
||||
// If we made it this far, objects
|
||||
// are considered equivalent
|
||||
return true;
|
||||
},
|
||||
resetCounters: function () {
|
||||
this._counters_prev = [];
|
||||
},
|
||||
parseCounters: function (elems) {
|
||||
for (let l = 0; l < elems.length; l++) {
|
||||
|
||||
setActiveFeedId(feed, is_cat);
|
||||
if (this._counters_prev[l] && this.counterEquals(elems[l], this._counters_prev[l])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (viewfeed_debug) {
|
||||
window.open("backend.php?" +
|
||||
dojo.objectToQuery(
|
||||
Object.assign({debug: 1, csrf_token: getInitParam("csrf_token")}, query)
|
||||
));
|
||||
}
|
||||
const id = elems[l].id;
|
||||
const kind = elems[l].kind;
|
||||
const ctr = parseInt(elems[l].counter);
|
||||
const error = elems[l].error;
|
||||
const has_img = elems[l].has_img;
|
||||
const updated = elems[l].updated;
|
||||
const auxctr = parseInt(elems[l].auxcounter);
|
||||
|
||||
if (id == "global-unread") {
|
||||
App.global_unread = ctr;
|
||||
App.updateTitle();
|
||||
continue;
|
||||
}
|
||||
|
||||
if (id == "subscribed-feeds") {
|
||||
/* feeds_found = ctr; */
|
||||
continue;
|
||||
}
|
||||
|
||||
/*if (getFeedUnread(id, (kind == "cat")) != ctr ||
|
||||
(kind == "cat")) {
|
||||
}*/
|
||||
|
||||
setFeedUnread(id, (kind == "cat"), ctr);
|
||||
setFeedValue(id, (kind == "cat"), 'auxcounter', auxctr);
|
||||
|
||||
if (kind != "cat") {
|
||||
setFeedValue(id, false, 'error', error);
|
||||
setFeedValue(id, false, 'updated', updated);
|
||||
|
||||
if (id > 0) {
|
||||
if (has_img) {
|
||||
setFeedIcon(id, false,
|
||||
getInitParam("icons_url") + "/" + id + ".ico?" + has_img);
|
||||
} else {
|
||||
setFeedIcon(id, false, 'images/blank_icon.gif');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.hideOrShowFeeds(getInitParam("hide_read_feeds") == 1);
|
||||
this._counters_prev = elems;
|
||||
},
|
||||
viewCurrentFeed: function(method) {
|
||||
console.log("viewCurrentFeed: " + method);
|
||||
|
||||
if (this.getActiveFeedId() != undefined) {
|
||||
this.viewfeed({feed: Feeds.getActiveFeedId(), is_cat: Feeds.activeFeedIsCat(), method: method});
|
||||
}
|
||||
return false; // block unneeded form submits
|
||||
},
|
||||
openNextUnreadFeed: function() {
|
||||
const is_cat = Feeds.activeFeedIsCat();
|
||||
const nuf = getNextUnreadFeed(Feeds.getActiveFeedId(), is_cat);
|
||||
if (nuf) this.viewfeed({feed: nuf, is_cat: is_cat});
|
||||
},
|
||||
collapseFeedlist: function() {
|
||||
Element.toggle("feeds-holder");
|
||||
|
||||
const splitter = $("feeds-holder_splitter");
|
||||
|
||||
Element.visible("feeds-holder") ? splitter.show() : splitter.hide();
|
||||
|
||||
dijit.byId("main").resize();
|
||||
},
|
||||
cancelSearch: function() {
|
||||
this._search_query = "";
|
||||
Feeds.viewCurrentFeed();
|
||||
},
|
||||
requestCounters: function(force) {
|
||||
const date = new Date();
|
||||
const timestamp = Math.round(date.getTime() / 1000);
|
||||
|
||||
if (force || timestamp - counters_last_request > 5) {
|
||||
console.log("scheduling request of counters...");
|
||||
|
||||
counters_last_request = timestamp;
|
||||
|
||||
let query = {op: "rpc", method: "getAllCounters", seq: App.next_seq()};
|
||||
|
||||
if (!force)
|
||||
query.last_article_id = getInitParam("last_article_id");
|
||||
|
||||
window.clearTimeout(_viewfeed_wait_timeout);
|
||||
_viewfeed_wait_timeout = window.setTimeout(() => {
|
||||
catchupBatchedArticles(() => {
|
||||
xhrPost("backend.php", query, (transport) => {
|
||||
App.handleRpcJson(transport);
|
||||
});
|
||||
|
||||
} else {
|
||||
console.log("request_counters: rate limit reached: " + (timestamp - counters_last_request));
|
||||
}
|
||||
},
|
||||
reload: function() {
|
||||
try {
|
||||
Element.show("feedlistLoading");
|
||||
|
||||
this.resetCounters();
|
||||
|
||||
if (dijit.byId("feedTree")) {
|
||||
dijit.byId("feedTree").destroyRecursive();
|
||||
}
|
||||
|
||||
const store = new dojo.data.ItemFileWriteStore({
|
||||
url: "backend.php?op=pref_feeds&method=getfeedtree&mode=2"
|
||||
});
|
||||
|
||||
const treeModel = new fox.FeedStoreModel({
|
||||
store: store,
|
||||
query: {
|
||||
"type": getInitParam('enable_feed_cats') == 1 ? "category" : "feed"
|
||||
},
|
||||
rootId: "root",
|
||||
rootLabel: "Feeds",
|
||||
childrenAttrs: ["items"]
|
||||
});
|
||||
|
||||
const tree = new fox.FeedTree({
|
||||
model: treeModel,
|
||||
onClick: function (item, node) {
|
||||
const id = String(item.id);
|
||||
const is_cat = id.match("^CAT:");
|
||||
const feed = id.substr(id.indexOf(":") + 1);
|
||||
Feeds.viewfeed({feed: feed, is_cat: is_cat});
|
||||
return false;
|
||||
},
|
||||
openOnClick: false,
|
||||
showRoot: false,
|
||||
persist: true,
|
||||
id: "feedTree",
|
||||
}, "feedTree");
|
||||
|
||||
const tmph = dojo.connect(dijit.byId('feedMenu'), '_openMyself', function (event) {
|
||||
console.log(dijit.getEnclosingWidget(event.target));
|
||||
dojo.disconnect(tmph);
|
||||
});
|
||||
|
||||
$("feeds-holder").appendChild(tree.domNode);
|
||||
|
||||
const tmph2 = dojo.connect(tree, 'onLoad', function () {
|
||||
dojo.disconnect(tmph2);
|
||||
Element.hide("feedlistLoading");
|
||||
|
||||
try {
|
||||
setFeedExpandoIcon(feed, is_cat, 'images/blank_icon.gif');
|
||||
headlines_callback2(transport, offset);
|
||||
PluginHost.run(PluginHost.HOOK_FEED_LOADED, [feed, is_cat]);
|
||||
Feeds.init();
|
||||
setLoadingProgress(25);
|
||||
} catch (e) {
|
||||
exception_error(e);
|
||||
}
|
||||
});
|
||||
|
||||
tree.startup();
|
||||
} catch (e) {
|
||||
exception_error(e);
|
||||
}
|
||||
},
|
||||
init: function() {
|
||||
console.log("in feedlist init");
|
||||
|
||||
setLoadingProgress(50);
|
||||
|
||||
document.onkeydown = App.hotkeyHandler;
|
||||
setInterval(hotkeyPrefixTimeout, 3 * 1000);
|
||||
setInterval(catchupBatchedArticles, 10 * 1000);
|
||||
|
||||
if (!this.getActiveFeedId()) {
|
||||
this.viewfeed({feed: -3});
|
||||
} else {
|
||||
this.viewfeed({feed: this.getActiveFeedId(), is_cat: this.activeFeedIsCat()});
|
||||
}
|
||||
|
||||
this.hideOrShowFeeds(getInitParam("hide_read_feeds") == 1);
|
||||
|
||||
if (getInitParam("is_default_pw")) {
|
||||
console.warn("user password is at default value");
|
||||
|
||||
const dialog = new dijit.Dialog({
|
||||
title: __("Your password is at default value"),
|
||||
href: "backend.php?op=dlg&method=defaultpasswordwarning",
|
||||
id: 'infoBox',
|
||||
style: "width: 600px",
|
||||
onCancel: function () {
|
||||
return true;
|
||||
},
|
||||
onExecute: function () {
|
||||
return true;
|
||||
},
|
||||
onClose: function () {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
// bw_limit disables timeout() so we request initial counters separately
|
||||
if (getInitParam("bw_limit") == "1") {
|
||||
this.requestCounters(true);
|
||||
} else {
|
||||
setTimeout(() => {
|
||||
this.requestCounters(true);
|
||||
|
||||
setInterval(() => {
|
||||
this.requestCounters();
|
||||
}, 60 * 1000)
|
||||
}, 250);
|
||||
}
|
||||
},
|
||||
activeFeedIsCat: function() {
|
||||
return !!this._active_feed_is_cat;
|
||||
},
|
||||
getActiveFeedId: function() {
|
||||
return this._active_feed_id;
|
||||
},
|
||||
setActiveFeedId: function(id, is_cat) {
|
||||
hash_set('f', id);
|
||||
hash_set('c', is_cat ? 1 : 0);
|
||||
|
||||
this._active_feed_id = id;
|
||||
this._active_feed_is_cat = is_cat;
|
||||
|
||||
$("headlines-frame").setAttribute("feed-id", id);
|
||||
$("headlines-frame").setAttribute("is-cat", is_cat ? 1 : 0);
|
||||
|
||||
this.selectFeed(id, is_cat);
|
||||
|
||||
PluginHost.run(PluginHost.HOOK_FEED_SET_ACTIVE, _active_article_id);
|
||||
},
|
||||
selectFeed: function(feed, is_cat) {
|
||||
const tree = dijit.byId("feedTree");
|
||||
|
||||
if (tree) return tree.selectFeed(feed, is_cat);
|
||||
},
|
||||
toggleDispRead: function() {
|
||||
const hide = !(getInitParam("hide_read_feeds") == "1");
|
||||
|
||||
xhrPost("backend.php", {op: "rpc", method: "setpref", key: "HIDE_READ_FEEDS", value: hide}, () => {
|
||||
this.hideOrShowFeeds(hide);
|
||||
setInitParam("hide_read_feeds", hide);
|
||||
});
|
||||
}, delayed ? 250 : 0);
|
||||
}
|
||||
},
|
||||
hideOrShowFeeds: function(hide) {
|
||||
const tree = dijit.byId("feedTree");
|
||||
|
||||
function feedlist_init() {
|
||||
console.log("in feedlist init");
|
||||
if (tree)
|
||||
return tree.hideRead(hide, getInitParam("hide_read_shows_special"));
|
||||
},
|
||||
viewfeed: function(params) {
|
||||
const feed = params.feed;
|
||||
const is_cat = !!params.is_cat || false;
|
||||
const offset = params.offset || 0;
|
||||
const viewfeed_debug = params.viewfeed_debug;
|
||||
const method = params.method;
|
||||
// this is used to quickly switch between feeds, sets active but xhr is on a timeout
|
||||
const delayed = params.delayed || false;
|
||||
|
||||
setLoadingProgress(50);
|
||||
if (feed != Feeds.getActiveFeedId() || Feeds.activeFeedIsCat() != is_cat) {
|
||||
this._search_query = false;
|
||||
setActiveArticleId(0);
|
||||
}
|
||||
|
||||
document.onkeydown = hotkey_handler;
|
||||
setInterval(hotkeyPrefixTimeout, 3*1000);
|
||||
setInterval(catchupBatchedArticles, 10*1000);
|
||||
if (offset != 0) {
|
||||
if (this.infscroll_in_progress)
|
||||
return;
|
||||
|
||||
if (!getActiveFeedId()) {
|
||||
viewfeed({feed: -3});
|
||||
} else {
|
||||
viewfeed({feed: getActiveFeedId(), is_cat: activeFeedIsCat()});
|
||||
}
|
||||
this.infscroll_in_progress = 1;
|
||||
|
||||
hideOrShowFeeds(getInitParam("hide_read_feeds") == 1);
|
||||
window.clearTimeout(this._infscroll_timeout);
|
||||
this._infscroll_timeout = window.setTimeout(() => {
|
||||
console.log('infscroll request timed out, aborting');
|
||||
this.infscroll_in_progress = 0;
|
||||
|
||||
if (getInitParam("is_default_pw")) {
|
||||
console.warn("user password is at default value");
|
||||
// call scroll handler to maybe repeat infscroll request
|
||||
Headlines.scrollHandler();
|
||||
}, 10 * 1000);
|
||||
}
|
||||
|
||||
const dialog = new dijit.Dialog({
|
||||
title: __("Your password is at default value"),
|
||||
href: "backend.php?op=dlg&method=defaultpasswordwarning",
|
||||
id: 'infoBox',
|
||||
style: "width: 600px",
|
||||
onCancel: function() {
|
||||
return true;
|
||||
},
|
||||
onExecute: function() {
|
||||
return true;
|
||||
},
|
||||
onClose: function() {
|
||||
return true;
|
||||
Form.enable("main_toolbar_form");
|
||||
|
||||
let query = Object.assign({op: "feeds", method: "view", feed: feed},
|
||||
dojo.formToObject("main_toolbar_form"));
|
||||
|
||||
if (method) query.m = method;
|
||||
|
||||
if (offset > 0) {
|
||||
if (current_first_id) {
|
||||
query.fid = current_first_id;
|
||||
}
|
||||
});
|
||||
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
// bw_limit disables timeout() so we request initial counters separately
|
||||
if (getInitParam("bw_limit") == "1") {
|
||||
request_counters(true);
|
||||
} else {
|
||||
setTimeout(timeout, 250);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function request_counters(force) {
|
||||
const date = new Date();
|
||||
const timestamp = Math.round(date.getTime() / 1000);
|
||||
|
||||
if (force || timestamp - counters_last_request > 5) {
|
||||
console.log("scheduling request of counters...");
|
||||
|
||||
counters_last_request = timestamp;
|
||||
|
||||
let query = {op: "rpc", method: "getAllCounters", seq: next_seq()};
|
||||
|
||||
if (!force)
|
||||
query.last_article_id = getInitParam("last_article_id");
|
||||
|
||||
xhrPost("backend.php", query, (transport) => {
|
||||
handle_rpc_json(transport);
|
||||
});
|
||||
|
||||
} else {
|
||||
console.log("request_counters: rate limit reached: " + (timestamp - counters_last_request));
|
||||
}
|
||||
}
|
||||
|
||||
// NOTE: this implementation is incomplete
|
||||
// for general objects but good enough for counters
|
||||
// http://adripofjavascript.com/blog/drips/object-equality-in-javascript.html
|
||||
function counter_is_equal(a, b) {
|
||||
// Create arrays of property names
|
||||
const aProps = Object.getOwnPropertyNames(a);
|
||||
const bProps = Object.getOwnPropertyNames(b);
|
||||
|
||||
// If number of properties is different,
|
||||
// objects are not equivalent
|
||||
if (aProps.length != bProps.length) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (let i = 0; i < aProps.length; i++) {
|
||||
const propName = aProps[i];
|
||||
|
||||
// If values of same property are not equal,
|
||||
// objects are not equivalent
|
||||
if (a[propName] !== b[propName]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// If we made it this far, objects
|
||||
// are considered equivalent
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
function parse_counters(elems) {
|
||||
for (let l = 0; l < elems.length; l++) {
|
||||
|
||||
if (_counters_prev[l] && counter_is_equal(elems[l], _counters_prev[l])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const id = elems[l].id;
|
||||
const kind = elems[l].kind;
|
||||
const ctr = parseInt(elems[l].counter);
|
||||
const error = elems[l].error;
|
||||
const has_img = elems[l].has_img;
|
||||
const updated = elems[l].updated;
|
||||
const auxctr = parseInt(elems[l].auxcounter);
|
||||
|
||||
if (id == "global-unread") {
|
||||
global_unread = ctr;
|
||||
updateTitle();
|
||||
continue;
|
||||
if (this._search_query) {
|
||||
query = Object.assign(query, this._search_query);
|
||||
}
|
||||
|
||||
if (id == "subscribed-feeds") {
|
||||
/* feeds_found = ctr; */
|
||||
continue;
|
||||
if (offset != 0) {
|
||||
query.skip = offset;
|
||||
|
||||
// to prevent duplicate feed titles when showing grouped vfeeds
|
||||
if (vgroup_last_feed) {
|
||||
query.vgrlf = vgroup_last_feed;
|
||||
}
|
||||
} else if (!is_cat && feed == Feeds.getActiveFeedId() && !params.method) {
|
||||
query.m = "ForceUpdate";
|
||||
}
|
||||
|
||||
/*if (getFeedUnread(id, (kind == "cat")) != ctr ||
|
||||
(kind == "cat")) {
|
||||
}*/
|
||||
Form.enable("main_toolbar_form");
|
||||
|
||||
setFeedUnread(id, (kind == "cat"), ctr);
|
||||
setFeedValue(id, (kind == "cat"), 'auxcounter', auxctr);
|
||||
if (!delayed)
|
||||
if (!setFeedExpandoIcon(feed, is_cat,
|
||||
(is_cat) ? 'images/indicator_tiny.gif' : 'images/indicator_white.gif'))
|
||||
notify_progress("Loading, please wait...", true);
|
||||
|
||||
if (kind != "cat") {
|
||||
setFeedValue(id, false, 'error', error);
|
||||
setFeedValue(id, false, 'updated', updated);
|
||||
query.cat = is_cat;
|
||||
|
||||
if (id > 0) {
|
||||
if (has_img) {
|
||||
setFeedIcon(id, false,
|
||||
getInitParam("icons_url") + "/" + id + ".ico?" + has_img);
|
||||
} else {
|
||||
setFeedIcon(id, false, 'images/blank_icon.gif');
|
||||
Feeds.setActiveFeedId(feed, is_cat);
|
||||
|
||||
if (viewfeed_debug) {
|
||||
window.open("backend.php?" +
|
||||
dojo.objectToQuery(
|
||||
Object.assign({debug: 1, csrf_token: getInitParam("csrf_token")}, query)
|
||||
));
|
||||
}
|
||||
|
||||
window.clearTimeout(this._viewfeed_wait_timeout);
|
||||
this._viewfeed_wait_timeout = window.setTimeout(() => {
|
||||
catchupBatchedArticles(() => {
|
||||
xhrPost("backend.php", query, (transport) => {
|
||||
try {
|
||||
setFeedExpandoIcon(feed, is_cat, 'images/blank_icon.gif');
|
||||
Headlines.onLoaded(transport, offset);
|
||||
PluginHost.run(PluginHost.HOOK_FEED_LOADED, [feed, is_cat]);
|
||||
} catch (e) {
|
||||
exception_error(e);
|
||||
}
|
||||
});
|
||||
});
|
||||
}, delayed ? 250 : 0);
|
||||
},
|
||||
catchupAllFeeds: function() {
|
||||
const str = __("Mark all articles as read?");
|
||||
|
||||
if (getInitParam("confirm_feed_catchup") != 1 || confirm(str)) {
|
||||
|
||||
notify_progress("Marking all feeds as read...");
|
||||
|
||||
xhrPost("backend.php", {op: "feeds", method: "catchupAll"}, () => {
|
||||
this.requestCounters(true);
|
||||
this.viewCurrentFeed();
|
||||
});
|
||||
|
||||
App.global_unread = 0;
|
||||
App.updateTitle();
|
||||
}
|
||||
},
|
||||
decrementFeedCounter: function(feed, is_cat) {
|
||||
let ctr = getFeedUnread(feed, is_cat);
|
||||
|
||||
if (ctr > 0) {
|
||||
setFeedUnread(feed, is_cat, ctr - 1);
|
||||
App.global_unread -= 1;
|
||||
App.updateTitle();
|
||||
|
||||
if (!is_cat) {
|
||||
const cat = parseInt(getFeedCategory(feed));
|
||||
|
||||
if (!isNaN(cat)) {
|
||||
ctr = getFeedUnread(cat, true);
|
||||
|
||||
if (ctr > 0) {
|
||||
setFeedUnread(cat, true, ctr - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
hideOrShowFeeds(getInitParam("hide_read_feeds") == 1);
|
||||
|
||||
_counters_prev = elems;
|
||||
}
|
||||
};
|
||||
|
||||
function getFeedUnread(feed, is_cat) {
|
||||
try {
|
||||
|
@ -326,13 +454,6 @@ function getFeedCategory(feed) {
|
|||
return false;
|
||||
}
|
||||
|
||||
function hideOrShowFeeds(hide) {
|
||||
const tree = dijit.byId("feedTree");
|
||||
|
||||
if (tree)
|
||||
return tree.hideRead(hide, getInitParam("hide_read_shows_special"));
|
||||
}
|
||||
|
||||
function getFeedName(feed, is_cat) {
|
||||
|
||||
if (isNaN(feed)) return feed; // it's a tag
|
||||
|
@ -375,12 +496,6 @@ function setFeedValue(feed, is_cat, key, value) {
|
|||
}
|
||||
}
|
||||
|
||||
function selectFeed(feed, is_cat) {
|
||||
const tree = dijit.byId("feedTree");
|
||||
|
||||
if (tree) return tree.selectFeed(feed, is_cat);
|
||||
}
|
||||
|
||||
function setFeedIcon(feed, is_cat, src) {
|
||||
const tree = dijit.byId("feedTree");
|
||||
|
||||
|
@ -404,7 +519,7 @@ function getNextUnreadFeed(feed, is_cat) {
|
|||
}
|
||||
|
||||
function catchupCurrentFeed(mode) {
|
||||
catchupFeed(getActiveFeedId(), activeFeedIsCat(), mode);
|
||||
catchupFeed(Feeds.getActiveFeedId(), Feeds.activeFeedIsCat(), mode);
|
||||
}
|
||||
|
||||
function catchupFeedInGroup(id) {
|
||||
|
@ -440,13 +555,13 @@ function catchupFeedInGroup(id) {
|
|||
}
|
||||
}
|
||||
|
||||
updateFloatingTitle(true);
|
||||
Headlines.updateFloatingTitle(true);
|
||||
}
|
||||
|
||||
notify_progress("Loading, please wait...", true);
|
||||
|
||||
xhrPost("backend.php", { op: "rpc", method: "catchupFeed", feed_id: id, is_cat: false}, (transport) => {
|
||||
handle_rpc_json(transport);
|
||||
App.handleRpcJson(transport);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -487,7 +602,7 @@ function catchupFeed(feed, is_cat, mode) {
|
|||
notify_progress("Loading, please wait...", true);
|
||||
|
||||
xhrPost("backend.php", catchup_query, (transport) => {
|
||||
handle_rpc_json(transport);
|
||||
App.handleRpcJson(transport);
|
||||
|
||||
const show_next_feed = getInitParam("on_catchup_show_next_feed") == "1";
|
||||
|
||||
|
@ -495,37 +610,15 @@ function catchupFeed(feed, is_cat, mode) {
|
|||
const nuf = getNextUnreadFeed(feed, is_cat);
|
||||
|
||||
if (nuf) {
|
||||
viewfeed({feed: nuf, is_cat: is_cat});
|
||||
Feeds.viewfeed({feed: nuf, is_cat: is_cat});
|
||||
}
|
||||
} else if (feed == getActiveFeedId() && is_cat == activeFeedIsCat()) {
|
||||
viewCurrentFeed();
|
||||
} else if (feed == Feeds.getActiveFeedId() && is_cat == Feeds.activeFeedIsCat()) {
|
||||
Feeds.viewCurrentFeed();
|
||||
}
|
||||
|
||||
notify("");
|
||||
});
|
||||
}
|
||||
|
||||
function decrementFeedCounter(feed, is_cat) {
|
||||
let ctr = getFeedUnread(feed, is_cat);
|
||||
|
||||
if (ctr > 0) {
|
||||
setFeedUnread(feed, is_cat, ctr - 1);
|
||||
global_unread = global_unread - 1;
|
||||
updateTitle();
|
||||
|
||||
if (!is_cat) {
|
||||
const cat = parseInt(getFeedCategory(feed));
|
||||
|
||||
if (!isNaN(cat)) {
|
||||
ctr = getFeedUnread(cat, true);
|
||||
|
||||
if (ctr > 0) {
|
||||
setFeedUnread(cat, true, ctr - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
178
js/functions.js
178
js/functions.js
|
@ -50,13 +50,85 @@ function xhrJson(url, params, complete) {
|
|||
}
|
||||
|
||||
/* add method to remove element from array */
|
||||
|
||||
Array.prototype.remove = function(s) {
|
||||
for (let i=0; i < this.length; i++) {
|
||||
if (s == this[i]) this.splice(i, 1);
|
||||
}
|
||||
};
|
||||
|
||||
const Utils = {
|
||||
cleanupMemory: function(root) {
|
||||
const dijits = dojo.query("[widgetid]", dijit.byId(root).domNode).map(dijit.byNode);
|
||||
|
||||
dijits.each(function (d) {
|
||||
dojo.destroy(d.domNode);
|
||||
});
|
||||
|
||||
$$("#" + root + " *").each(function (i) {
|
||||
i.parentNode ? i.parentNode.removeChild(i) : true;
|
||||
});
|
||||
},
|
||||
helpDialog: function(topic) {
|
||||
const query = "backend.php?op=backend&method=help&topic=" + param_escape(topic);
|
||||
|
||||
if (dijit.byId("helpDlg"))
|
||||
dijit.byId("helpDlg").destroyRecursive();
|
||||
|
||||
const dialog = new dijit.Dialog({
|
||||
id: "helpDlg",
|
||||
title: __("Help"),
|
||||
style: "width: 600px",
|
||||
href: query,
|
||||
});
|
||||
|
||||
dialog.show();
|
||||
},
|
||||
displayDlg: function(title, id, param, callback) {
|
||||
notify_progress("Loading, please wait...", true);
|
||||
|
||||
const query = {op: "dlg", method: id, param: param};
|
||||
|
||||
xhrPost("backend.php", query, (transport) => {
|
||||
try {
|
||||
const content = transport.responseText;
|
||||
|
||||
let dialog = dijit.byId("infoBox");
|
||||
|
||||
if (!dialog) {
|
||||
dialog = new dijit.Dialog({
|
||||
title: title,
|
||||
id: 'infoBox',
|
||||
style: "width: 600px",
|
||||
onCancel: function () {
|
||||
return true;
|
||||
},
|
||||
onExecute: function () {
|
||||
return true;
|
||||
},
|
||||
onClose: function () {
|
||||
return true;
|
||||
},
|
||||
content: content
|
||||
});
|
||||
} else {
|
||||
dialog.attr('title', title);
|
||||
dialog.attr('content', content);
|
||||
}
|
||||
|
||||
dialog.show();
|
||||
|
||||
notify("");
|
||||
|
||||
if (callback) callback(transport);
|
||||
} catch (e) {
|
||||
exception_error(e);
|
||||
}
|
||||
});
|
||||
|
||||
return false;
|
||||
},
|
||||
};
|
||||
|
||||
function report_error(message, filename, lineno, colno, error) {
|
||||
exception_error(error, null, filename, lineno);
|
||||
}
|
||||
|
@ -324,51 +396,6 @@ function closeInfoBox() {
|
|||
return false;
|
||||
}
|
||||
|
||||
function displayDlg(title, id, param, callback) {
|
||||
notify_progress("Loading, please wait...", true);
|
||||
|
||||
const query = { op: "dlg", method: id, param: param };
|
||||
|
||||
xhrPost("backend.php", query, (transport) => {
|
||||
try {
|
||||
const content = transport.responseText;
|
||||
|
||||
let dialog = dijit.byId("infoBox");
|
||||
|
||||
if (!dialog) {
|
||||
dialog = new dijit.Dialog({
|
||||
title: title,
|
||||
id: 'infoBox',
|
||||
style: "width: 600px",
|
||||
onCancel: function () {
|
||||
return true;
|
||||
},
|
||||
onExecute: function () {
|
||||
return true;
|
||||
},
|
||||
onClose: function () {
|
||||
return true;
|
||||
},
|
||||
content: content
|
||||
});
|
||||
} else {
|
||||
dialog.attr('title', title);
|
||||
dialog.attr('content', content);
|
||||
}
|
||||
|
||||
dialog.show();
|
||||
|
||||
notify("");
|
||||
|
||||
if (callback) callback(transport);
|
||||
} catch (e) {
|
||||
exception_error(e);
|
||||
}
|
||||
});
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function getInitParam(key) {
|
||||
return init_params[key];
|
||||
}
|
||||
|
@ -453,7 +480,7 @@ function filterDlgCheckAction(sender) {
|
|||
|
||||
|
||||
function explainError(code) {
|
||||
return displayDlg(__("Error explained"), "explainError", code);
|
||||
return Utils.displayDlg(__("Error explained"), "explainError", code);
|
||||
}
|
||||
|
||||
function setLoadingProgress(p) {
|
||||
|
@ -489,9 +516,9 @@ function uploadIconHandler(rc) {
|
|||
case 0:
|
||||
notify_info("Upload complete.");
|
||||
if (inPreferences()) {
|
||||
updateFeedList();
|
||||
Feeds.reload();
|
||||
} else {
|
||||
setTimeout('updateFeedList(false, false)', 50);
|
||||
setTimeout('Feeds.reload(false, false)', 50);
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
|
@ -514,9 +541,9 @@ function removeFeedIcon(id) {
|
|||
xhrPost("backend.php", query, (transport) => {
|
||||
notify_info("Feed icon removed.");
|
||||
if (inPreferences()) {
|
||||
updateFeedList();
|
||||
Feeds.reload();
|
||||
} else {
|
||||
setTimeout('updateFeedList(false, false)', 50);
|
||||
setTimeout('Feeds.reload(false, false)', 50);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -556,7 +583,7 @@ function addLabel(select, callback) {
|
|||
} else if (inPreferences()) {
|
||||
updateLabelList();
|
||||
} else {
|
||||
updateFeedList();
|
||||
Feeds.reload();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -616,7 +643,7 @@ function quickAddFeed() {
|
|||
dialog.hide();
|
||||
notify_info(__("Subscribed to %s").replace("%s", feed_url));
|
||||
|
||||
updateFeedList();
|
||||
Feeds.reload();
|
||||
break;
|
||||
case 2:
|
||||
dialog.show_error(__("Specified URL seems to be invalid."));
|
||||
|
@ -889,7 +916,7 @@ function quickAddFilter() {
|
|||
|
||||
if (!inPreferences()) {
|
||||
query = { op: "pref-filters", method: "newfilter",
|
||||
feed: getActiveFeedId(), is_cat: activeFeedIsCat() };
|
||||
feed: Feeds.getActiveFeedId(), is_cat: Feeds.activeFeedIsCat() };
|
||||
} else {
|
||||
query = { op: "pref-filters", method: "newfilter" };
|
||||
}
|
||||
|
@ -973,8 +1000,8 @@ function quickAddFilter() {
|
|||
|
||||
if (selectedText != "") {
|
||||
|
||||
const feed_id = activeFeedIsCat() ? 'CAT:' + parseInt(getActiveFeedId()) :
|
||||
getActiveFeedId();
|
||||
const feed_id = Feeds.activeFeedIsCat() ? 'CAT:' + parseInt(Feeds.getActiveFeedId()) :
|
||||
Feeds.getActiveFeedId();
|
||||
|
||||
const rule = { reg_exp: selectedText, feed_id: [feed_id], filter_type: 1 };
|
||||
|
||||
|
@ -991,12 +1018,12 @@ function quickAddFilter() {
|
|||
|
||||
if (reply && reply.title) title = reply.title;
|
||||
|
||||
if (title || getActiveFeedId() || activeFeedIsCat()) {
|
||||
if (title || Feeds.getActiveFeedId() || Feeds.activeFeedIsCat()) {
|
||||
|
||||
console.log(title + " " + getActiveFeedId());
|
||||
console.log(title + " " + Feeds.getActiveFeedId());
|
||||
|
||||
const feed_id = activeFeedIsCat() ? 'CAT:' + parseInt(getActiveFeedId()) :
|
||||
getActiveFeedId();
|
||||
const feed_id = Feeds.activeFeedIsCat() ? 'CAT:' + parseInt(Feeds.getActiveFeedId()) :
|
||||
Feeds.getActiveFeedId();
|
||||
|
||||
const rule = { reg_exp: title, feed_id: [feed_id], filter_type: 1 };
|
||||
|
||||
|
@ -1024,12 +1051,13 @@ function unsubscribeFeed(feed_id, title) {
|
|||
if (dijit.byId("feedEditDlg")) dijit.byId("feedEditDlg").hide();
|
||||
|
||||
if (inPreferences()) {
|
||||
updateFeedList();
|
||||
Feeds.reload();
|
||||
} else {
|
||||
if (feed_id == getActiveFeedId())
|
||||
setTimeout(function() { viewfeed({feed:-5}) }, 100);
|
||||
if (feed_id == Feeds.getActiveFeedId())
|
||||
setTimeout(() => { Feeds.viewfeed({feed:-5}) },
|
||||
100);
|
||||
|
||||
if (feed_id < 0) updateFeedList();
|
||||
if (feed_id < 0) Feeds.reload();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -1219,7 +1247,7 @@ function editFeed(feed) {
|
|||
xhrPost("backend.php", dialog.attr('value'), () => {
|
||||
dialog.hide();
|
||||
notify('');
|
||||
updateFeedList();
|
||||
Feeds.reload();
|
||||
});
|
||||
}
|
||||
},
|
||||
|
@ -1290,7 +1318,7 @@ function feedBrowser() {
|
|||
|
||||
xhrPost("backend.php", query, () => {
|
||||
notify('');
|
||||
updateFeedList();
|
||||
Feeds.reload();
|
||||
});
|
||||
|
||||
} else {
|
||||
|
@ -1375,7 +1403,7 @@ function showFeedsWithErrors() {
|
|||
xhrPost("backend.php", query, () => {
|
||||
notify('');
|
||||
dialog.hide();
|
||||
updateFeedList();
|
||||
Feeds.reload();
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -1399,22 +1427,6 @@ function get_timestamp() {
|
|||
return Math.round(date.getTime() / 1000);
|
||||
}
|
||||
|
||||
function helpDialog(topic) {
|
||||
const query = "backend.php?op=backend&method=help&topic=" + param_escape(topic);
|
||||
|
||||
if (dijit.byId("helpDlg"))
|
||||
dijit.byId("helpDlg").destroyRecursive();
|
||||
|
||||
const dialog = new dijit.Dialog({
|
||||
id: "helpDlg",
|
||||
title: __("Help"),
|
||||
style: "width: 600px",
|
||||
href: query,
|
||||
});
|
||||
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
// noinspection JSUnusedGlobalSymbols
|
||||
function label_to_feed_id(label) {
|
||||
return _label_base_index - 1 - Math.abs(label);
|
||||
|
|
26
js/prefs.js
26
js/prefs.js
|
@ -6,7 +6,7 @@ function notify_callback2(transport, sticky) {
|
|||
notify_info(transport.responseText, sticky);
|
||||
}
|
||||
|
||||
function updateFeedList() {
|
||||
function Feeds.reload() {
|
||||
|
||||
const user_search = $("feed_search");
|
||||
let search = "";
|
||||
|
@ -324,7 +324,7 @@ function removeSelectedFeeds() {
|
|||
ids: sel_rows.toString() };
|
||||
|
||||
xhrPost("backend.php", query, () => {
|
||||
updateFeedList();
|
||||
Feeds.reload();
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -524,7 +524,7 @@ function editSelectedFeeds() {
|
|||
|
||||
xhrPost("backend.php", query, () => {
|
||||
dialog.hide();
|
||||
updateFeedList();
|
||||
Feeds.reload();
|
||||
});
|
||||
}
|
||||
},
|
||||
|
@ -618,7 +618,7 @@ function selectTab(id, noupdate) {
|
|||
|
||||
switch (id) {
|
||||
case "feedConfig":
|
||||
updateFeedList();
|
||||
Feeds.reload();
|
||||
break;
|
||||
case "filterConfig":
|
||||
updateFilterList();
|
||||
|
@ -764,7 +764,7 @@ function pref_hotkey_handler(e) {
|
|||
quickAddFilter();
|
||||
return false;
|
||||
case "help_dialog":
|
||||
helpDialog("main");
|
||||
Utils.helpDialog("main");
|
||||
return false;
|
||||
default:
|
||||
console.log("unhandled action: " + action_name + "; keycode: " + e.which);
|
||||
|
@ -782,7 +782,7 @@ function removeCategory(id, item) {
|
|||
|
||||
xhrPost("backend.php", query, () => {
|
||||
notify('');
|
||||
updateFeedList();
|
||||
Feeds.reload();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -798,7 +798,7 @@ function removeSelectedCategories() {
|
|||
ids: sel_rows.toString() };
|
||||
|
||||
xhrPost("backend.php", query, () => {
|
||||
updateFeedList();
|
||||
Feeds.reload();
|
||||
});
|
||||
}
|
||||
} else {
|
||||
|
@ -816,7 +816,7 @@ function createCategory() {
|
|||
|
||||
xhrPost("backend.php", { op: "pref-feeds", method: "addCat", cat: title }, () => {
|
||||
notify('');
|
||||
updateFeedList();
|
||||
Feeds.reload();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -847,7 +847,7 @@ function showInactiveFeeds() {
|
|||
xhrPost("backend.php", query, () => {
|
||||
notify('');
|
||||
dialog.hide();
|
||||
updateFeedList();
|
||||
Feeds.reload();
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -1037,7 +1037,7 @@ function resetFeedOrder() {
|
|||
notify_progress("Loading, please wait...");
|
||||
|
||||
xhrPost("backend.php", { op: "pref-feeds", method: "feedsortreset" }, () => {
|
||||
updateFeedList();
|
||||
Feeds.reload();
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -1045,7 +1045,7 @@ function resetCatOrder() {
|
|||
notify_progress("Loading, please wait...");
|
||||
|
||||
xhrPost("backend.php", { op: "pref-feeds", method: "catsortreset" }, () => {
|
||||
updateFeedList();
|
||||
Feeds.reload();
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -1057,7 +1057,7 @@ function editCat(id, item) {
|
|||
notify_progress("Loading, please wait...");
|
||||
|
||||
xhrPost("backend.php", { op: 'pref-feeds', method: 'renamecat', id: id, title: new_name }, () => {
|
||||
updateFeedList();
|
||||
Feeds.reload();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -1176,7 +1176,7 @@ function batchSubscribe() {
|
|||
|
||||
xhrPost("backend.php", this.attr('value'), () => {
|
||||
notify("");
|
||||
updateFeedList();
|
||||
Feeds.reload();
|
||||
dialog.hide();
|
||||
});
|
||||
}
|
||||
|
|
635
js/tt-rss.js
635
js/tt-rss.js
|
@ -1,148 +1,215 @@
|
|||
/* global dijit, __ */
|
||||
|
||||
let global_unread = -1;
|
||||
let _widescreen_mode = false;
|
||||
let _rpc_seq = 0;
|
||||
let _active_feed_id = 0;
|
||||
let _active_feed_is_cat = false;
|
||||
let hotkey_actions = {};
|
||||
let _headlines_scroll_timeout = false;
|
||||
|
||||
function next_seq() {
|
||||
_rpc_seq += 1;
|
||||
return _rpc_seq;
|
||||
}
|
||||
const App = {
|
||||
_rpc_seq: 0,
|
||||
global_unread: -1,
|
||||
next_seq: function() {
|
||||
this._rpc_seq += 1;
|
||||
return this._rpc_seq;
|
||||
},
|
||||
get_seq: function() {
|
||||
return this._rpc_seq;
|
||||
},
|
||||
updateTitle: function() {
|
||||
let tmp = "Tiny Tiny RSS";
|
||||
|
||||
function get_seq() {
|
||||
return _rpc_seq;
|
||||
}
|
||||
|
||||
function activeFeedIsCat() {
|
||||
return !!_active_feed_is_cat;
|
||||
}
|
||||
|
||||
function getActiveFeedId() {
|
||||
return _active_feed_id;
|
||||
}
|
||||
|
||||
function setActiveFeedId(id, is_cat) {
|
||||
hash_set('f', id);
|
||||
hash_set('c', is_cat ? 1 : 0);
|
||||
|
||||
_active_feed_id = id;
|
||||
_active_feed_is_cat = is_cat;
|
||||
|
||||
$("headlines-frame").setAttribute("feed-id", id);
|
||||
$("headlines-frame").setAttribute("is-cat", is_cat ? 1 : 0);
|
||||
|
||||
selectFeed(id, is_cat);
|
||||
|
||||
PluginHost.run(PluginHost.HOOK_FEED_SET_ACTIVE, _active_article_id);
|
||||
}
|
||||
|
||||
|
||||
function updateFeedList() {
|
||||
try {
|
||||
Element.show("feedlistLoading");
|
||||
|
||||
resetCounterCache();
|
||||
|
||||
if (dijit.byId("feedTree")) {
|
||||
dijit.byId("feedTree").destroyRecursive();
|
||||
if (this.global_unread > 0) {
|
||||
tmp = "(" + this.global_unread + ") " + tmp;
|
||||
}
|
||||
|
||||
const store = new dojo.data.ItemFileWriteStore({
|
||||
url: "backend.php?op=pref_feeds&method=getfeedtree&mode=2"
|
||||
});
|
||||
document.title = tmp;
|
||||
},
|
||||
isCombinedMode: function() {
|
||||
return getInitParam("combined_display_mode");
|
||||
},
|
||||
hotkeyHandler(event) {
|
||||
if (event.target.nodeName == "INPUT" || event.target.nodeName == "TEXTAREA") return;
|
||||
|
||||
const treeModel = new fox.FeedStoreModel({
|
||||
store: store,
|
||||
query: {
|
||||
"type": getInitParam('enable_feed_cats') == 1 ? "category" : "feed"
|
||||
},
|
||||
rootId: "root",
|
||||
rootLabel: "Feeds",
|
||||
childrenAttrs: ["items"]
|
||||
});
|
||||
const action_name = keyeventToAction(event);
|
||||
|
||||
const tree = new fox.FeedTree({
|
||||
model: treeModel,
|
||||
onClick: function (item, node) {
|
||||
const id = String(item.id);
|
||||
const is_cat = id.match("^CAT:");
|
||||
const feed = id.substr(id.indexOf(":") + 1);
|
||||
viewfeed({feed: feed, is_cat: is_cat});
|
||||
if (action_name) {
|
||||
const action_func = hotkey_actions[action_name];
|
||||
|
||||
if (action_func != null) {
|
||||
action_func();
|
||||
event.stopPropagation();
|
||||
return false;
|
||||
},
|
||||
openOnClick: false,
|
||||
showRoot: false,
|
||||
persist: true,
|
||||
id: "feedTree",
|
||||
}, "feedTree");
|
||||
|
||||
var tmph = dojo.connect(dijit.byId('feedMenu'), '_openMyself', function (event) {
|
||||
console.log(dijit.getEnclosingWidget(event.target));
|
||||
dojo.disconnect(tmph);
|
||||
});
|
||||
|
||||
$("feeds-holder").appendChild(tree.domNode);
|
||||
|
||||
var tmph = dojo.connect(tree, 'onLoad', function () {
|
||||
dojo.disconnect(tmph);
|
||||
Element.hide("feedlistLoading");
|
||||
|
||||
try {
|
||||
feedlist_init();
|
||||
|
||||
setLoadingProgress(25);
|
||||
} catch (e) {
|
||||
exception_error(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
switchPanelMode: function(wide) {
|
||||
if (App.isCombinedMode()) return;
|
||||
|
||||
tree.startup();
|
||||
} catch (e) {
|
||||
exception_error(e);
|
||||
}
|
||||
}
|
||||
const article_id = getActiveArticleId();
|
||||
|
||||
function catchupAllFeeds() {
|
||||
if (wide) {
|
||||
dijit.byId("headlines-wrap-inner").attr("design", 'sidebar');
|
||||
dijit.byId("content-insert").attr("region", "trailing");
|
||||
|
||||
const str = __("Mark all articles as read?");
|
||||
dijit.byId("content-insert").domNode.setStyle({width: '50%',
|
||||
height: 'auto',
|
||||
borderTopWidth: '0px' });
|
||||
|
||||
if (getInitParam("confirm_feed_catchup") != 1 || confirm(str)) {
|
||||
if (parseInt(getCookie("ttrss_ci_width")) > 0) {
|
||||
dijit.byId("content-insert").domNode.setStyle(
|
||||
{width: getCookie("ttrss_ci_width") + "px" });
|
||||
}
|
||||
|
||||
notify_progress("Marking all feeds as read...");
|
||||
$("headlines-frame").setStyle({ borderBottomWidth: '0px' });
|
||||
$("headlines-frame").addClassName("wide");
|
||||
|
||||
xhrPost("backend.php", {op: "feeds", method: "catchupAll"}, () => {
|
||||
request_counters(true);
|
||||
viewCurrentFeed();
|
||||
});
|
||||
} else {
|
||||
|
||||
global_unread = 0;
|
||||
updateTitle("");
|
||||
}
|
||||
}
|
||||
dijit.byId("content-insert").attr("region", "bottom");
|
||||
|
||||
function viewCurrentFeed(method) {
|
||||
console.log("viewCurrentFeed: " + method);
|
||||
dijit.byId("content-insert").domNode.setStyle({width: 'auto',
|
||||
height: '50%',
|
||||
borderTopWidth: '0px'});
|
||||
|
||||
if (getActiveFeedId() != undefined) {
|
||||
viewfeed({feed: getActiveFeedId(), is_cat: activeFeedIsCat(), method: method});
|
||||
}
|
||||
return false; // block unneeded form submits
|
||||
}
|
||||
if (parseInt(getCookie("ttrss_ci_height")) > 0) {
|
||||
dijit.byId("content-insert").domNode.setStyle(
|
||||
{height: getCookie("ttrss_ci_height") + "px" });
|
||||
}
|
||||
|
||||
function timeout() {
|
||||
if (getInitParam("bw_limit") != "1") {
|
||||
request_counters(true);
|
||||
setTimeout(timeout, 60*1000);
|
||||
}
|
||||
}
|
||||
$("headlines-frame").setStyle({ borderBottomWidth: '1px' });
|
||||
$("headlines-frame").removeClassName("wide");
|
||||
|
||||
}
|
||||
|
||||
Article.closeArticlePanel();
|
||||
|
||||
if (article_id) view(article_id);
|
||||
|
||||
xhrPost("backend.php", {op: "rpc", method: "setpanelmode", wide: wide ? 1 : 0});
|
||||
},
|
||||
parseRuntimeInfo: function(data) {
|
||||
|
||||
//console.log("parsing runtime info...");
|
||||
|
||||
for (const k in data) {
|
||||
const v = data[k];
|
||||
|
||||
if (k == "dep_ts" && parseInt(getInitParam("dep_ts")) > 0) {
|
||||
if (parseInt(getInitParam("dep_ts")) < parseInt(v) && getInitParam("reload_on_ts_change")) {
|
||||
window.location.reload();
|
||||
}
|
||||
}
|
||||
|
||||
if (k == "daemon_is_running" && v != 1) {
|
||||
notify_error("<span onclick=\"explainError(1)\">Update daemon is not running.</span>", true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (k == "update_result") {
|
||||
const updatesIcon = dijit.byId("updatesIcon").domNode;
|
||||
|
||||
if (v) {
|
||||
Element.show(updatesIcon);
|
||||
} else {
|
||||
Element.hide(updatesIcon);
|
||||
}
|
||||
}
|
||||
|
||||
if (k == "daemon_stamp_ok" && v != 1) {
|
||||
notify_error("<span onclick=\"explainError(3)\">Update daemon is not updating feeds.</span>", true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (k == "max_feed_id" || k == "num_feeds") {
|
||||
if (init_params[k] != v) {
|
||||
console.log("feed count changed, need to reload feedlist.");
|
||||
Feeds.reload();
|
||||
}
|
||||
}
|
||||
|
||||
init_params[k] = v;
|
||||
notify('');
|
||||
}
|
||||
|
||||
PluginHost.run(PluginHost.HOOK_RUNTIME_INFO_LOADED, data);
|
||||
},
|
||||
handleRpcJson: function(transport) {
|
||||
|
||||
const netalert_dijit = dijit.byId("net-alert");
|
||||
let netalert = false;
|
||||
|
||||
if (netalert_dijit) netalert = netalert_dijit.domNode;
|
||||
|
||||
try {
|
||||
const reply = JSON.parse(transport.responseText);
|
||||
|
||||
if (reply) {
|
||||
|
||||
const error = reply['error'];
|
||||
|
||||
if (error) {
|
||||
const code = error['code'];
|
||||
const msg = error['msg'];
|
||||
|
||||
console.warn("[handleRpcJson] received fatal error " + code + "/" + msg);
|
||||
|
||||
if (code != 0) {
|
||||
fatalError(code, msg);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
const seq = reply['seq'];
|
||||
|
||||
if (seq && this.get_seq() != seq) {
|
||||
console.log("[handleRpcJson] sequence mismatch: " + seq +
|
||||
" (want: " + this.get_seq() + ")");
|
||||
return true;
|
||||
}
|
||||
|
||||
const message = reply['message'];
|
||||
|
||||
if (message == "UPDATE_COUNTERS") {
|
||||
console.log("need to refresh counters...");
|
||||
setInitParam("last_article_id", -1);
|
||||
Feeds.requestCounters(true);
|
||||
}
|
||||
|
||||
const counters = reply['counters'];
|
||||
|
||||
if (counters)
|
||||
Feeds.parseCounters(counters);
|
||||
|
||||
const runtime_info = reply['runtime-info'];
|
||||
|
||||
if (runtime_info)
|
||||
this.parseRuntimeInfo(runtime_info);
|
||||
|
||||
if (netalert) netalert.hide();
|
||||
|
||||
return reply;
|
||||
|
||||
} else {
|
||||
if (netalert)
|
||||
netalert.show();
|
||||
else
|
||||
notify_error("Communication problem with server.");
|
||||
}
|
||||
|
||||
} catch (e) {
|
||||
if (netalert)
|
||||
netalert.show();
|
||||
else
|
||||
notify_error("Communication problem with server.");
|
||||
|
||||
console.error(e);
|
||||
}
|
||||
|
||||
return false;
|
||||
},
|
||||
};
|
||||
|
||||
function search() {
|
||||
const query = "backend.php?op=feeds&method=search¶m=" +
|
||||
param_escape(getActiveFeedId() + ":" + activeFeedIsCat());
|
||||
param_escape(Feeds.getActiveFeedId() + ":" + Feeds.activeFeedIsCat());
|
||||
|
||||
if (dijit.byId("searchDlg"))
|
||||
dijit.byId("searchDlg").destroyRecursive();
|
||||
|
@ -153,9 +220,9 @@ function search() {
|
|||
style: "width: 600px",
|
||||
execute: function() {
|
||||
if (this.validate()) {
|
||||
_search_query = this.attr('value');
|
||||
Feeds._search_query = this.attr('value');
|
||||
this.hide();
|
||||
viewCurrentFeed();
|
||||
Feeds.viewCurrentFeed();
|
||||
}
|
||||
},
|
||||
href: query});
|
||||
|
@ -163,16 +230,6 @@ function search() {
|
|||
dialog.show();
|
||||
}
|
||||
|
||||
function updateTitle() {
|
||||
let tmp = "Tiny Tiny RSS";
|
||||
|
||||
if (global_unread > 0) {
|
||||
tmp = "(" + global_unread + ") " + tmp;
|
||||
}
|
||||
|
||||
document.title = tmp;
|
||||
}
|
||||
|
||||
function genericSanityCheck() {
|
||||
setCookie("ttrss_test", "TEST");
|
||||
|
||||
|
@ -272,15 +329,15 @@ function init() {
|
|||
function init_hotkey_actions() {
|
||||
hotkey_actions["next_feed"] = function() {
|
||||
const rv = dijit.byId("feedTree").getNextFeed(
|
||||
getActiveFeedId(), activeFeedIsCat());
|
||||
Feeds.getActiveFeedId(), Feeds.activeFeedIsCat());
|
||||
|
||||
if (rv) 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() {
|
||||
const rv = dijit.byId("feedTree").getPreviousFeed(
|
||||
getActiveFeedId(), activeFeedIsCat());
|
||||
Feeds.getActiveFeedId(), Feeds.activeFeedIsCat());
|
||||
|
||||
if (rv) 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() {
|
||||
moveToPost('next');
|
||||
|
@ -320,7 +377,7 @@ function init_hotkey_actions() {
|
|||
}
|
||||
hotkey_actions["open_in_new_window"] = function() {
|
||||
if (getActiveArticleId()) {
|
||||
openArticleInNewWindow(getActiveArticleId());
|
||||
Article.openArticleInNewWindow(getActiveArticleId());
|
||||
}
|
||||
};
|
||||
hotkey_actions["catchup_below"] = function() {
|
||||
|
@ -336,10 +393,10 @@ function init_hotkey_actions() {
|
|||
scrollArticle(-40);
|
||||
};
|
||||
hotkey_actions["close_article"] = function() {
|
||||
if (isCombinedMode()) {
|
||||
if (App.isCombinedMode()) {
|
||||
cdmCollapseActive();
|
||||
} else {
|
||||
closeArticlePanel();
|
||||
Article.closeArticlePanel();
|
||||
}
|
||||
};
|
||||
hotkey_actions["email_article"] = function() {
|
||||
|
@ -370,20 +427,20 @@ function init_hotkey_actions() {
|
|||
selectArticles('none');
|
||||
};
|
||||
hotkey_actions["feed_refresh"] = function() {
|
||||
if (getActiveFeedId() != undefined) {
|
||||
viewfeed({feed: getActiveFeedId(), is_cat: activeFeedIsCat()});
|
||||
if (Feeds.getActiveFeedId() != undefined) {
|
||||
Feeds.viewfeed({feed: Feeds.getActiveFeedId(), is_cat: Feeds.activeFeedIsCat()});
|
||||
return;
|
||||
}
|
||||
};
|
||||
hotkey_actions["feed_unhide_read"] = function() {
|
||||
toggleDispRead();
|
||||
Feeds.toggleDispRead();
|
||||
};
|
||||
hotkey_actions["feed_subscribe"] = function() {
|
||||
quickAddFeed();
|
||||
};
|
||||
hotkey_actions["feed_debug_update"] = function() {
|
||||
if (!activeFeedIsCat() && parseInt(getActiveFeedId()) > 0) {
|
||||
window.open("backend.php?op=feeds&method=update_debugger&feed_id=" + getActiveFeedId() +
|
||||
if (!Feeds.activeFeedIsCat() && parseInt(Feeds.getActiveFeedId()) > 0) {
|
||||
window.open("backend.php?op=feeds&method=update_debugger&feed_id=" + Feeds.getActiveFeedId() +
|
||||
"&csrf_token=" + getInitParam("csrf_token"));
|
||||
} else {
|
||||
alert("You can't debug this kind of feed.");
|
||||
|
@ -391,17 +448,17 @@ function init_hotkey_actions() {
|
|||
};
|
||||
|
||||
hotkey_actions["feed_debug_viewfeed"] = function() {
|
||||
viewfeed({feed: getActiveFeedId(), is_cat: activeFeedIsCat(), viewfeed_debug: true});
|
||||
Feeds.viewfeed({feed: Feeds.getActiveFeedId(), is_cat: Feeds.activeFeedIsCat(), viewfeed_debug: true});
|
||||
};
|
||||
|
||||
hotkey_actions["feed_edit"] = function() {
|
||||
if (activeFeedIsCat())
|
||||
if (Feeds.activeFeedIsCat())
|
||||
alert(__("You can't edit this kind of feed."));
|
||||
else
|
||||
editFeed(getActiveFeedId());
|
||||
editFeed(Feeds.getActiveFeedId());
|
||||
};
|
||||
hotkey_actions["feed_catchup"] = function() {
|
||||
if (getActiveFeedId() != undefined) {
|
||||
if (Feeds.getActiveFeedId() != undefined) {
|
||||
catchupCurrentFeed();
|
||||
return;
|
||||
}
|
||||
|
@ -411,32 +468,32 @@ function init_hotkey_actions() {
|
|||
};
|
||||
hotkey_actions["feed_toggle_vgroup"] = function() {
|
||||
xhrPost("backend.php", {op: "rpc", method: "togglepref", key: "VFEED_GROUP_BY_FEED"}, () => {
|
||||
viewCurrentFeed();
|
||||
Feeds.viewCurrentFeed();
|
||||
})
|
||||
};
|
||||
hotkey_actions["catchup_all"] = function() {
|
||||
catchupAllFeeds();
|
||||
Feeds.catchupAllFeeds();
|
||||
};
|
||||
hotkey_actions["cat_toggle_collapse"] = function() {
|
||||
if (activeFeedIsCat()) {
|
||||
dijit.byId("feedTree").collapseCat(getActiveFeedId());
|
||||
if (Feeds.activeFeedIsCat()) {
|
||||
dijit.byId("feedTree").collapseCat(Feeds.getActiveFeedId());
|
||||
return;
|
||||
}
|
||||
};
|
||||
hotkey_actions["goto_all"] = function() {
|
||||
viewfeed({feed: -4});
|
||||
Feeds.viewfeed({feed: -4});
|
||||
};
|
||||
hotkey_actions["goto_fresh"] = function() {
|
||||
viewfeed({feed: -3});
|
||||
Feeds.viewfeed({feed: -3});
|
||||
};
|
||||
hotkey_actions["goto_marked"] = function() {
|
||||
viewfeed({feed: -1});
|
||||
Feeds.viewfeed({feed: -1});
|
||||
};
|
||||
hotkey_actions["goto_published"] = function() {
|
||||
viewfeed({feed: -2});
|
||||
Feeds.viewfeed({feed: -2});
|
||||
};
|
||||
hotkey_actions["goto_tagcloud"] = function() {
|
||||
displayDlg(__("Tag cloud"), "printTagCloud");
|
||||
Utils.displayDlg(__("Tag cloud"), "printTagCloud");
|
||||
};
|
||||
hotkey_actions["goto_prefs"] = function() {
|
||||
gotoPreferences();
|
||||
|
@ -467,7 +524,7 @@ function init_hotkey_actions() {
|
|||
quickAddFilter();
|
||||
};
|
||||
hotkey_actions["collapse_sidebar"] = function() {
|
||||
collapse_feedlist();
|
||||
Feeds.viewCurrentFeed();
|
||||
};
|
||||
hotkey_actions["toggle_embed_original"] = function() {
|
||||
if (typeof embedOriginalArticle != "undefined") {
|
||||
|
@ -478,32 +535,32 @@ function init_hotkey_actions() {
|
|||
}
|
||||
};
|
||||
hotkey_actions["toggle_widescreen"] = function() {
|
||||
if (!isCombinedMode()) {
|
||||
if (!App.isCombinedMode()) {
|
||||
_widescreen_mode = !_widescreen_mode;
|
||||
|
||||
// reset stored sizes because geometry changed
|
||||
setCookie("ttrss_ci_width", 0);
|
||||
setCookie("ttrss_ci_height", 0);
|
||||
|
||||
switchPanelMode(_widescreen_mode);
|
||||
App.switchPanelMode(_widescreen_mode);
|
||||
} else {
|
||||
alert(__("Widescreen is not available in combined mode."));
|
||||
}
|
||||
};
|
||||
hotkey_actions["help_dialog"] = function() {
|
||||
helpDialog("main");
|
||||
Utils.helpDialog("main");
|
||||
};
|
||||
hotkey_actions["toggle_combined_mode"] = function() {
|
||||
notify_progress("Loading, please wait...");
|
||||
|
||||
const value = isCombinedMode() ? "false" : "true";
|
||||
const value = App.isCombinedMode() ? "false" : "true";
|
||||
|
||||
xhrPost("backend.php", {op: "rpc", method: "setpref", key: "COMBINED_DISPLAY_MODE", value: value}, () => {
|
||||
setInitParam("combined_display_mode",
|
||||
!getInitParam("combined_display_mode"));
|
||||
|
||||
closeArticlePanel();
|
||||
viewCurrentFeed();
|
||||
Article.closeArticlePanel();
|
||||
Feeds.viewCurrentFeed();
|
||||
})
|
||||
};
|
||||
hotkey_actions["toggle_cdm_expanded"] = function() {
|
||||
|
@ -513,15 +570,15 @@ function init_hotkey_actions() {
|
|||
|
||||
xhrPost("backend.php", { op: "rpc", method: "setpref", key: "CDM_EXPANDED", value: value }, () => {
|
||||
setInitParam("cdm_expanded", !getInitParam("cdm_expanded"));
|
||||
viewCurrentFeed();
|
||||
Feeds.viewCurrentFeed();
|
||||
});
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
function init_second_stage() {
|
||||
updateFeedList();
|
||||
closeArticlePanel();
|
||||
Feeds.reload();
|
||||
Article.closeArticlePanel();
|
||||
|
||||
if (parseInt(getCookie("ttrss_fh_width")) > 0) {
|
||||
dijit.byId("feeds-holder").domNode.setStyle(
|
||||
|
@ -559,7 +616,7 @@ function init_second_stage() {
|
|||
const hash_feed_is_cat = hash_get('c') == "1";
|
||||
|
||||
if (hash_feed_id != undefined) {
|
||||
setActiveFeedId(hash_feed_id, hash_feed_is_cat);
|
||||
Feeds.setActiveFeedId(hash_feed_id, hash_feed_is_cat);
|
||||
}
|
||||
|
||||
setLoadingProgress(50);
|
||||
|
@ -569,15 +626,9 @@ function init_second_stage() {
|
|||
sessionStorage.clear();
|
||||
|
||||
_widescreen_mode = getInitParam("widescreen");
|
||||
switchPanelMode(_widescreen_mode);
|
||||
App.switchPanelMode(_widescreen_mode);
|
||||
|
||||
$("headlines-frame").onscroll = (event) => {
|
||||
clearTimeout(_headlines_scroll_timeout);
|
||||
_headlines_scroll_timeout = window.setTimeout(function() {
|
||||
//console.log('done scrolling', event);
|
||||
headlinesScrollHandler(event);
|
||||
}, 50);
|
||||
}
|
||||
Headlines.initScrollHandler();
|
||||
|
||||
console.log("second stage ok");
|
||||
|
||||
|
@ -596,7 +647,7 @@ function quickMenuGo(opid) {
|
|||
document.location.href = "backend.php?op=logout";
|
||||
break;
|
||||
case "qmcTagCloud":
|
||||
displayDlg(__("Tag cloud"), "printTagCloud");
|
||||
Utils.displayDlg(__("Tag cloud"), "printTagCloud");
|
||||
break;
|
||||
case "qmcSearch":
|
||||
search();
|
||||
|
@ -608,15 +659,15 @@ function quickMenuGo(opid) {
|
|||
window.location.href = "backend.php?op=digest";
|
||||
break;
|
||||
case "qmcEditFeed":
|
||||
if (activeFeedIsCat())
|
||||
if (Feeds.activeFeedIsCat())
|
||||
alert(__("You can't edit this kind of feed."));
|
||||
else
|
||||
editFeed(getActiveFeedId());
|
||||
editFeed(Feeds.getActiveFeedId());
|
||||
break;
|
||||
case "qmcRemoveFeed":
|
||||
var actid = getActiveFeedId();
|
||||
var actid = Feeds.getActiveFeedId();
|
||||
|
||||
if (activeFeedIsCat()) {
|
||||
if (Feeds.activeFeedIsCat()) {
|
||||
alert(__("You can't unsubscribe from the category."));
|
||||
return;
|
||||
}
|
||||
|
@ -635,120 +686,35 @@ function quickMenuGo(opid) {
|
|||
}
|
||||
break;
|
||||
case "qmcCatchupAll":
|
||||
catchupAllFeeds();
|
||||
Feeds.catchupAllFeeds();
|
||||
break;
|
||||
case "qmcShowOnlyUnread":
|
||||
toggleDispRead();
|
||||
Feeds.toggleDispRead();
|
||||
break;
|
||||
case "qmcToggleWidescreen":
|
||||
if (!isCombinedMode()) {
|
||||
if (!App.isCombinedMode()) {
|
||||
_widescreen_mode = !_widescreen_mode;
|
||||
|
||||
// reset stored sizes because geometry changed
|
||||
setCookie("ttrss_ci_width", 0);
|
||||
setCookie("ttrss_ci_height", 0);
|
||||
|
||||
switchPanelMode(_widescreen_mode);
|
||||
App.switchPanelMode(_widescreen_mode);
|
||||
} else {
|
||||
alert(__("Widescreen is not available in combined mode."));
|
||||
}
|
||||
break;
|
||||
case "qmcHKhelp":
|
||||
helpDialog("main");
|
||||
Utils.helpDialog("main");
|
||||
break;
|
||||
default:
|
||||
console.log("quickMenuGo: unknown action: " + opid);
|
||||
}
|
||||
}
|
||||
|
||||
function toggleDispRead() {
|
||||
|
||||
const hide = !(getInitParam("hide_read_feeds") == "1");
|
||||
|
||||
xhrPost("backend.php", {op: "rpc", method: "setpref", key: "HIDE_READ_FEEDS", value: hide}, () => {
|
||||
hideOrShowFeeds(hide);
|
||||
setInitParam("hide_read_feeds", hide);
|
||||
});
|
||||
}
|
||||
|
||||
function parse_runtime_info(data) {
|
||||
|
||||
//console.log("parsing runtime info...");
|
||||
|
||||
for (const k in data) {
|
||||
const v = data[k];
|
||||
|
||||
// console.log("RI: " + k + " => " + v);
|
||||
|
||||
if (k == "dep_ts" && parseInt(getInitParam("dep_ts")) > 0) {
|
||||
if (parseInt(getInitParam("dep_ts")) < parseInt(v) && getInitParam("reload_on_ts_change")) {
|
||||
window.location.reload();
|
||||
}
|
||||
}
|
||||
|
||||
if (k == "daemon_is_running" && v != 1) {
|
||||
notify_error("<span onclick=\"explainError(1)\">Update daemon is not running.</span>", true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (k == "update_result") {
|
||||
const updatesIcon = dijit.byId("updatesIcon").domNode;
|
||||
|
||||
if (v) {
|
||||
Element.show(updatesIcon);
|
||||
} else {
|
||||
Element.hide(updatesIcon);
|
||||
}
|
||||
}
|
||||
|
||||
if (k == "daemon_stamp_ok" && v != 1) {
|
||||
notify_error("<span onclick=\"explainError(3)\">Update daemon is not updating feeds.</span>", true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (k == "max_feed_id" || k == "num_feeds") {
|
||||
if (init_params[k] != v) {
|
||||
console.log("feed count changed, need to reload feedlist.");
|
||||
updateFeedList();
|
||||
}
|
||||
}
|
||||
|
||||
init_params[k] = v;
|
||||
notify('');
|
||||
}
|
||||
|
||||
PluginHost.run(PluginHost.HOOK_RUNTIME_INFO_LOADED, data);
|
||||
}
|
||||
|
||||
function collapse_feedlist() {
|
||||
Element.toggle("feeds-holder");
|
||||
|
||||
const splitter = $("feeds-holder_splitter");
|
||||
|
||||
Element.visible("feeds-holder") ? splitter.show() : splitter.hide();
|
||||
|
||||
dijit.byId("main").resize();
|
||||
}
|
||||
|
||||
function viewModeChanged() {
|
||||
cache_clear();
|
||||
return viewCurrentFeed('');
|
||||
}
|
||||
|
||||
function hotkey_handler(e) {
|
||||
if (e.target.nodeName == "INPUT" || e.target.nodeName == "TEXTAREA") return;
|
||||
|
||||
const action_name = keyeventToAction(e);
|
||||
|
||||
if (action_name) {
|
||||
const action_func = hotkey_actions[action_name];
|
||||
|
||||
if (action_func != null) {
|
||||
action_func();
|
||||
e.stopPropagation();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return Feeds.viewCurrentFeed('');
|
||||
}
|
||||
|
||||
function inPreferences() {
|
||||
|
@ -769,136 +735,15 @@ function reverseHeadlineOrder() {
|
|||
|
||||
order_by.attr('value', value);
|
||||
|
||||
viewCurrentFeed();
|
||||
Feeds.viewCurrentFeed();
|
||||
|
||||
}
|
||||
|
||||
function handle_rpc_json(transport, scheduled_call) {
|
||||
|
||||
const netalert_dijit = dijit.byId("net-alert");
|
||||
let netalert = false;
|
||||
|
||||
if (netalert_dijit) netalert = netalert_dijit.domNode;
|
||||
|
||||
try {
|
||||
const reply = JSON.parse(transport.responseText);
|
||||
|
||||
if (reply) {
|
||||
|
||||
const error = reply['error'];
|
||||
|
||||
if (error) {
|
||||
const code = error['code'];
|
||||
const msg = error['msg'];
|
||||
|
||||
console.warn("[handle_rpc_json] received fatal error " + code + "/" + msg);
|
||||
|
||||
if (code != 0) {
|
||||
fatalError(code, msg);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
const seq = reply['seq'];
|
||||
|
||||
if (seq && get_seq() != seq) {
|
||||
console.log("[handle_rpc_json] sequence mismatch: " + seq +
|
||||
" (want: " + get_seq() + ")");
|
||||
return true;
|
||||
}
|
||||
|
||||
const message = reply['message'];
|
||||
|
||||
if (message == "UPDATE_COUNTERS") {
|
||||
console.log("need to refresh counters...");
|
||||
setInitParam("last_article_id", -1);
|
||||
request_counters(true);
|
||||
}
|
||||
|
||||
const counters = reply['counters'];
|
||||
|
||||
if (counters)
|
||||
parse_counters(counters, scheduled_call);
|
||||
|
||||
const runtime_info = reply['runtime-info'];
|
||||
|
||||
if (runtime_info)
|
||||
parse_runtime_info(runtime_info);
|
||||
|
||||
if (netalert) netalert.hide();
|
||||
|
||||
return reply;
|
||||
|
||||
} else {
|
||||
if (netalert)
|
||||
netalert.show();
|
||||
else
|
||||
notify_error("Communication problem with server.");
|
||||
}
|
||||
|
||||
} catch (e) {
|
||||
if (netalert)
|
||||
netalert.show();
|
||||
else
|
||||
notify_error("Communication problem with server.");
|
||||
|
||||
console.error(e);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function switchPanelMode(wide) {
|
||||
if (isCombinedMode()) return;
|
||||
|
||||
const article_id = getActiveArticleId();
|
||||
|
||||
if (wide) {
|
||||
dijit.byId("headlines-wrap-inner").attr("design", 'sidebar');
|
||||
dijit.byId("content-insert").attr("region", "trailing");
|
||||
|
||||
dijit.byId("content-insert").domNode.setStyle({width: '50%',
|
||||
height: 'auto',
|
||||
borderTopWidth: '0px' });
|
||||
|
||||
if (parseInt(getCookie("ttrss_ci_width")) > 0) {
|
||||
dijit.byId("content-insert").domNode.setStyle(
|
||||
{width: getCookie("ttrss_ci_width") + "px" });
|
||||
}
|
||||
|
||||
$("headlines-frame").setStyle({ borderBottomWidth: '0px' });
|
||||
$("headlines-frame").addClassName("wide");
|
||||
|
||||
} else {
|
||||
|
||||
dijit.byId("content-insert").attr("region", "bottom");
|
||||
|
||||
dijit.byId("content-insert").domNode.setStyle({width: 'auto',
|
||||
height: '50%',
|
||||
borderTopWidth: '0px'});
|
||||
|
||||
if (parseInt(getCookie("ttrss_ci_height")) > 0) {
|
||||
dijit.byId("content-insert").domNode.setStyle(
|
||||
{height: getCookie("ttrss_ci_height") + "px" });
|
||||
}
|
||||
|
||||
$("headlines-frame").setStyle({ borderBottomWidth: '1px' });
|
||||
$("headlines-frame").removeClassName("wide");
|
||||
|
||||
}
|
||||
|
||||
closeArticlePanel();
|
||||
|
||||
if (article_id) view(article_id);
|
||||
|
||||
xhrPost("backend.php", {op: "rpc", method: "setpanelmode", wide: wide ? 1 : 0});
|
||||
}
|
||||
|
||||
function update_random_feed() {
|
||||
console.log("in update_random_feed");
|
||||
|
||||
xhrPost("backend.php", { op: "rpc", method: "updateRandomFeed" }, (transport) => {
|
||||
handle_rpc_json(transport, true);
|
||||
App.handleRpcJson(transport, true);
|
||||
window.setTimeout(update_random_feed, 30*1000);
|
||||
});
|
||||
}
|
||||
|
|
842
js/viewfeed.js
842
js/viewfeed.js
File diff suppressed because it is too large
Load Diff
|
@ -93,7 +93,7 @@ class Af_Psql_Trgm extends Plugin {
|
|||
print " <a target=\"_blank\" rel=\"noopener noreferrer\" href=\"$article_link\">".
|
||||
$line["title"]."</a>";
|
||||
|
||||
print " (<a href=\"#\" onclick=\"viewfeed({feed:".$line["feed_id"]."})\">".
|
||||
print " (<a href=\"#\" onclick=\"Feeds.viewfeed({feed:".$line["feed_id"]."})\">".
|
||||
htmlspecialchars($line["feed_title"])."</a>)";
|
||||
|
||||
print " <span class='insensitive'>($sm)</span>";
|
||||
|
|
|
@ -21,7 +21,7 @@ class Close_Button extends Plugin {
|
|||
if (!get_pref("COMBINED_DISPLAY_MODE")) {
|
||||
$rv = "<img src=\"plugins/close_button/button.png\"
|
||||
class='tagsPic' style=\"cursor : pointer\"
|
||||
onclick=\"closeArticlePanel()\"
|
||||
onclick=\"Article.closeArticlePanel()\"
|
||||
title='".__('Close article')."'>";
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
require(['dojo/_base/kernel', 'dojo/ready'], function (dojo, ready) {
|
||||
ready(function () {
|
||||
updateTitle = function () {
|
||||
App.updateTitle = function () {
|
||||
document.title = "Tiny Tiny RSS";
|
||||
};
|
||||
});
|
||||
|
|
|
@ -18,7 +18,7 @@ class Toggle_Sidebar extends Plugin {
|
|||
function hook_main_toolbar_button() {
|
||||
?>
|
||||
|
||||
<button dojoType="dijit.form.Button" onclick="collapse_feedlist()">
|
||||
<button dojoType="dijit.form.Button" onclick="Feeds.collapseFeedlist()">
|
||||
<img src="plugins/toggle_sidebar/application_side_list.png"
|
||||
title="<?php echo __('Collapse feedlist') ?>">
|
||||
</button>
|
||||
|
|
Loading…
Reference in New Issue