keyboard navigation: left/right
This commit is contained in:
parent
683d804127
commit
9f684a7b68
1 changed files with 29 additions and 7 deletions
|
@ -48,7 +48,11 @@ function ComicBook(id, srcs, opts) {
|
|||
zoomMode: "fitWidth", // manual / fitWidth
|
||||
manga: false, // true / false
|
||||
savePosition: true, // true / false
|
||||
enhance: {}
|
||||
enhance: {},
|
||||
keyboard: {
|
||||
next: 78,
|
||||
previous: 80
|
||||
}
|
||||
};
|
||||
|
||||
var options = merge(defaults, opts); // options array for internal use
|
||||
|
@ -137,6 +141,7 @@ function ComicBook(id, srcs, opts) {
|
|||
// add page controls
|
||||
// TODO: add IE event listeners too.
|
||||
canvas.addEventListener("click", ComicBook.prototype.navigation, false);
|
||||
window.addEventListener("keydown", ComicBook.prototype.navigation, false);
|
||||
window.addEventListener("hashchange", checkHash, false);
|
||||
//setInterval(function() { checkHash(); }, 300); // TODO: enable this when there is no onhashchange event
|
||||
}
|
||||
|
@ -455,13 +460,27 @@ function ComicBook(id, srcs, opts) {
|
|||
};
|
||||
|
||||
ComicBook.prototype.navigation = function (e) {
|
||||
|
||||
if (e.type === "click") {
|
||||
|
||||
var side = getCursorPosition(e);
|
||||
|
||||
|
||||
var side;
|
||||
|
||||
switch (e.type) {
|
||||
case "click":
|
||||
side = getCursorPosition(e);
|
||||
break;
|
||||
case "keydown":
|
||||
if (e.keyCode === options.keyboard.previous) { side = "left"; }
|
||||
if (e.keyCode === options.keyboard.next) { side = "right"; }
|
||||
break;
|
||||
default:
|
||||
throw "invalid navigation event: " + e.type;
|
||||
}
|
||||
|
||||
if (side) {
|
||||
|
||||
e.stopPropagation();
|
||||
|
||||
window.scroll(0,0); // make sure the top of the page is in view
|
||||
|
||||
|
||||
// western style (left to right)
|
||||
if (!options.manga) {
|
||||
if (side === "left") { ComicBook.prototype.drawPrevPage(); }
|
||||
|
@ -472,6 +491,9 @@ function ComicBook(id, srcs, opts) {
|
|||
if (side === "left") { ComicBook.prototype.drawNextPage(); }
|
||||
if (side === "right") { ComicBook.prototype.drawPrevPage(); }
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue