Fixes to make it work again on FxOS, and to keep the new structure compatible with unit tests

+ a few cosmetic modifications
This commit is contained in:
mossroy 2014-02-28 11:44:49 +01:00
parent 3f7abc7a24
commit 84f5ab62a3
5 changed files with 1048 additions and 1038 deletions

View File

@ -2,12 +2,12 @@
"version": "1.1.0-SNAPSHOT", "version": "1.1.0-SNAPSHOT",
"name": "Evopedia", "name": "Evopedia",
"description": "Offline Wikipedia Viewer", "description": "Offline Wikipedia Viewer",
"launch_path": "/index.html", "launch_path": "/www/index.html",
"icons": { "icons": {
"16": "/img/icons/evopedia-16.png", "16": "/www/img/icons/evopedia-16.png",
"48": "/img/icons/evopedia-48.png", "48": "/www/img/icons/evopedia-48.png",
"60": "/img/icons/evopedia-60.png", "60": "/www/img/icons/evopedia-60.png",
"128": "/img/icons/evopedia-128.png" "128": "/www/img/icons/evopedia-128.png"
}, },
"developer": { "developer": {
"name": "Mossroy <mossroy@free.fr>", "name": "Mossroy <mossroy@free.fr>",

View File

@ -33,7 +33,7 @@
http://requirejs.org/docs/api.html#jsfiles --> http://requirejs.org/docs/api.html#jsfiles -->
<script type="text/javascript" <script type="text/javascript"
data-main="tests/init.js" data-main="tests/init.js"
src="js/lib/require.js"></script> src="www/js/lib/require.js"></script>
</head> </head>

View File

@ -21,7 +21,7 @@
* along with Evopedia (file LICENSE-GPLv3.txt). If not, see <http://www.gnu.org/licenses/> * along with Evopedia (file LICENSE-GPLv3.txt). If not, see <http://www.gnu.org/licenses/>
*/ */
require.config({ require.config({
baseUrl: 'js/lib', baseUrl: 'www/js/lib',
paths: { paths: {
'zepto': 'zepto', 'zepto': 'zepto',
'jquery': 'jquery-2.0.3', 'jquery': 'jquery-2.0.3',
@ -30,4 +30,4 @@ require.config({
} }
}); });
requirejs(['../../tests/tests']); requirejs(['../../../tests/tests']);

View File

@ -32,17 +32,21 @@ define(function(require) {
var titleIterators = require('titleIterators'); var titleIterators = require('titleIterators');
// Declare the webworker that can uncompress with bzip2 algorithm // Declare the webworker that can uncompress with bzip2 algorithm
var webworkerBzip2 = new Worker("js/lib/webworker_bzip2.js"); var webworkerBzip2;
try {
// When using the application normally
webworkerBzip2 = new Worker("js/lib/webworker_bzip2.js");
}
catch(e) {
// When using unit tests
webworkerBzip2 = new Worker("www/js/lib/webworker_bzip2.js");
}
// Size of chunks read in the dump files : 128 KB // Size of chunks read in the dump files : 128 KB
var CHUNK_SIZE = 131072; var CHUNK_SIZE = 131072;
// The maximum number of titles that can have the same name after normalizing // The maximum number of titles that can have the same name after normalizing
// This is used by the algorithm that searches for a specific article by its name // This is used by the algorithm that searches for a specific article by its name
var MAX_TITLES_WITH_SAME_NORMALIZED_NAME = 30; var MAX_TITLES_WITH_SAME_NORMALIZED_NAME = 30;
// Maximum length of a title
// 300 bytes is arbitrary : we actually do not really know how long the titles will be
// But mediawiki titles seem to be limited to ~200 bytes, so 300 should be more than enough
var MAX_TITLE_LENGTH = 300;
// A rectangle representing all the earth globe // A rectangle representing all the earth globe
var GLOBE_RECTANGLE = new geometry.rect(-181, -90, 361, 181); var GLOBE_RECTANGLE = new geometry.rect(-181, -90, 361, 181);
@ -313,14 +317,15 @@ define(function(require) {
*/ */
LocalArchive.prototype.getTitlesStartingAtOffset = function(titleOffset, titleCount, callbackFunction) { LocalArchive.prototype.getTitlesStartingAtOffset = function(titleOffset, titleCount, callbackFunction) {
var titles = []; var titles = [];
var currentLocalArchiveInstance = this;
jQuery.when().then(function() { jQuery.when().then(function() {
var iterator = new titleIterators.SequentialTitleIterator(this, titleOffset); var iterator = new titleIterators.SequentialTitleIterator(currentLocalArchiveInstance, titleOffset);
function addNext() { function addNext() {
if (titles.length >= titleCount) { if (titles.length >= titleCount) {
return titles; return titles;
} }
return iterator.advance().then(function(title) { return iterator.advance().then(function(title) {
if (title == null) if (title === null)
return titles; return titles;
titles.push(title); titles.push(title);
return addNext(); return addNext();

View File

@ -30,13 +30,15 @@ define(['utf8', 'title', 'util', 'jquery'], function(utf8, evopediaTitle, util,
* Iterates over all titles starting at the given offset. * Iterates over all titles starting at the given offset.
* The asynchronous method advance has to be called before this.title is * The asynchronous method advance has to be called before this.title is
* valid. * valid.
* @param archive
* @param offset
*/ */
function SequentialTitleIterator(archive, offset) { function SequentialTitleIterator(archive, offset) {
this._titleFile = archive.titleFile; this._titleFile = archive.titleFile;
this._archive = archive; this._archive = archive;
this._offset = offset; this._offset = offset;
this.title = null; this.title = null;
} };
/** /**
* Advances to the next title (or the first), if possible. * Advances to the next title (or the first), if possible.
* @returns jQuery promise containing the next title or null if there is no * @returns jQuery promise containing the next title or null if there is no
@ -59,12 +61,15 @@ define(['utf8', 'title', 'util', 'jquery'], function(utf8, evopediaTitle, util,
that._offset += newLineIndex + 1; that._offset += newLineIndex + 1;
return that._title; return that._title;
}); });
} };
/** /**
* Searches for the offset into the given title file where the first title * Searches for the offset into the given title file where the first title
* with the given prefix (or lexicographically larger) is located. * with the given prefix (or lexicographically larger) is located.
* The given function normalize is applied to every title before comparison. * The given function normalize is applied to every title before comparison.
* @param titleFile
* @param prefix
* @param normalize function to be applied to every title before comparison
* @returns jQuery promise giving the offset * @returns jQuery promise giving the offset
*/ */
function FindPrefixOffset(titleFile, prefix, normalize) { function FindPrefixOffset(titleFile, prefix, normalize) {
@ -107,7 +112,7 @@ define(['utf8', 'title', 'util', 'jquery'], function(utf8, evopediaTitle, util,
return iterate(); return iterate();
}); });
} }
} };
return iterate(); return iterate();
} }