var re = 0;
for (var i = 0; i < this.bookmarks.length; i++) {
var b = this.bookmarks[i];
- if (b > this.fluidbook.getMaxPage()) {
+ if (b > this.fluidbook.contentlock.getMaxPage()) {
continue;
}
if (rs == 0) {
var res = [];
var nb;
var groupId;
- for (var i = 1; i <= this.fluidbook.getMaxPage();) {
+ for (var i = 1; i <= this.fluidbook.contentlock.getMaxPage();) {
if (this.isBookmarked(i) || !onlyBookmarked) {
groupId = this.getGroupOfPage(i);
nb = this.getPagesNumberInGroup(groupId);
var bookmarks = "";
for (var i = pageNr; i <= to; i++) {
- if (i > 0 && i <= this.fluidbook.getMaxPage()) {
+ if (i > 0 && i <= this.fluidbook.contentlock.getMaxPage()) {
var side;
if (allwaysAtRight) {
side = 'right';
--- /dev/null
+function FluidbookContentLock(fluidbook) {
+ this.fluidbook = fluidbook;
+ this.maxPage;
+ this.linksActions = {};
+ this.locks = this.fluidbook.datas.content_lock;
+}
+
+FluidbookContentLock.prototype = {
+ init: function () {
+ var $this = this;
+
+ key('⌘+alt+u, ctrl+alt+u', function () {
+ $this.setMaxPage();
+ });
+
+ this.maxPage = this.getNextLockPage();
+ if (this.maxPage <= 0) {
+ this.maxPage = this.fluidbook.datas.pages;
+ }
+ },
+
+ getNextLockPage: function () {
+ var res = 0;
+
+ $.each(this.locks, function (k, v) {
+ if (v.unlocked === 1) {
+ return;
+ }
+ res = k;
+ return true;
+ });
+ return res;
+ },
+
+ setMaxPage: function (p, allowbackwards) {
+ var currentMaxPage = this.maxPage;
+ if (allowbackwards === undefined) {
+ allowbackwards = false;
+ }
+ if (p === undefined || p <= 0) {
+ p = this.fluidbook.datas.pages;
+ }
+
+ if (!allowbackwards && p < this.maxPage) {
+ return;
+ }
+
+ this.maxPage = Math.min(p, this.fluidbook.datas.pages);
+ if (currentMaxPage === this.maxPage) {
+ return;
+ }
+ $(this.fluidbook).trigger('fluidbook.maxpage.set', [this.maxPage]);
+ this.updateMaxPage();
+ },
+
+ getMaxPage: function () {
+ return this.maxPage;
+ },
+
+ updateMaxPage: function () {
+ if (this.fluidbook.currentPage > this.maxPage) {
+ this.fluidbook.setCurrentPage(this.maxPage);
+ }
+
+ var $this = this;
+ $.each(this.locks, function (k, v) {
+ if ($this.maxPage > k) {
+ $this.locks.unlocked = 1;
+ }
+ }
+ );
+
+ this.fluidbook.hideUnnecessaryButtons();
+ resize();
+ },
+
+ addAction: function (linkId, action) {
+
+ if (this.linksActions[linkId] === undefined) {
+ this.linksActions[linkId] = [];
+ }
+ if (this.linksActions[linkId].indexOf(action) === -1) {
+ this.linksActions[linkId].push(action);
+ }
+
+ console.log(this.linksActions);
+
+ this.testConditions();
+ },
+
+ testConditions: function () {
+ var $this=this;
+ var change = false;
+ $.each(this.locks, function (k, v) {
+ if (v.unlocked === 1) {
+ return;
+ }
+ if (v.conditions.length === 0) {
+ return;
+ }
+
+ var conditionsToObserve = v.conditions.length;
+ $.each(v.conditions, function (i, c) {
+ if ($this.testCondition(c)) {
+ conditionsToObserve--;
+ }
+ });
+
+ if (conditionsToObserve === 0) {
+ $this.locks[k].unlocked = 1;
+ change = true;
+ }
+ });
+
+ if (change) {
+ this.setMaxPage(this.getNextLockPage(), false)
+ }
+ },
+
+ testCondition: function (condition) {
+ var linkId = condition[0];
+ var action = condition[1];
+
+ if (this.linksActions[linkId] === undefined) {
+ return false;
+ }
+
+ return this.linksActions[linkId].indexOf(action) >= 0;
+ },
+}
\ No newline at end of file
if (this.datas.landingPage != undefined && this.datas.landingPage != '') {
this.landingpage = new FluidbookLandingPage(this);
}
+ this.contentlock = new FluidbookContentLock(this);
this.menu = new FluidbookMenu(this);
this.zoom = new FluidbookZoom(this);
this.zoom.resetZoom();
$('html').addClass(this.datas.mobileLVersion);
this.currentPage = -1;
- this.initMaxPage();
+ this.contentlock.init();
this.resize = new FluidbookResize(this);
this.stats = new FluidbookStats(this);
}, 10);
},
- initMaxPage: function () {
- var $this = this;
- key('⌘+alt+r, ctrl+alt+u', function () {
- $this.setMaxPage(0);
- });
-
- this.maxPage = this.datas.pages;
- if (this.datas.maxPages > 0) {
- this.maxPage = Math.min(this.datas.maxPages, this.datas.pages);
- }
- },
-
setMaxPage: function (p, allowbackwards) {
- var currentMaxPage = this.maxPage;
- if (allowbackwards === undefined) {
- allowbackwards = false;
- }
- if (p === undefined || p <= 0) {
- p = this.datas.pages;
- }
-
- if (!allowbackwards && p < this.maxPage) {
- return;
- }
-
- this.maxPage = Math.min(p, this.datas.pages);
- if (currentMaxPage === this.maxPage) {
- return;
- }
- $(this).trigger('fluidbook.maxpage.set', [this.maxPage]);
- this.updateMaxPage();
- },
-
- getMaxPage: function () {
- return this.maxPage;
- },
-
- updateMaxPage: function () {
- if (this.currentPage > this.maxPage) {
- this.setCurrentPage(this.maxPage);
- } else {
- //this.reloadCurrentPage();
- }
- this.hideUnnecessaryButtons();
- resize();
+ return this.contentlock.setMaxPage(p, allowbackwards);
},
initTheme: function () {
});
},
initKeyboardShortcuts: function () {
-
// General keyboard shortcuts
key('home', this.goFirstPage.bind(this));
key('end', this.goLastPage.bind(this));
return;
}
this.transitionAxis = 'x';
- this.setCurrentPage(this.getMaxPage());
+ this.setCurrentPage(this.contentlock.getMaxPage());
},
goNextChapter: function () {
if (this.transitionning) {
this.setCurrentPage(this.normalizePage(prev));
},
normalizePage: function (page) {
- page = Math.max(1, Math.min(page, this.getMaxPage()));
+ page = Math.max(1, Math.min(page, this.contentlock.getMaxPage()));
if (!this.displayOnePage && page % 2 == 1) {
page--;
}
if (center) {
if (newPage <= 1) {
res.center = -1;
- } else if (this.getMaxPage() % 2 == 0 && newPage == this.getMaxPage()) {
+ } else if (this.contentlock.getMaxPage() % 2 == 0 && newPage == this.contentlock.getMaxPage()) {
res.center = 1;
}
}
speed = 0;
}
- var max = this.getMaxPage() % 2 == 1 ? this.getMaxPage() - 1 : this.getMaxPage();
+ var max = this.contentlock.getMaxPage() % 2 == 1 ? this.contentlock.getMaxPage() - 1 : this.contentlock.getMaxPage();
var next = page < max;
var previous = (page > 1);
if (this.displayOnePage) {
right = true;
} else {
- if ((page <= 1 && this.l10n.dir == 'ltr') || (page >= this.getMaxPage() && this.l10n.dir == 'rtl')) {
+ if ((page <= 1 && this.l10n.dir == 'ltr') || (page >= this.contentlock.getMaxPage() && this.l10n.dir == 'rtl')) {
left = false;
- } else if ((page <= 1 && this.l10n.dir == 'rtl') || (page >= this.getMaxPage() && this.l10n.dir == 'ltr')) {
+ } else if ((page <= 1 && this.l10n.dir == 'rtl') || (page >= this.contentlock.getMaxPage() && this.l10n.dir == 'ltr')) {
right = false;
}
}
$(".axis_y").removeClass('axis_y');
$(".axis_x").removeClass('axis_x');
$("#links").hide();
+ this.scorm.hideScormLinks();
this.hideLoader();
this.hideUnnecessaryButtons(page);
var animationDuration = d <= 1 ? 0 : parseFloat(this.datas.mobileTransitionDuration);
}
this.transitionning = false;
if (this.pad.enabled) {
- if (this.currentPage == this.getMaxPage()) {
+ if (this.currentPage == this.contentlock.getMaxPage()) {
$("#down").css('opacity', 0);
} else {
$("#down").css('opacity', 1);
var pdf;
var pdfName;
- console.log('open PDF : ' + this.datas.pages + " || " + this.getMaxPage());
+ console.log('open PDF : ' + this.datas.pages + " || " + this.contentlock.getMaxPage());
- if (this.datas.pages != this.getMaxPage()) {
- pdf = 'https://workshop.fluidbook.com/s/e/' + this.datas.cid + '/1-' + this.getMaxPage();
+ if (this.datas.pages != this.contentlock.getMaxPage()) {
+ pdf = 'https://workshop.fluidbook.com/s/e/' + this.datas.cid + '/1-' + this.contentlock.getMaxPage();
} else if (this.datas.pdfName.substr(0, 4) == 'http') {
pdf = this.datas.pdfName;
} else {
this.lowdef = this.fluidbook.support.android || this.fluidbook.support.iOS;
+ $(document).on('click', '[data-id] a', function () {
+ $this.fluidbook.contentlock.addAction($(this).closest('[data-id]').attr('data-id'), 'click');
+ return true;
+ });
+
$(document).on('click', '[href^="#"]:not([href="#"])', function () {
location.hash = $(this).attr('href');
return false;
var $callback = callback;
var $page = $pages.shift();
- if ($page > this.fluidbook.getMaxPage() || $page < 1) {
+ if ($page > this.fluidbook.contentlock.getMaxPage() || $page < 1) {
$this.preloadPagesBeforeTransition($pages, $callback);
return;
}
numPreloadAfter = 3;
numPreloadBefore = 1;
}
- var max = Math.min(page + numPreloadAfter, this.fluidbook.getMaxPage());
+ var max = Math.min(page + numPreloadAfter, this.fluidbook.contentlock.getMaxPage());
var min = Math.max(1, page - numPreloadBefore);
this.toPreload = [];
for (var i = min; i <= max; i++) {
this.preloadPages();
},
cleanPreloaded: function () {
- for (var i = 1; i <= this.fluidbook.getMaxPage(); i++) {
+ for (var i = 1; i <= this.fluidbook.contentlock.getMaxPage(); i++) {
if (this.backgrounds[i] != undefined && this.toPreload.indexOf(i) == -1) {
this.deletePage(i);
}
return this.loadImage('images/shadows/pages/' + position + '.png', this.fluidbook.datas.width / 4, this.fluidbook.datas.height);
},
loadLeftPage: function (page, doublePage, callback) {
- if (page > 0 && page <= this.fluidbook.getMaxPage()) {
+ if (page > 0 && page <= this.fluidbook.contentlock.getMaxPage()) {
this.loadPage(page, doublePage, 'left', callback);
} else {
$(doublePage).find('.left').remove();
}
},
loadRightPage: function (page, doublePage, callback) {
- if (!this.fluidbook.displayOnePage && page <= this.fluidbook.getMaxPage() && page > 0) {
+ if (!this.fluidbook.displayOnePage && page <= this.fluidbook.contentlock.getMaxPage() && page > 0) {
this.loadPage(page, doublePage, 'right', callback);
} else {
$(doublePage).find('.right').remove();
this.resultPages = [];
var q, v, k, kk, word, wordata, page, occurences, p;
- var maxPage = this.fluidbook.getMaxPage();
+ var maxPage = this.fluidbook.contentlock.getMaxPage();
for (kk in words) {
q = words[kk];
var terms = [];
var total = 0;
var doublesPages = [];
- var maxPage = this.fluidbook.getMaxPage();
+ var maxPage = this.fluidbook.contentlock.getMaxPage();
for (var p in TEXTS) {
var t = TEXTS[p];
}
pageNrs.push(pageNr);
pageNr++;
- if (pageNr < this.fluidbook.getMaxPage()) {
+ if (pageNr < this.fluidbook.contentlock.getMaxPage()) {
pageNrs.push(pageNr);
}
}
var hits = [];
// Create a list of all pages so we can record which ones have a hit on the search term
- for (var i = 0; i <= this.fluidbook.getMaxPage(); i++) {
+ for (var i = 0; i <= this.fluidbook.contentlock.getMaxPage(); i++) {
hits[i] = 0;
}
// Map result hits to pages
pageMin = 0;
}
- return Math.min(this.fluidbook.getMaxPage(), Math.max(pageMin, page));
+ return Math.min(this.fluidbook.contentlock.getMaxPage(), Math.max(pageMin, page));
},
resize: function (ww, hh, single) {
updateSnaps: function (single) {
if (single) {
- this.snapsCount = this.fluidbook.getMaxPage();
+ this.snapsCount = this.fluidbook.contentlock.getMaxPage();
} else {
- this.snapsCount = Math.floor(this.fluidbook.getMaxPage() / 2) + 1;
+ this.snapsCount = Math.floor(this.fluidbook.contentlock.getMaxPage() / 2) + 1;
}
this.cursorWidth = Math.max(30, this.sliderWidth / this.snapsCount);
this.snapsWidth = (this.sliderWidth - this.cursorWidth) / (this.snapsCount - 1);
getCursorXByPage: function (page) {
var left;
if (this.fluidbook.l10n.rtl) {
- page = this.fluidbook.getMaxPage() - page;
+ page = this.fluidbook.contentlock.getMaxPage() - page;
}
if (this.fluidbook.resize.orientation == 'portrait') {
left = this.snapsWidth * (page - 1);
if (page > 0) {
left = page;
}
- if (page <= this.fluidbook.getMaxPage()) {
+ if (page <= this.fluidbook.contentlock.getMaxPage()) {
right = page + 1;
}
}
setThumb: function (thumb, page, shade) {
thumb.find('.bookmark').attr('data-page', page);
- if (page > 0 && page <= this.fluidbook.getMaxPage()) {
+ if (page > 0 && page <= this.fluidbook.contentlock.getMaxPage()) {
thumb.css('visibility', 'visible');
this.fluidbook.loader.getThumbImage(page, thumb.find('.img'), shade);
thumb.find('a').attr('href', '#/page/' + page);
page--;
}
- var last = this.fluidbook.getMaxPage();
+ var last = this.fluidbook.contentlock.getMaxPage();
if (last % 2 == 1) {
last++;
}
$this.resizeControls();
});
- $(window).on('videoFullscreenEntered', function() {
+ $(window).on('videoFullscreenEntered', function () {
//console.log('>>> Video player entered full screen mode...');
$this.fullscreenActive = true;
});
- $(window).on('videoFullscreenExited', function() {
+ $(window).on('videoFullscreenExited', function () {
//console.log('<<< Video player exited full screen mode.');
// Try resizing after a short delay. Depending on the system and the speed of the
- setTimeout(function() {
+ setTimeout(function () {
$this.fluidbook.resize.resize();
}, 250);
- setTimeout(function() {
+ setTimeout(function () {
$this.fullscreenActive = false; // Stop blocking orientation change / page updates
$this.fluidbook.resize.resize();
}, 1000);
});
-
this.fluidbook = fluidbook;
this.video = (Modernizr.video && (Modernizr.video.h264 || Modernizr.video.webm || Modernizr.video.ogg)) != false;
sound = $(e).data('sound'),
autoplay = $(e).data('autoplay'),
setup = $(e).data('setup'),
+ linkid = $(e).data('link-id'),
path,
poster,
html,
player.pause();
}, 100);
}
-
});
-
player.play(); // Start player to go to current position - necessary even if it will be paused immediately
if (settings.paused) {
player.pause();
}
+ setTimeout(function () {
+ $this.fluidbook.contentlock.addAction(linkid, 'complete');
+ }, (player.duration() - 5) * 1000);
+
// var playPromise = player.play();
// if (settings.paused) {
// if (playPromise && (typeof Promise !== 'undefined') && (playPromise instanceof Promise)) {
// $('#' + player.id()).attr('style', ''); // Reset inline styles
// });
- player.on('fullscreenchange', function() {
+ player.on('fullscreenchange', function () {
if (player.isFullscreen()) {
$(window).trigger('videoFullscreenEntered');
} else {
}
});
+ player.on('ended', function () {
+ $this.fluidbook.contentlock.addAction(linkid, 'complete');
+ });
},
openVideo: function (link) {
if (link === undefined) return false;
if (skipPopupVideos) {
// Filter out any videos that exist inside the #view element
playersToBeRemoved = playersToBeRemoved.filter(function (player) {
- return ! $.contains(document.getElementById('view'), document.getElementById(player.id()));
+ return !$.contains(document.getElementById('view'), document.getElementById(player.id()));
});
}
view += '<form class="cart-bourbon-suggest" action="" method="post">';
view += '<div>';
view += '<label>Page number';
- view += '<input type="text" id="bourbon-suggestion-page" data-parsley-type="integer" name="page" value="' + this.fluidbook.currentPage + '" min="0" max="' + this.fluidbook.getMaxPage() + '" tabindex="100" required>';
+ view += '<input type="text" id="bourbon-suggestion-page" data-parsley-type="integer" name="page" value="' + this.fluidbook.currentPage + '" min="0" max="' + this.fluidbook.contentlock.getMaxPage() + '" tabindex="100" required>';
view += '</label>';
view += '<label>Suggestion type';
view += '<select id="bourbon-suggestion-type"><option>TYPO / WORDING</option><option>CLARIFICATION REQUEST</option><option>IMPROVEMENT SUGGESTION (Gaps, Ideas, etc)</option></select>';
removeItemsAfterMaxPage: function () {
- var max = this.fluidbook.getMaxPage();
+ var max = this.fluidbook.contentlock.getMaxPage();
$('.mview[data-menu="chapters"] ul.chapters li[data-page]').each(function () {
var p = parseInt($(this).data('page'));
if (isNaN(p)) {
var c = '';
var s1, s2;
- for (var i = 0; i <= this.fluidbook.getMaxPage(); i += 2) {
+ for (var i = 0; i <= this.fluidbook.contentlock.getMaxPage(); i += 2) {
var pages = [];
j = i + 1;
ix1 = '';
s2 = 'left'
}
- if (j <= this.fluidbook.getMaxPage()) {
+ if (j <= this.fluidbook.contentlock.getMaxPage()) {
ix2 += '<div class="thumb ' + s1 + '"><a href="#/page/' + j + '">' + this.fluidbook.loader.getThumbImage(j, null, true) + '</a><span class="number">' + this.fluidbook.physicalToVirtual(j) + '</span>';
if (this.fluidbook.bookmarks.enabled) {
ix2 += this.fluidbook.bookmarks.getBookmarkForPage(j, true);
} else if (currentLocation.indexOf('{') === 0) {
var location = JSON.parse(currentLocation);
if (location.maxPage) {
- fluidbook.setMaxPage(location.maxPage, true);
+ fluidbook.contentlock.setMaxPage(location.maxPage, true);
}
if (location.page) {
fluidbook.setCurrentPage(location.page);
page = fluidbook.currentPage;
}
if (maxPage === undefined) {
- maxPage = fluidbook.getMaxPage();
+ maxPage = fluidbook.contentlock.getMaxPage();
}
setScormValue('location', JSON.stringify({page: page, maxPage: maxPage}));
}