]> _ Git - fluidbook-html5.git/commitdiff
WIP #3051 @5
authorStephen Cameron <stephen@cubedesigners.com>
Wed, 4 Dec 2019 18:05:26 +0000 (19:05 +0100)
committerStephen Cameron <stephen@cubedesigners.com>
Wed, 4 Dec 2019 18:05:26 +0000 (19:05 +0100)
js/libs/fluidbook/fluidbook.search.js

index fc17c3d02fc675bb729d0efaf30168deb649e8cc..51eff1f1a8d8ba63af513ff8cf7399da28457d9d 100644 (file)
@@ -38,6 +38,14 @@ FluidbookSearch.prototype = {
         this.initResultsNav();
     },
 
+    debugSearch: function(keyword) {
+      this._loadLib(function() {
+        console.log('Comparison of page results for keyword "'+ keyword +'"');
+        console.log('INDEX:', Object.keys(INDEX[keyword].p).join(', '));
+        console.log('HIGHLIGHTS:', Array.from(new Set(HIGHLIGHTS["loutres"].map(function(h) { return h.page }))).join(', '));
+      });
+    },
+
     // 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() {
@@ -74,7 +82,7 @@ FluidbookSearch.prototype = {
         });
 
         $(document).on('click', '.searchResultsNavField', function() {
-            $this.closeResultsNav();
+            $this.closeResultsNav(true);
             $this.fluidbook.nav.openSearch();
         });
 
@@ -96,6 +104,13 @@ FluidbookSearch.prototype = {
             $this.updateResultsNav($this.fluidbook.currentPage);
         });
 
+        // Close results nav when hitting escape
+        key('esc', function() {
+            if ($this.resultsNavActive()) {
+                $this.closeResultsNav();
+            }
+        })
+
 
     },
     resultsNavActive: function() {
@@ -124,8 +139,6 @@ FluidbookSearch.prototype = {
             this.resultNavPages = this.resultPages;
         }
 
-        console.log('updateResultsNav...', this.resultNavPages);
-
         var resultPagePosition = this.resultNavPages.indexOf(resultPage);
         // Convert from zero-based index. If page clicked isn't found in results pages, default to 1
         resultPagePosition = (resultPagePosition === -1) ? 1 : resultPagePosition + 1;
@@ -141,16 +154,23 @@ FluidbookSearch.prototype = {
         this.resultsNav.removeClass('hidden');
         $('body').addClass(this.resultsActiveClass);
     },
-    closeResultsNav: function() {
+    closeResultsNav: function(keepSearch) {
+        keepSearch = keepSearch !== 'undefined' ? keepSearch : false;
+
         this.hideableElements.removeClass('hidden');
         this.resultsNav.addClass('hidden');
+
+        if (!keepSearch) {
+            this.closeSearch();
+        }
+
         $('body').removeClass(this.resultsActiveClass);
     },
     nextResultsPage: function() {
         var currentIndex = this.resultNavPages.indexOf(fluidbook.currentPage);
         var nextIndex = currentIndex + 1;
 
-        if (nextIndex > this.resultNavPages.length) {
+        if (nextIndex >= this.resultNavPages.length) {
             nextIndex = 0; // Go back to beginning
         }
 
@@ -282,8 +302,6 @@ FluidbookSearch.prototype = {
 
                 matchedWord = INDEX[indexWord];
 
-                console.log('match found', indexWord, 'pages : ' + Object.keys(matchedWord.p).join(','));
-
                 for (page in matchedWord.p) {
                     var occurrences = matchedWord.p[page];
                     page = parseInt(page);
@@ -379,8 +397,6 @@ FluidbookSearch.prototype = {
             terms: terms
         };
 
-        console.log(returnVal);
-
         callback(returnVal);
     },
 
@@ -689,7 +705,6 @@ FluidbookSearch.prototype = {
 
         var $this = this;
         this.find(q, function (results) {
-            console.log('Search results', results);
             $this.openResults(results);
         });
     },