From 3618f9bcd3f284c8793463f5f620f44f981ff7a0 Mon Sep 17 00:00:00 2001 From: mossroy Date: Sun, 26 May 2013 16:24:34 +0200 Subject: [PATCH 1/2] Slightly improved the error handling, so that to : - avoid some infinite loops - display the error message when an unexpected error occurs --- www/js/lib/evopedia.js | 55 +++++++++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 22 deletions(-) diff --git a/www/js/lib/evopedia.js b/www/js/lib/evopedia.js index d505b21a..4ca96538 100644 --- a/www/js/lib/evopedia.js +++ b/www/js/lib/evopedia.js @@ -336,30 +336,41 @@ define(function(require) { alert('Data file read cancelled'); }; reader.onload = function(e) { - var compressedArticles = e.target.result; - var htmlArticles; try { - htmlArticles = bzip2.simple(bzip2.array(new Uint8Array( - compressedArticles))); - } catch (e) { - // TODO : rethrow exception if we reach the end of the file - currentLocalArchiveInstance.readArticleChunk(title, dataFile, reader, readLength + CHUNK_SIZE, - callbackFunction); - return; + var compressedArticles = e.target.result; + var htmlArticles; + try { + htmlArticles = bzip2.simple(bzip2.array(new Uint8Array( + compressedArticles))); + } catch (e) { + // TODO : there must be a better way to differentiate real exceptions + // and exceptions due to the fact that the article is too long to fit in the chunk + if (e != "No magic number found") { + currentLocalArchiveInstance.readArticleChunk(title, dataFile, reader, readLength + CHUNK_SIZE, + callbackFunction); + return; + } + else { + throw e; + } + } + // Start reading at offset, and keep length characters + var htmlArticle = htmlArticles.substring(title.blockOffset, + title.blockOffset + title.articleLength); + if (htmlArticle.length >= title.articleLength) { + // Keep only length characters + htmlArticle = htmlArticle.substring(0, title.articleLength); + // Decode UTF-8 encoding + htmlArticle = decodeURIComponent(escape(htmlArticle)); + callbackFunction(htmlArticle); + } else { + // TODO : throw exception if we reach the end of the file + currentLocalArchiveInstance.readArticleChunk(title, dataFile, reader, readLength + CHUNK_SIZE, + callbackFunction); + } } - // Start reading at offset, and keep length characters - var htmlArticle = htmlArticles.substring(title.blockOffset, - title.blockOffset + title.articleLength); - if (htmlArticle.length >= title.articleLength) { - // Keep only length characters - htmlArticle = htmlArticle.substring(0, title.articleLength); - // Decode UTF-8 encoding - htmlArticle = decodeURIComponent(escape(htmlArticle)); - callbackFunction(htmlArticle); - } else { - // TODO : throw exception if we reach the end of the file - currentLocalArchiveInstance.readArticleChunk(title, dataFile, reader, readLength + CHUNK_SIZE, - callbackFunction); + catch (e) { + callbackFunction("Error : " + e); } }; var blob = dataFile.slice(title.blockStart, title.blockStart From 2954f06c9567568726736b74ee29829b6b006ef0 Mon Sep 17 00:00:00 2001 From: mossroy Date: Sun, 26 May 2013 19:27:12 +0200 Subject: [PATCH 2/2] Implement the browser history handling, with HTML5 pushState --- tests/tests.js | 2 +- www/index.html | 1 - www/js/app.js | 35 ++++++++++++++++++++++++++++------- www/js/lib/evopedia.js | 2 +- 4 files changed, 30 insertions(+), 10 deletions(-) diff --git a/tests/tests.js b/tests/tests.js index a9e25028..eb10b345 100644 --- a/tests/tests.js +++ b/tests/tests.js @@ -113,7 +113,7 @@ define(function (require) { }); asyncTest("check readArticle", function(){ - var callbackFunction = function(htmlArticle) { + var callbackFunction = function(title, htmlArticle) { ok(htmlArticle && htmlArticle.length>0,"Article not empty"); // Remove new lines htmlArticle = htmlArticle.replace(/[\r\n]/g, " "); diff --git a/www/index.html b/www/index.html index 08716f35..07392312 100644 --- a/www/index.html +++ b/www/index.html @@ -64,7 +64,6 @@ License:
  • 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
  • -
  • Following the links in an article does not populate the history of the browser, which prevents the use of the back button