mirror of
https://github.com/janeczku/calibre-web
synced 2024-12-26 01:50:31 +00:00
Code cosmetics
This commit is contained in:
parent
34e9ef35f5
commit
2a78a02e0b
@ -15,7 +15,7 @@ bitjs.archive = bitjs.archive || {};
|
|||||||
|
|
||||||
// ===========================================================================
|
// ===========================================================================
|
||||||
// Stolen from Closure because it's the best way to do Java-like inheritance.
|
// Stolen from Closure because it's the best way to do Java-like inheritance.
|
||||||
bitjs.base = function(me, opt_methodName, var_args) {
|
bitjs.base = function(me, optMethodName, var_args) {
|
||||||
var caller = arguments.callee.caller;
|
var caller = arguments.callee.caller;
|
||||||
if (caller.superClass_) {
|
if (caller.superClass_) {
|
||||||
// This is a constructor. Call the superclass constructor.
|
// This is a constructor. Call the superclass constructor.
|
||||||
@ -27,10 +27,10 @@ bitjs.archive = bitjs.archive || {};
|
|||||||
var foundCaller = false;
|
var foundCaller = false;
|
||||||
for (var ctor = me.constructor;
|
for (var ctor = me.constructor;
|
||||||
ctor; ctor = ctor.superClass_ && ctor.superClass_.constructor) {
|
ctor; ctor = ctor.superClass_ && ctor.superClass_.constructor) {
|
||||||
if (ctor.prototype[opt_methodName] === caller) {
|
if (ctor.prototype[optMethodName] === caller) {
|
||||||
foundCaller = true;
|
foundCaller = true;
|
||||||
} else if (foundCaller) {
|
} else if (foundCaller) {
|
||||||
return ctor.prototype[opt_methodName].apply(me, args);
|
return ctor.prototype[optMethodName].apply(me, args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,12 +38,12 @@ bitjs.archive = bitjs.archive || {};
|
|||||||
// then one of two things happened:
|
// then one of two things happened:
|
||||||
// 1) The caller is an instance method.
|
// 1) The caller is an instance method.
|
||||||
// 2) This method was not called by the right caller.
|
// 2) This method was not called by the right caller.
|
||||||
if (me[opt_methodName] === caller) {
|
if (me[optMethodName] === caller) {
|
||||||
return me.constructor.prototype[opt_methodName].apply(me, args);
|
return me.constructor.prototype[optMethodName].apply(me, args);
|
||||||
} else {
|
} else {
|
||||||
throw Error(
|
throw Error(
|
||||||
'goog.base called from a method of one name ' +
|
"goog.base called from a method of one name " +
|
||||||
'to a method of a different name');
|
"to a method of a different name");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
bitjs.inherits = function(childCtor, parentCtor) {
|
bitjs.inherits = function(childCtor, parentCtor) {
|
||||||
@ -75,12 +75,12 @@ bitjs.archive = bitjs.archive || {};
|
|||||||
* The UnarchiveEvent types.
|
* The UnarchiveEvent types.
|
||||||
*/
|
*/
|
||||||
bitjs.archive.UnarchiveEvent.Type = {
|
bitjs.archive.UnarchiveEvent.Type = {
|
||||||
START: 'start',
|
START: "start",
|
||||||
PROGRESS: 'progress',
|
PROGRESS: "progress",
|
||||||
EXTRACT: 'extract',
|
EXTRACT: "extract",
|
||||||
FINISH: 'finish',
|
FINISH: "finish",
|
||||||
INFO: 'info',
|
INFO: "info",
|
||||||
ERROR: 'error'
|
ERROR: "error"
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -141,12 +141,12 @@ bitjs.archive = bitjs.archive || {};
|
|||||||
* Progress event.
|
* Progress event.
|
||||||
*/
|
*/
|
||||||
bitjs.archive.UnarchiveProgressEvent = function(
|
bitjs.archive.UnarchiveProgressEvent = function(
|
||||||
currentFilename,
|
currentFilename,
|
||||||
currentFileNumber,
|
currentFileNumber,
|
||||||
currentBytesUnarchivedInFile,
|
currentBytesUnarchivedInFile,
|
||||||
currentBytesUnarchived,
|
currentBytesUnarchived,
|
||||||
totalUncompressedBytesInArchive,
|
totalUncompressedBytesInArchive,
|
||||||
totalFilesInArchive)
|
totalFilesInArchive)
|
||||||
{
|
{
|
||||||
bitjs.base(this, bitjs.archive.UnarchiveEvent.Type.PROGRESS);
|
bitjs.base(this, bitjs.archive.UnarchiveEvent.Type.PROGRESS);
|
||||||
|
|
||||||
@ -188,10 +188,10 @@ bitjs.archive = bitjs.archive || {};
|
|||||||
* Base class for all Unarchivers.
|
* Base class for all Unarchivers.
|
||||||
*
|
*
|
||||||
* @param {ArrayBuffer} arrayBuffer The Array Buffer.
|
* @param {ArrayBuffer} arrayBuffer The Array Buffer.
|
||||||
* @param {string} opt_pathToBitJS Optional string for where the BitJS files are located.
|
* @param {string} optPathToBitJS Optional string for where the BitJS files are located.
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
bitjs.archive.Unarchiver = function(arrayBuffer, opt_pathToBitJS) {
|
bitjs.archive.Unarchiver = function(arrayBuffer, optPathToBitJS) {
|
||||||
/**
|
/**
|
||||||
* The ArrayBuffer object.
|
* The ArrayBuffer object.
|
||||||
* @type {ArrayBuffer}
|
* @type {ArrayBuffer}
|
||||||
@ -204,7 +204,7 @@ bitjs.archive = bitjs.archive || {};
|
|||||||
* @type {string}
|
* @type {string}
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
this.pathToBitJS_ = opt_pathToBitJS || '';
|
this.pathToBitJS_ = optPathToBitJS || "";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A map from event type to an array of listeners.
|
* A map from event type to an array of listeners.
|
||||||
@ -229,7 +229,7 @@ bitjs.archive = bitjs.archive || {};
|
|||||||
* @protected.
|
* @protected.
|
||||||
*/
|
*/
|
||||||
bitjs.archive.Unarchiver.prototype.getScriptFileName = function() {
|
bitjs.archive.Unarchiver.prototype.getScriptFileName = function() {
|
||||||
throw 'Subclasses of AbstractUnarchiver must overload getScriptFileName()';
|
throw "Subclasses of AbstractUnarchiver must overload getScriptFileName()";
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -240,7 +240,7 @@ bitjs.archive = bitjs.archive || {};
|
|||||||
*/
|
*/
|
||||||
bitjs.archive.Unarchiver.prototype.addEventListener = function(type, listener) {
|
bitjs.archive.Unarchiver.prototype.addEventListener = function(type, listener) {
|
||||||
if (type in this.listeners_) {
|
if (type in this.listeners_) {
|
||||||
if (this.listeners_[type].indexOf(listener) == -1) {
|
if (this.listeners_[type].indexOf(listener) === -1) {
|
||||||
this.listeners_[type].push(listener);
|
this.listeners_[type].push(listener);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -255,7 +255,7 @@ bitjs.archive = bitjs.archive || {};
|
|||||||
bitjs.archive.Unarchiver.prototype.removeEventListener = function(type, listener) {
|
bitjs.archive.Unarchiver.prototype.removeEventListener = function(type, listener) {
|
||||||
if (type in this.listeners_) {
|
if (type in this.listeners_) {
|
||||||
var index = this.listeners_[type].indexOf(listener);
|
var index = this.listeners_[type].indexOf(listener);
|
||||||
if (index != -1) {
|
if (index !== -1) {
|
||||||
this.listeners_[type].splice(index, 1);
|
this.listeners_[type].splice(index, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -270,8 +270,10 @@ bitjs.archive = bitjs.archive || {};
|
|||||||
bitjs.archive.Unarchiver.prototype.handleWorkerEvent_ = function(e) {
|
bitjs.archive.Unarchiver.prototype.handleWorkerEvent_ = function(e) {
|
||||||
if ((e instanceof bitjs.archive.UnarchiveEvent || e.type) &&
|
if ((e instanceof bitjs.archive.UnarchiveEvent || e.type) &&
|
||||||
this.listeners_[e.type] instanceof Array) {
|
this.listeners_[e.type] instanceof Array) {
|
||||||
this.listeners_[e.type].forEach(function (listener) { listener(e) });
|
this.listeners_[e.type].forEach(function (listener) {
|
||||||
if (e.type == bitjs.archive.UnarchiveEvent.Type.FINISH) {
|
listener(e);
|
||||||
|
});
|
||||||
|
if (e.type === bitjs.archive.UnarchiveEvent.Type.FINISH) {
|
||||||
this.worker_.terminate();
|
this.worker_.terminate();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -281,20 +283,20 @@ bitjs.archive = bitjs.archive || {};
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts the unarchive in a separate Web Worker thread and returns immediately.
|
* Starts the unarchive in a separate Web Worker thread and returns immediately.
|
||||||
*/
|
*/
|
||||||
bitjs.archive.Unarchiver.prototype.start = function() {
|
bitjs.archive.Unarchiver.prototype.start = function() {
|
||||||
var me = this;
|
var me = this;
|
||||||
var scriptFileName = this.pathToBitJS_ + this.getScriptFileName();
|
var scriptFileName = this.pathToBitJS_ + this.getScriptFileName();
|
||||||
if (scriptFileName) {
|
if (scriptFileName) {
|
||||||
this.worker_ = new Worker(scriptFileName);
|
this.worker_ = new Worker(scriptFileName);
|
||||||
|
|
||||||
this.worker_.onerror = function(e) {
|
this.worker_.onerror = function(e) {
|
||||||
console.log('Worker error: message = ' + e.message);
|
console.log("Worker error: message = " + e.message);
|
||||||
throw e;
|
throw e;
|
||||||
};
|
};
|
||||||
|
|
||||||
this.worker_.onmessage = function(e) {
|
this.worker_.onmessage = function(e) {
|
||||||
if (typeof e.data == 'string') {
|
if (typeof e.data == "string") {
|
||||||
// Just log any strings the workers pump our way.
|
// Just log any strings the workers pump our way.
|
||||||
console.log(e.data);
|
console.log(e.data);
|
||||||
} else {
|
} else {
|
||||||
@ -323,32 +325,38 @@ bitjs.archive = bitjs.archive || {};
|
|||||||
* @extends {bitjs.archive.Unarchiver}
|
* @extends {bitjs.archive.Unarchiver}
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
bitjs.archive.Unzipper = function(arrayBuffer, opt_pathToBitJS) {
|
bitjs.archive.Unzipper = function(arrayBuffer, optPathToBitJS) {
|
||||||
bitjs.base(this, arrayBuffer, opt_pathToBitJS);
|
bitjs.base(this, arrayBuffer, optPathToBitJS);
|
||||||
};
|
};
|
||||||
bitjs.inherits(bitjs.archive.Unzipper, bitjs.archive.Unarchiver);
|
bitjs.inherits(bitjs.archive.Unzipper, bitjs.archive.Unarchiver);
|
||||||
bitjs.archive.Unzipper.prototype.getScriptFileName = function() { return 'unzip.js' };
|
bitjs.archive.Unzipper.prototype.getScriptFileName = function() {
|
||||||
|
return "unzip.js";
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unrarrer
|
* Unrarrer
|
||||||
* @extends {bitjs.archive.Unarchiver}
|
* @extends {bitjs.archive.Unarchiver}
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
bitjs.archive.Unrarrer = function(arrayBuffer, opt_pathToBitJS) {
|
bitjs.archive.Unrarrer = function(arrayBuffer, optPathToBitJS) {
|
||||||
bitjs.base(this, arrayBuffer, opt_pathToBitJS);
|
bitjs.base(this, arrayBuffer, optPathToBitJS);
|
||||||
};
|
};
|
||||||
bitjs.inherits(bitjs.archive.Unrarrer, bitjs.archive.Unarchiver);
|
bitjs.inherits(bitjs.archive.Unrarrer, bitjs.archive.Unarchiver);
|
||||||
bitjs.archive.Unrarrer.prototype.getScriptFileName = function() { return 'unrar.js' };
|
bitjs.archive.Unrarrer.prototype.getScriptFileName = function() {
|
||||||
|
return "unrar.js";
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Untarrer
|
* Untarrer
|
||||||
* @extends {bitjs.archive.Unarchiver}
|
* @extends {bitjs.archive.Unarchiver}
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
bitjs.archive.Untarrer = function(arrayBuffer, opt_pathToBitJS) {
|
bitjs.archive.Untarrer = function(arrayBuffer, optPathToBitJS) {
|
||||||
bitjs.base(this, arrayBuffer, opt_pathToBitJS);
|
bitjs.base(this, arrayBuffer, optPathToBitJS);
|
||||||
};
|
};
|
||||||
bitjs.inherits(bitjs.archive.Untarrer, bitjs.archive.Unarchiver);
|
bitjs.inherits(bitjs.archive.Untarrer, bitjs.archive.Unarchiver);
|
||||||
bitjs.archive.Untarrer.prototype.getScriptFileName = function() { return 'untar.js' };
|
bitjs.archive.Untarrer.prototype.getScriptFileName = function() {
|
||||||
|
return "untar.js";
|
||||||
|
};
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
@ -417,14 +417,14 @@ bitjs.io = bitjs.io || {};
|
|||||||
*/
|
*/
|
||||||
bitjs.io.ByteBuffer.prototype.writeNumber = function(num, numBytes) {
|
bitjs.io.ByteBuffer.prototype.writeNumber = function(num, numBytes) {
|
||||||
if (numBytes < 1) {
|
if (numBytes < 1) {
|
||||||
throw 'Trying to write into too few bytes: ' + numBytes;
|
throw "Trying to write into too few bytes: " + numBytes;
|
||||||
}
|
}
|
||||||
if (num < 0) {
|
if (num < 0) {
|
||||||
throw 'Trying to write a negative number (' + num +
|
throw "Trying to write a negative number (" + num +
|
||||||
') as an unsigned number to an ArrayBuffer';
|
") as an unsigned number to an ArrayBuffer";
|
||||||
}
|
}
|
||||||
if (num > (Math.pow(2, numBytes * 8) - 1)) {
|
if (num > (Math.pow(2, numBytes * 8) - 1)) {
|
||||||
throw 'Trying to write ' + num + ' into only ' + numBytes + ' bytes';
|
throw "Trying to write " + num + " into only " + numBytes + " bytes";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Roll 8-bits at a time into an array of bytes.
|
// Roll 8-bits at a time into an array of bytes.
|
||||||
|
@ -17,9 +17,13 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
if (window.opera) {
|
if (window.opera) {
|
||||||
window.console.log = function(str) {opera.postError(str);};
|
window.console.log = function(str) {
|
||||||
|
opera.postError(str);
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var kthoom;
|
||||||
|
|
||||||
// gets the element with the given id
|
// gets the element with the given id
|
||||||
function getElem(id) {
|
function getElem(id) {
|
||||||
if (document.documentElement.querySelector) {
|
if (document.documentElement.querySelector) {
|
||||||
@ -31,7 +35,7 @@ function getElem(id) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (window.kthoom === undefined) {
|
if (window.kthoom === undefined) {
|
||||||
var kthoom = {};
|
kthoom = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
// key codes
|
// key codes
|
||||||
@ -58,27 +62,23 @@ var imageFiles = [];
|
|||||||
var imageFilenames = [];
|
var imageFilenames = [];
|
||||||
var totalImages = 0;
|
var totalImages = 0;
|
||||||
var lastCompletion = 0;
|
var lastCompletion = 0;
|
||||||
var library = {
|
|
||||||
allBooks: [],
|
|
||||||
currentBookNum: 0,
|
|
||||||
};
|
|
||||||
|
|
||||||
var hflip = false, vflip = false, fitMode = kthoom.Key.B;
|
var hflip = false, vflip = false, fitMode = kthoom.Key.B;
|
||||||
var canKeyNext = true, canKeyPrev = true;
|
var canKeyNext = true, canKeyPrev = true;
|
||||||
|
|
||||||
kthoom.saveSettings = function() {
|
kthoom.saveSettings = function() {
|
||||||
localStorage.kthoom_settings = JSON.stringify({
|
localStorage.kthoomSettings = JSON.stringify({
|
||||||
rotateTimes: kthoom.rotateTimes,
|
rotateTimes: kthoom.rotateTimes,
|
||||||
hflip: hflip,
|
hflip: hflip,
|
||||||
vflip: vflip,
|
vflip: vflip,
|
||||||
fitMode: fitMode
|
fitMode: fitMode
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
kthoom.loadSettings = function() {
|
kthoom.loadSettings = function() {
|
||||||
try {
|
try {
|
||||||
if (localStorage.kthoom_settings.length < 10) return;
|
if (localStorage.kthoomSettings.length < 10) return;
|
||||||
var s = JSON.parse(localStorage.kthoom_settings);
|
var s = JSON.parse(localStorage.kthoomSettings);
|
||||||
kthoom.rotateTimes = s.rotateTimes;
|
kthoom.rotateTimes = s.rotateTimes;
|
||||||
hflip = s.hflip;
|
hflip = s.hflip;
|
||||||
vflip = s.vflip;
|
vflip = s.vflip;
|
||||||
@ -88,6 +88,36 @@ kthoom.loadSettings = function() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var createURLFromArray = function(array, mimeType) {
|
||||||
|
var offset = array.byteOffset, len = array.byteLength;
|
||||||
|
var bb, url;
|
||||||
|
var blob;
|
||||||
|
|
||||||
|
// TODO: Move all this browser support testing to a common place
|
||||||
|
// and do it just once.
|
||||||
|
|
||||||
|
// Blob constructor, see http://dev.w3.org/2006/webapi/FileAPI/#dfn-Blob.
|
||||||
|
if (typeof Blob == "function") {
|
||||||
|
blob = new Blob([array], {type: mimeType});
|
||||||
|
} else {
|
||||||
|
throw "Browser support for Blobs is missing."
|
||||||
|
}
|
||||||
|
|
||||||
|
if (blob.slice) {
|
||||||
|
blob = blob.slice(offset, offset + len, mimeType);
|
||||||
|
} else {
|
||||||
|
throw "Browser support for Blobs is missing."
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((typeof URL != "function" && typeof URL != "object") ||
|
||||||
|
typeof URL.createObjectURL != "function") {
|
||||||
|
throw "Browser support for Object URLs is missing";
|
||||||
|
}
|
||||||
|
|
||||||
|
return URL.createObjectURL(blob);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Stores an image filename and its data: URI.
|
// Stores an image filename and its data: URI.
|
||||||
// TODO: investigate if we really need to store as base64 (leave off ;base64 and just
|
// TODO: investigate if we really need to store as base64 (leave off ;base64 and just
|
||||||
// non-safe URL characters are encoded as %xx ?)
|
// non-safe URL characters are encoded as %xx ?)
|
||||||
@ -95,9 +125,9 @@ kthoom.loadSettings = function() {
|
|||||||
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" :
|
var mimeType = fileExtension === "png" ? "image/png" :
|
||||||
(fileExtension === "jpg" || fileExtension === "jpeg") ? "image/jpeg" :
|
(fileExtension === "jpg" || fileExtension === "jpeg") ? "image/jpeg" :
|
||||||
fileExtension === "gif" ? "image/gif" : undefined;
|
fileExtension === "gif" ? "image/gif" : null;
|
||||||
this.dataURI = createURLFromArray(file.fileData, mimeType);
|
this.dataURI = createURLFromArray(file.fileData, mimeType);
|
||||||
this.data = file;
|
this.data = file;
|
||||||
};
|
};
|
||||||
@ -189,52 +219,51 @@ kthoom.initProgressMeter = function() {
|
|||||||
pdiv.appendChild(svg);
|
pdiv.appendChild(svg);
|
||||||
|
|
||||||
svg.onclick = function(e) {
|
svg.onclick = function(e) {
|
||||||
for (var x = pdiv, l = 0; x != document.documentElement; x = x.parentNode) l += x.offsetLeft;
|
for (var x = pdiv, l = 0; x !== document.documentElement; x = x.parentNode) l += x.offsetLeft;
|
||||||
var page = Math.max(1, Math.ceil(((e.clientX - l)/pdiv.offsetWidth) * totalImages)) - 1;
|
var page = Math.max(1, Math.ceil(((e.clientX - l) / pdiv.offsetWidth) * totalImages)) - 1;
|
||||||
currentImage = page;
|
currentImage = page;
|
||||||
updatePage();
|
updatePage();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
kthoom.setProgressMeter = function(pct, opt_label) {
|
kthoom.setProgressMeter = function(pct, optLabel) {
|
||||||
var pct = (pct*100);
|
pct = (pct * 100);
|
||||||
var part = 1/totalImages;
|
var part = 1 / totalImages;
|
||||||
var remain = ((pct - lastCompletion)/100)/part;
|
var remain = ((pct - lastCompletion) / 100) / part;
|
||||||
var fract = Math.min(1, remain);
|
var fract = Math.min(1, remain);
|
||||||
var smartpct = ((imageFiles.length/totalImages) + fract * part )* 100;
|
var smartpct = ((imageFiles.length / totalImages) + (fract * part))* 100;
|
||||||
if (totalImages == 0) smartpct = pct;
|
if (totalImages === 0) smartpct = pct;
|
||||||
|
|
||||||
// + Math.min((pct - lastCompletion), 100/totalImages * 0.9 + (pct - lastCompletion - 100/totalImages)/2, 100/totalImages);
|
// + Math.min((pct - lastCompletion), 100/totalImages * 0.9 + (pct - lastCompletion - 100/totalImages)/2, 100/totalImages);
|
||||||
var oldval = parseFloat(getElem("meter").getAttribute("width"));
|
var oldval = parseFloat(getElem("meter").getAttribute("width"));
|
||||||
if (isNaN(oldval)) oldval = 0;
|
if (isNaN(oldval)) oldval = 0;
|
||||||
var weight = 0.5;
|
var weight = 0.5;
|
||||||
smartpct = (weight * smartpct + (1-weight) * oldval);
|
smartpct = ((weight * smartpct) + ((1 - weight) * oldval));
|
||||||
if (pct == 100) smartpct = 100;
|
if (pct == 100) smartpct = 100;
|
||||||
|
|
||||||
if (!isNaN(smartpct)) {
|
if (!isNaN(smartpct)) {
|
||||||
getElem("meter").setAttribute("width", smartpct + "%");
|
getElem("meter").setAttribute("width", smartpct + "%");
|
||||||
}
|
}
|
||||||
var title = getElem("progress_title");
|
var title = getElem("progress_title");
|
||||||
while (title.firstChild) title.removeChild(title.firstChild);
|
while (title.firstChild) title.removeChild(title.firstChild);
|
||||||
|
|
||||||
var labelText = pct.toFixed(2) + "% " + imageFiles.length + "/" + totalImages + "";
|
var labelText = pct.toFixed(2) + "% " + imageFiles.length + "/" + totalImages + "";
|
||||||
if (opt_label) {
|
if (optLabel) {
|
||||||
labelText = opt_label + " " + labelText;
|
labelText = optLabel + " " + labelText;
|
||||||
}
|
}
|
||||||
title.appendChild(document.createTextNode(labelText));
|
title.appendChild(document.createTextNode(labelText));
|
||||||
|
|
||||||
getElem("meter2").setAttribute("width",
|
getElem("meter2").setAttribute("width",
|
||||||
100 * (totalImages == 0 ? 0 : ((currentImage+1)/totalImages)) + "%");
|
100 * (totalImages == 0 ? 0 : ((currentImage+1) / totalImages)) + "%");
|
||||||
|
|
||||||
var title = getElem("page");
|
var title = getElem("page");
|
||||||
while (title.firstChild) title.removeChild(title.firstChild);
|
while (title.firstChild) title.removeChild(title.firstChild);
|
||||||
title.appendChild(document.createTextNode( (currentImage+1) + '/' + totalImages ));
|
title.appendChild(document.createTextNode( (currentImage+1) + '/' + totalImages ));
|
||||||
|
|
||||||
|
if (pct > 0) {
|
||||||
if (pct > 0) {
|
|
||||||
//getElem('nav').className = '';
|
//getElem('nav').className = '';
|
||||||
getElem("progress").className = '';
|
getElem("progress").className = '';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadFromArrayBuffer(ab) {
|
function loadFromArrayBuffer(ab) {
|
||||||
@ -275,43 +304,15 @@ function loadFromArrayBuffer(ab) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
unarchiver.addEventListener(bitjs.archive.UnarchiveEvent.Type.FINISH,
|
unarchiver.addEventListener(bitjs.archive.UnarchiveEvent.Type.FINISH,
|
||||||
function(e) {
|
function(e) {
|
||||||
var diff = ((new Date).getTime() - start)/1000;
|
var diff = ((new Date).getTime() - start)/1000;
|
||||||
console.log("Unarchiving done in " + diff + "s");
|
console.log("Unarchiving done in " + diff + "s");
|
||||||
});
|
});
|
||||||
unarchiver.start();
|
unarchiver.start();
|
||||||
} else {
|
} else {
|
||||||
alert("Some error");
|
alert("Some error");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var createURLFromArray = function(array, mimeType) {
|
|
||||||
var offset = array.byteOffset, len = array.byteLength;
|
|
||||||
var bb, url;
|
|
||||||
var blob;
|
|
||||||
|
|
||||||
// TODO: Move all this browser support testing to a common place
|
|
||||||
// and do it just once.
|
|
||||||
|
|
||||||
// Blob constructor, see http://dev.w3.org/2006/webapi/FileAPI/#dfn-Blob.
|
|
||||||
if (typeof Blob == "function") {
|
|
||||||
blob = new Blob([array], {type: mimeType});
|
|
||||||
} else {
|
|
||||||
throw "Browser support for Blobs is missing."
|
|
||||||
}
|
|
||||||
|
|
||||||
if (blob.slice) {
|
|
||||||
blob = blob.slice(offset, offset + len, mimeType);
|
|
||||||
} else {
|
|
||||||
throw "Browser support for Blobs is missing."
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((typeof URL != "function" && typeof URL != "object") ||
|
|
||||||
typeof URL.createObjectURL != "function") {
|
|
||||||
throw "Browser support for Object URLs is missing";
|
|
||||||
}
|
|
||||||
|
|
||||||
return URL.createObjectURL(blob);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function updatePage() {
|
function updatePage() {
|
||||||
@ -319,8 +320,8 @@ function updatePage() {
|
|||||||
while (title.firstChild) title.removeChild(title.firstChild);
|
while (title.firstChild) title.removeChild(title.firstChild);
|
||||||
title.appendChild(document.createTextNode( (currentImage+1) + "/" + totalImages ));
|
title.appendChild(document.createTextNode( (currentImage+1) + "/" + totalImages ));
|
||||||
|
|
||||||
getElem("meter2").setAttribute("width",
|
getElem('meter2').setAttribute('width',
|
||||||
100 * (totalImages == 0 ? 0 : ((currentImage+1)/totalImages)) + "%");
|
100 * (totalImages == 0 ? 0 : ((currentImage+1)/totalImages)) + "%");
|
||||||
if (imageFiles[currentImage]) {
|
if (imageFiles[currentImage]) {
|
||||||
setImage(imageFiles[currentImage].dataURI);
|
setImage(imageFiles[currentImage].dataURI);
|
||||||
} else {
|
} else {
|
||||||
@ -414,56 +415,42 @@ function setImage(url) {
|
|||||||
|
|
||||||
function showPrevPage() {
|
function showPrevPage() {
|
||||||
currentImage--;
|
currentImage--;
|
||||||
|
|
||||||
if (currentImage < 0) {
|
if (currentImage < 0) {
|
||||||
if (library.allBooks.length == 1) {
|
// Freeze on the current page.
|
||||||
currentImage = imageFiles.length - 1;
|
currentImage++;
|
||||||
} else if (library.currentBookNum > 0) {
|
} else {
|
||||||
loadPrevBook();
|
updatePage();
|
||||||
} else {
|
|
||||||
// Freeze on the current page.
|
|
||||||
currentImage++;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
updatePage();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function showNextPage() {
|
function showNextPage() {
|
||||||
currentImage++;
|
currentImage++;
|
||||||
|
|
||||||
if (currentImage >= Math.max(totalImages, imageFiles.length)) {
|
if (currentImage >= Math.max(totalImages, imageFiles.length)) {
|
||||||
if (library.allBooks.length == 1) {
|
// Freeze on the current page.
|
||||||
currentImage = 0;
|
currentImage--;
|
||||||
} else if (library.currentBookNum < library.allBooks.length - 1) {
|
} else {
|
||||||
loadNextBook();
|
updatePage();
|
||||||
} else {
|
|
||||||
// Freeze on the current page.
|
|
||||||
currentImage--;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
updatePage();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateScale(clear) {
|
function updateScale(clear) {
|
||||||
var mainImageStyle = getElem("mainImage").style;
|
var mainImageStyle = getElem('mainImage').style;
|
||||||
mainImageStyle.width = "";
|
mainImageStyle.width = '';
|
||||||
mainImageStyle.height = "";
|
mainImageStyle.height = '';
|
||||||
mainImageStyle.maxWidth = "";
|
mainImageStyle.maxWidth = '';
|
||||||
mainImageStyle.maxHeight = "";
|
mainImageStyle.maxHeight = '';
|
||||||
var maxheight = innerHeight - 15;
|
var maxheight = innerHeight - 15;
|
||||||
if (!/main/.test(getElem("titlebar").className)) {
|
if (!/main/.test(getElem('titlebar').className)) {
|
||||||
maxheight -= 25;
|
maxheight -= 25;
|
||||||
}
|
}
|
||||||
if (clear || fitMode == kthoom.Key.N) {
|
if (clear || fitMode == kthoom.Key.N) {
|
||||||
} else if (fitMode == kthoom.Key.B) {
|
} else if (fitMode == kthoom.Key.B) {
|
||||||
mainImageStyle.maxWidth = "100%";
|
mainImageStyle.maxWidth = '100%';
|
||||||
mainImageStyle.maxHeight = maxheight + "px";
|
mainImageStyle.maxHeight = maxheight + 'px';
|
||||||
} else if (fitMode == kthoom.Key.H) {
|
} else if (fitMode == kthoom.Key.H) {
|
||||||
mainImageStyle.height = maxheight + "px";
|
mainImageStyle.height = maxheight + 'px';
|
||||||
} else if (fitMode == kthoom.Key.W) {
|
} else if (fitMode == kthoom.Key.W) {
|
||||||
mainImageStyle.width = "100%";
|
mainImageStyle.width = '100%';
|
||||||
}
|
}
|
||||||
kthoom.saveSettings();
|
kthoom.saveSettings();
|
||||||
}
|
}
|
||||||
@ -471,8 +458,9 @@ function updateScale(clear) {
|
|||||||
function keyHandler(evt) {
|
function keyHandler(evt) {
|
||||||
var code = evt.keyCode;
|
var code = evt.keyCode;
|
||||||
|
|
||||||
if (getComputedStyle(getElem("progress")).display == "none") return;
|
if ($("#progress").css('display') == "none")
|
||||||
canKeyNext = ((document.body.offsetWidth+document.body.scrollLeft)/ document.body.scrollWidth) >= 1;
|
return;
|
||||||
|
canKeyNext = (($("body").css("offsetWidth")+$("body").css("scrollLeft"))/ $("body").css("scrollWidth")) >= 1;
|
||||||
canKeyPrev = (scrollX <= 0);
|
canKeyPrev = (scrollX <= 0);
|
||||||
|
|
||||||
if (evt.ctrlKey || evt.shiftKey || evt.metaKey) return;
|
if (evt.ctrlKey || evt.shiftKey || evt.metaKey) return;
|
||||||
@ -561,8 +549,8 @@ function init(filename) {
|
|||||||
$("#mainImage").click(function(evt) {
|
$("#mainImage").click(function(evt) {
|
||||||
// Firefox does not support offsetX/Y so we have to manually calculate
|
// Firefox does not support offsetX/Y so we have to manually calculate
|
||||||
// where the user clicked in the image.
|
// where the user clicked in the image.
|
||||||
var mainContentWidth = getElem("mainContent").clientWidth;
|
var mainContentWidth = $("#mainContent").width();
|
||||||
var mainContentHeight = getElem("mainContent").clientHeight;
|
var mainContentHeight = $("#mainContent").height();
|
||||||
var comicWidth = evt.target.clientWidth;
|
var comicWidth = evt.target.clientWidth;
|
||||||
var comicHeight = evt.target.clientHeight;
|
var comicHeight = evt.target.clientHeight;
|
||||||
var offsetX = (mainContentWidth - comicWidth) / 2;
|
var offsetX = (mainContentWidth - comicWidth) / 2;
|
||||||
@ -588,9 +576,9 @@ function init(filename) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (clickedPrev) {
|
if (clickedPrev) {
|
||||||
showPrevPage();
|
showPrevPage();
|
||||||
} else {
|
} else {
|
||||||
showNextPage();
|
showNextPage();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,7 @@ var postProgress = function() {
|
|||||||
var readCleanString = function(bstr, numBytes) {
|
var readCleanString = function(bstr, numBytes) {
|
||||||
var str = bstr.readString(numBytes);
|
var str = bstr.readString(numBytes);
|
||||||
var zIndex = str.indexOf(String.fromCharCode(0));
|
var zIndex = str.indexOf(String.fromCharCode(0));
|
||||||
return zIndex != -1 ? str.substr(0, zIndex) : str;
|
return zIndex !== -1 ? str.substr(0, zIndex) : str;
|
||||||
};
|
};
|
||||||
|
|
||||||
// takes a ByteStream and parses out the local file information
|
// takes a ByteStream and parses out the local file information
|
||||||
@ -61,7 +61,7 @@ var TarLocalFile = function(bstream) {
|
|||||||
this.linkname = readCleanString(bstream, 100);
|
this.linkname = readCleanString(bstream, 100);
|
||||||
this.maybeMagic = readCleanString(bstream, 6);
|
this.maybeMagic = readCleanString(bstream, 6);
|
||||||
|
|
||||||
if (this.maybeMagic == "ustar") {
|
if (this.maybeMagic === "ustar") {
|
||||||
this.version = readCleanString(bstream, 2);
|
this.version = readCleanString(bstream, 2);
|
||||||
this.uname = readCleanString(bstream, 32);
|
this.uname = readCleanString(bstream, 32);
|
||||||
this.gname = readCleanString(bstream, 32);
|
this.gname = readCleanString(bstream, 32);
|
||||||
@ -71,10 +71,10 @@ var TarLocalFile = function(bstream) {
|
|||||||
|
|
||||||
if (this.prefix.length) {
|
if (this.prefix.length) {
|
||||||
this.name = this.prefix + this.name;
|
this.name = this.prefix + this.name;
|
||||||
}
|
}
|
||||||
bstream.readBytes(12); // 512 - 500
|
bstream.readBytes(12); // 512 - 500
|
||||||
} else {
|
} else {
|
||||||
bstream.readBytes(255); // 512 - 257
|
bstream.readBytes(255); // 512 - 257
|
||||||
}
|
}
|
||||||
|
|
||||||
// Done header, now rest of blocks are the file contents.
|
// Done header, now rest of blocks are the file contents.
|
||||||
@ -86,7 +86,7 @@ var TarLocalFile = function(bstream) {
|
|||||||
info(" typeflag = " + this.typeflag);
|
info(" typeflag = " + this.typeflag);
|
||||||
|
|
||||||
// A regular file.
|
// A regular file.
|
||||||
if (this.typeflag == 0) {
|
if (this.typeflag === 0) {
|
||||||
info(" This is a regular file.");
|
info(" This is a regular file.");
|
||||||
var sizeInBytes = parseInt(this.size);
|
var sizeInBytes = parseInt(this.size);
|
||||||
this.fileData = new Uint8Array(bstream.bytes.buffer, bstream.ptr, this.size);
|
this.fileData = new Uint8Array(bstream.bytes.buffer, bstream.ptr, this.size);
|
||||||
@ -101,8 +101,8 @@ var TarLocalFile = function(bstream) {
|
|||||||
if (remaining > 0 && remaining < 512) {
|
if (remaining > 0 && remaining < 512) {
|
||||||
bstream.readBytes(remaining);
|
bstream.readBytes(remaining);
|
||||||
}
|
}
|
||||||
} else if (this.typeflag == 5) {
|
} else if (this.typeflag === 5) {
|
||||||
info(" This is a directory.")
|
info(" This is a directory.");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -122,7 +122,7 @@ var untar = function(arrayBuffer) {
|
|||||||
var localFiles = [];
|
var localFiles = [];
|
||||||
|
|
||||||
// While we don't encounter an empty block, keep making TarLocalFiles.
|
// While we don't encounter an empty block, keep making TarLocalFiles.
|
||||||
while (bstream.peekNumber(4) != 0) {
|
while (bstream.peekNumber(4) !== 0) {
|
||||||
var oneLocalFile = new TarLocalFile(bstream);
|
var oneLocalFile = new TarLocalFile(bstream);
|
||||||
if (oneLocalFile && oneLocalFile.isValid) {
|
if (oneLocalFile && oneLocalFile.isValid) {
|
||||||
localFiles.push(oneLocalFile);
|
localFiles.push(oneLocalFile);
|
||||||
@ -132,7 +132,7 @@ var untar = function(arrayBuffer) {
|
|||||||
totalFilesInArchive = localFiles.length;
|
totalFilesInArchive = localFiles.length;
|
||||||
|
|
||||||
// got all local files, now sort them
|
// got all local files, now sort them
|
||||||
localFiles.sort(function(a,b) {
|
localFiles.sort(function(a, b) {
|
||||||
var aname = a.filename.toLowerCase();
|
var aname = a.filename.toLowerCase();
|
||||||
var bname = b.filename.toLowerCase();
|
var bname = b.filename.toLowerCase();
|
||||||
return aname > bname ? 1 : -1;
|
return aname > bname ? 1 : -1;
|
||||||
|
Loading…
Reference in New Issue
Block a user