created functions for get/set hash
This commit is contained in:
parent
f821168360
commit
3759157f6b
1 changed files with 19 additions and 7 deletions
24
lib/ComicBook.js
Normal file → Executable file
24
lib/ComicBook.js
Normal file → Executable file
|
@ -70,7 +70,7 @@ function ComicBook(id, srcs, opts) {
|
||||||
**/
|
**/
|
||||||
function checkHash() {
|
function checkHash() {
|
||||||
|
|
||||||
var hash = parseInt(location.hash.substring(1),10) - 1 || 0;
|
var hash = getHash();
|
||||||
|
|
||||||
if (hash !== pointer && loaded.indexOf(hash) > -1) {
|
if (hash !== pointer && loaded.indexOf(hash) > -1) {
|
||||||
pointer = hash;
|
pointer = hash;
|
||||||
|
@ -78,6 +78,20 @@ function ComicBook(id, srcs, opts) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getHash() {
|
||||||
|
return parseInt(location.hash.substring(1),10) - 1 || 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
function setHash() {
|
||||||
|
|
||||||
|
var pageNo = pointer + 1;
|
||||||
|
|
||||||
|
if (getHash() !== '#'+pageNo) {
|
||||||
|
location.hash = pageNo;
|
||||||
|
if (options.savePosition === true) { setLastPage(pageNo); };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Figure out the cursor position relative to the canvas.
|
* Figure out the cursor position relative to the canvas.
|
||||||
*
|
*
|
||||||
|
@ -104,9 +118,9 @@ function ComicBook(id, srcs, opts) {
|
||||||
/**
|
/**
|
||||||
* Tell the library app where the user is up to
|
* Tell the library app where the user is up to
|
||||||
**/
|
**/
|
||||||
function setLastPage() {
|
function setLastPage(pageNo) {
|
||||||
if (!options.data.comicId) { throw 'options.data.comicId is not set.'; }
|
if (!options.data.comicId) { throw 'options.data.comicId is not set.'; }
|
||||||
$.post('/comic/setlastpage', { page: pointer+1, comic: options.data.comicId });
|
$.post('/comic/setlastpage', { page: pageNo, comic: options.data.comicId });
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -220,8 +234,6 @@ function ComicBook(id, srcs, opts) {
|
||||||
var page = pages[pointer];
|
var page = pages[pointer];
|
||||||
var page2 = pages[pointer + 1];
|
var page2 = pages[pointer + 1];
|
||||||
|
|
||||||
if (options.savePosition === true) { setLastPage(); };
|
|
||||||
|
|
||||||
if (typeof page !== "object") { throw "invalid page type '"+ typeof page +"'"; }
|
if (typeof page !== "object") { throw "invalid page type '"+ typeof page +"'"; }
|
||||||
|
|
||||||
var width = page.width;
|
var width = page.width;
|
||||||
|
@ -299,7 +311,7 @@ function ComicBook(id, srcs, opts) {
|
||||||
context.drawImage(page, offsetW, offsetH, page_width, page_height);
|
context.drawImage(page, offsetW, offsetH, page_width, page_height);
|
||||||
if (options.displayMode === "double" && typeof page2 === "object") { context.drawImage(page2, page_width + offsetW, offsetH, page_width, page_height); }
|
if (options.displayMode === "double" && typeof page2 === "object") { context.drawImage(page2, page_width + offsetW, offsetH, page_width, page_height); }
|
||||||
|
|
||||||
location.hash = pointer + 1;
|
setHash(pointer + 1);
|
||||||
|
|
||||||
// apply any image enhancements previously defined
|
// apply any image enhancements previously defined
|
||||||
$.each(options.enhance, function(action, options) {
|
$.each(options.enhance, function(action, options) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue