]> _ Git - fluidbook-html5.git/commitdiff
wait #5575 @1
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 24 Nov 2022 09:26:32 +0000 (10:26 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 24 Nov 2022 09:26:32 +0000 (10:26 +0100)
js/libs/fluidbook/fluidbook.search.js

index 6313808f408735edaa8020715945de5e3934ef60..f6791468a25ce97c09b49515eecfbf378a9a8b1d 100644 (file)
@@ -108,8 +108,7 @@ FluidbookSearch.prototype = {
 
             $this.updateResultsNav($this.fluidbook.currentPage);
         });
-    },
-    resultsNavActive: function () {
+    }, resultsNavActive: function () {
         return $('body').hasClass(this.resultsActiveClass);
     },
 
@@ -144,8 +143,7 @@ FluidbookSearch.prototype = {
 
         this.resultsNav.find('.searchResultsNavQuery').text($('#q').val());
         this.resultsNav.find('.searchResultsNavCounter').text(counterText);
-    },
-    openResultsNav: function (resultPage) {
+    }, openResultsNav: function (resultPage) {
         this.updateResultsNav(resultPage);
         this.hideableElements.addClass('hidden');
         this.resultsNav.removeClass('hidden');
@@ -183,8 +181,7 @@ FluidbookSearch.prototype = {
         }
 
         $('body').removeClass(this.resultsActiveClass);
-    },
-    nextResultsPage: function () {
+    }, nextResultsPage: function () {
         var currentIndex = this.resultNavPages.indexOf(fluidbook.currentPage);
         var nextIndex = currentIndex + 1;
 
@@ -196,8 +193,7 @@ FluidbookSearch.prototype = {
 
         this.updateResultsNav(nextPage);
         this.fluidbook.setCurrentPage(nextPage);
-    },
-    previousResultsPage: function () {
+    }, previousResultsPage: function () {
         var currentIndex = this.resultNavPages.indexOf(fluidbook.currentPage);
         var prevIndex = currentIndex - 1;
 
@@ -216,14 +212,12 @@ FluidbookSearch.prototype = {
         this._loadLib(function () {
             $this._getHints(q, callback);
         });
-    },
-    find: function (q, callback) {
+    }, find: function (q, callback) {
         var $this = this;
         this._loadLib(function () {
             $this._find(q, callback);
         });
-    },
-    _loadLib: function (callback) {
+    }, _loadLib: function (callback) {
         if (this.indexLoaded) {
             return callback();
         }
@@ -251,8 +245,7 @@ FluidbookSearch.prototype = {
         } else {
             callback();
         }
-    },
-    _getHints: function (q, callback) {
+    }, _getHints: function (q, callback) {
         var words = this.normalizeQuery(q, true);
         q = words.pop();
         var res = [];
@@ -361,9 +354,7 @@ FluidbookSearch.prototype = {
 
 
         var returnVal = {
-            total: total,
-            results: res,
-            terms: terms
+            total: total, results: res, terms: terms
         };
 
         callback(returnVal);
@@ -410,9 +401,7 @@ FluidbookSearch.prototype = {
             terms = words;
         }
         var returnVal = {
-            total: total,
-            results: res,
-            terms: terms
+            total: total, results: res, terms: terms
         };
 
         callback(returnVal);
@@ -420,11 +409,9 @@ FluidbookSearch.prototype = {
 
     sortHints: function (a, b) {
         return b[1] - a[1];
-    },
-    kill: function () {
+    }, kill: function () {
 
-    },
-    normalizeQuery: function (q, split) {
+    }, normalizeQuery: function (q, split) {
         q = this.noAccents(q);
         q = q.toLowerCase();
         if (split) {
@@ -432,8 +419,7 @@ FluidbookSearch.prototype = {
         }
         return q;
 
-    },
-    noAccents: function (source) {
+    }, noAccents: function (source) {
         source = source.replace(/[àáâãäå]/g, "a");
         source = source.replace(/[ÀÁÂÃÄÅ]/g, "A");
         source = source.replace(/[èéêë]/g, "e");
@@ -459,8 +445,7 @@ FluidbookSearch.prototype = {
         source = source.replace(/[œ]/g, "oe");
         source = source.replace(/[Œ]/g, "OE");
         return source;
-    },
-    setHighlightTerms: function (terms) {
+    }, setHighlightTerms: function (terms) {
         if (!this.highlightEnabled || window.HIGHLIGHTS === undefined) {
             return;
         }
@@ -497,15 +482,13 @@ FluidbookSearch.prototype = {
                 this.highlights.push(h);
             }
         }
-    },
-    clearHighlights: function () {
+    }, clearHighlights: function () {
         $("#searchHighlights").html('');
         for (var p in this.plugins) {
             var plugin = this.plugins[p];
             plugin.clearHighlights();
         }
-    },
-    highlightSearchTerms: function (pageNr) {
+    }, highlightSearchTerms: function (pageNr) {
         if (!this.highlightEnabled) {
             console.warn('hightlight disabled');
             return;
@@ -620,16 +603,14 @@ FluidbookSearch.prototype = {
         // if (this.menuSearchHints.hasClass('mm-hidden')) {
         //     this.nav.menuAPI.openPanel(this.menuSearchHints, false);
         // }
-    },
-    getSearchHints: function (q) {
+    }, getSearchHints: function (q) {
 
         var $this = this;
         this.killLastSearchHint();
         this.getHints(q, function (r) {
             $this.displaySearchHints(r);
         });
-    },
-    displaySearchHints: function (hints) {
+    }, displaySearchHints: function (hints) {
         var $this = this;
 
         if (hints.length == 0) {
@@ -653,8 +634,7 @@ FluidbookSearch.prototype = {
         }
 
         this.menuSearchHints.perfectScrollbar({
-            suppressScrollX: true,
-            minScrollbarLength: 40
+            suppressScrollX: true, minScrollbarLength: 40
         });
 
         $("#searchHints").css({top: top, left: left}).show();
@@ -767,14 +747,17 @@ FluidbookSearch.prototype = {
         var spreadEnabled = 0;
         // Process each spread of pages to collect the ones with results
         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, pagesWithHits = [];
+
+            var firstPageWithResult;
 
             // Get total number of hits for pages in this spread
             for (var i in currentPages) {
                 var pageNum = parseInt(currentPages[i]);
                 if (hits[pageNum] > 0) {
+                    if (firstPageWithResult === undefined) {
+                        firstPageWithResult = currentPages[i];
+                    }
                     totalHits += hits[pageNum];
                     pagesWithHits.push(currentPages[i]);
                 }
@@ -797,8 +780,8 @@ FluidbookSearch.prototype = {
                 }
             } else {
                 spreadEnabled++;
-
-                var url = '#/page/' + $(this).attr('page');
+                p = $this.fluidbook.displayOnePage ? firstPageWithResult : $(this).attr('page');
+                var url = '#/page/' + p;
                 if ($this.fluidbook.pad.enabled) {
                     if (pagesWithHits.length == 1) {
                         url = '#/page/' + pagesWithHits[0];
@@ -840,15 +823,11 @@ FluidbookSearch.prototype = {
 
         // Initialise scrollbar after populating so bars appear immediately
         this.menuSearchResults.perfectScrollbar({
-            suppressScrollX: true,
-            minScrollbarLength: 40,
-            //maxScrollbarLength: 60
+            suppressScrollX: true, minScrollbarLength: 40, //maxScrollbarLength: 60
         });
-    },
-    registerPlugin: function (p) {
+    }, registerPlugin: function (p) {
         this.plugins.push(p);
-    },
-    closeKeyboardonTouchDevices: function () {
+    }, closeKeyboardonTouchDevices: function () {
         if (this.fluidbook.support.iOS || this.fluidbook.support.android) {
             $("#q").blur();
         }