miniflux-legacy/assets/js/feed.js
Mathias Kresin a4d8abb631 Move update icon and update icon blinking to css
Use CSS3 Animation for the "loading icon" blinking and move the definition of
the loading icon to CSS as well.

CSS3 Animations are supported by IE10, Firefox and using the -webkit prefix by
Chrome and Safari.

I've dropped the usage of element.classList in favour of supporting refreshing/
article downloading in IE9 (again). The classList stuff isn't necessarily
needed, as the elements in question only get one or no class assigned.

I've dropped no longer supported css options like:

the appearance option isn't supported by any browser, the -webkit-appearance
doesn't change anything visible.

-webkit-font-smoothing support was dropped in chrome 22 and font-smoothing
isn't specified anywhere.
2014-12-26 23:01:05 +01:00

66 lines
2.3 KiB
JavaScript

Miniflux.Feed = (function() {
// List of subscriptions
var feeds = [];
// List of feeds currently updating
var queue = [];
// Number of concurrent requests when updating all feeds
var queue_length = 5;
// Update the items unread/total count for the feed
function updateItemsCounter(feed_id, counts)
{
var container = document.getElementById("items-count-" + feed_id);
if (container) container.innerHTML = counts["items_unread"] + "/" + counts['items_total'];
}
return {
Update: function(feed_id, callback) {
var container = document.getElementById("items-count-" + feed_id);
if (! container) return;
//add data-feed-id to article element and couse the first h2
container.parentNode.className = "loading-icon";
var request = new XMLHttpRequest();
request.onload = function() {
container.parentNode.className = "";
var response = JSON.parse(this.responseText);
if (response.result) updateItemsCounter(feed_id, response.items_count);
if (callback) callback(response);
};
request.open("POST", "?action=refresh-feed&feed_id=" + feed_id, true);
request.send();
},
UpdateAll: function() {
var links = document.getElementsByTagName("a");
for (var i = 0, ilen = links.length; i < ilen; i++) {
var feed_id = links[i].getAttribute('data-feed-id');
if (feed_id) feeds.push(parseInt(feed_id));
}
var interval = setInterval(function() {
while (feeds.length > 0 && queue.length < queue_length) {
var feed_id = feeds.shift();
queue.push(feed_id);
Miniflux.Feed.Update(feed_id, function(response) {
var index = queue.indexOf(response.feed_id);
if (index >= 0) queue.splice(index, 1);
if (feeds.length === 0 && queue.length === 0) {
clearInterval(interval);
window.location.href = "?action=unread";
}
});
}
}, 100);
}
};
})();