Add best-fit mode

This commit is contained in:
klutzy 2013-05-17 23:23:47 +09:00
parent d113b9d950
commit 2f7a3268f1
3 changed files with 30 additions and 0 deletions

View file

@ -243,6 +243,15 @@ function ComicBook(id, srcs, opts) {
ComicBook.prototype.drawPage();
})
)
.append(
$(document.createElement("button"))
.attr("title", "fit to page width/height")
.addClass("cb-fit-best")
.click(function(){
options.zoomMode = "fitBest"
ComicBook.prototype.drawPage();
})
)
.append(
$(document.createElement("button"))
.attr("title", ((options.manga == true) ? "change reading direction to 'left-to-right'" : "change reading direction to 'right-to-left'"))
@ -601,6 +610,7 @@ function ComicBook(id, srcs, opts) {
}
var width = page.width;
var height = page.height;
// reset the canvas to stop duplicate pages showing
canvas.width = 0;
@ -642,6 +652,21 @@ function ComicBook(id, srcs, opts) {
scale = zoom_scale
break;
case "fitBest":
document.body.style.overflowX = "hidden";
var width_scale = (windowWidth() > width)
? ((windowWidth() - width) / windowWidth()) + 1 // scale up if the window is wider than the page
: windowWidth() / width; // scale down if the window is narrower than the page
var windowHeight = window.innerHeight;
var height_scale = (windowHeight > height)
? ((windowHeight - height) / windowHeight) + 1 // scale up if the window is wider than the page
: windowHeight / height; // scale down if the window is narrower than the page
zoom_scale = (width_scale > height_scale)? height_scale : width_scale;
scale = zoom_scale;
break;
default:
throw ComicBookException.INVALID_ZOOM_MODE+' '+options.zoomMode;
}
@ -697,6 +722,7 @@ function ComicBook(id, srcs, opts) {
// disable the fit width button if needed
$("button.cb-fit-width").attr("disabled", (options.zoomMode === "fitWidth"));
$("button.cb-fit-best").attr("disabled", (options.zoomMode === "fitBest"));
//Change the icon on the read direction
if(options.manga == true)