diff --git a/browser-tests/nightwatch_runner.js b/browser-tests/nightwatch_runner.js index 92739e565..aa449871e 100644 --- a/browser-tests/nightwatch_runner.js +++ b/browser-tests/nightwatch_runner.js @@ -65,10 +65,10 @@ module.exports = { .useXpath() .waitForElementVisible("//div[@id='articleList']/a[text()='Ray Charles']", 20000) .click("//div[@id='articleList']/a[text()='Ray Charles']") - .useCss() + .useXpath() .frame('articleContent') - .waitForElementPresent('#mweQ', 2000000) - .assert.containsText('#mweQ', 'Life and career') + .waitForElementPresent("//div[@id='content']/div[@id='mw-content-text']/h2[@id='mweQ']", 2000000) + .assert.containsText("//div[@id='content']/div[@id='mw-content-text']/h2[@id='mweQ']", 'Life and career') .end(); } }; diff --git a/service-worker.js b/service-worker.js index 05e1a48a6..afbd08ca1 100644 --- a/service-worker.js +++ b/service-worker.js @@ -87,15 +87,12 @@ var regexpCSS = new RegExp(/\.css$/i); // Pattern for ZIM file namespace - see http://www.openzim.org/wiki/ZIM_file_format#Namespaces var regexpZIMUrlWithNamespace = new RegExp(/(?:^|\/)([-ABIJMUVWX])\/(.+)/); -var regexpDummyArticle = new RegExp(/dummyArticle\.html$/); function fetchEventListener(event) { if (fetchCaptureEnabled) { console.log('ServiceWorker handling fetch event for : ' + event.request.url); - // TODO handle the dummy article more properly - if (regexpZIMUrlWithNamespace.test(event.request.url) - && !regexpDummyArticle.test(event.request.url)) { + if (regexpZIMUrlWithNamespace.test(event.request.url)) { console.log('Asking app.js for a content', event.request.url); event.respondWith(new Promise(function(resolve, reject) { diff --git a/www/dummyArticle.html b/www/dummyArticle.html deleted file mode 100644 index 084a7ce1a..000000000 --- a/www/dummyArticle.html +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - dummy Article - - - - diff --git a/www/js/app.js b/www/js/app.js index de058edb2..a8ee4277f 100644 --- a/www/js/app.js +++ b/www/js/app.js @@ -748,8 +748,6 @@ define(['jquery', 'zimArchiveLoader', 'util', 'uiUtil', 'cookies','abstractFiles selectedArchive.resolveRedirect(dirEntry, readArticle); } else { - //Void the iframe - document.getElementById("articleContent").src = "dummyArticle.html"; selectedArchive.readArticle(dirEntry, displayArticleInForm); } } @@ -841,21 +839,33 @@ define(['jquery', 'zimArchiveLoader', 'util', 'uiUtil', 'cookies','abstractFiles var urlPath = regexpPath.test(dirEntry.url) ? urlPath = dirEntry.url.match(regexpPath)[1] : ""; var baseUrl = dirEntry.namespace + "/" + urlPath; - //Inject base tag into html + // Inject base tag into html htmlArticle = htmlArticle.replace(/(]*>\s*)/i, '$1\r\n'); // Display the article inside the web page. - document.getElementById("articleContent").contentDocument.documentElement.innerHTML = htmlArticle; + var iframeArticleContent = document.getElementById("articleContent"); + var articleContent = iframeArticleContent.contentDocument; + articleContent.open(); + articleContent.write(htmlArticle); // If the ServiceWorker is not useable, we need to fallback to parse the DOM - // to inject math images, and replace some links with javascript calls + // to inject images, CSS etc, and replace links with javascript calls if (contentInjectionMode === 'jquery') { - parseAnchorsJQuery(); - loadImagesJQuery(); - loadCSSJQuery(); - //JavaScript loading currently disabled - //loadJavaScriptJQuery(); + iframeArticleContent.onload = function() { + parseAnchorsJQuery(); + loadImagesJQuery(); + loadCSSJQuery(); + //JavaScript loading currently disabled + //loadJavaScriptJQuery(); + }; } + else { + // Removes the onload in case the user switches from jquery to serviceworker mode + iframeArticleContent.onload = function() {}; + } + + // Close the article content after the onload event is set, to avoid a potential race condition + articleContent.close(); function parseAnchorsJQuery() { var currentProtocol = location.protocol;