]> _ Git - fluidbook-html5.git/commitdiff
wait #7985 @3:00
authorsoufiane <soufiane@cubedesigners.com>
Tue, 10 Feb 2026 16:12:36 +0000 (17:12 +0100)
committersoufiane <soufiane@cubedesigners.com>
Tue, 10 Feb 2026 16:12:36 +0000 (17:12 +0100)
js/libs/fluidbook/fluidbook.search.js

index dbecec4f638c8cba8cb73de13b9b73cc642c5204..6930736189f7b3989795d2ca7cdae77e61acdff4 100644 (file)
@@ -58,7 +58,6 @@ FluidbookSearch.prototype = {
         });
     },
 
-
     // The results nav bar provides navigation between results without needing the menu to be open
     // When it is active, the rest of the interface is hidden
     initResultsNav: function () {
@@ -998,6 +997,7 @@ FluidbookSearch.prototype = {
         }
 
         var $this = this;
+        let r = new Map();
         this.find(q, function (results) {
             $this.openResults(results);
         });
@@ -1041,8 +1041,11 @@ FluidbookSearch.prototype = {
 
         var spreadEnabled = 0;
         // Process each spread of pages to collect the ones with results
+
+        var pagesWithHits = [];
+
         this.menuSearchResults.find('.doubleThumb').each(function () {
-            var currentPages = $(this).data('pages').toString().split(','), totalHits = 0, pagesWithHits = [];
+            var currentPages = $(this).data('pages').toString().split(','), totalHits = 0;
 
             var firstPageWithResult;
 
@@ -1058,7 +1061,6 @@ FluidbookSearch.prototype = {
                 }
             }
 
-
             // If there's already a .hits element, this spread has already been processed
             if ($(this).find('.hits').length > 0) {
                 return;
@@ -1093,6 +1095,9 @@ FluidbookSearch.prototype = {
             }
         });
 
+        let referencePage = pagesWithHits.find((el) => el >= $this.fluidbook.currentPage) ?? parseInt(pagesWithHits[0])
+        console.log(referencePage)
+
         // Set Highlighting of results keywords
         this.setHighlightTerms(results.terms);
         this.hideSearchHints();
@@ -1101,8 +1106,8 @@ FluidbookSearch.prototype = {
         // Redirect to the only result page if the flag is enabled
         if(this.fluidbook.search.isSearchfloatActive && $this.menuSearchResults.find('.doubleThumb[data-enabled="1"]').length > 0) {
             setTimeout(function () {
-                fluidbook.setCurrentPage($this.menuSearchResults.find('.doubleThumb[data-enabled="1"]').attr('page'));
-                var pageNumber = parseInt($("#menuSearchResults a").find('.doubleThumb').attr('page'));
+                fluidbook.setCurrentPage($this.menuSearchResults.find('.doubleThumb[data-enabled="1"][data-pages*='+referencePage+']').attr('page'));
+                var pageNumber = parseInt($("#menuSearchResults a").find('.doubleThumb[data-enabled="1"][data-pages*='+referencePage+']').attr('page'));
                 $this.openResultsNav(pageNumber);
                 fluidbook.nav.burger.close();
             }, 100);