]> _ Git - fluidbook-html5.git/commitdiff
wait #6167 @2
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 24 Aug 2023 09:31:59 +0000 (11:31 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 24 Aug 2023 09:31:59 +0000 (11:31 +0200)
js/libs/fluidbook/fluidbook.tabs.js

index 30568046e65e1028522815dbf44ff6fb5500c4af..7252b1cb82925af4a609ba6597b803cfd12e275b 100644 (file)
@@ -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];
+    },
 };