This is a preliminary work on the port of Evopedia (offline wikipedia reader) in HTML5/Javascript, with Firefox OS as the primary target
The original application is at http://www.evopedia.info/
On desktops, it works on recent Firefox and Chrome, and maybe on other browsers
-
On the Firefos OS simulator, you have to put the archive files in a "fake-sdcard/evopedia" folder of your firefox profile (ex : ~/.mozilla/firefox/xxxx.default/extensions/r2d2b2g@mozilla.org/profile/fake-sdcard). It looks for evopedia/*/titles.idx in it. You also need to install the application from the dashboard of the simulator instead of accessing via the browser (due to security restrictions in Firefox OS : only certified webapps can access the sdcard)
+
On desktops, it works on recent Firefox and Chrome, and maybe on other browsers. In this case, you have to select manually some files from your dump
+
On the Firefos OS simulator, you have to put the archive files in a "fake-sdcard/evopedia" folder of your firefox profile (ex : ~/.mozilla/firefox/xxxx.default/extensions/r2d2b2g@mozilla.org/profile/fake-sdcard). It looks for evopedia/*/titles.idx in it. You need to install the application from the dashboard of the simulator (due to security restrictions in Firefox OS : only certified webapps can access the sdcard)
On a real Firefox OS device, you also have to put the archive files in an "evopedia" directory at the root of your sdcard, so that it finds a file /evopedia/*/titles.idx on it
@@ -64,7 +61,6 @@ License:
The performance has to be optimized when reading an article
Some searches (for example with prefix "a" on the French dump) do not give any result even if they should
In some cases, the links inside an article do not work, or do not lead to the right article
-
On a real device, reading an article sometimes crashes because it loads too many things in memory
It is hardly usable on a device because the buttons and inputs are too small
@@ -74,6 +70,12 @@ License:
id="titleFile" /> Please select the files wikipedia_*.dat
from the same dump :
+
+ Scanning your sdcard for archives... Please wait
+
+
+ Please select the archive you want to use :
+
Find titles starting with :
diff --git a/www/js/app.js b/www/js/app.js
index e5848f44..106cf56e 100644
--- a/www/js/app.js
+++ b/www/js/app.js
@@ -50,8 +50,9 @@ define(function(require) {
if (storage != null) {
// If DeviceStorage is available, we look for archives in it
+ $('#scanningForArchives').show();
var directory = 'evopedia';
- evopedia.LocalArchive.scanForArchives(storage,directory,selectFirstArchive);
+ evopedia.LocalArchive.scanForArchives(storage,directory,populateDropDownListOfArchives);
}
else {
// If DeviceStorage is not available, we display the file select components
@@ -65,13 +66,36 @@ define(function(require) {
goToArticle(titleName);
};
+ /**
+ * Populate the drop-down list of titles with the given list
+ */
+ function populateDropDownListOfArchives(archiveDirectories) {
+ $('#scanningForArchives').hide();
+ $('#chooseArchiveFromLocalStorage').show();
+ var comboArchiveList = document.getElementById('archiveList');
+ comboArchiveList.options.length = 0;
+ for (var i=0; i0) {
+ // Set the localArchive from the first result
+ setLocalArchiveFromArchiveList();
+ }
+ else {
+ alert("No Evopedia archive found in your sdcard. Please see 'About' for more info");
+ }
+ }
+
/**
- * Selects the first archive found on device storage
+ * Sets the localArchive from the selected archive in the drop-down list
*/
- function selectFirstArchive(archiveDirectories) {
+ function setLocalArchiveFromArchiveList() {
+ var archiveDirectory = $('#archiveList').val();
localArchive = new evopedia.LocalArchive();
- localArchive.readTitleFile(storage, archiveDirectories[0]);
- localArchive.readDataFiles(storage, archiveDirectories[0], 0);
+ localArchive.readTitleFile(storage, archiveDirectory);
+ localArchive.readDataFiles(storage, archiveDirectory, 0);
}
/**
@@ -83,6 +107,9 @@ define(function(require) {
$('#titleFile').on('change', setLocalArchiveFromFileSelect);
}
+ /**
+ * Sets the localArchive from the File selects populated by user
+ */
function setLocalArchiveFromFileSelect() {
dataFiles=document.getElementById('dataFiles').files;
titleFile=document.getElementById('titleFile').files[0];
diff --git a/www/js/lib/evopedia.js b/www/js/lib/evopedia.js
index 4b133cfb..74575ddf 100644
--- a/www/js/lib/evopedia.js
+++ b/www/js/lib/evopedia.js
@@ -445,7 +445,6 @@ define(function(require) {
// We want to return the directory where titles.idx is stored
var directory = fileName.substring(0, fileName.lastIndexOf('/'));
- console.log(directory);
directories.push(directory);
cursor.continue();
}
@@ -455,10 +454,15 @@ define(function(require) {
};
};
+ /**
+ * Utility function : return true if the given string ends with the suffix
+ * @param str
+ * @param suffix
+ * @returns {Boolean}
+ */
function endsWith(str, suffix) {
return str.indexOf(suffix, str.length - suffix.length) !== -1;
}
-
/**