|
|
@ -99,14 +99,15 @@ kthoom.setSettings = function() {
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var createURLFromArray = function(array, mimeType) {
|
|
|
|
var createURLFromArray = function(array, mimeType) {
|
|
|
|
var offset = array.byteOffset, len = array.byteLength;
|
|
|
|
var offset = array.byteOffset;
|
|
|
|
|
|
|
|
var len = array.byteLength;
|
|
|
|
var url;
|
|
|
|
var url;
|
|
|
|
var blob;
|
|
|
|
var blob;
|
|
|
|
|
|
|
|
|
|
|
|
if (mimeType === 'image/xml+svg') {
|
|
|
|
if (mimeType === 'image/xml+svg') {
|
|
|
|
const xmlStr = new TextDecoder('utf-8').decode(array);
|
|
|
|
const xmlStr = new TextDecoder('utf-8').decode(array);
|
|
|
|
return 'data:image/svg+xml;UTF-8,' + encodeURIComponent(xmlStr);
|
|
|
|
return 'data:image/svg+xml;UTF-8,' + encodeURIComponent(xmlStr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: Move all this browser support testing to a common place
|
|
|
|
// TODO: Move all this browser support testing to a common place
|
|
|
|
// and do it just once.
|
|
|
|
// and do it just once.
|
|
|
@ -137,11 +138,13 @@ var createURLFromArray = function(array, mimeType) {
|
|
|
|
kthoom.ImageFile = function(file) {
|
|
|
|
kthoom.ImageFile = function(file) {
|
|
|
|
this.filename = file.filename;
|
|
|
|
this.filename = file.filename;
|
|
|
|
var fileExtension = file.filename.split(".").pop().toLowerCase();
|
|
|
|
var fileExtension = file.filename.split(".").pop().toLowerCase();
|
|
|
|
var mimeType = fileExtension === "png" ? "image/png" :
|
|
|
|
this.mimeType = fileExtension === "png" ? "image/png" :
|
|
|
|
(fileExtension === "jpg" || fileExtension === "jpeg") ? "image/jpeg" :
|
|
|
|
(fileExtension === "jpg" || fileExtension === "jpeg") ? "image/jpeg" :
|
|
|
|
fileExtension === "gif" ? "image/gif" : fileExtension == 'svg' ? 'image/xml+svg' : undefined;
|
|
|
|
fileExtension === "gif" ? "image/gif" : fileExtension == 'svg' ? 'image/xml+svg' : undefined;
|
|
|
|
this.dataURI = createURLFromArray(file.fileData, mimeType);
|
|
|
|
if ( this.mimeType !== undefined) {
|
|
|
|
this.data = file;
|
|
|
|
this.dataURI = createURLFromArray(file.fileData, this.mimeType);
|
|
|
|
|
|
|
|
this.data = file;
|
|
|
|
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -169,34 +172,42 @@ function loadFromArrayBuffer(ab) {
|
|
|
|
unarchiver.addEventListener(bitjs.archive.UnarchiveEvent.Type.PROGRESS,
|
|
|
|
unarchiver.addEventListener(bitjs.archive.UnarchiveEvent.Type.PROGRESS,
|
|
|
|
function(e) {
|
|
|
|
function(e) {
|
|
|
|
var percentage = e.currentBytesUnarchived / e.totalUncompressedBytesInArchive;
|
|
|
|
var percentage = e.currentBytesUnarchived / e.totalUncompressedBytesInArchive;
|
|
|
|
totalImages = e.totalFilesInArchive;
|
|
|
|
if (totalImages === 0) {
|
|
|
|
|
|
|
|
totalImages = e.totalFilesInArchive;
|
|
|
|
|
|
|
|
}
|
|
|
|
updateProgress(percentage *100);
|
|
|
|
updateProgress(percentage *100);
|
|
|
|
lastCompletion = percentage * 100;
|
|
|
|
lastCompletion = percentage * 100;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
unarchiver.addEventListener(bitjs.archive.UnarchiveEvent.Type.EXTRACT,
|
|
|
|
unarchiver.addEventListener(bitjs.archive.UnarchiveEvent.Type.EXTRACT,
|
|
|
|
function(e) {
|
|
|
|
function(e) {
|
|
|
|
// convert DecompressedFile into a bunch of ImageFiles
|
|
|
|
// convert DecompressedFile into a bunch of ImageFiles
|
|
|
|
if (e.unarchivedFile) {
|
|
|
|
if (e.unarchivedFile) {
|
|
|
|
var f = e.unarchivedFile;
|
|
|
|
var f = e.unarchivedFile;
|
|
|
|
// add any new pages based on the filename
|
|
|
|
// add any new pages based on the filename
|
|
|
|
if (imageFilenames.indexOf(f.filename) === -1) {
|
|
|
|
if (imageFilenames.indexOf(f.filename) === -1) {
|
|
|
|
imageFilenames.push(f.filename);
|
|
|
|
var test = new kthoom.ImageFile(f);
|
|
|
|
imageFiles.push(new kthoom.ImageFile(f));
|
|
|
|
if ( test.mimeType !== undefined) {
|
|
|
|
// add thumbnails to the TOC list
|
|
|
|
imageFilenames.push(f.filename);
|
|
|
|
$("#thumbnails").append(
|
|
|
|
imageFiles.push(test);
|
|
|
|
"<li>" +
|
|
|
|
// add thumbnails to the TOC list
|
|
|
|
"<a data-page='" + imageFiles.length + "'>" +
|
|
|
|
$("#thumbnails").append(
|
|
|
|
"<img src='" + imageFiles[imageFiles.length - 1].dataURI + "'/>" +
|
|
|
|
"<li>" +
|
|
|
|
"<span>" + imageFiles.length + "</span>" +
|
|
|
|
"<a data-page='" + imageFiles.length + "'>" +
|
|
|
|
"</a>" +
|
|
|
|
"<img src='" + imageFiles[imageFiles.length - 1].dataURI + "'/>" +
|
|
|
|
"</li>"
|
|
|
|
"<span>" + imageFiles.length + "</span>" +
|
|
|
|
);
|
|
|
|
"</a>" +
|
|
|
|
|
|
|
|
"</li>"
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
// display first page if we haven't yet
|
|
|
|
|
|
|
|
if (imageFiles.length === currentImage + 1) {
|
|
|
|
|
|
|
|
updatePage(lastCompletion);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
totalImages--;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// display first page if we haven't yet
|
|
|
|
|
|
|
|
if (imageFiles.length === currentImage + 1) {
|
|
|
|
|
|
|
|
updatePage(lastCompletion);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
unarchiver.addEventListener(bitjs.archive.UnarchiveEvent.Type.FINISH,
|
|
|
|
unarchiver.addEventListener(bitjs.archive.UnarchiveEvent.Type.FINISH,
|
|
|
|
function() {
|
|
|
|
function() {
|
|
|
|