From: Stephen Cameron Date: Wed, 4 Dec 2019 18:05:26 +0000 (+0100) Subject: WIP #3051 @5 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=000dbec5afaf39e5d9b8ee60c42450f210aa9276;p=fluidbook-html5.git WIP #3051 @5 --- diff --git a/js/libs/fluidbook/fluidbook.search.js b/js/libs/fluidbook/fluidbook.search.js index fc17c3d0..51eff1f1 100644 --- a/js/libs/fluidbook/fluidbook.search.js +++ b/js/libs/fluidbook/fluidbook.search.js @@ -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); }); },