diff --git a/README.md b/README.md index 4d5c081a0..8ecd09f1a 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,8 @@ Technically, after reading an article from a ZIM file, there is a need to "injec This application is released under the GPL v3 license. See http://www.gnu.org/licenses/ or the included LICENSE-GPLv3.txt file The source code can be found at https://github.com/kiwix/kiwix-html5 -Unit tests can be run by opening tests.html file on Firefox. +Unit tests can be run by opening tests.html file on Firefox (or Chromium/Chrome with some tweaks). -The first versions of this application were originally part of the Evopedia project: http://www.evopedia.info (now discontinued) -These first versions were targeting Firefox OS (now discontinued too : we're not lucky ;-) ). \ No newline at end of file +The first versions of this application were originally part of the Evopedia project: http://www.evopedia.info (now discontinued). There was a "articles nearby" feature, that was able to find articles around your location. It has been deleted from the source code with everything related to Evopedia (but still in git history in versions<=2.0.0) +These first versions were targeting Firefox OS (now discontinued too : we're not lucky ;-) ). +Some Phonegap/Cordova port had been started but never finished (see in git history in versions<=2.0.0). \ No newline at end of file diff --git a/browser-tests/nightwatch_runner.js b/browser-tests/nightwatch_runner.js index f9273b369..ead9590be 100644 --- a/browser-tests/nightwatch_runner.js +++ b/browser-tests/nightwatch_runner.js @@ -16,14 +16,14 @@ module.exports = { .execute(function() { window.setRemoteArchive('https://kiwix.github.io/kiwix-html5/tests/wikipedia_en_ray_charles_2015-06.zim'); }) - .waitForElementVisible('#formTitleSearch', 20000) - .waitForElementVisible('#searchTitles', 20000) + .waitForElementVisible('#formArticleSearch', 20000) + .waitForElementVisible('#searchArticles', 20000) .setValue('#prefix', "Ray") - .click('#searchTitles') - .waitForElementVisible('#titleList', 20000) + .click('#searchArticles') + .waitForElementVisible('#articleList', 20000) .useXpath() - .waitForElementVisible("//div[@id='titleList']/a[text()='Ray Charles']", 20000) - .click("//div[@id='titleList']/a[text()='Ray Charles']") + .waitForElementVisible("//div[@id='articleList']/a[text()='Ray Charles']", 20000) + .click("//div[@id='articleList']/a[text()='Ray Charles']") .useCss() .frame('articleContent') .waitForElementPresent('#mweQ', 2000000) diff --git a/service-worker.js b/service-worker.js index 5b5d40734..8a4dce1ff 100644 --- a/service-worker.js +++ b/service-worker.js @@ -99,39 +99,39 @@ function fetchEventListener(event) { console.log('Asking app.js for a content', event.request.url); event.respondWith(new Promise(function(resolve, reject) { var nameSpace; - var titleName; - var titleNameWithNameSpace; + var title; + var titleWithNameSpace; var contentType; if (regexpContentUrlWithoutNamespace.test(event.request.url)) { // When the request URL is in the same folder, // it means it's a link to an article (namespace A) var regexpResult = regexpContentUrlWithoutNamespace.exec(event.request.url); nameSpace = 'A'; - titleName = regexpResult[1]; + title = regexpResult[1]; } else { var regexpResult = regexpContentUrlWithNamespace.exec(event.request.url); nameSpace = regexpResult[1]; - titleName = regexpResult[2]; + title = regexpResult[2]; } // The namespace defines the type of content. See http://www.openzim.org/wiki/ZIM_file_format#Namespaces // TODO : read the contentType from the ZIM file instead of hard-coding it here if (nameSpace === 'A') { - console.log("It's an article : " + titleName); + console.log("It's an article : " + title); contentType = 'text/html'; } else if (nameSpace === 'I' || nameSpace === 'J') { - console.log("It's an image : " + titleName); - if (regexpJPEG.test(titleName)) { + console.log("It's an image : " + title); + if (regexpJPEG.test(title)) { contentType = 'image/jpeg'; } - else if (regexpPNG.test(titleName)) { + else if (regexpPNG.test(title)) { contentType = 'image/png'; } } else if (nameSpace === '-') { - console.log("It's a layout dependency : " + titleName); - if (regexpJS.test(titleName)) { + console.log("It's a layout dependency : " + title); + if (regexpJS.test(title)) { contentType = 'text/javascript'; var responseInit = { status: 200, @@ -147,21 +147,21 @@ function fetchEventListener(event) { resolve(httpResponse); return; } - else if (regexpCSS.test(titleName)) { + else if (regexpCSS.test(title)) { contentType = 'text/css'; } } // We need to remove the potential parameters in the URL - titleName = removeUrlParameters(decodeURIComponent(titleName)); + title = removeUrlParameters(decodeURIComponent(title)); - titleNameWithNameSpace = nameSpace + '/' + titleName; + titleWithNameSpace = nameSpace + '/' + title; // Let's instanciate a new messageChannel, to allow app.s to give us the content var messageChannel = new MessageChannel(); messageChannel.port1.onmessage = function(event) { if (event.data.action === 'giveContent') { - console.log('content message received for ' + titleNameWithNameSpace, event.data); + console.log('content message received for ' + titleWithNameSpace, event.data); var responseInit = { status: 200, statusText: 'OK', @@ -172,16 +172,16 @@ function fetchEventListener(event) { var httpResponse = new Response(event.data.content, responseInit); - console.log('ServiceWorker responding to the HTTP request for ' + titleNameWithNameSpace + ' (size=' + event.data.content.length + ' octets)' , httpResponse); + console.log('ServiceWorker responding to the HTTP request for ' + titleWithNameSpace + ' (size=' + event.data.content.length + ' octets)' , httpResponse); resolve(httpResponse); } else { - console.log('Invalid message received from app.js for ' + titleNameWithNameSpace, event.data); + console.log('Invalid message received from app.js for ' + titleWithNameSpace, event.data); reject(event.data); } }; - console.log('Eventlistener added to listen for an answer to ' + titleNameWithNameSpace); - outgoingMessagePort.postMessage({'action': 'askForContent', 'titleName': titleNameWithNameSpace}, [messageChannel.port2]); + console.log('Eventlistener added to listen for an answer to ' + titleWithNameSpace); + outgoingMessagePort.postMessage({'action': 'askForContent', 'title': titleWithNameSpace}, [messageChannel.port2]); console.log('Message sent to app.js through outgoingMessagePort'); })); } diff --git a/tests/tests.js b/tests/tests.js index 603651662..91113098e 100644 --- a/tests/tests.js +++ b/tests/tests.js @@ -110,10 +110,10 @@ define(['jquery', 'zimArchive', 'zimDirEntry', 'util', 'utf8'], assert.equal(util.ucEveryFirstLetter(testString3), "Le Couvre-Chef Est Sur Le Porte-Manteaux", "The first letter of every word should be upper-case"); assert.equal(util.ucFirstLetter(testString4), "Épée", "The first letter should be upper-case (with accent)"); }); - QUnit.test("check remove duplicates of an array of title objects", function(assert) { + QUnit.test("check remove duplicates of an array of dirEntry objects", function(assert) { var array = [{title:"a"}, {title:"b"}, {title:"c"}, {title:"a"}, {title:"c"}, {title:"d"}]; var expectedArray = [{title:"a"}, {title:"b"}, {title:"c"}, {title:"d"}]; - assert.deepEqual(util.removeDuplicateTitlesInArray(array), expectedArray, "Duplicates should be removed from the array"); + assert.deepEqual(util.removeDuplicateTitlesInDirEntryArray(array), expectedArray, "Duplicates should be removed from the array"); }); QUnit.module("ZIM initialisation"); @@ -121,13 +121,13 @@ define(['jquery', 'zimArchive', 'zimDirEntry', 'util', 'utf8'], assert.ok(localZimArchive.isReady() === true, "ZIM archive should be set as ready"); }); - QUnit.module("zim_title_search_and_read"); + QUnit.module("zim_direntry_search_and_read"); QUnit.test("check DirEntry.fromStringId 'A Fool for You'", function(assert) { var done = assert.async(); var aFoolForYouDirEntry = zimDirEntry.DirEntry.fromStringId(localZimArchive._file, "5856|7|A|0|2|A_Fool_for_You.html|A Fool for You|false|undefined"); assert.expect(2); - var callbackFunction = function(title, htmlArticle) { + var callbackFunction = function(dirEntry, htmlArticle) { assert.ok(htmlArticle && htmlArticle.length > 0, "Article not empty"); // Remove new lines htmlArticle = htmlArticle.replace(/[\r\n]/g, " "); @@ -136,51 +136,51 @@ define(['jquery', 'zimArchive', 'zimDirEntry', 'util', 'utf8'], }; localZimArchive.readArticle(aFoolForYouDirEntry, callbackFunction); }); - QUnit.test("check findTitlesWithPrefix 'A'", function(assert) { + QUnit.test("check findDirEntriesWithPrefix 'A'", function(assert) { var done = assert.async(); assert.expect(2); - var callbackFunction = function(titleList) { - assert.ok(titleList && titleList.length === 5, "Article list with 5 results"); - var firstTitle = titleList[0]; - assert.equal(firstTitle.title , 'A Fool for You', 'First result should be "A Fool for You"'); + var callbackFunction = function(dirEntryList) { + assert.ok(dirEntryList && dirEntryList.length === 5, "Article list with 5 results"); + var firstDirEntry = dirEntryList[0]; + assert.equal(firstDirEntry.title , 'A Fool for You', 'First result should be "A Fool for You"'); done(); }; - localZimArchive.findTitlesWithPrefix('A', 5, callbackFunction); + localZimArchive.findDirEntriesWithPrefix('A', 5, callbackFunction); }); - QUnit.test("check findTitlesWithPrefix 'a'", function(assert) { + QUnit.test("check findDirEntriesWithPrefix 'a'", function(assert) { var done = assert.async(); assert.expect(2); - var callbackFunction = function(titleList) { - assert.ok(titleList && titleList.length === 5, "Article list with 5 results"); - var firstTitle = titleList[0]; - assert.equal(firstTitle.title , 'A Fool for You', 'First result should be "A Fool for You"'); + var callbackFunction = function(dirEntryList) { + assert.ok(dirEntryList && dirEntryList.length === 5, "Article list with 5 results"); + var firstDirEntry = dirEntryList[0]; + assert.equal(firstDirEntry.title , 'A Fool for You', 'First result should be "A Fool for You"'); done(); }; - localZimArchive.findTitlesWithPrefix('a', 5, callbackFunction); + localZimArchive.findDirEntriesWithPrefix('a', 5, callbackFunction); }); - QUnit.test("check findTitlesWithPrefix 'blues brothers'", function(assert) { + QUnit.test("check findDirEntriesWithPrefix 'blues brothers'", function(assert) { var done = assert.async(); assert.expect(2); - var callbackFunction = function(titleList) { - assert.ok(titleList && titleList.length === 3, "Article list with 3 result"); - var firstTitle = titleList[0]; - assert.equal(firstTitle.title , 'Blues Brothers (film)', 'First result should be "Blues Brothers (film)"'); + var callbackFunction = function(dirEntryList) { + assert.ok(dirEntryList && dirEntryList.length === 3, "Article list with 3 result"); + var firstDirEntry = dirEntryList[0]; + assert.equal(firstDirEntry.title , 'Blues Brothers (film)', 'First result should be "Blues Brothers (film)"'); done(); }; - localZimArchive.findTitlesWithPrefix('blues brothers', 5, callbackFunction); + localZimArchive.findDirEntriesWithPrefix('blues brothers', 5, callbackFunction); }); QUnit.test("article '(The Night Time Is) The Right Time' correctly redirects to 'Night Time Is the Right Time'", function(assert) { var done = assert.async(); assert.expect(6); - localZimArchive.getTitleByName("A/(The_Night_Time_Is)_The_Right_Time.html").then(function(title) { - assert.ok(title !== null, "Title found"); - if (title !== null) { - assert.ok(title.isRedirect(), "Title is a redirect."); - assert.equal(title.name(), "(The Night Time Is) The Right Time", "Correct redirect title name."); - localZimArchive.resolveRedirect(title, function(title) { - assert.ok(title !== null, "Title found"); - assert.ok(!title.isRedirect(), "Title is not a redirect."); - assert.equal(title.name(), "Night Time Is the Right Time", "Correct redirected title name."); + localZimArchive.getDirEntryByTitle("A/(The_Night_Time_Is)_The_Right_Time.html").then(function(dirEntry) { + assert.ok(dirEntry !== null, "DirEntry found"); + if (dirEntry !== null) { + assert.ok(dirEntry.isRedirect(), "DirEntry is a redirect."); + assert.equal(dirEntry.title, "(The Night Time Is) The Right Time", "Correct redirect title name."); + localZimArchive.resolveRedirect(dirEntry, function(dirEntry) { + assert.ok(dirEntry !== null, "DirEntry found"); + assert.ok(!dirEntry.isRedirect(), "DirEntry is not a redirect."); + assert.equal(dirEntry.title, "Night Time Is the Right Time", "Correct redirected title name."); done(); }); } else { @@ -191,15 +191,15 @@ define(['jquery', 'zimArchive', 'zimDirEntry', 'util', 'utf8'], QUnit.test("article 'Raelettes' correctly redirects to 'The Raelettes'", function(assert) { var done = assert.async(); assert.expect(6); - localZimArchive.getTitleByName("A/Raelettes.html").then(function(title) { - assert.ok(title !== null, "Title found"); - if (title !== null) { - assert.ok(title.isRedirect(), "Title is a redirect."); - assert.equal(title.name(), "Raelettes", "Correct redirect title name."); - localZimArchive.resolveRedirect(title, function(title) { - assert.ok(title !== null, "Title found"); - assert.ok(!title.isRedirect(), "Title is not a redirect."); - assert.equal(title.name(), "The Raelettes", "Correct redirected title name."); + localZimArchive.getDirEntryByTitle("A/Raelettes.html").then(function(dirEntry) { + assert.ok(dirEntry !== null, "DirEntry found"); + if (dirEntry !== null) { + assert.ok(dirEntry.isRedirect(), "DirEntry is a redirect."); + assert.equal(dirEntry.title, "Raelettes", "Correct redirect title name."); + localZimArchive.resolveRedirect(dirEntry, function(dirEntry) { + assert.ok(dirEntry !== null, "DirEntry found"); + assert.ok(!dirEntry.isRedirect(), "DirEntry is not a redirect."); + assert.equal(dirEntry.title, "The Raelettes", "Correct redirected title name."); done(); }); } else { @@ -210,15 +210,15 @@ define(['jquery', 'zimArchive', 'zimDirEntry', 'util', 'utf8'], QUnit.test("article 'Bein Green' correctly redirects to 'Bein' Green", function(assert) { var done = assert.async(); assert.expect(6); - localZimArchive.getTitleByName("A/Bein_Green.html").then(function(title) { - assert.ok(title !== null, "Title found"); - if (title !== null) { - assert.ok(title.isRedirect(), "Title is a redirect."); - assert.equal(title.name(), "Bein Green", "Correct redirect title name."); - localZimArchive.resolveRedirect(title, function(title) { - assert.ok(title !== null, "Title found"); - assert.ok(!title.isRedirect(), "Title is not a redirect."); - assert.equal(title.name(), "Bein' Green", "Correct redirected title name."); + localZimArchive.getDirEntryByTitle("A/Bein_Green.html").then(function(dirEntry) { + assert.ok(dirEntry !== null, "DirEntry found"); + if (dirEntry !== null) { + assert.ok(dirEntry.isRedirect(), "DirEntry is a redirect."); + assert.equal(dirEntry.title, "Bein Green", "Correct redirect title name."); + localZimArchive.resolveRedirect(dirEntry, function(dirEntry) { + assert.ok(dirEntry !== null, "DirEntry found"); + assert.ok(!dirEntry.isRedirect(), "DirEntry is not a redirect."); + assert.equal(dirEntry.title, "Bein' Green", "Correct redirected title name."); done(); }); } else { @@ -229,15 +229,15 @@ define(['jquery', 'zimArchive', 'zimDirEntry', 'util', 'utf8'], QUnit.test("article 'America, the Beautiful' correctly redirects to 'America the Beautiful'", function(assert) { var done = assert.async(); assert.expect(6); - localZimArchive.getTitleByName("A/America,_the_Beautiful.html").then(function(title) { - assert.ok(title !== null, "Title found"); - if (title !== null) { - assert.ok(title.isRedirect(), "Title is a redirect."); - assert.equal(title.name(), "America, the Beautiful", "Correct redirect title name."); - localZimArchive.resolveRedirect(title, function(title) { - assert.ok(title !== null, "Title found"); - assert.ok(!title.isRedirect(), "Title is not a redirect."); - assert.equal(title.name(), "America the Beautiful", "Correct redirected title name."); + localZimArchive.getDirEntryByTitle("A/America,_the_Beautiful.html").then(function(dirEntry) { + assert.ok(dirEntry !== null, "DirEntry found"); + if (dirEntry !== null) { + assert.ok(dirEntry.isRedirect(), "DirEntry is a redirect."); + assert.equal(dirEntry.title, "America, the Beautiful", "Correct redirect title name."); + localZimArchive.resolveRedirect(dirEntry, function(dirEntry) { + assert.ok(dirEntry !== null, "DirEntry found"); + assert.ok(!dirEntry.isRedirect(), "DirEntry is not a redirect."); + assert.equal(dirEntry.title, "America the Beautiful", "Correct redirected title name."); done(); }); } else { @@ -248,11 +248,11 @@ define(['jquery', 'zimArchive', 'zimDirEntry', 'util', 'utf8'], QUnit.test("Image 'm/RayCharles_AManAndHisSoul.jpg' can be loaded", function(assert) { var done = assert.async(); assert.expect(4); - localZimArchive.getTitleByName("I/m/RayCharles_AManAndHisSoul.jpg").then(function(title) { - assert.ok(title !== null, "Title found"); - if (title !== null) { - assert.equal(title.namespace +"/"+ title.url, "I/m/RayCharles_AManAndHisSoul.jpg", "URL is correct."); - localZimArchive.readBinaryFile(title, function(title, data) { + localZimArchive.getDirEntryByTitle("I/m/RayCharles_AManAndHisSoul.jpg").then(function(dirEntry) { + assert.ok(dirEntry !== null, "DirEntry found"); + if (dirEntry !== null) { + assert.equal(dirEntry.namespace +"/"+ dirEntry.url, "I/m/RayCharles_AManAndHisSoul.jpg", "URL is correct."); + localZimArchive.readBinaryFile(dirEntry, function(title, data) { assert.equal(data.length, 4951, "Data length is correct."); var beginning = new Uint8Array([255, 216, 255, 224, 0, 16, 74, 70, 73, 70, 0, 1, 1, 0, 0, 1]); @@ -268,11 +268,11 @@ define(['jquery', 'zimArchive', 'zimDirEntry', 'util', 'utf8'], var done = assert.async(); assert.expect(4); - localZimArchive.getTitleByName("-/s/style.css").then(function(title) { - assert.ok(title !== null, "Title found"); - if (title !== null) { - assert.equal(title.namespace +"/"+ title.url, "-/s/style.css", "URL is correct."); - localZimArchive.readBinaryFile(title, function(title, data) { + localZimArchive.getDirEntryByTitle("-/s/style.css").then(function(dirEntry) { + assert.ok(dirEntry !== null, "DirEntry found"); + if (dirEntry !== null) { + assert.equal(dirEntry.namespace +"/"+ dirEntry.url, "-/s/style.css", "URL is correct."); + localZimArchive.readBinaryFile(dirEntry, function(dirEntry, data) { assert.equal(data.length, 104495, "Data length is correct."); data = utf8.parse(data); var beginning = "\n/* start http://en.wikipedia.org/w/load.php?debug=false&lang=en&modules=site&only=styles&skin=vector"; @@ -287,11 +287,11 @@ define(['jquery', 'zimArchive', 'zimDirEntry', 'util', 'utf8'], QUnit.test("Javascript '-/j/local.js' can be loaded", function(assert) { var done = assert.async(); assert.expect(4); - localZimArchive.getTitleByName("-/j/local.js").then(function(title) { - assert.ok(title !== null, "Title found"); - if (title !== null) { - assert.equal(title.namespace +"/"+ title.url, "-/j/local.js", "URL is correct."); - localZimArchive.readBinaryFile(title, function(title, data) { + localZimArchive.getDirEntryByTitle("-/j/local.js").then(function(dirEntry) { + assert.ok(dirEntry !== null, "DirEntry found"); + if (dirEntry !== null) { + assert.equal(dirEntry.namespace +"/"+ dirEntry.url, "-/j/local.js", "URL is correct."); + localZimArchive.readBinaryFile(dirEntry, function(dirEntry, data) { assert.equal(data.length, 41, "Data length is correct."); data = utf8.parse(data); var beginning = "console.log( \"mw.loader"; @@ -307,12 +307,12 @@ define(['jquery', 'zimArchive', 'zimDirEntry', 'util', 'utf8'], QUnit.test("Split article 'A/Ray_Charles.html' can be loaded", function(assert) { var done = assert.async(); assert.expect(6); - localZimArchive.getTitleByName("A/Ray_Charles.html").then(function(title) { - assert.ok(title !== null, "Title found"); - if (title !== null) { - assert.equal(title.namespace +"/"+ title.url, "A/Ray_Charles.html", "URL is correct."); - localZimArchive.readArticle(title, function(titleName, data) { - assert.equal(titleName, "Ray Charles", "Title is correct."); + localZimArchive.getDirEntryByTitle("A/Ray_Charles.html").then(function(dirEntry) { + assert.ok(dirEntry !== null, "Title found"); + if (dirEntry !== null) { + assert.equal(dirEntry.namespace +"/"+ dirEntry.url, "A/Ray_Charles.html", "URL is correct."); + localZimArchive.readArticle(dirEntry, function(title, data) { + assert.equal(title, "Ray Charles", "Title is correct."); assert.equal(data.length, 157186, "Data length is correct."); assert.equal(data.indexOf("the only true genius in show business"), 5535, "Specific substring at beginning found."); assert.equal(data.indexOf("Random Access Memories"), 154107, "Specific substring at end found."); @@ -324,28 +324,28 @@ define(['jquery', 'zimArchive', 'zimDirEntry', 'util', 'utf8'], }); }); - QUnit.module("zim_random_and_main_title"); - QUnit.test("check that a random title is found", function(assert) { + QUnit.module("zim_random_and_main_article"); + QUnit.test("check that a random article is found", function(assert) { var done = assert.async(); assert.expect(2); - var callbackRandomTitleFound = function(title) { - assert.ok(title !== null, "One title should be found"); - assert.ok(title.name() !== null, "The random title should have a name" ); + var callbackRandomArticleFound = function(dirEntry) { + assert.ok(dirEntry !== null, "One DirEntry should be found"); + assert.ok(dirEntry.title !== null, "The random DirEntry should have a title" ); done(); }; - localZimArchive.getRandomTitle(callbackRandomTitleFound); + localZimArchive.getRandomDirEntry(callbackRandomArticleFound); }); - QUnit.test("check that the main title is found", function(assert) { + QUnit.test("check that the main article is found", function(assert) { var done = assert.async(); assert.expect(2); - var callbackMainPageTitleFound = function(title) { - assert.ok(title !== null, "Main title should be found"); - assert.equal(title.name(), "Summary", "The main title should be called Summary" ); + var callbackMainPageArticleFound = function(dirEntry) { + assert.ok(dirEntry !== null, "Main DirEntry should be found"); + assert.equal(dirEntry.title, "Summary", "The main DirEntry should be called Summary" ); done(); }; - localZimArchive.getMainPageTitle(callbackMainPageTitleFound); + localZimArchive.getMainPageDirEntry(callbackMainPageArticleFound); }); }; }); diff --git a/www/css/app.css b/www/css/app.css index d4e14efd4..28ed033bc 100644 --- a/www/css/app.css +++ b/www/css/app.css @@ -59,7 +59,7 @@ padding-left: 1px !important; } -#searchingForTitles .floating { +#searchingForArticles .floating { position: relative; z-index: 10; top: 20px; diff --git a/www/index.html b/www/index.html index 144e36ec0..5387e2341 100644 --- a/www/index.html +++ b/www/index.html @@ -66,13 +66,13 @@