Code cosmetics
This commit is contained in:
parent
d76f812310
commit
aae9e285a8
|
@ -15,7 +15,6 @@
|
|||
* Typed Arrays: http://www.khronos.org/registry/typedarray/specs/latest/#6
|
||||
|
||||
*/
|
||||
/* global bitjs */
|
||||
|
||||
var start = 0;
|
||||
|
||||
|
@ -56,7 +55,7 @@ kthoom.Key = {
|
|||
};
|
||||
|
||||
// global variables
|
||||
var unarchiver = null;
|
||||
// var unarchiver = null;
|
||||
var currentImage = 0;
|
||||
var imageFiles = [];
|
||||
var imageFilenames = [];
|
||||
|
@ -68,10 +67,10 @@ var settings = {
|
|||
vflip: false,
|
||||
rotateTimes: 0,
|
||||
fitMode: kthoom.Key.B,
|
||||
theme: 'light'
|
||||
theme: "light"
|
||||
};
|
||||
|
||||
var canKeyNext = true, canKeyPrev = true;
|
||||
// var canKeyNext = true, canKeyPrev = true;
|
||||
|
||||
kthoom.saveSettings = function() {
|
||||
localStorage.kthoomSettings = JSON.stringify(settings);
|
||||
|
@ -95,14 +94,14 @@ kthoom.setSettings = function() {
|
|||
// Set settings control values
|
||||
$.each(settings, function(key, value) {
|
||||
if (typeof value === "boolean") {
|
||||
$('input[name='+key+']').prop('checked', value);
|
||||
$("input[name=" + key + "]").prop("checked", value);
|
||||
} else {
|
||||
$('input[name='+key+']').val([value]);
|
||||
$("input[name=" + key + "]").val([value]);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
var createURLFromArray = function(array, mimeType) {
|
||||
/* var createURLFromArray = function(array, mimeType) {
|
||||
var offset = array.byteOffset, len = array.byteLength;
|
||||
var url;
|
||||
var blob;
|
||||
|
@ -129,20 +128,13 @@ var createURLFromArray = function(array, mimeType) {
|
|||
}
|
||||
|
||||
return URL.createObjectURL(blob);
|
||||
};
|
||||
};*/
|
||||
|
||||
|
||||
// Stores an image filename and its data: URI.
|
||||
// TODO: investigate if we really need to store as base64 (leave off ;base64 and just
|
||||
// non-safe URL characters are encoded as %xx ?)
|
||||
// This would save 25% on memory since base64-encoded strings are 4/3 the size of the binary
|
||||
kthoom.ImageFile = function(file) {
|
||||
this.filename = file.filename;
|
||||
/*var fileExtension = file.filename.split(".").pop().toLowerCase();
|
||||
var mimeType = fileExtension === "png" ? "image/png" :
|
||||
(fileExtension === "jpg" || fileExtension === "jpeg") ? "image/jpeg" :
|
||||
fileExtension === "gif" ? "image/gif" : null;*/
|
||||
this.dataURI = file.fileData; // createURLFromArray(file.fileData, mimeType);
|
||||
this.dataURI = file.fileData;
|
||||
this.data = file;
|
||||
};
|
||||
|
||||
|
@ -231,14 +223,14 @@ kthoom.initProgressMeter = function() {
|
|||
|
||||
svg.appendChild(g);
|
||||
pdiv.appendChild(svg);
|
||||
var l;
|
||||
var l = 0;
|
||||
svg.onclick = function(e) {
|
||||
for (var x = pdiv, l = 0; x !== document.documentElement; x = x.parentNode) l += x.offsetLeft;
|
||||
for (var x = pdiv; x !== document.documentElement; x = x.parentNode) l += x.offsetLeft;
|
||||
var page = Math.max(1, Math.ceil(((e.clientX - l) / pdiv.offsetWidth) * totalImages)) - 1;
|
||||
currentImage = page;
|
||||
updatePage();
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
kthoom.setProgressMeter = function(pct, optLabel) {
|
||||
pct = (pct * 100);
|
||||
|
@ -290,13 +282,13 @@ function loadFromArrayBuffer(ab) {
|
|||
imageFiles.push(new kthoom.ImageFile(f));
|
||||
|
||||
// add thumbnails to the TOC list
|
||||
$('#thumbnails').append(
|
||||
"<li> \
|
||||
<a data-page='"+ imageFiles.length +"'> \
|
||||
<img src='"+ imageFiles[imageFiles.length - 1].dataURI +"' /> \
|
||||
<span>"+ imageFiles.length +"</span> \
|
||||
</a> \
|
||||
</li>"
|
||||
$("#thumbnails").append(
|
||||
"<li>" +
|
||||
"<a data-page='" + imageFiles.length + "'>" +
|
||||
"<img src='" + imageFiles[imageFiles.length - 1].dataURI + "'/>" +
|
||||
"<span>" + imageFiles.length + "</span>" +
|
||||
"</a>" +
|
||||
"</li>"
|
||||
);
|
||||
}
|
||||
var percentage = (ab.page + 1) / (ab.last + 1);
|
||||
|
@ -324,7 +316,7 @@ function updatePage() {
|
|||
setImage("loading");
|
||||
}
|
||||
|
||||
$('body').toggleClass('dark-theme', settings.theme === 'dark');
|
||||
$("body").toggleClass("dark-theme", settings.theme === "dark");
|
||||
|
||||
kthoom.setSettings();
|
||||
kthoom.saveSettings();
|
||||
|
@ -375,7 +367,6 @@ function setImage(url) {
|
|||
if (/(html|htm)$/.test(imageFiles[currentImage].filename)) {
|
||||
xhr.open("GET", url, true);
|
||||
xhr.onload = function() {
|
||||
//document.getElementById('mainText').style.display = '';
|
||||
$("#mainText").css("display", "");
|
||||
$("#mainText").innerHTML("<iframe style=\"width:100%;height:700px;border:0\" src=\"data:text/html," + escape(xhr.responseText) + "\"></iframe>");
|
||||
}
|
||||
|
@ -465,7 +456,7 @@ function updateScale(clear) {
|
|||
} else if (settings.fitMode === kthoom.Key.W) {
|
||||
mainImageStyle.width = "100%";
|
||||
}
|
||||
$('#mainContent').css({maxHeight: maxheight + 5});
|
||||
$("#mainContent").css({maxHeight: maxheight + 5});
|
||||
kthoom.setSettings();
|
||||
kthoom.saveSettings();
|
||||
}
|
||||
|
@ -476,8 +467,8 @@ function keyHandler(evt) {
|
|||
if ($("#progress").css("display") === "none") {
|
||||
return;
|
||||
}
|
||||
canKeyNext = (($("body").css("offsetWidth") + $("body").css("scrollLeft")) / $("body").css("scrollWidth")) >= 1;
|
||||
canKeyPrev = (scrollX <= 0);
|
||||
// canKeyNext = (($("body").css("offsetWidth") + $("body").css("scrollLeft")) / $("body").css("scrollWidth")) >= 1;
|
||||
// canKeyPrev = (scrollX <= 0);
|
||||
|
||||
if (evt.ctrlKey || evt.shiftKey || evt.metaKey) return;
|
||||
switch (code) {
|
||||
|
@ -555,7 +546,7 @@ function ImageLoadCallback(event) {
|
|||
else
|
||||
{
|
||||
var diff = ((new Date).getTime() - start) / 1000;
|
||||
console.log('Transfer done in ' + diff + 's');
|
||||
console.log("Transfer done in " + diff + "s");
|
||||
}
|
||||
loadFromArrayBuffer(jso);
|
||||
}
|
||||
|
@ -580,20 +571,20 @@ function init(fileid) {
|
|||
|
||||
// Open TOC menu
|
||||
$("#slider").click(function(evt) {
|
||||
$('#sidebar').toggleClass('open');
|
||||
$('#main').toggleClass('closed');
|
||||
$(this).toggleClass('icon-menu icon-right');
|
||||
$("#sidebar").toggleClass("open");
|
||||
$("#main").toggleClass("closed");
|
||||
$(this).toggleClass("icon-menu icon-right");
|
||||
});
|
||||
|
||||
// Open Settings modal
|
||||
$("#setting").click(function(evt) {
|
||||
$("#settings-modal").toggleClass('md-show');
|
||||
$("#settings-modal").toggleClass("md-show");
|
||||
});
|
||||
|
||||
// On Settings input change
|
||||
$("#settings input").on("change", function(evt) {
|
||||
// Get either the checked boolean or the assigned value
|
||||
var value = this.type === 'checkbox' ? this.checked : this.value;
|
||||
var value = this.type === "checkbox" ? this.checked : this.value;
|
||||
|
||||
// If it's purely numeric, parse it to an integer
|
||||
value = /^\d+$/.test(value) ? parseInt(value) : value;
|
||||
|
@ -605,12 +596,12 @@ function init(fileid) {
|
|||
|
||||
// Close modal
|
||||
$(".closer, .overlay").click(function(evt) {
|
||||
$(".md-show").removeClass('md-show');
|
||||
$(".md-show").removeClass("md-show");
|
||||
});
|
||||
|
||||
// TOC thumbnail pagination
|
||||
$('#thumbnails').on("click", "a", function(evt) {
|
||||
currentImage = $(this).data('page') - 1;
|
||||
$("#thumbnails").on("click", "a", function(evt) {
|
||||
currentImage = $(this).data("page") - 1;
|
||||
updatePage();
|
||||
});
|
||||
|
||||
|
@ -621,7 +612,7 @@ function init(fileid) {
|
|||
});
|
||||
|
||||
if (screenfull.raw) {
|
||||
var $button = $('#fullscreen');
|
||||
var $button = $("#fullscreen");
|
||||
document.addEventListener(screenfull.raw.fullscreenchange,function() {
|
||||
screenfull.isFullscreen
|
||||
? $button.addClass("icon-resize-small").removeClass("icon-resize-full")
|
||||
|
@ -639,8 +630,8 @@ function init(fileid) {
|
|||
var comicHeight = evt.target.clientHeight;
|
||||
var offsetX = (mainContentWidth - comicWidth) / 2;
|
||||
var offsetY = (mainContentHeight - comicHeight) / 2;
|
||||
var clickX = !!evt.offsetX ? evt.offsetX : (evt.clientX - offsetX);
|
||||
var clickY = !!evt.offsetY ? evt.offsetY : (evt.clientY - offsetY);
|
||||
var clickX = evt.offsetX ? evt.offsetX : (evt.clientX - offsetX);
|
||||
var clickY = evt.offsetY ? evt.offsetY : (evt.clientY - offsetY);
|
||||
|
||||
// Determine if the user clicked/tapped the left side or the
|
||||
// right side of the page.
|
||||
|
|
Loading…
Reference in New Issue
Block a user