send ajax statement to the library to save current page

This commit is contained in:
Bala Clark 2011-01-06 18:13:29 +01:00
parent 3aa2f5da84
commit f1636dd3a4

View file

@ -67,7 +67,9 @@ function ComicBook(id, srcs, opts) {
// the current page, can pass a default as a url hash // the current page, can pass a default as a url hash
var pointer = (parseInt(location.hash.substring(1),10) - 1) || 0; var pointer = (parseInt(location.hash.substring(1),10) - 1) || 0;
// enables the back button /**
* enables the back button
**/
function checkHash() { function checkHash() {
var hash = parseInt(location.hash.substring(1),10) - 1 || 0; 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 // check if the user clicked on the left or right side
return (x <= canvas.width / 2) ? 'left' : 'right'; 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. * Setup the canvas element for use throughout the class.
* *
@ -211,7 +223,9 @@ function ComicBook(id, srcs, opts) {
var offsetW = 0, offsetH = 0; var offsetW = 0, offsetH = 0;
var page = pages[pointer]; var page = pages[pointer];
var page2 = pages[pointer + 1]; var page2 = pages[pointer + 1];
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;
@ -320,7 +334,7 @@ function ComicBook(id, srcs, opts) {
ComicBook.prototype.drawPrevPage = function () { 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 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) { if (pointer > 0) {
pointer -= (options.displayMode === "single" || is_double_page_spread) ? 1 : 2; pointer -= (options.displayMode === "single" || is_double_page_spread) ? 1 : 2;
this.drawPage(); this.drawPage();