diff --git a/lib/ComicBook.js b/lib/ComicBook.js index e5a7a70..ae57161 100644 --- a/lib/ComicBook.js +++ b/lib/ComicBook.js @@ -67,7 +67,9 @@ function ComicBook(id, srcs, opts) { // the current page, can pass a default as a url hash var pointer = (parseInt(location.hash.substring(1),10) - 1) || 0; - // enables the back button + /** + * enables the back button + **/ function checkHash() { var hash = parseInt(location.hash.substring(1),10) - 1 || 0; @@ -100,7 +102,17 @@ function ComicBook(id, srcs, opts) { // check if the user clicked on the left or right side return (x <= canvas.width / 2) ? 'left' : 'right'; } - + + /** + * Tell the library app where the user is up to + **/ + function setLastPage() { + if (!options.data.comicId) { throw 'options.data.comicId is not set.'; } + $.get('/comic/setlastpage', { page: pointer+1, comic: options.data.comicId }, function(error){ + console.log(error); + }); + } + /** * Setup the canvas element for use throughout the class. * @@ -211,7 +223,9 @@ function ComicBook(id, srcs, opts) { var offsetW = 0, offsetH = 0; var page = pages[pointer]; var page2 = pages[pointer + 1]; - + + setLastPage(); + if (typeof page !== "object") { throw "invalid page type '"+ typeof page +"'"; } var width = page.width; @@ -320,7 +334,7 @@ function ComicBook(id, srcs, opts) { ComicBook.prototype.drawPrevPage = function () { is_double_page_spread = (pages[pointer-1].width > pages[pointer-1].height); // need to run double page check again here as we are going backwards - + if (pointer > 0) { pointer -= (options.displayMode === "single" || is_double_page_spread) ? 1 : 2; this.drawPage();