diff --git a/www/index.html b/www/index.html index 93b379cd..141d5e92 100644 --- a/www/index.html +++ b/www/index.html @@ -42,20 +42,17 @@ License:

Evopedia

-
+ + +
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; } - /**