From 45bf9957735cd9965879492128fd49e5213be8b5 Mon Sep 17 00:00:00 2001
From: Andy Valencia
Date: Thu, 18 Feb 2016 20:58:07 -0800
Subject: [PATCH 1/6] Use document element (base is deprecated). Use timeout
(updating URL hash, among others, resets scroll position).
---
js/App.js | 24 ++++++++++++++++--------
1 file changed, 16 insertions(+), 8 deletions(-)
diff --git a/js/App.js b/js/App.js
index ff92dad..cfac263 100644
--- a/js/App.js
+++ b/js/App.js
@@ -37,7 +37,7 @@ App.prototype.after_login = function(backend) {
var url = window.location.hash;
- if(url == "#list") {
+ if (url == "#list") {
_this.setCurrentRead();
_this.changeToPage("#list");
} else if(url == "#reload") {
@@ -135,18 +135,26 @@ App.prototype.changeToPage = function(page) {
// FIXME
var active = $(".active");
- if(active.id == "list") {
- this.saveScrollTop = document.body.scrollTop;
- }
- if(page == "#list") {
- document.body.scrollTop = this.saveScrollTop;
- } else {
- window.scroll(0, 0);
+ // Save old position
+ if (active.id == "list") {
+ this.saveScrollTop = document.documentElement.scrollTop;
}
+ // Switch displays
active.removeClass("active");
$(page).addClass("active");
+
+ if (page == "#list") {
+ var elem = document.documentElement;
+ var posit = this.saveScrollTop;
+
+ // Restore old position, after display settles
+ setTimeout(function() { elem.scrollTop = posit; }, 500);
+ } else {
+ // Else top of page
+ window.scroll(0, 0);
+ }
};
App.prototype.setColor = function(color) {
From 0b2888d4a80b64bc30a1a53e5a1f7f2fd3698778 Mon Sep 17 00:00:00 2001
From: Andy Valencia
Date: Sat, 28 Jan 2017 20:27:39 -0800
Subject: [PATCH 2/6] Group posts by feed name. Step #1 of getting collapsing
feeds so it's easier to swim through larger feeds.
---
css/screen.css | 4 +--
js/App.js | 84 +++++++++++++++++++++++++++++++++++++-------------
2 files changed, 64 insertions(+), 24 deletions(-)
diff --git a/css/screen.css b/css/screen.css
index 15170fc..b635a28 100644
--- a/css/screen.css
+++ b/css/screen.css
@@ -204,11 +204,11 @@ canvas {
.blue #list li { border-bottom: 1px solid #2980b9; }
.yellow #list li { border-bottom: 1px solid #f39c12; }
-#list li:after {
+#list li li:after {
content: "";
position: absolute;
right: 7px;
- top: 0.1em;
+ top: -0.2em;
font-weight: 100;
font-size: 3em;
font-family: "Entypo";
diff --git a/js/App.js b/js/App.js
index cfac263..3a13209 100644
--- a/js/App.js
+++ b/js/App.js
@@ -22,9 +22,11 @@ App.prototype.authenticate = function() {
App.prototype.after_login = function(backend) {
- var request = window.navigator.mozApps.getSelf();
- request.onsuccess = function() {
- $("#version").innerHTML = request.result.manifest.version;
+ if (window.navigator.mozApps) {
+ var request = window.navigator.mozApps.getSelf();
+ request.onsuccess = function() {
+ $("#version").innerHTML = request.result.manifest.version;
+ }
}
var _this = this;
@@ -227,15 +229,53 @@ App.prototype.validate = function(articles) {
App.prototype.populateList = function() {
+ // First pull all articles together from each distinct feed
+ var ua = this.unread_articles;
+ var newarts = [], byfeed = [];
+ while (ua.length > 0) {
+ article = ua[0];
+
+ // Next feed ID
+ var fid = article.feed_id;
+ // Here's all the articles under that ID
+ var feeds =
+ ua.filter( function(a) { return a.feed_id == fid; } );
+ // Keep a list of them so it's easy to tabulate
+ byfeed.push(feeds);
+
+ // Add them on to the new unread_articles, so they're
+ // in order.
+ newarts = newarts.concat(feeds);
+
+ // Trim them off the old, unsorted article list
+ ua = ua.filter( function(a) { return a.feed_id != fid; } );
+ }
+
+ // Make the reordered article list the "official" one
+ ua = this.unread_articles = newarts;
+
+ // Now build the article list; it's a of feeds,
+ // then sub- of articles in that feed
var html_str = "";
- for (var i = 0; i < this.unread_articles.length; i++) {
- var article = this.unread_articles[i];
- html_str += "- ";
- html_str += "";
- html_str += "
" + article.feed_title + "
";
+ var artidx = 0;
+ for (i = 0; i < byfeed.length; ++i) {
+ var feed = byfeed[i];
+ html_str += "- " + feed[0].feed_title;
+ html_str += "
";
}
$("#list ul").innerHTML = html_str;
@@ -244,22 +284,22 @@ App.prototype.populateList = function() {
};
App.prototype.updateList = function() {
- var unread = 0;
- $$("#list ul li").forEach(function(o, i) {
-
- if(!this.unread_articles[i].unread) {
- o.removeClass("unread");
- }
- else {
- unread++;
- o.addClass("unread");
- }
+ var unread = 0, artnum = 0;
+ $$("#list ul ul li").forEach(function(o, i) {
+
+ if (!this.unread_articles[artnum++].unread) {
+ o.removeClass("unread");
+ }
+ else {
+ unread++;
+ o.addClass("unread");
+ }
}, this);
- if(unread > 0) {
- $("#all-read").addClass('inactive');
+ if (unread > 0) {
+ $("#all-read").addClass('inactive');
} else {
- $("#all-read").removeClass('inactive');
+ $("#all-read").removeClass('inactive');
}
this.updatePieChart();
From 124f6ac7ada0b1e4bb5fa0e07b3aa2527d647a1d Mon Sep 17 00:00:00 2001
From: Andy Valencia
Date: Sat, 28 Jan 2017 21:13:19 -0800
Subject: [PATCH 3/6] Make collapsing feed article lists
---
js/App.js | 7 +++++--
js/application.js | 9 +++++++++
2 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/js/App.js b/js/App.js
index 3a13209..9601734 100644
--- a/js/App.js
+++ b/js/App.js
@@ -260,8 +260,11 @@ App.prototype.populateList = function() {
var artidx = 0;
for (i = 0; i < byfeed.length; ++i) {
var feed = byfeed[i];
- html_str += "- " + feed[0].feed_title;
- html_str += "
";
+ html_str += '- ' + feed[0].feed_title + '';
+ var feedid = '"feed' + i.toString() + '"';
+ html_str += '
'
for (var j = 0; j < feed.length; ++j) {
article = ua[artidx];
html_str += "-
Date: Sun, 29 Jan 2017 09:03:51 -0800
Subject: [PATCH 4/6] Allow for successive growing of "unread_articles". Move
helper function adjacent to method which uses it.
---
js/App.js | 71 +++++++++++++++++++++++++----------------------
js/application.js | 9 ------
2 files changed, 38 insertions(+), 42 deletions(-)
diff --git a/js/App.js b/js/App.js
index 9601734..70e9dbe 100644
--- a/js/App.js
+++ b/js/App.js
@@ -227,46 +227,52 @@ App.prototype.validate = function(articles) {
return false;
};
+// Utility function to toggle feed content visibility
+function toggleFeed(feedid) {
+ var e = document.getElementById("feed" + feedid.toString());
+ if (e.style.display == "none") {
+ e.style.display = "";
+ } else {
+ e.style.display = "none";
+ }
+}
+
App.prototype.populateList = function() {
- // First pull all articles together from each distinct feed
- var ua = this.unread_articles;
- var newarts = [], byfeed = [];
- while (ua.length > 0) {
- article = ua[0];
-
- // Next feed ID
- var fid = article.feed_id;
- // Here's all the articles under that ID
- var feeds =
- ua.filter( function(a) { return a.feed_id == fid; } );
- // Keep a list of them so it's easy to tabulate
- byfeed.push(feeds);
-
- // Add them on to the new unread_articles, so they're
- // in order.
- newarts = newarts.concat(feeds);
-
- // Trim them off the old, unsorted article list
- ua = ua.filter( function(a) { return a.feed_id != fid; } );
+ // Tabulate all articles, grouped by feed.
+ // Note that this.unread_articles[] can be growing even
+ // as our user reads, so we have to leave it alone and
+ // just point to the appropriate articles in situ.
+ const ua = this.unread_articles, ual = ua.length;
+ const byfeed = {}, feeds = [];
+ for (let x = 0; x < ual; ++x) {
+ const article = ua[x];
+
+ // Add this article to an existing feed list, or
+ // or start one for this feed ID.
+ const fid = article.feed_id;
+ if (fid in byfeed) {
+ byfeed[fid].push(x);
+ } else {
+ byfeed[fid] = [x];
+ feeds.push( {"fid": fid, "name": article.feed_title} );
+ }
}
- // Make the reordered article list the "official" one
- ua = this.unread_articles = newarts;
-
// Now build the article list; it's a
of feeds,
// then sub- of articles in that feed
- var html_str = "";
- var artidx = 0;
- for (i = 0; i < byfeed.length; ++i) {
- var feed = byfeed[i];
+ let html_str = "";
+ for (let x = 0; x < feeds.length; ++x) {
+ const xs = x.toString();
+ const f = feeds[x];
+ const feed = byfeed[f.fid];
html_str += '- ' + feed[0].feed_title + '';
- var feedid = '"feed' + i.toString() + '"';
+ ' onclick="return(toggleFeed(' + xs + '));"' +
+ '>' + f.name + '';
+ const feedid = '"feed' + xs + '"';
html_str += '
";
}
html_str += "";
- artidx += 1;
}
html_str += "";
}
diff --git a/js/application.js b/js/application.js
index d8ebd6a..5e38312 100644
--- a/js/application.js
+++ b/js/application.js
@@ -8,15 +8,6 @@ function debug(obj) {
alert(obj)
}
-function toggleFeed(feedid) {
- var e = document.getElementById("feed" + feedid.toString());
- if (e.style.display == "none") {
- e.style.display = "";
- } else {
- e.style.display = "none";
- }
-}
-
function $(obj) {
if(typeof obj == "string") return document.querySelector(obj);
else return obj;
From d3f2337fd7ab3d8e764510ae1d4f6d3e3eb9bf77 Mon Sep 17 00:00:00 2001
From: Andy Valencia
Date: Sun, 29 Jan 2017 11:15:16 -0800
Subject: [PATCH 5/6] With change in article numbering, need way to tie article
back to HTML element. Use an ID.
---
js/App.js | 26 ++++++++++++++++----------
1 file changed, 16 insertions(+), 10 deletions(-)
diff --git a/js/App.js b/js/App.js
index 70e9dbe..10da474 100644
--- a/js/App.js
+++ b/js/App.js
@@ -273,8 +273,10 @@ App.prototype.populateList = function() {
html_str += ''
for (let artidx of byfeed[f.fid]) {
const article = ua[artidx];
- html_str += "- ";
+ html_str += '
- ';
html_str += "";
html_str += "
" + article.title + "
";
if (article.excerpt) {
@@ -292,17 +294,21 @@ App.prototype.populateList = function() {
};
App.prototype.updateList = function() {
- var unread = 0, artnum = 0;
- $$("#list ul ul li").forEach(function(o, i) {
+ var unread = 0;
+ const ua = this.unread_articles, ual = ua.length;
- if (!this.unread_articles[artnum++].unread) {
- o.removeClass("unread");
- }
- else {
+ // Walk "unread" articles, keep count of those still
+ // unread and update display.
+ for (let i = 0; i < ual; ++i) {
+ const art = ua[i];
+ const e = document.getElementById("art" + i.toString());
+ if (art.unread) {
+ e.addClass("unread");
unread++;
- o.addClass("unread");
+ } else {
+ e.removeClass("unread");
}
- }, this);
+ }
if (unread > 0) {
$("#all-read").addClass('inactive');
From cc41a55ccef5a04d4bce44909cdc2352ebe4763d Mon Sep 17 00:00:00 2001
From: Andy Valencia
Date: Fri, 10 Feb 2017 11:34:14 -0800
Subject: [PATCH 6/6] Have next/prev honor grouped display of articles under
feeds.
---
js/App.js | 47 ++++++++++++++++++++++++++++++++---------------
1 file changed, 32 insertions(+), 15 deletions(-)
diff --git a/js/App.js b/js/App.js
index 10da474..6daa9eb 100644
--- a/js/App.js
+++ b/js/App.js
@@ -129,6 +129,7 @@ App.prototype.after_login = function(backend) {
App.prototype.logout = function() {
this.backend.logOut();
this.unread_articles = [];
+ this.next_articles = [];
this.populateList();
this.login.log_out();
};
@@ -168,6 +169,7 @@ App.prototype.setColor = function(color) {
App.prototype.reload = function() {
this.unread_articles = [];
+ this.next_articles = [];
$("#all-read").addClass('inactive');
var number=parseInt(localStorage.numArticles);
this.backend.reload(this.gotUnreadFeeds.bind(this),number);
@@ -262,6 +264,7 @@ App.prototype.populateList = function() {
// Now build the article list; it's a of feeds,
// then sub- of articles in that feed
let html_str = "";
+ this.next_articles = [];
for (let x = 0; x < feeds.length; ++x) {
const xs = x.toString();
const f = feeds[x];
@@ -272,6 +275,7 @@ App.prototype.populateList = function() {
const feedid = '"feed' + xs + '"';
html_str += ''
for (let artidx of byfeed[f.fid]) {
+ this.next_articles.push(artidx);
const article = ua[artidx];
html_str += '- = this.unread_articles.length - 1) {
- this.goToList();
- } else {
- this.currentIndex++;
- this.showFull(this.unread_articles[this.currentIndex], false);
- }
+ const na = this.next_articles;
+ let curidx = na.indexOf(this.currentIndex);
+
+ // Huh, not listed?
+ if (curidx < 0) {
+ this.goToList();
+ return;
+ }
+
+ curidx += 1;
+ if (curidx >= na.length) {
+ this.goToList();
+ } else {
+ this.currentIndex = na[curidx];
+ this.showFull(this.unread_articles[this.currentIndex], false);
+ }
};
App.prototype.showPrevious = function() {
- this.setCurrentRead();
-
- if(this.currentIndex <= 0) {
- this.goToList();
- } else {
- this.currentIndex--;
- this.showFull(this.unread_articles[this.currentIndex], true);
- }
+ this.setCurrentRead();
+
+ const na = this.next_articles;
+ const curidx = na.indexOf(this.currentIndex)-1;
+ if (curidx < 0) {
+ // This handles not found, and also no previous article
+ this.goToList();
+ return;
+ }
+ this.currentIndex = na[curidx];
+ this.showFull(this.unread_articles[this.currentIndex], true);
};
App.prototype.setCurrentRead = function() {