diff --git a/lib/ComicBook.js b/lib/ComicBook.js index 9fe9b9f..d2e447d 100755 --- a/lib/ComicBook.js +++ b/lib/ComicBook.js @@ -76,7 +76,7 @@ var ComicBook = (function ($) { var defaults = { displayMode: 'double', // single / double - zoomMode: 'fitWidth', // manual / fitWidth + zoomMode: 'fitWindow', // manual / fitWidth / fitWindow manga: false, // true / false enhance: {}, keyboard: { @@ -338,7 +338,12 @@ var ComicBook = (function ($) { ComicBook.prototype.fitWidth = function () { options.zoomMode = 'fitWidth'; - ComicBook.prototype.drawPage(); + self.drawPage(); + }; + + ComicBook.prototype.fitWindow = function () { + options.zoomMode = 'fitWindow'; + self.drawPage(); }; /** @@ -465,7 +470,7 @@ var ComicBook = (function ($) { throw ComicBookException.INVALID_PAGE_TYPE + ' ' + typeof page; } - var width = page.width; + var width = page.width, height = page.height; // reset the canvas to stop duplicate pages showing canvas.width = 0; @@ -507,6 +512,21 @@ var ComicBook = (function ($) { scale = zoom_scale; break; + case 'fitWindow': + 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; } @@ -569,6 +589,7 @@ var ComicBook = (function ($) { // disable the fit width button if needed $('button.cb-fit-width').attr('disabled', (options.zoomMode === 'fitWidth')); + $('button.cb-fit-window').attr('disabled', (options.zoomMode === 'fitWindow')); // disable prev/next buttons if not needed $('.navigate').show(); diff --git a/templates/toolbar.handlebars b/templates/toolbar.handlebars index d6704d7..5f47a2b 100644 --- a/templates/toolbar.handlebars +++ b/templates/toolbar.handlebars @@ -47,6 +47,9 @@
  • +
  • + +