mirror of
https://github.com/kiwix/kiwix-js.git
synced 2025-09-24 04:54:51 -04:00
parent
a89e462fa9
commit
ddaa3586f1
@ -84,6 +84,7 @@ var regexpJPEG = new RegExp(/\.jpe?g$/i);
|
|||||||
var regexpPNG = new RegExp(/\.png$/i);
|
var regexpPNG = new RegExp(/\.png$/i);
|
||||||
var regexpJS = new RegExp(/\.js/i);
|
var regexpJS = new RegExp(/\.js/i);
|
||||||
var regexpCSS = new RegExp(/\.css$/i);
|
var regexpCSS = new RegExp(/\.css$/i);
|
||||||
|
var regexpSVG = new RegExp(/\.svg$/i);
|
||||||
|
|
||||||
// Pattern for ZIM file namespace - see http://www.openzim.org/wiki/ZIM_file_format#Namespaces
|
// Pattern for ZIM file namespace - see http://www.openzim.org/wiki/ZIM_file_format#Namespaces
|
||||||
var regexpZIMUrlWithNamespace = new RegExp(/(?:^|\/)([-ABIJMUVWX])\/(.+)/);
|
var regexpZIMUrlWithNamespace = new RegExp(/(?:^|\/)([-ABIJMUVWX])\/(.+)/);
|
||||||
@ -117,6 +118,9 @@ function fetchEventListener(event) {
|
|||||||
}
|
}
|
||||||
else if (regexpPNG.test(title)) {
|
else if (regexpPNG.test(title)) {
|
||||||
contentType = 'image/png';
|
contentType = 'image/png';
|
||||||
|
}
|
||||||
|
else if (regexpSVG.test(title)) {
|
||||||
|
contentType = 'image/svg+xml';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (nameSpace === '-') {
|
else if (nameSpace === '-') {
|
||||||
|
@ -934,7 +934,16 @@ define(['jquery', 'zimArchiveLoader', 'util', 'uiUtil', 'cookies','abstractFiles
|
|||||||
selectedArchive.getDirEntryByTitle(title).then(function(dirEntry) {
|
selectedArchive.getDirEntryByTitle(title).then(function(dirEntry) {
|
||||||
selectedArchive.readBinaryFile(dirEntry, function (fileDirEntry, content) {
|
selectedArchive.readBinaryFile(dirEntry, function (fileDirEntry, content) {
|
||||||
// TODO : use the complete MIME-type of the image (as read from the ZIM file)
|
// TODO : use the complete MIME-type of the image (as read from the ZIM file)
|
||||||
uiUtil.feedNodeWithBlob(image, 'src', content, 'image');
|
var url = fileDirEntry.url;
|
||||||
|
// Attempt to construct a generic mimetype first as a catchall
|
||||||
|
var mimetype = url.match(/\.(\w{2,4})$/);
|
||||||
|
mimetype = mimetype ? "image/" + mimetype[1].toLowerCase() : "image";
|
||||||
|
// Then make more specific for known image types
|
||||||
|
mimetype = /\.jpg$/i.test(url) ? "image/jpeg" : mimetype;
|
||||||
|
mimetype = /\.tif$/i.test(url) ? "image/tiff" : mimetype;
|
||||||
|
mimetype = /\.ico$/i.test(url) ? "image/x-icon" : mimetype;
|
||||||
|
mimetype = /\.svg$/i.test(url) ? "image/svg+xml" : mimetype;
|
||||||
|
uiUtil.feedNodeWithBlob(image, 'src', content, mimetype);
|
||||||
});
|
});
|
||||||
}).fail(function (e) {
|
}).fail(function (e) {
|
||||||
console.error("could not find DirEntry for image:" + title, e);
|
console.error("could not find DirEntry for image:" + title, e);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user