From e7ff0c8dd3d4855c2d498165bbe9436f8babb9ca Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Wed, 11 Jul 2018 17:46:13 +0200 Subject: [PATCH] wip #2132 @6 --- js/libs/fluidbook/fluidbook.bookmarks.js | 9 ++++-- js/libs/fluidbook/fluidbook.js | 34 ++++++++++++++------ js/libs/fluidbook/fluidbook.menu.js | 1 + js/libs/fluidbook/fluidbook.search.js | 14 ++++---- js/libs/fluidbook/fluidbook.slider.js | 3 +- js/libs/fluidbook/menu/fluidbook.chapters.js | 33 ++++++++++++++++--- js/libs/fluidbook/menu/fluidbook.index.js | 4 ++- js/libs/scorm/scorm.js | 2 +- 8 files changed, 73 insertions(+), 27 deletions(-) diff --git a/js/libs/fluidbook/fluidbook.bookmarks.js b/js/libs/fluidbook/fluidbook.bookmarks.js index 01e26f6d..3bb3efdd 100644 --- a/js/libs/fluidbook/fluidbook.bookmarks.js +++ b/js/libs/fluidbook/fluidbook.bookmarks.js @@ -120,7 +120,7 @@ FluidbookBookmarks.prototype = { return g.join(','); }, addGroup: function (from, nb, name) { - var to = Math.min(from + (nb - 1), this.fluidbook.getMaxPage()); + var to = Math.min(from + (nb - 1), this.fluidbook.pages); for (var i = from; i <= to; i++) { this._pagesToGroup[i] = this._groups; } @@ -129,13 +129,15 @@ FluidbookBookmarks.prototype = { this._groups++; }, completeGroups: function () { - for (var i = 1; i <= this.fluidbook.getMaxPage(); i++) { + for (var i = 1; i <= this.fluidbook.pages; i++) { if (this._pagesToGroup[i] == undefined || this._pagesToGroup[i] == null) { this._pagesToGroup[i] = this._groups; this._groupOrder.push(this._groups); this._groups++; } } + + console.log(this._pagesToGroup); }, getPreviousGroup: function (group) { var o = this.getOrderGroup(group); @@ -173,7 +175,7 @@ FluidbookBookmarks.prototype = { }, getPagesOfGroup: function (groupId) { var res = []; - for (var i = 1; i <= this.fluidbook.getMaxPage(); i++) { + for (var i = 1; i <= this.fluidbook.pages; i++) { if (this._pagesToGroup[i] == groupId) { res.push(i); } @@ -269,6 +271,7 @@ FluidbookBookmarks.prototype = { cornersOnly = false; } var pages = this.getLinkedPages(page); + console.log(pages); for (i in pages) { var page = pages[i]; if (!cornersOnly) { diff --git a/js/libs/fluidbook/fluidbook.js b/js/libs/fluidbook/fluidbook.js index 13acf3e5..8b9f0618 100644 --- a/js/libs/fluidbook/fluidbook.js +++ b/js/libs/fluidbook/fluidbook.js @@ -90,7 +90,10 @@ Fluidbook.prototype = { } $('html').addClass(this.datas.mobileLVersion); this.currentPage = -1; - this.maxPage = this.getMaxPage(); + this.maxPage = this.datas.pages; + if (this.datas.maxPages > 0) { + this.maxPage = Math.min(this.datas.maxPages, this.datas.pages); + } this.resize = new FluidbookResize(this); this.stats = new FluidbookStats(this); @@ -101,7 +104,11 @@ Fluidbook.prototype = { }, setMaxPage: function (p) { - this.maxPage = p; + if (p === undefined) { + p = this.datas.pages; + } + + this.maxPage = Math.min(p, this.datas.pages); this.updateMaxPage(); }, @@ -109,8 +116,14 @@ Fluidbook.prototype = { return this.maxPage; }, - updateMaxPage() { - + updateMaxPage: function () { + if (this.currentPage > this.maxPage) { + this.setCurrentPage(this.maxPage); + } else { + this.reloadCurrentPage(); + } + this.hideUnnecessaryButtons(); + resize(); }, initTheme: function () { @@ -353,7 +366,7 @@ Fluidbook.prototype = { this.transitionAxis = 'x'; } if (page != $this.currentPage) { - $($this).trigger('changePage', [page]); + $($this).trigger('fluidbook.page.navigation', [page]); } if (this.landingpage !== undefined) { this.landingpage.hide(); @@ -404,7 +417,6 @@ Fluidbook.prototype = { return; }, pageTransition: function (pageNr) { - $(this).trigger('fluidbook.beforePageTransition'); this.tooltip.hideTooltip(); @@ -419,15 +431,12 @@ Fluidbook.prototype = { if (pageNr == this.normalizePage(this.currentPage) || this.currentPage == -1 || !this.support.transitions2d || this.datas.mobileTransitions == 'none') { return this.pageTransition1D(pageNr); } - if (this.displayOnePage) { return this.pageTransition2DPortrait(pageNr); } - if (!this.support.transitions3d || this.datas.mobileTransitions == 'slide') { return this.pageTransition2D(pageNr); } - return this.pageTransition3D(pageNr); }, pageTransition3D: function (pageNr) { @@ -869,7 +878,12 @@ Fluidbook.prototype = { var $this = this; var pdf; var pdfName; - if (this.datas.pdfName.substr(0, 4) == 'http') { + + console.log('open PDF : ' + this.datas.pages + " || " + this.getMaxPage()); + + if (this.datas.pages != this.getMaxPage()) { + pdf = 'https://workshop.fluidbook.com/s/e/' + this.datas.cid + '/1-' + this.getMaxPage(); + } else if (this.datas.pdfName.substr(0, 4) == 'http') { pdf = this.datas.pdfName; } else { pdf = this.relativeToAbsolute('data/' + this.datas.pdfName); diff --git a/js/libs/fluidbook/fluidbook.menu.js b/js/libs/fluidbook/fluidbook.menu.js index 9e42ce78..873a347a 100644 --- a/js/libs/fluidbook/fluidbook.menu.js +++ b/js/libs/fluidbook/fluidbook.menu.js @@ -374,6 +374,7 @@ FluidbookMenu.prototype = { } $("#view").append(''); + this.fluidbook.chapters.removeItemsAfterMaxPage(); if (callback != undefined) { callback(); } diff --git a/js/libs/fluidbook/fluidbook.search.js b/js/libs/fluidbook/fluidbook.search.js index e5e959c8..7783e850 100644 --- a/js/libs/fluidbook/fluidbook.search.js +++ b/js/libs/fluidbook/fluidbook.search.js @@ -112,7 +112,7 @@ FluidbookSearch.prototype = { this.resultPages = []; var q, v, k, kk, word, wordata, page, occurences, p; - + var maxPage = this.fluidbook.getMaxPage(); for (kk in words) { q = words[kk]; @@ -133,6 +133,9 @@ FluidbookSearch.prototype = { for (page in v.p) { var occurences = v.p[page]; page = parseInt(page); + if (page > maxPage) { + continue; + } if ((page % 2) == 1) { page--; } @@ -182,6 +185,7 @@ FluidbookSearch.prototype = { var terms = []; var total = 0; var doublesPages = []; + var maxPage = this.fluidbook.getMaxPage(); for (var p in TEXTS) { var t = TEXTS[p]; @@ -197,6 +201,9 @@ FluidbookSearch.prototype = { continue; } page = parseInt(p); + if (page > maxPage) { + continue; + } if ((page % 2) == 1) { page--; } @@ -425,10 +432,8 @@ FluidbookSearch.prototype = { }); }, displaySearchHints: function (hints) { - var $this = this; - //this.hideSearchHints(); if (hints.length == 0) { return; } @@ -454,9 +459,6 @@ FluidbookSearch.prototype = { this.kill(); }, hideSearchHints: function () { - // this.killLastSearchHint(); - // $("#searchHints").html(''); - // $("#searchHints").hide(); this.menuSearchHints.html('').hide(); // Clear and hide all hints }, diff --git a/js/libs/fluidbook/fluidbook.slider.js b/js/libs/fluidbook/fluidbook.slider.js index 22970704..80a40603 100644 --- a/js/libs/fluidbook/fluidbook.slider.js +++ b/js/libs/fluidbook/fluidbook.slider.js @@ -109,16 +109,15 @@ FluidbookSlider.prototype = { } return Math.min(this.fluidbook.getMaxPage(), Math.max(pageMin, page)); - }, resize: function (ww, hh, single) { - if (single) { this.sliderWidth = ww / 2; } else { this.sliderWidth = this.fluidbook.resize.getScreenFluidbookWidth() * 0.4; } + this.sliderWidth = Math.round(this.sliderWidth); var bottom = 26; if (single) { diff --git a/js/libs/fluidbook/menu/fluidbook.chapters.js b/js/libs/fluidbook/menu/fluidbook.chapters.js index 10b7b595..bbc8d5f2 100644 --- a/js/libs/fluidbook/menu/fluidbook.chapters.js +++ b/js/libs/fluidbook/menu/fluidbook.chapters.js @@ -21,6 +21,7 @@ FluidbookChapters.prototype = { if (this.html[sub] == null) { this.makeView(sub); } + return {sub: sub, view: this.html[sub], title: this.titles[sub], color: this.colors[sub]}; }, makeView: function (sub) { @@ -143,9 +144,11 @@ FluidbookChapters.prototype = { var href; var level = chapter.level - baseLevel; + var p = ''; if (chapter.page != '') { - var p = this.fluidbook.virtualToPhysical(chapter.page); + p = this.fluidbook.virtualToPhysical(chapter.page); if (p === false) { + p=''; href = this.cascade ? 'href="#"' : "nohref"; } else { href = 'href="#/page/' + p + '"'; @@ -154,9 +157,9 @@ FluidbookChapters.prototype = { href = this.cascade ? 'href="#"' : "nohref"; } if (this.style == 'classic') { - res += '
  • '; + res += '
  • '; } else if (this.style == 'ina') { - res += '
  • '; + res += '
  • '; } res += '' + chapter.label + ''; if (href != 'nohref') { @@ -181,6 +184,28 @@ FluidbookChapters.prototype = { res += '
  • '; return res; - } + }, + + removeItemsAfterMaxPage: function () { + + var max = this.fluidbook.getMaxPage(); + $('.mview[data-menu="chapters"] ul.chapters li[data-page]').each(function () { + var p = parseInt($(this).data('page')); + if (isNaN(p)) { + return; + } + if (p > max) { + $(this).remove(); + } + }); + + for(var i=0;i<=10;i++) { + $('.mview[data-menu="chapters"] ul.chapters li[data-page=""]').each(function () { + if ($(this).find('ul li').length == 0) { + $(this).remove(); + } + }); + } + }, }; diff --git a/js/libs/fluidbook/menu/fluidbook.index.js b/js/libs/fluidbook/menu/fluidbook.index.js index 424d26e2..7badda99 100644 --- a/js/libs/fluidbook/menu/fluidbook.index.js +++ b/js/libs/fluidbook/menu/fluidbook.index.js @@ -8,6 +8,7 @@ FluidbookIndex.prototype = { this.normalHTML = ''; this.padHTML = ''; }, + getView: function (group) { if (this.fluidbook.pad.enabled) { return this.getPadView(group); @@ -15,11 +16,12 @@ FluidbookIndex.prototype = { return this.getNormalView(); } }, + getPadView: function (group) { return this.fluidbook.bookmarks.getIndex(true, group); }, - getNormalView: function () { + getNormalView: function () { if (this.normalHTML == '') { this.normalHTML += '
    '; var j = 0; diff --git a/js/libs/scorm/scorm.js b/js/libs/scorm/scorm.js index 7c99737e..edd4a396 100644 --- a/js/libs/scorm/scorm.js +++ b/js/libs/scorm/scorm.js @@ -82,7 +82,7 @@ function initScormEvents() { console.log(err); } - $(fluidbook).on('changePage', function (e, page) { + $(fluidbook).on('fluidbook.page.navigation', function (e, page) { setScormValue('location', 'page_' + page); }); -- 2.39.5