Improve app.js and update french translation

This commit is contained in:
Frederic Guillot 2013-09-14 12:10:38 -04:00
parent a221fdbf8b
commit cc0adbb750
3 changed files with 124 additions and 133 deletions

View File

@ -1,15 +1,20 @@
(function() { (function() {
// List of subscriptions
var feeds = []; var feeds = [];
// List of feeds currently updating
var queue = []; var queue = [];
// Number of concurrent requests when updating all feeds
var queue_length = 5; var queue_length = 5;
// Keyboard shortcuts queue
var keyqueue = []; var keyqueue = [];
// Download full content from the original website
function download_item() function download_item()
{ {
// Change link container
var container = document.getElementById("download-item"); var container = document.getElementById("download-item");
if (! container) return; if (! container) return;
@ -59,7 +64,7 @@
request.send(); request.send();
} }
// Flip item status between unread and read
function switch_status(item_id, hide) function switch_status(item_id, hide)
{ {
var request = new XMLHttpRequest(); var request = new XMLHttpRequest();
@ -82,7 +87,7 @@
request.send(); request.send();
} }
// Set all items of the current page to the status read and redirect to the main page
function mark_items_as_read() function mark_items_as_read()
{ {
var articles = document.getElementsByTagName("article"); var articles = document.getElementsByTagName("article");
@ -95,7 +100,6 @@
var request = new XMLHttpRequest(); var request = new XMLHttpRequest();
request.onload = function() { request.onload = function() {
window.location.href = "?action=unread"; window.location.href = "?action=unread";
}; };
@ -103,14 +107,12 @@
request.send(JSON.stringify(idlist)); request.send(JSON.stringify(idlist));
} }
// Mark the current item read and hide this item
function mark_as_read(item_id) function mark_as_read(item_id)
{ {
var request = new XMLHttpRequest(); var request = new XMLHttpRequest();
request.onload = function() { request.onload = function() {
//find_next_item();
remove_item(item_id); remove_item(item_id);
}; };
@ -118,14 +120,12 @@
request.send(); request.send();
} }
// Set the current item unread and hide this item
function mark_as_unread(item_id) function mark_as_unread(item_id)
{ {
var request = new XMLHttpRequest(); var request = new XMLHttpRequest();
request.onload = function() { request.onload = function() {
//find_next_item();
remove_item(item_id); remove_item(item_id);
}; };
@ -133,7 +133,7 @@
request.send(); request.send();
} }
// Bookmark the selected item
function bookmark_item() function bookmark_item()
{ {
var item = document.getElementById("current-item"); var item = document.getElementById("current-item");
@ -147,7 +147,7 @@
} }
} }
// Show the refresh icon when updating a feed
function show_refresh_icon(feed_id) function show_refresh_icon(feed_id)
{ {
var container = document.getElementById("loading-feed-" + feed_id); var container = document.getElementById("loading-feed-" + feed_id);
@ -161,7 +161,7 @@
} }
} }
// Hide the refresh icon after update
function hide_refresh_icon(feed_id) function hide_refresh_icon(feed_id)
{ {
var container = document.getElementById("loading-feed-" + feed_id); var container = document.getElementById("loading-feed-" + feed_id);
@ -171,7 +171,7 @@
if (container) container.innerHTML = container.getAttribute("data-after-update"); if (container) container.innerHTML = container.getAttribute("data-after-update");
} }
// Update one feed in the background and execute a callback after that
function refresh_feed(feed_id, callback) function refresh_feed(feed_id, callback)
{ {
if (! feed_id) return false; if (! feed_id) return false;
@ -180,22 +180,16 @@
var request = new XMLHttpRequest(); var request = new XMLHttpRequest();
request.onreadystatechange = function() { request.onload = function() {
if (request.readyState === 4) {
hide_refresh_icon(feed_id); hide_refresh_icon(feed_id);
try { try {
var response = JSON.parse(this.responseText);
if (callback) { if (callback) {
callback(response); callback(JSON.parse(this.responseText));
} }
} }
catch (e) {} catch (e) {}
}
}; };
request.open("POST", "?action=refresh-feed&feed_id=" + feed_id, true); request.open("POST", "?action=refresh-feed&feed_id=" + feed_id, true);
@ -204,22 +198,18 @@
return true; return true;
} }
// Get all subscriptions from the feeds page
function get_feeds() function get_feeds()
{ {
var links = document.getElementsByTagName("a"); var links = document.getElementsByTagName("a");
for (var i = 0, ilen = links.length; i < ilen; i++) { for (var i = 0, ilen = links.length; i < ilen; i++) {
var feed_id = links[i].getAttribute('data-feed-id'); var feed_id = links[i].getAttribute('data-feed-id');
if (feed_id) feeds.push(parseInt(feed_id));
if (feed_id) {
feeds.push(parseInt(feed_id));
}
} }
} }
// Refresh all feeds (use a queue to allow 5 concurrent feed updates)
function refresh_all() function refresh_all()
{ {
get_feeds(); get_feeds();
@ -229,20 +219,14 @@
while (feeds.length > 0 && queue.length < queue_length) { while (feeds.length > 0 && queue.length < queue_length) {
var feed_id = feeds.shift(); var feed_id = feeds.shift();
queue.push(feed_id); queue.push(feed_id);
refresh_feed(feed_id, function(response) { refresh_feed(feed_id, function(response) {
var index = queue.indexOf(response.feed_id); var index = queue.indexOf(response.feed_id);
if (index >= 0) queue.splice(index, 1);
if (index >= 0) {
queue.splice(index, 1);
}
if (feeds.length == 0 && queue.length == 0) { if (feeds.length == 0 && queue.length == 0) {
clearInterval(interval); clearInterval(interval);
window.location.href = "?action=unread"; window.location.href = "?action=unread";
} }
@ -252,27 +236,26 @@
}, 100); }, 100);
} }
// Go the next page
function open_next_page() function open_next_page()
{ {
var link = document.getElementById("next-page"); var link = document.getElementById("next-page");
if (link) link.click(); if (link) link.click();
} }
// Go to the previous page
function open_previous_page() function open_previous_page()
{ {
var link = document.getElementById("previous-page"); var link = document.getElementById("previous-page");
if (link) link.click(); if (link) link.click();
} }
// Hide one item and update the item counter on the top
function remove_item(item_id) function remove_item(item_id)
{ {
var item = document.getElementById("item-" + item_id); var item = document.getElementById("item-" + item_id);
if (! item) { if (! item) {
item = document.getElementById("current-item"); item = document.getElementById("current-item");
if (item.getAttribute("data-item-id") != item_id) item = false; if (item.getAttribute("data-item-id") != item_id) item = false;
} }
@ -280,7 +263,6 @@
if (item) { if (item) {
item.parentNode.removeChild(item); item.parentNode.removeChild(item);
var container = document.getElementById("page-counter"); var container = document.getElementById("page-counter");
if (container) { if (container) {
@ -301,7 +283,7 @@
} }
} }
// Open the original url inside a new tab
function open_original_item() function open_original_item()
{ {
var link = document.getElementById("original-item"); var link = document.getElementById("original-item");
@ -317,14 +299,14 @@
} }
} }
// Show item content
function open_item() function open_item()
{ {
var link = document.getElementById("open-item"); var link = document.getElementById("open-item");
if (link) link.click(); if (link) link.click();
} }
// Show the next item
function open_next_item() function open_next_item()
{ {
var link = document.getElementById("next-item"); var link = document.getElementById("next-item");
@ -339,7 +321,7 @@
} }
} }
// Show the previous item
function open_previous_item() function open_previous_item()
{ {
var link = document.getElementById("previous-item"); var link = document.getElementById("previous-item");
@ -354,7 +336,7 @@
} }
} }
// Change item status and select the next item in the list
function change_item_status() function change_item_status()
{ {
if (is_listing() && ! document.getElementById("current-item")) { if (is_listing() && ! document.getElementById("current-item")) {
@ -368,7 +350,7 @@
} }
} }
// Scroll automatically the page when using keyboard shortcuts
function scroll_page_to(item) function scroll_page_to(item)
{ {
var clientHeight = pageYOffset + document.documentElement.clientHeight; var clientHeight = pageYOffset + document.documentElement.clientHeight;
@ -379,7 +361,7 @@
} }
} }
// Prepare the DOM for the selected item
function set_links_item(item_id) function set_links_item(item_id)
{ {
var link = document.getElementById("current-item"); var link = document.getElementById("current-item");
@ -398,7 +380,7 @@
if (link) link.id = "open-item"; if (link) link.id = "open-item";
} }
// Find the next item in the listing page
function find_next_item() function find_next_item()
{ {
var items = document.getElementsByTagName("article"); var items = document.getElementsByTagName("article");
@ -428,7 +410,7 @@
} }
} }
// Find the previous item in the listing page
function find_previous_item() function find_previous_item()
{ {
var items = document.getElementsByTagName("article"); var items = document.getElementsByTagName("article");
@ -458,14 +440,14 @@
} }
} }
// Check if we are on a listing page
function is_listing() function is_listing()
{ {
if (document.getElementById("listing")) return true; if (document.getElementById("listing")) return true;
return false; return false;
} }
// Authentication with Mozilla Persona
function mozilla_auth(action) function mozilla_auth(action)
{ {
navigator.id.watch({ navigator.id.watch({
@ -488,7 +470,7 @@
navigator.id.request(); navigator.id.request();
} }
// Click event handler, if there is a "data-action" attribute execute the corresponding callback
document.onclick = function(e) { document.onclick = function(e) {
var action = e.target.getAttribute("data-action"); var action = e.target.getAttribute("data-action");
@ -539,10 +521,13 @@
} }
}; };
// Keyboard handler, handle keyboard shortcuts
document.onkeypress = function(e) { document.onkeypress = function(e) {
keyqueue.push(e.keyCode);
if (keyqueue[0]==103) keyqueue.push(e.keyCode || e.which);
{
if (keyqueue[0] == 103) { // g
switch (keyqueue[1]) { switch (keyqueue[1]) {
case undefined: case undefined:
break; break;
@ -571,9 +556,10 @@
break; break;
} }
} }
else else {
{
keyqueue = []; keyqueue = [];
switch (e.keyCode || e.which) { switch (e.keyCode || e.which) {
case 100: // d case 100: // d
download_item(); download_item();

View File

@ -1,6 +1,11 @@
<?php <?php
return array( return array(
'Go to unread' => 'Voir les éléments non lus',
'Go to bookmarks' => 'Voir les favoris',
'Go to history' => 'Voir l\'historique',
'Go to subscriptions' => 'Voir les abonnements',
'Go to preferences' => 'Voir les préférences',
'Your Google Account is linked to Miniflux' => 'Votre compte Google est relié à Miniflux', 'Your Google Account is linked to Miniflux' => 'Votre compte Google est relié à Miniflux',
'Link Miniflux to my Google account' => 'Lier Miniflux à mon compte Google', 'Link Miniflux to my Google account' => 'Lier Miniflux à mon compte Google',
'Your Mozilla Persona Account is linked to Miniflux' => 'Votre compte Mozilla Persona est relié à Miniflux', 'Your Mozilla Persona Account is linked to Miniflux' => 'Votre compte Mozilla Persona est relié à Miniflux',