},
_preloadPage: function (page, callback) {
+ var $this = this;
+ var _cb = function (data) {
+ $this._preloadPageAfterSecurityChecks(page, callback);
+ };
+ if (this.fluidbook.settings.recaptcha) {
+ this.fluidbook.secure.recaptcha('loadpage', _cb);
+ return;
+ }
+ _cb();
+ },
+
+ _preloadPageAfterSecurityChecks: function (page, callback) {
if (page == undefined || page == 'undefined' || page > this.fluidbook.contentlock.getMaxPage() || page < 1) {
callback();
return;
}
$("#loadedcontents [data-page='" + page + "']").remove();
- },
- setContentsInDoublePage: function (doublePage, pages, immediate, callback) {
+ }, setContentsInDoublePage: function (doublePage, pages, immediate, callback) {
var $this = this;
var leftPage = pages[0];
});
});
}
- },
- loadPage: function (pageNr, doublePage, position, callback) {
+ }, loadPage: function (pageNr, doublePage, position, callback) {
+
if (pageNr <= 0 || pageNr > this.fluidbook.settings.pages) {
callback();
return;
loadPageShade: function (position) {
return this.loadImage('images/shadows/pages/' + position + '.png', this.fluidbook.settings.width / 4, this.fluidbook.settings.height);
- },
- loadLeftPage: function (page, doublePage, callback) {
+ }, loadLeftPage: function (page, doublePage, callback) {
if (page > 0 && page <= this.fluidbook.contentlock.getMaxPage()) {
this.loadPage(page, doublePage, 'left', callback);
} else {
$(doublePage).find('.left').remove();
callback();
}
- },
- loadRightPage: function (page, doublePage, callback) {
+ }, loadRightPage: function (page, doublePage, callback) {
if (!this.fluidbook.displayOnePage && page <= this.fluidbook.contentlock.getMaxPage() && page > 0) {
this.loadPage(page, doublePage, 'right', callback);
} else {
$(doublePage).find('.right').remove();
callback();
}
- },
- getBackgroundURL: function (page) {
+ }, getBackgroundURL: function (page) {
var version = this.getVersionToLoad(page);
if (version === 'vector') {
return false;
getTextsURL: function (page) {
return 'data/contents/p' + page + '.svg';
- },
- setBackground: function (page, callback) {
+ }, setBackground: function (page, callback) {
var $this = this;
var back = $("#page_" + page + ' .background');
this._loadBackground(page, function () {
$(back).append($this.backgrounds[page]);
callback();
});
- },
- setOnStage: function (element) {
+ }, setOnStage: function (element) {
if (element === undefined || element == null) {
return;
}
if (!isOnStage(element)) {
$("#loadedcontents").append($(element));
}
- },
- _loadBackground: function (page, callback) {
+ }, _loadBackground: function (page, callback) {
if (page <= 0 || page > this.fluidbook.settings.pages) {
callback();
return;
this.__loadBackground(page, callback);
}
}
- },
- __loadBackground: function (page, callback) {
+ }, __loadBackground: function (page, callback) {
if (page <= 0 || page > this.fluidbook.settings.pages) {
callback();
return;
return false;
}
this.backgrounds[page] = this.loadImage(url, null, null, null, page, callback);
- },
- needSeparateTextures: function (page) {
+ }, needSeparateTextures: function (page) {
if (this._needSeparateTextures[page] === undefined) {
var $this = this;
this._needSeparateTextures[page] = false;
});
}
return this._needSeparateTextures[page];
- },
- loadTexture: function (page, callback, enter) {
+ }, loadTexture: function (page, callback, enter) {
if (enter === undefined) {
enter = true;
}
}
- if (
- (enter && this.textures[page] !== undefined && this.textures[page] !== null) ||
- (!enter && this.leaveTextures[page] !== undefined && this.leaveTextures[page] !== null)
- ) {
+ if ((enter && this.textures[page] !== undefined && this.textures[page] !== null) || (!enter && this.leaveTextures[page] !== undefined && this.leaveTextures[page] !== null)) {
callback();
} else {
try {
var url = this.getTextsURL(pageNr);
if (this.fluidbook.support.svgtocanvg) {
$.ajax({
- url: url,
- dataType: 'text',
+ url: url, dataType: 'text',
}).done(function (data) {
$this.texts[pageNr] = data;
callback();
} else {
this.texts[pageNr] = this.loadImage(url, null, null, 'image/svg+xml', pageNr, callback);
}
- },
- loadDatas: function (pageNr, callback) {
+ }, loadDatas: function (pageNr, callback) {
var $this = this;
this.loadTexts(pageNr, function () {
$this.setBackground(pageNr, function () {
callback();
});
});
- },
- getImage: function (src, width, height, type, callback) {
+ }, getImage: function (src, width, height, type, callback) {
var img = this.loadImage(src, width, height, type, null, callback);
return $(img).get(0).outerHTML;
},
function FluidbookSecure(fluidbook) {
this.fluidbook = fluidbook;
+ this.serverSideRecaptcha = true;
+ this.lastRecaptchaCall = 0;
this.init();
}
FluidbookSecure.prototype = {
init: function () {
+ if (this.fluidbook.settings.recaptcha) {
+ this.recaptcha('load', function () {
+
+ });
+ }
if (this.fluidbook.settings.restrictPrintDownload !== '') {
if (window.location.search.indexOf(this.fluidbook.settings.restrictPrintDownload) === -1) {
if (this.fluidbook.settings.restrictPrint) {
}
},
+ recaptcha: function (action, callback) {
+ var now = Date.now();
+ var limit = now - 60000;
+ if (this.lastRecaptchaCall > limit) {
+ callback();
+ return;
+ }
+ this.lastRecaptchaCall = now;
+
+ var $this = this;
+ try {
+ grecaptcha.ready(function () {
+ grecaptcha.execute(this.fluidbook.settings.recaptcha, {action: action}).then(function (token) {
+ if ($this.serverSideRecaptcha) {
+ $.ajax({
+ method: 'post',
+ url: '_recaptcha.php',
+ data: {token: token},
+ complete: callback,
+ error: function (data) {
+ $this.serverSideRecaptcha = false;
+ callback();
+ },
+ });
+ } else {
+ callback();
+ }
+ });
+ });
+ } catch (e) {
+ callback();
+ }
+ },
+
checkSecure: function (callback) {
if (this.fluidbook.settings.secureURL !== 'http://' && this.fluidbook.settings.secureURL !== '') {
return this.checkSecureByURL(callback);
checkSecureByURL: function (callback) {
var $this = this;
$.ajax({
- url: $this.fluidbook.settings.secureURL,
- crossDomain: true,
- method: 'GET',
- type: 'json',
- xhrFields: {
+ url: $this.fluidbook.settings.secureURL, crossDomain: true, method: 'GET', type: 'json', xhrFields: {
withCredentials: true
- },
- success: function (data) {
+ }, success: function (data) {
var res = data.data[0]['logged-in'];
if (res !== undefined && res !== null) {
if (res === true) {
$this.secureByURLNOK();
}
}
- },
- error: function (e) {
+ }, error: function (e) {
console.log(e);
callback();
}