]> _ Git - fluidbook-html5.git/commitdiff
wait #5519 @1.5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 13 Oct 2022 12:50:47 +0000 (14:50 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 13 Oct 2022 12:50:47 +0000 (14:50 +0200)
js/libs/fluidbook/fluidbook.tabs.js

index 850950cc335827595f2875dd3250597596a5afd1..6b5e2c0c1e72403572687f9785e3017c3406d275 100644 (file)
@@ -118,13 +118,6 @@ FluidbookTabs.prototype = {
     },
 
     addLinks: function (pages) {
-        pages = pages.map(function (x) {
-            if (x === '-') {
-                return '-';
-            }
-            return parseInt(x);
-        });
-
         this.links = [];
         var $this = this;
         var sections = [];
@@ -134,12 +127,21 @@ FluidbookTabs.prototype = {
                 var sectionPages = [];
                 var foundOnePage = false;
                 $.each(pages, function (k, p) {
+                    let weight = 1;
+                    let e = p.split('*');
+                    if (e.length === 2) {
+                        weight = parseInt(e[1]);
+                        p = e[0];
+                    }
+                    let page = {page: p, weight: weight};
+
                     if (p === '-' && foundOnePage) {
-                        sectionPages.push(p);
+                        sectionPages.push(page);
                     } else {
-                        if ($this.getSectionByPageNumber(p) - 1 === id) {
+                        page.page = parseInt(page.page);
+                        if ($this.getSectionByPageNumber(page.page) - 1 === id) {
                             foundOnePage = true;
-                            sectionPages.push(p);
+                            sectionPages.push(page);
                         } else if (foundOnePage) {
                             // Assume that if this page is not in the current section, next ones won't be either
                             return false;
@@ -149,28 +151,42 @@ FluidbookTabs.prototype = {
                 sections.push(sectionPages);
             });
         } else {
-            sections.push(pages);
+            var section = [];
+            $.each(pages, function (k, p) {
+                let weight = 1;
+                let e = p.toString().split('*');
+                if (e.length === 2) {
+                    weight = parseInt(e[1]);
+                    p = e[0];
+                }
+                section.push({page: p, weight: weight});
+            });
+            sections.push(section);
         }
 
         var index = 1;
         $.each(sections, function (k, sectionPages) {
-            var nbPages = sectionPages.length;
+            var totalWeight = 0;
+            $.each(sectionPages, function (k, value) {
+                totalWeight += value.weight;
+            });
+
             var i = 0;
             $.each(sectionPages, function (k, value) {
-                if (value !== '-') {
-                    var activeLandscape = value;
+                if (value.page !== '-') {
+                    var activeLandscape = parseInt(value.page);
                     if (!$this.fluidbook.alwaysDisplayOnePage && value % 2 === 1) {
                         activeLandscape--;
                     }
                     $this.links.push({
-                        css: {height: (100 / nbPages) + '%', top: (100 / nbPages * i) + '%'},
-                        page: parseInt(value),
+                        css: {height: (value.weight * (100 / totalWeight)) + '%', top: (100 / totalWeight * i) + '%'},
+                        page: parseInt(value.page),
                         pageActiveLandscape: activeLandscape,
                         index: index,
                         id: 'o' + index
                     });
                 }
-                i++;
+                i += value.weight;
                 index++;
             });
         });
@@ -216,6 +232,7 @@ FluidbookTabs.prototype = {
                 }
             });
         }
+        console.log(page,id);
 
         if (id === 'none') {
             this.svg.find('[id^="o"].active').removeClass('active');
@@ -254,7 +271,7 @@ FluidbookTabs.prototype = {
         }
         var section = 0;
         $.each(this.sections, function (k, v) {
-            if (page >= v) {
+            if (parseInt(page) >= v) {
                 section = k + 1;
             }
         });