Compatibility with absolute URLs (from a ZIM) in jQuery mode.

For example for wikipedia_fr_all_09_2012.zim
This commit is contained in:
mossroy 2016-01-08 20:21:52 +01:00
parent 21ce7b14d3
commit f574e053fe

View File

@ -879,6 +879,8 @@ define(['jquery', 'abstractBackend', 'util', 'cookies','geometry','osabstraction
var regexpPath = /^(.*\/)[^\/]+$/;
var regexpImageUrl = /^\.\.\/(I\/.*)$/;
var regexpMetadataUrl = /^\.\.\/(-\/.*)$/;
var regexpImageAbsoluteUrl = /^\/(I\/.*)$/;
var regexpMetadataAbsoluteUrl = /^\/(-\/.*)$/;
/**
* Display the the given HTML article in the web page,
@ -955,9 +957,14 @@ define(['jquery', 'abstractBackend', 'util', 'cookies','geometry','osabstraction
// It's a link to another article
// Add an onclick event to go to this article
// instead of following the link
if (url.length>=2 && url.substring(0, 2) === "./") {
url = url.substring(2);
}
// Remove the initial slash if it's an absolute URL
else if (url.length>=1 && url.substring(0, 1) === "/") {
url = url.substring(1);
}
$(this).on('click', function(e) {
var titleName = decodeURIComponent(url);
pushBrowserHistoryState(titleName);
@ -978,7 +985,11 @@ define(['jquery', 'abstractBackend', 'util', 'cookies','geometry','osabstraction
});
} else {
// It's a standard image contained in the ZIM file
var imageMatch = image.attr("src").match(regexpImageUrl);
// We try to find its name (from an absolute or relative URL)
var imageMatch = image.attr("src").match(regexpImageAbsoluteUrl);
if (!(imageMatch)) {
imageMatch = image.attr("src").match(regexpImageUrl);
}
if (imageMatch) {
selectedArchive.getTitleByName(imageMatch[1]).then(function(title) {
selectedArchive.readBinaryFile(title, function (readableTitleName, content) {
@ -995,7 +1006,11 @@ define(['jquery', 'abstractBackend', 'util', 'cookies','geometry','osabstraction
// Load CSS content
$('#articleContent').contents().find('link[rel=stylesheet]').each(function() {
var link = $(this);
var hrefMatch = link.attr("href").match(regexpMetadataUrl);
// We try to find its name (from an absolute or relative URL)
var hrefMatch = link.attr("href").match(regexpMetadataAbsoluteUrl);
if (!(hrefMatch)) {
hrefMatch = link.attr("href").match(regexpMetadataUrl);
}
if (hrefMatch) {
// It's a CSS file contained in the ZIM file
var titleName = util.removeUrlParameters(hrefMatch[1]);
@ -1013,7 +1028,11 @@ define(['jquery', 'abstractBackend', 'util', 'cookies','geometry','osabstraction
// Load Javascript content
$('#articleContent').contents().find('script').each(function() {
var script = $(this);
var srcMatch = script.attr("src").match(regexpMetadataUrl);
// We try to find its name (from an absolute or relative URL)
var srcMatch = script.attr("src").match(regexpMetadataAbsoluteUrl);
if (!(srcMatch)) {
srcMatch = script.attr("src").match(regexpMetadataUrl);
}
// TODO check that the type of the script is text/javascript or application/javascript
if (srcMatch) {
// It's a Javascript file contained in the ZIM file