summaryrefslogtreecommitdiff
path: root/js/Feeds.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/Feeds.js')
-rw-r--r--js/Feeds.js150
1 files changed, 99 insertions, 51 deletions
diff --git a/js/Feeds.js b/js/Feeds.js
index 986936285..5a2dee5cf 100644
--- a/js/Feeds.js
+++ b/js/Feeds.js
@@ -1,8 +1,9 @@
'use strict'
-/* global __, App, Headlines, xhrPost, dojo, dijit, Form, fox, PluginHost, Notify, $$, fox */
+/* global __, App, Headlines, xhr, dojo, dijit, fox, PluginHost, Notify, fox */
const Feeds = {
+ _default_feed_id: -3,
counters_last_request: 0,
_active_feed_id: undefined,
_active_feed_is_cat: false,
@@ -12,6 +13,19 @@ const Feeds = {
_search_query: false,
last_search_query: [],
_viewfeed_wait_timeout: false,
+ _feeds_holder_observer: new IntersectionObserver(
+ (entries/*, observer*/) => {
+ entries.forEach((entry) => {
+ //console.log('feeds',entry.target, entry.intersectionRatio);
+
+ if (entry.intersectionRatio == 0)
+ Feeds.onHide(entry);
+ else
+ Feeds.onShow(entry);
+ });
+ },
+ {threshold: [0, 1], root: document.querySelector("body")}
+ ),
_counters_prev: [],
// NOTE: this implementation is incomplete
// for general objects but good enough for counters
@@ -109,6 +123,9 @@ const Feeds = {
}
return false; // block unneeded form submits
},
+ openDefaultFeed: function() {
+ this.open({feed: this._default_feed_id});
+ },
openNextUnread: function() {
const is_cat = this.activeIsCat();
const nuf = this.getNextUnread(this.getActive(), is_cat);
@@ -116,23 +133,20 @@ const Feeds = {
},
toggle: function() {
Element.toggle("feeds-holder");
-
- const splitter = $("feeds-holder_splitter");
-
- Element.visible("feeds-holder") ? splitter.show() : splitter.hide();
-
- dijit.byId("main").resize();
-
- Headlines.updateCurrentUnread();
},
cancelSearch: function() {
this._search_query = "";
this.reloadCurrent();
},
- requestCounters: function() {
- xhrPost("backend.php", {op: "rpc", method: "getAllCounters", seq: App.next_seq()}, (transport) => {
- App.handleRpcJson(transport);
- });
+ // null = get all data, [] would give empty response for specific type
+ requestCounters: function(feed_ids = null, label_ids = null) {
+ xhr.json("backend.php", {op: "rpc",
+ method: "getAllCounters",
+ "feed_ids[]": feed_ids,
+ "feed_id_count": feed_ids ? feed_ids.length : -1,
+ "label_ids[]": label_ids,
+ "label_id_count": label_ids ? label_ids.length : -1,
+ seq: App.next_seq()});
},
reload: function() {
try {
@@ -180,7 +194,7 @@ const Feeds = {
dojo.disconnect(tmph);
});
- $("feeds-holder").appendChild(tree.domNode);
+ App.byId("feeds-holder").appendChild(tree.domNode);
const tmph2 = dojo.connect(tree, 'onLoad', function () {
dojo.disconnect(tmph2);
@@ -199,9 +213,23 @@ const Feeds = {
App.Error.report(e);
}
},
+ onHide: function() {
+ App.byId("feeds-holder_splitter").hide();
+
+ dijit.byId("main").resize();
+ Headlines.updateCurrentUnread();
+ },
+ onShow: function() {
+ App.byId("feeds-holder_splitter").show();
+
+ dijit.byId("main").resize();
+ Headlines.updateCurrentUnread();
+ },
init: function() {
console.log("in feedlist init");
+ this._feeds_holder_observer.observe(App.byId("feeds-holder"));
+
App.setLoadingProgress(50);
//document.onkeydown = (event) => { return App.hotkeyHandler(event) };
@@ -215,7 +243,7 @@ const Feeds = {
if (hash_feed_id != undefined) {
this.open({feed: hash_feed_id, is_cat: hash_feed_is_cat});
} else {
- this.open({feed: -3});
+ this.openDefaultFeed();
}
this.hideOrShowFeeds(App.getInitParam("hide_read_feeds"));
@@ -260,10 +288,10 @@ const Feeds = {
// bw_limit disables timeout() so we request initial counters separately
if (App.getInitParam("bw_limit")) {
- this.requestCounters(true);
+ this.requestCounters();
} else {
setTimeout(() => {
- this.requestCounters(true);
+ this.requestCounters();
setInterval(() => { this.requestCounters(); }, 60 * 1000)
}, 250);
}
@@ -284,8 +312,8 @@ const Feeds = {
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);
+ App.byId("headlines-frame").setAttribute("feed-id", id);
+ App.byId("headlines-frame").setAttribute("is-cat", is_cat ? 1 : 0);
this.select(id, is_cat);
@@ -299,7 +327,7 @@ const Feeds = {
toggleUnread: function() {
const hide = !App.getInitParam("hide_read_feeds");
- xhrPost("backend.php", {op: "rpc", method: "setpref", key: "HIDE_READ_FEEDS", value: hide}, () => {
+ xhr.post("backend.php", {op: "rpc", method: "setpref", key: "HIDE_READ_FEEDS", value: hide}, () => {
this.hideOrShowFeeds(hide);
App.setInitParam("hide_read_feeds", hide);
});
@@ -310,14 +338,13 @@ const Feeds = {
if (tree)
return tree.hideRead(hide, App.getInitParam("hide_read_shows_special"));*/
- $$("body")[0].setAttribute("hide-read-feeds", !!hide);
- $$("body")[0].setAttribute("hide-read-shows-special", !!App.getInitParam("hide_read_shows_special"));
+ App.findAll("body")[0].setAttribute("hide-read-feeds", !!hide);
+ App.findAll("body")[0].setAttribute("hide-read-shows-special", !!App.getInitParam("hide_read_shows_special"));
},
open: 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 append = params.append || false;
const method = params.method;
// this is used to quickly switch between feeds, sets active but xhr is on a timeout
@@ -339,7 +366,7 @@ const Feeds = {
}, 10 * 1000);
}
- Form.enable("toolbar-main");
+ //Form.enable("toolbar-main");
let query = Object.assign({op: "feeds", method: "view", feed: feed},
dojo.formToObject("toolbar-main"));
@@ -362,8 +389,6 @@ const Feeds = {
query.m = "ForceUpdate";
}
- Form.enable("toolbar-main");
-
if (!delayed)
if (!this.setExpando(feed, is_cat,
(is_cat) ? 'images/indicator_tiny.gif' : 'images/indicator_white.gif'))
@@ -373,20 +398,13 @@ const Feeds = {
this.setActive(feed, is_cat);
- if (viewfeed_debug) {
- window.open("backend.php?" +
- dojo.objectToQuery(
- Object.assign({csrf_token: App.getInitParam("csrf_token")}, query)
- ));
- }
-
window.clearTimeout(this._viewfeed_wait_timeout);
this._viewfeed_wait_timeout = window.setTimeout(() => {
- xhrPost("backend.php", query, (transport) => {
+ xhr.json("backend.php", query, (reply) => {
try {
window.clearTimeout(this._infscroll_timeout);
this.setExpando(feed, is_cat, 'images/blank_icon.gif');
- Headlines.onLoaded(transport, offset, append);
+ Headlines.onLoaded(reply, offset, append);
PluginHost.run(PluginHost.HOOK_FEED_LOADED, [feed, is_cat]);
} catch (e) {
App.Error.report(e);
@@ -401,8 +419,7 @@ const Feeds = {
Notify.progress("Marking all feeds as read...");
- xhrPost("backend.php", {op: "feeds", method: "catchupAll"}, () => {
- this.requestCounters(true);
+ xhr.json("backend.php", {op: "feeds", method: "catchupAll"}, () => {
this.reloadCurrent();
});
@@ -447,9 +464,7 @@ const Feeds = {
Notify.progress("Loading, please wait...", true);
- xhrPost("backend.php", catchup_query, (transport) => {
- App.handleRpcJson(transport);
-
+ xhr.json("backend.php", catchup_query, () => {
const show_next_feed = App.getInitParam("on_catchup_show_next_feed");
// only select next unread feed if catching up entirely (as opposed to last week etc)
@@ -476,9 +491,9 @@ const Feeds = {
if (App.getInitParam("confirm_feed_catchup") != 1 || confirm(str)) {
- const rows = $$("#headlines-frame > div[id*=RROW][class*=Unread][data-orig-feed-id='" + id + "']");
+ const rows = App.findAll("#headlines-frame > div[id*=RROW][class*=Unread][data-orig-feed-id='" + id + "']");
- rows.each((row) => {
+ rows.forEach((row) => {
row.removeClassName("Unread");
})
}
@@ -501,7 +516,7 @@ const Feeds = {
const tree = dijit.byId("feedTree");
if (tree && tree.model)
- return tree.getFeedCategory(feed);
+ return tree._cat_of_feed(feed);
} catch (e) {
//
@@ -566,14 +581,42 @@ const Feeds = {
return tree.model.store.getValue(nuf, 'bare_id');
},
search: function() {
- xhrPost("backend.php",
- {op: "feeds", method: "search",
- param: Feeds.getActive() + ":" + Feeds.activeIsCat()},
- (transport) => {
+ xhr.json("backend.php",
+ {op: "feeds", method: "search"},
+ (reply) => {
try {
const dialog = new fox.SingleUseDialog({
- id: "searchDlg",
- content: transport.responseText,
+ content: `
+ <form onsubmit='return false'>
+ <section>
+ <fieldset>
+ <input dojoType='dijit.form.ValidationTextBox' id='search_query'
+ style='font-size : 16px; width : 540px;'
+ placeHolder="${__("Search %s...").replace("%s", Feeds.getName(Feeds.getActive(), Feeds.activeIsCat()))}"
+ name='query' type='search' value=''>
+ </fieldset>
+
+ ${reply.show_language ?
+ `
+ <fieldset>
+ <label class='inline'>${__("Language:")}</label>
+ ${App.FormFields.select_tag("search_language", reply.default_language, reply.all_languages,
+ {title: __('Used for word stemming')}, "search_language")}
+ </fieldset>
+ ` : ''}
+ </section>
+
+ <footer>
+ ${reply.show_syntax_help ?
+ `${App.FormFields.button_tag(App.FormFields.icon("help") + " " + __("Search syntax"), "",
+ {class: 'alt-info pull-left', onclick: "window.open('https://tt-rss.org/wiki/SearchSyntax')"})}
+ ` : ''}
+
+ ${App.FormFields.submit_tag(__('Search'), {onclick: "App.dialogOf(this).execute()"})}
+ ${App.FormFields.cancel_dialog_tag(__('Cancel'))}
+ </footer>
+ </form>
+ `,
title: __("Search"),
execute: function () {
if (this.validate()) {
@@ -613,8 +656,13 @@ const Feeds = {
updateRandom: function() {
console.log("in update_random_feed");
- xhrPost("backend.php", {op: "rpc", method: "updaterandomfeed"}, (transport) => {
- App.handleRpcJson(transport, true);
+ xhr.json("backend.php", {op: "rpc", method: "updaterandomfeed"}, () => {
+ //
});
},
+ renderIcon: function(feed_id, exists) {
+ return feed_id && exists ?
+ `<img class="icon" src="${App.escapeHtml(App.getInitParam("icons_url"))}/${feed_id}.ico">` :
+ `<i class='icon-no-feed material-icons'>rss_feed</i>`;
+ }
};