From 3759157f6b035d43880b3c5425bc8dc558191da1 Mon Sep 17 00:00:00 2001 From: Bala Clark Date: Sun, 28 Aug 2011 19:22:38 +0200 Subject: [PATCH] created functions for get/set hash --- lib/ComicBook.js | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) mode change 100644 => 100755 lib/ComicBook.js diff --git a/lib/ComicBook.js b/lib/ComicBook.js old mode 100644 new mode 100755 index 468e339..4065b75 --- a/lib/ComicBook.js +++ b/lib/ComicBook.js @@ -70,13 +70,27 @@ function ComicBook(id, srcs, opts) { **/ function checkHash() { - var hash = parseInt(location.hash.substring(1),10) - 1 || 0; + var hash = getHash(); if (hash !== pointer && loaded.indexOf(hash) > -1) { pointer = hash; ComicBook.prototype.draw(); } } + + 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. @@ -104,9 +118,9 @@ function ComicBook(id, srcs, opts) { /** * 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.'; } - $.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 page2 = pages[pointer + 1]; - if (options.savePosition === true) { setLastPage(); }; - if (typeof page !== "object") { throw "invalid page type '"+ typeof page +"'"; } var width = page.width; @@ -299,8 +311,8 @@ function ComicBook(id, srcs, opts) { 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); } - location.hash = pointer + 1; - + setHash(pointer + 1); + // apply any image enhancements previously defined $.each(options.enhance, function(action, options) { ComicBook.prototype.enhance[action](options);