Merge pull request #157 from kiwix/absolute-URLs-compatibility

Compatibility with absolute URLs (from a ZIM) in jQuery mode.
This commit is contained in:
Mossroy 2016-01-16 13:58:25 +01:00
commit 9209b3277b

View File

@ -877,8 +877,10 @@ define(['jquery', 'abstractBackend', 'util', 'cookies','geometry','osabstraction
var regexpImageLink = /^.?\/?[^:]+:(.*)/;
var regexpMathImageUrl = /^\/math.*\/([0-9a-f]{32})\.png$/;
var regexpPath = /^(.*\/)[^\/]+$/;
var regexpImageUrl = /^\.\.\/(I\/.*)$/;
var regexpMetadataUrl = /^\.\.\/(-\/.*)$/;
// These regular expressions match both relative and absolute URLs
// Since late 2014, all ZIM files should use relative URLs
var regexpImageUrl = /^(?:\.\.\/|\/)(I\/.*)$/;
var regexpMetadataUrl = /^(?:\.\.\/|\/)(-\/.*)$/;
/**
* 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) === "./") {
if (url.substring(0, 2) === "./") {
url = url.substring(2);
}
// Remove the initial slash if it's an absolute URL
else if (url.substring(0, 1) === "/") {
url = url.substring(1);
}
$(this).on('click', function(e) {
var titleName = decodeURIComponent(url);
pushBrowserHistoryState(titleName);
@ -978,6 +985,7 @@ define(['jquery', 'abstractBackend', 'util', 'cookies','geometry','osabstraction
});
} else {
// It's a standard image contained in the ZIM file
// We try to find its name (from an absolute or relative URL)
var imageMatch = image.attr("src").match(regexpImageUrl);
if (imageMatch) {
var titleName = decodeURIComponent(imageMatch[1]);
@ -996,6 +1004,7 @@ define(['jquery', 'abstractBackend', 'util', 'cookies','geometry','osabstraction
// Load CSS content
$('#articleContent').contents().find('link[rel=stylesheet]').each(function() {
var link = $(this);
// We try to find its name (from an absolute or relative URL)
var hrefMatch = link.attr("href").match(regexpMetadataUrl);
if (hrefMatch) {
// It's a CSS file contained in the ZIM file
@ -1034,6 +1043,7 @@ define(['jquery', 'abstractBackend', 'util', 'cookies','geometry','osabstraction
// Load Javascript content
$('#articleContent').contents().find('script').each(function() {
var script = $(this);
// We try to find its name (from an absolute or relative URL)
var srcMatch = script.attr("src").match(regexpMetadataUrl);
// TODO check that the type of the script is text/javascript or application/javascript
if (srcMatch) {