disable the strech button if in an auto zoom mode
This commit is contained in:
parent
f049aa9899
commit
81a5dc907f
3 changed files with 36 additions and 33 deletions
|
@ -105,7 +105,8 @@
|
||||||
background-position-x: -24px;
|
background-position-x: -24px;
|
||||||
}
|
}
|
||||||
|
|
||||||
#cb-toolbar button.disabled {
|
#cb-toolbar button[disabled=disabled] {
|
||||||
|
cursor: auto;
|
||||||
background-position-x: -48px;
|
background-position-x: -48px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,7 @@
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
book.draw();
|
book.draw();
|
||||||
|
|
||||||
window.onresize = book.drawPage;
|
window.onresize = book.drawPage;
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
|
|
||||||
Fo sho:
|
Fo sho:
|
||||||
- fix last page loading bug
|
- fix last page loading bug
|
||||||
- disable the strech button if in an auto zoom mode
|
|
||||||
- improve prev/next buttons, only show them when they can possibly work (not at beginning/end)
|
- improve prev/next buttons, only show them when they can possibly work (not at beginning/end)
|
||||||
- check for html5 feature support where used: diveintohtml5.org/everything.html or www.modernizr.com
|
- check for html5 feature support where used: diveintohtml5.org/everything.html or www.modernizr.com
|
||||||
- write bin scripts to minify & join all js
|
- write bin scripts to minify & join all js
|
||||||
|
@ -103,24 +102,24 @@ function ComicBook(id, srcs, opts) {
|
||||||
* Gets the window.innerWidth - scrollbars
|
* Gets the window.innerWidth - scrollbars
|
||||||
*/
|
*/
|
||||||
function windowWidth() {
|
function windowWidth() {
|
||||||
|
|
||||||
var height = window.innerHeight + 1;
|
var height = window.innerHeight + 1;
|
||||||
|
|
||||||
if (shiv === false) {
|
if (shiv === false) {
|
||||||
shiv = $(document.createElement("div"))
|
shiv = $(document.createElement("div"))
|
||||||
.attr("id", "cb-width-shiv")
|
.attr("id", "cb-width-shiv")
|
||||||
.css({
|
.css({
|
||||||
width: "100%",
|
width: "100%",
|
||||||
position: "absolute",
|
position: "absolute",
|
||||||
top: 0,
|
top: 0,
|
||||||
zIndex: "-1000"
|
zIndex: "-1000"
|
||||||
});
|
});
|
||||||
|
|
||||||
$("body").append(shiv);
|
$("body").append(shiv);
|
||||||
}
|
}
|
||||||
|
|
||||||
shiv.height(height);
|
shiv.height(height);
|
||||||
|
|
||||||
return shiv.innerWidth();
|
return shiv.innerWidth();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -311,7 +310,7 @@ function ComicBook(id, srcs, opts) {
|
||||||
ComicBook.prototype.drawNextPage();
|
ComicBook.prototype.drawNextPage();
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
loadingOverlay: $(document.createElement("div"))
|
loadingOverlay: $(document.createElement("div"))
|
||||||
.attr("id", "cb-loading-overlay")
|
.attr("id", "cb-loading-overlay")
|
||||||
.addClass("cb-control")
|
.addClass("cb-control")
|
||||||
|
@ -321,7 +320,7 @@ function ComicBook(id, srcs, opts) {
|
||||||
* TODO: center, make sure they never leave the visible portion of the screen
|
* TODO: center, make sure they never leave the visible portion of the screen
|
||||||
*/
|
*/
|
||||||
ComicBook.prototype.renderControls = function() {
|
ComicBook.prototype.renderControls = function() {
|
||||||
|
|
||||||
$(canvas)
|
$(canvas)
|
||||||
.before(this.getControl("loadingOverlay"))
|
.before(this.getControl("loadingOverlay"))
|
||||||
.before(this.getControl("status"))
|
.before(this.getControl("status"))
|
||||||
|
@ -329,11 +328,11 @@ function ComicBook(id, srcs, opts) {
|
||||||
.after(this.getControl("navigation").left)
|
.after(this.getControl("navigation").left)
|
||||||
.after(this.getControl("navigation").right)
|
.after(this.getControl("navigation").right)
|
||||||
.after(this.getControl("color").hide());
|
.after(this.getControl("color").hide());
|
||||||
|
|
||||||
$(".cb-menu-button").click(function(e) {
|
$(".cb-menu-button").click(function(e) {
|
||||||
$(this).toggleClass("active");
|
$(this).toggleClass("active");
|
||||||
});
|
});
|
||||||
|
|
||||||
$("#cb-desaturate").click(function(){
|
$("#cb-desaturate").click(function(){
|
||||||
if ($(this).is(":checked")) {
|
if ($(this).is(":checked")) {
|
||||||
ComicBook.prototype.enhance.desaturate();
|
ComicBook.prototype.enhance.desaturate();
|
||||||
|
@ -401,11 +400,11 @@ function ComicBook(id, srcs, opts) {
|
||||||
* @return Image
|
* @return Image
|
||||||
*/
|
*/
|
||||||
ComicBook.prototype.getPage = function(i) {
|
ComicBook.prototype.getPage = function(i) {
|
||||||
|
|
||||||
if (i < 0 || i > srcs.length) {
|
if (i < 0 || i > srcs.length) {
|
||||||
throw new ComicBookException(ComicBookException.INVALID_PAGE, i);
|
throw new ComicBookException(ComicBookException.INVALID_PAGE, i);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof pages[i] === "object") {
|
if (typeof pages[i] === "object") {
|
||||||
return pages[i];
|
return pages[i];
|
||||||
} else {
|
} else {
|
||||||
|
@ -425,7 +424,7 @@ function ComicBook(id, srcs, opts) {
|
||||||
$(".cb-control.cb-navigate").outerHeight(window.innerHeight);
|
$(".cb-control.cb-navigate").outerHeight(window.innerHeight);
|
||||||
$("#cb-toolbar").outerWidth(windowWidth());
|
$("#cb-toolbar").outerWidth(windowWidth());
|
||||||
$("#cb-loading-overlay").outerWidth(windowWidth()).height(window.innerHeight);
|
$("#cb-loading-overlay").outerWidth(windowWidth()).height(window.innerHeight);
|
||||||
|
|
||||||
// preload images if needed
|
// preload images if needed
|
||||||
if (pages.length !== no_pages) {
|
if (pages.length !== no_pages) {
|
||||||
this.preload();
|
this.preload();
|
||||||
|
@ -451,7 +450,7 @@ function ComicBook(id, srcs, opts) {
|
||||||
* @see #drawPage
|
* @see #drawPage
|
||||||
*/
|
*/
|
||||||
ComicBook.prototype.preload = function () {
|
ComicBook.prototype.preload = function () {
|
||||||
|
|
||||||
this.showControl("loadingOverlay");
|
this.showControl("loadingOverlay");
|
||||||
|
|
||||||
//var srcs = this.srcs;
|
//var srcs = this.srcs;
|
||||||
|
@ -492,16 +491,16 @@ function ComicBook(id, srcs, opts) {
|
||||||
|
|
||||||
// double page mode needs an extra page added to the buffer
|
// double page mode needs an extra page added to the buffer
|
||||||
padding = (options.displayMode === "double") ? 1 : 0;
|
padding = (options.displayMode === "double") ? 1 : 0;
|
||||||
|
|
||||||
// start rendering the comic when the buffer level has been reached (FIXME: buggy, fails if trying to load the last couple of pages)
|
// start rendering the comic when the buffer level has been reached (FIXME: buggy, fails if trying to load the last couple of pages)
|
||||||
if (loaded[loaded.length-1] === pointer + buffer + padding || loaded[loaded.length-1] === page_requested) {
|
if (loaded[loaded.length-1] === pointer + buffer + padding || loaded[loaded.length-1] === page_requested) {
|
||||||
|
|
||||||
// if the user is waiting for a page to be loaded, render that one instead of the default pointer
|
// if the user is waiting for a page to be loaded, render that one instead of the default pointer
|
||||||
if (typeof page_requested === "number") {
|
if (typeof page_requested === "number") {
|
||||||
pointer = page_requested-1;
|
pointer = page_requested-1;
|
||||||
page_requested = false;
|
page_requested = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
ComicBook.prototype.drawPage();
|
ComicBook.prototype.drawPage();
|
||||||
ComicBook.prototype.hideControl("loadingOverlay");
|
ComicBook.prototype.hideControl("loadingOverlay");
|
||||||
}
|
}
|
||||||
|
@ -512,7 +511,7 @@ function ComicBook(id, srcs, opts) {
|
||||||
// manually trigger the first load
|
// manually trigger the first load
|
||||||
preload(i);
|
preload(i);
|
||||||
};
|
};
|
||||||
|
|
||||||
ComicBook.prototype.pageLoaded = function (page_no) {
|
ComicBook.prototype.pageLoaded = function (page_no) {
|
||||||
return (typeof loaded[page_no-1] !== "undefined");
|
return (typeof loaded[page_no-1] !== "undefined");
|
||||||
};
|
};
|
||||||
|
@ -521,9 +520,9 @@ function ComicBook(id, srcs, opts) {
|
||||||
* Draw the current page in the canvas
|
* Draw the current page in the canvas
|
||||||
*/
|
*/
|
||||||
ComicBook.prototype.drawPage = function(page_no) {
|
ComicBook.prototype.drawPage = function(page_no) {
|
||||||
|
|
||||||
// if a specific page is given try to render it, if not bail and wait for preload() to render it
|
// if a specific page is given try to render it, if not bail and wait for preload() to render it
|
||||||
if (typeof page_no === "number" && page_no < srcs.length) {
|
if (typeof page_no === "number" && page_no < srcs.length) {
|
||||||
pointer = page_no-1;
|
pointer = page_no-1;
|
||||||
if (!this.pageLoaded(page_no)) {
|
if (!this.pageLoaded(page_no)) {
|
||||||
this.showControl("loadingOverlay");
|
this.showControl("loadingOverlay");
|
||||||
|
@ -546,7 +545,7 @@ function ComicBook(id, srcs, opts) {
|
||||||
// reset the canvas to stop duplicate pages showing
|
// reset the canvas to stop duplicate pages showing
|
||||||
canvas.width = 0;
|
canvas.width = 0;
|
||||||
canvas.height = 0;
|
canvas.height = 0;
|
||||||
|
|
||||||
// show double page spreads on a single page
|
// show double page spreads on a single page
|
||||||
is_double_page_spread = ((page.width > page.height || page2.width > page2.height) && options.displayMode === "double");
|
is_double_page_spread = ((page.width > page.height || page2.width > page2.height) && options.displayMode === "double");
|
||||||
if (is_double_page_spread) { options.displayMode = "single"; }
|
if (is_double_page_spread) { options.displayMode = "single"; }
|
||||||
|
@ -570,7 +569,7 @@ function ComicBook(id, srcs, opts) {
|
||||||
|
|
||||||
case "fitWidth":
|
case "fitWidth":
|
||||||
document.body.style.overflowX = "hidden";
|
document.body.style.overflowX = "hidden";
|
||||||
|
|
||||||
zoom_scale = (windowWidth() > width)
|
zoom_scale = (windowWidth() > width)
|
||||||
? ((windowWidth() - width) / windowWidth()) + 1 // scale up if the window is wider than the page
|
? ((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
|
: windowWidth() / width; // scale down if the window is narrower than the page
|
||||||
|
@ -629,6 +628,9 @@ function ComicBook(id, srcs, opts) {
|
||||||
// revert page mode back to double if it was auto switched for a double page spread
|
// revert page mode back to double if it was auto switched for a double page spread
|
||||||
if (is_double_page_spread) { options.displayMode = "double"; }
|
if (is_double_page_spread) { options.displayMode = "double"; }
|
||||||
|
|
||||||
|
// disable the fit width button if needed
|
||||||
|
$("button.cb-fit-width").attr("disabled", (options.zoomMode === "fitWidth"));
|
||||||
|
|
||||||
// user callback
|
// user callback
|
||||||
if (typeof options.afterDrawPage === "function") {
|
if (typeof options.afterDrawPage === "function") {
|
||||||
options.afterDrawPage(pointer + 1);
|
options.afterDrawPage(pointer + 1);
|
||||||
|
@ -638,7 +640,7 @@ function ComicBook(id, srcs, opts) {
|
||||||
if (getHash() !== pointer) {
|
if (getHash() !== pointer) {
|
||||||
setHash(pointer + 1);
|
setHash(pointer + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// make sure the top of the page is in view
|
// make sure the top of the page is in view
|
||||||
window.scroll(0, 0);
|
window.scroll(0, 0);
|
||||||
};
|
};
|
||||||
|
@ -649,9 +651,9 @@ function ComicBook(id, srcs, opts) {
|
||||||
* @see #drawPage
|
* @see #drawPage
|
||||||
*/
|
*/
|
||||||
ComicBook.prototype.drawNextPage = function () {
|
ComicBook.prototype.drawNextPage = function () {
|
||||||
|
|
||||||
if (!this.getPage(pointer+1)) { return false; }
|
if (!this.getPage(pointer+1)) { return false; }
|
||||||
|
|
||||||
if (pointer + 1 < pages.length) {
|
if (pointer + 1 < pages.length) {
|
||||||
pointer += (options.displayMode === "single" || is_double_page_spread) ? 1 : 2;
|
pointer += (options.displayMode === "single" || is_double_page_spread) ? 1 : 2;
|
||||||
this.drawPage();
|
this.drawPage();
|
||||||
|
@ -664,10 +666,10 @@ function ComicBook(id, srcs, opts) {
|
||||||
* @see #drawPage
|
* @see #drawPage
|
||||||
*/
|
*/
|
||||||
ComicBook.prototype.drawPrevPage = function () {
|
ComicBook.prototype.drawPrevPage = function () {
|
||||||
|
|
||||||
var page = this.getPage(pointer-1);
|
var page = this.getPage(pointer-1);
|
||||||
if (!page) { return false; }
|
if (!page) { return false; }
|
||||||
|
|
||||||
is_double_page_spread = (page.width > page.height); // need to run double page check again here as we are going backwards
|
is_double_page_spread = (page.width > page.height); // need to run double page check again here as we are going backwards
|
||||||
|
|
||||||
if (pointer > 0) {
|
if (pointer > 0) {
|
||||||
|
@ -793,7 +795,7 @@ function ComicBook(id, srcs, opts) {
|
||||||
ComicBook.prototype.toggleToolbar();
|
ComicBook.prototype.toggleToolbar();
|
||||||
break;
|
break;
|
||||||
case "keydown":
|
case "keydown":
|
||||||
|
|
||||||
// navigation
|
// navigation
|
||||||
if (e.keyCode === options.keyboard.previous) { side = "left"; }
|
if (e.keyCode === options.keyboard.previous) { side = "left"; }
|
||||||
if (e.keyCode === options.keyboard.next) { side = "right"; }
|
if (e.keyCode === options.keyboard.next) { side = "right"; }
|
||||||
|
@ -830,5 +832,5 @@ function ComicBook(id, srcs, opts) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue