Code cosmetics

pull/406/head
OzzieIsaacs 7 years ago
parent d76f812310
commit aae9e285a8

@ -15,7 +15,6 @@
* Typed Arrays: http://www.khronos.org/registry/typedarray/specs/latest/#6 * Typed Arrays: http://www.khronos.org/registry/typedarray/specs/latest/#6
*/ */
/* global bitjs */
var start = 0; var start = 0;
@ -56,7 +55,7 @@ kthoom.Key = {
}; };
// global variables // global variables
var unarchiver = null; // var unarchiver = null;
var currentImage = 0; var currentImage = 0;
var imageFiles = []; var imageFiles = [];
var imageFilenames = []; var imageFilenames = [];
@ -68,10 +67,10 @@ var settings = {
vflip: false, vflip: false,
rotateTimes: 0, rotateTimes: 0,
fitMode: kthoom.Key.B, fitMode: kthoom.Key.B,
theme: 'light' theme: "light"
}; };
var canKeyNext = true, canKeyPrev = true; // var canKeyNext = true, canKeyPrev = true;
kthoom.saveSettings = function() { kthoom.saveSettings = function() {
localStorage.kthoomSettings = JSON.stringify(settings); localStorage.kthoomSettings = JSON.stringify(settings);
@ -95,14 +94,14 @@ kthoom.setSettings = function() {
// Set settings control values // Set settings control values
$.each(settings, function(key, value) { $.each(settings, function(key, value) {
if (typeof value === "boolean") { if (typeof value === "boolean") {
$('input[name='+key+']').prop('checked', value); $("input[name=" + key + "]").prop("checked", value);
} else { } 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 offset = array.byteOffset, len = array.byteLength;
var url; var url;
var blob; var blob;
@ -129,20 +128,13 @@ var createURLFromArray = function(array, mimeType) {
} }
return URL.createObjectURL(blob); 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
// 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) { kthoom.ImageFile = function(file) {
this.filename = file.filename; this.filename = file.filename;
/*var fileExtension = file.filename.split(".").pop().toLowerCase(); this.dataURI = file.fileData;
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.data = file; this.data = file;
}; };
@ -231,14 +223,14 @@ kthoom.initProgressMeter = function() {
svg.appendChild(g); svg.appendChild(g);
pdiv.appendChild(svg); pdiv.appendChild(svg);
var l; var l = 0;
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; 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, optLabel) { kthoom.setProgressMeter = function(pct, optLabel) {
pct = (pct * 100); pct = (pct * 100);
@ -290,13 +282,13 @@ function loadFromArrayBuffer(ab) {
imageFiles.push(new kthoom.ImageFile(f)); imageFiles.push(new kthoom.ImageFile(f));
// add thumbnails to the TOC list // add thumbnails to the TOC list
$('#thumbnails').append( $("#thumbnails").append(
"<li> \ "<li>" +
<a data-page='"+ imageFiles.length +"'> \ "<a data-page='" + imageFiles.length + "'>" +
<img src='"+ imageFiles[imageFiles.length - 1].dataURI +"' /> \ "<img src='" + imageFiles[imageFiles.length - 1].dataURI + "'/>" +
<span>"+ imageFiles.length +"</span> \ "<span>" + imageFiles.length + "</span>" +
</a> \ "</a>" +
</li>" "</li>"
); );
} }
var percentage = (ab.page + 1) / (ab.last + 1); var percentage = (ab.page + 1) / (ab.last + 1);
@ -324,7 +316,7 @@ function updatePage() {
setImage("loading"); setImage("loading");
} }
$('body').toggleClass('dark-theme', settings.theme === 'dark'); $("body").toggleClass("dark-theme", settings.theme === "dark");
kthoom.setSettings(); kthoom.setSettings();
kthoom.saveSettings(); kthoom.saveSettings();
@ -375,7 +367,6 @@ function setImage(url) {
if (/(html|htm)$/.test(imageFiles[currentImage].filename)) { if (/(html|htm)$/.test(imageFiles[currentImage].filename)) {
xhr.open("GET", url, true); xhr.open("GET", url, true);
xhr.onload = function() { xhr.onload = function() {
//document.getElementById('mainText').style.display = '';
$("#mainText").css("display", ""); $("#mainText").css("display", "");
$("#mainText").innerHTML("<iframe style=\"width:100%;height:700px;border:0\" src=\"data:text/html," + escape(xhr.responseText) + "\"></iframe>"); $("#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) { } else if (settings.fitMode === kthoom.Key.W) {
mainImageStyle.width = "100%"; mainImageStyle.width = "100%";
} }
$('#mainContent').css({maxHeight: maxheight + 5}); $("#mainContent").css({maxHeight: maxheight + 5});
kthoom.setSettings(); kthoom.setSettings();
kthoom.saveSettings(); kthoom.saveSettings();
} }
@ -476,8 +467,8 @@ function keyHandler(evt) {
if ($("#progress").css("display") === "none") { if ($("#progress").css("display") === "none") {
return; return;
} }
canKeyNext = (($("body").css("offsetWidth") + $("body").css("scrollLeft")) / $("body").css("scrollWidth")) >= 1; // 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;
switch (code) { switch (code) {
@ -555,7 +546,7 @@ function ImageLoadCallback(event) {
else else
{ {
var diff = ((new Date).getTime() - start) / 1000; var diff = ((new Date).getTime() - start) / 1000;
console.log('Transfer done in ' + diff + 's'); console.log("Transfer done in " + diff + "s");
} }
loadFromArrayBuffer(jso); loadFromArrayBuffer(jso);
} }
@ -580,20 +571,20 @@ function init(fileid) {
// Open TOC menu // Open TOC menu
$("#slider").click(function(evt) { $("#slider").click(function(evt) {
$('#sidebar').toggleClass('open'); $("#sidebar").toggleClass("open");
$('#main').toggleClass('closed'); $("#main").toggleClass("closed");
$(this).toggleClass('icon-menu icon-right'); $(this).toggleClass("icon-menu icon-right");
}); });
// Open Settings modal // Open Settings modal
$("#setting").click(function(evt) { $("#setting").click(function(evt) {
$("#settings-modal").toggleClass('md-show'); $("#settings-modal").toggleClass("md-show");
}); });
// On Settings input change // On Settings input change
$("#settings input").on("change", function(evt) { $("#settings input").on("change", function(evt) {
// Get either the checked boolean or the assigned value // 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 // If it's purely numeric, parse it to an integer
value = /^\d+$/.test(value) ? parseInt(value) : value; value = /^\d+$/.test(value) ? parseInt(value) : value;
@ -605,12 +596,12 @@ function init(fileid) {
// Close modal // Close modal
$(".closer, .overlay").click(function(evt) { $(".closer, .overlay").click(function(evt) {
$(".md-show").removeClass('md-show'); $(".md-show").removeClass("md-show");
}); });
// TOC thumbnail pagination // TOC thumbnail pagination
$('#thumbnails').on("click", "a", function(evt) { $("#thumbnails").on("click", "a", function(evt) {
currentImage = $(this).data('page') - 1; currentImage = $(this).data("page") - 1;
updatePage(); updatePage();
}); });
@ -621,7 +612,7 @@ function init(fileid) {
}); });
if (screenfull.raw) { if (screenfull.raw) {
var $button = $('#fullscreen'); var $button = $("#fullscreen");
document.addEventListener(screenfull.raw.fullscreenchange,function() { document.addEventListener(screenfull.raw.fullscreenchange,function() {
screenfull.isFullscreen screenfull.isFullscreen
? $button.addClass("icon-resize-small").removeClass("icon-resize-full") ? $button.addClass("icon-resize-small").removeClass("icon-resize-full")
@ -639,8 +630,8 @@ function init(fileid) {
var comicHeight = evt.target.clientHeight; var comicHeight = evt.target.clientHeight;
var offsetX = (mainContentWidth - comicWidth) / 2; var offsetX = (mainContentWidth - comicWidth) / 2;
var offsetY = (mainContentHeight - comicHeight) / 2; var offsetY = (mainContentHeight - comicHeight) / 2;
var clickX = !!evt.offsetX ? evt.offsetX : (evt.clientX - offsetX); var clickX = evt.offsetX ? evt.offsetX : (evt.clientX - offsetX);
var clickY = !!evt.offsetY ? evt.offsetY : (evt.clientY - offsetY); var clickY = evt.offsetY ? evt.offsetY : (evt.clientY - offsetY);
// Determine if the user clicked/tapped the left side or the // Determine if the user clicked/tapped the left side or the
// right side of the page. // right side of the page.

Loading…
Cancel
Save