From: Vincent Vanwaelscappel Date: Thu, 24 Aug 2023 09:31:59 +0000 (+0200) Subject: wait #6167 @2 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=51616e6b2bd50d1f861e0e8b63a497a6cd9aea88;p=fluidbook-html5.git wait #6167 @2 --- diff --git a/js/libs/fluidbook/fluidbook.tabs.js b/js/libs/fluidbook/fluidbook.tabs.js index 30568046..7252b1cb 100644 --- a/js/libs/fluidbook/fluidbook.tabs.js +++ b/js/libs/fluidbook/fluidbook.tabs.js @@ -117,11 +117,18 @@ FluidbookTabs.prototype = { this.changePage(this.fluidbook.currentPage); }, + areLinksSetFromEditor: function () { + return this.fluidbook.settings.links.tabs !== undefined && this.fluidbook.settings.links.tabs.normal !== undefined; + }, + addLinks: function (pages) { + if (this.areLinksSetFromEditor()) { + return; + } this.links = []; + var $this = this; var sections = []; - if (this.hasSections()) { $.each(this.sections, function (id, limit) { var sectionPages = []; @@ -232,8 +239,6 @@ FluidbookTabs.prototype = { } }); } - console.log(page, id); - if (id === 'none') { this.svg.find('[id^="o"].active').removeClass('active'); } else { @@ -300,6 +305,11 @@ FluidbookTabs.prototype = { createLinks: function () { var $this = this; + if (this.areLinksSetFromEditor()) { + this.createLinksFromEditor(); + return; + } + var commoncss = {}; commoncss.width = (100 * (this.linkWidth / this.naturalDimensions.width)) + "%"; commoncss.left = (-100 * (this.margin / this.naturalDimensions.width)) + "%"; @@ -322,6 +332,30 @@ FluidbookTabs.prototype = { }); }, + createLinksFromEditor: function () { + let $this = this; + const dims = ['left', 'top', 'width', 'height']; + $.each(this.fluidbook.settings.links.tabs.normal, function (k, link) { + var l = $(link); + $this.cont.append(l); + $.each(dims, function (k, dim) { + let v = parseFloat($(l).css(dim)); + let div = $this.naturalDimensions.height; + if (dim === 'left' || dim === 'width') { + div = $this.naturalDimensions.width; + } + $(l).css(dim, (100 * (v / div) + '%')); + }); + const a = $(l).find('a'); + let href = a.attr('href'); + href = href.replace(/^#\/page\/o(\d+)$/, function (match, tab, offset, string) { + return '#/page/' + $this.getTabPageNumber(tab); + }); + $(a).attr('href', href); + $(l).addClass('tablink'); + }); + }, + initStandardEvents: function () { var $this = this; @@ -462,4 +496,8 @@ FluidbookTabs.prototype = { console.log(css); this.cont.css(css); }, + + getTabPageNumber: function (tab) { + return this.fluidbook.settings.tabsPages[tab - 1]; + }, };