mirror of
https://github.com/kiwix/kiwix-js.git
synced 2025-09-24 04:54:51 -04:00
Merge branch 'master' of https://github.com/mossroy/evopedia-html5
Conflicts: www/index.html www/js/app.js
This commit is contained in:
commit
d3a30a40de
@ -113,7 +113,7 @@ define(function (require) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
asyncTest("check readArticle", function(){
|
asyncTest("check readArticle", function(){
|
||||||
var callbackFunction = function(htmlArticle) {
|
var callbackFunction = function(title, htmlArticle) {
|
||||||
ok(htmlArticle && htmlArticle.length>0,"Article not empty");
|
ok(htmlArticle && htmlArticle.length>0,"Article not empty");
|
||||||
// Remove new lines
|
// Remove new lines
|
||||||
htmlArticle = htmlArticle.replace(/[\r\n]/g, " ");
|
htmlArticle = htmlArticle.replace(/[\r\n]/g, " ");
|
||||||
|
@ -66,7 +66,6 @@ License:
|
|||||||
<li>In some cases, the links inside an article do not work, or do not lead to the right article</li>
|
<li>In some cases, the links inside an article do not work, or do not lead to the right article</li>
|
||||||
<li>On a real device, reading an article sometimes crashes because it loads too many things in memory</li>
|
<li>On a real device, reading an article sometimes crashes because it loads too many things in memory</li>
|
||||||
<li>It is hardly usable on a device because the buttons and inputs are too small</li>
|
<li>It is hardly usable on a device because the buttons and inputs are too small</li>
|
||||||
<li>Following the links in an article does not populate the history of the browser, which prevents the use of the back button</li>
|
|
||||||
</ul>
|
</ul>
|
||||||
<br />
|
<br />
|
||||||
</div>
|
</div>
|
||||||
|
@ -32,7 +32,10 @@ define(function(require) {
|
|||||||
searchTitlesFromPrefix($('#prefix').val());
|
searchTitlesFromPrefix($('#prefix').val());
|
||||||
});
|
});
|
||||||
$('#readData').on('click', function(e) {
|
$('#readData').on('click', function(e) {
|
||||||
findTitleFromTitleIdAndLaunchArticleRead($('#titleList').val());
|
var titleId = $('#titleList').val();
|
||||||
|
findTitleFromTitleIdAndLaunchArticleRead(titleId);
|
||||||
|
var title = evopedia.Title.parseTitleId(localArchive,titleId);
|
||||||
|
pushBrowserHistoryState(title.name);
|
||||||
});
|
});
|
||||||
$('#prefix').on('keyup', function(e) {
|
$('#prefix').on('keyup', function(e) {
|
||||||
onKeyUpPrefix(e);
|
onKeyUpPrefix(e);
|
||||||
@ -57,6 +60,12 @@ define(function(require) {
|
|||||||
setLocalArchiveFromFileSelect();
|
setLocalArchiveFromFileSelect();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Display the article when the user goes back in the browser history
|
||||||
|
window.onpopstate = function(event) {
|
||||||
|
var titleName = event.state.titleName;
|
||||||
|
goToArticle(titleName);
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Displays the zone to select files from the dump
|
* Displays the zone to select files from the dump
|
||||||
*/
|
*/
|
||||||
@ -116,9 +125,9 @@ define(function(require) {
|
|||||||
* and call the function to read the corresponding article
|
* and call the function to read the corresponding article
|
||||||
*/
|
*/
|
||||||
function findTitleFromTitleIdAndLaunchArticleRead(titleId) {
|
function findTitleFromTitleIdAndLaunchArticleRead(titleId) {
|
||||||
$("#articleContent").html("Loading article from dump...");
|
|
||||||
if (localArchive.dataFiles && localArchive.dataFiles.length>0) {
|
if (localArchive.dataFiles && localArchive.dataFiles.length>0) {
|
||||||
var title = evopedia.Title.parseTitleId(localArchive,titleId);
|
var title = evopedia.Title.parseTitleId(localArchive,titleId);
|
||||||
|
$("#articleContent").html("Loading from dump article " + title.name + " ...");
|
||||||
if (title.fileNr == 255) {
|
if (title.fileNr == 255) {
|
||||||
localArchive.resolveRedirect(title, readArticle);
|
localArchive.resolveRedirect(title, readArticle);
|
||||||
}
|
}
|
||||||
@ -149,7 +158,7 @@ define(function(require) {
|
|||||||
* Display the the given HTML article in the web page,
|
* Display the the given HTML article in the web page,
|
||||||
* and convert links to javascript calls
|
* and convert links to javascript calls
|
||||||
*/
|
*/
|
||||||
function displayArticleInForm(htmlArticle) {
|
function displayArticleInForm(title, htmlArticle) {
|
||||||
// Display the article inside the web page.
|
// Display the article inside the web page.
|
||||||
$('#articleContent').html(htmlArticle);
|
$('#articleContent').html(htmlArticle);
|
||||||
|
|
||||||
@ -171,21 +180,32 @@ define(function(require) {
|
|||||||
// It's a link to another article : add an onclick event to go to this article
|
// It's a link to another article : add an onclick event to go to this article
|
||||||
// instead of following the link
|
// instead of following the link
|
||||||
$(this).on('click', function(e) {
|
$(this).on('click', function(e) {
|
||||||
goToArticle(decodeURIComponent($(this).attr("href")));
|
var titleName = decodeURIComponent($(this).attr("href"));
|
||||||
|
pushBrowserHistoryState(titleName);
|
||||||
|
goToArticle(titleName);
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Changes the URL of the browser page
|
||||||
|
*/
|
||||||
|
function pushBrowserHistoryState(titleName) {
|
||||||
|
if (titleName) {
|
||||||
|
var stateObj = { titleName: titleName};
|
||||||
|
window.history.pushState(stateObj,"Wikipedia Article : " + titleName,"#" + titleName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Replace article content with the one of the given title
|
* Replace article content with the one of the given title
|
||||||
*/
|
*/
|
||||||
function goToArticle(title) {
|
function goToArticle(titleName) {
|
||||||
$("#articleContent").html("Loading article from dump...");
|
$("#articleContent").html("Loading from dump article " + titleName + " ...");
|
||||||
localArchive.getTitleByName(title, readArticle);
|
localArchive.getTitleByName(titleName, readArticle);
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -336,30 +336,41 @@ define(function(require) {
|
|||||||
alert('Data file read cancelled');
|
alert('Data file read cancelled');
|
||||||
};
|
};
|
||||||
reader.onload = function(e) {
|
reader.onload = function(e) {
|
||||||
var compressedArticles = e.target.result;
|
|
||||||
var htmlArticles;
|
|
||||||
try {
|
try {
|
||||||
htmlArticles = bzip2.simple(bzip2.array(new Uint8Array(
|
var compressedArticles = e.target.result;
|
||||||
compressedArticles)));
|
var htmlArticles;
|
||||||
} catch (e) {
|
try {
|
||||||
// TODO : rethrow exception if we reach the end of the file
|
htmlArticles = bzip2.simple(bzip2.array(new Uint8Array(
|
||||||
currentLocalArchiveInstance.readArticleChunk(title, dataFile, reader, readLength + CHUNK_SIZE,
|
compressedArticles)));
|
||||||
callbackFunction);
|
} catch (e) {
|
||||||
return;
|
// 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(title, 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
|
catch (e) {
|
||||||
var htmlArticle = htmlArticles.substring(title.blockOffset,
|
callbackFunction("Error : " + e);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
var blob = dataFile.slice(title.blockStart, title.blockStart
|
var blob = dataFile.slice(title.blockStart, title.blockStart
|
||||||
|
Loading…
x
Reference in New Issue
Block a user