From 5e8196ebb91b151010cde8a317c466b4bb3e01ab Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Mon, 1 Oct 2018 17:37:10 +0200 Subject: [PATCH] wip #2251 @3 --- js/libs/fluidbook/fluidbook.search.js | 39 +++++++++++++++++++++---- js/libs/fluidbook/special/wescosales.js | 39 +++++++++++++++++++++++-- 2 files changed, 71 insertions(+), 7 deletions(-) diff --git a/js/libs/fluidbook/fluidbook.search.js b/js/libs/fluidbook/fluidbook.search.js index 8364cd5d..37ef9e1f 100644 --- a/js/libs/fluidbook/fluidbook.search.js +++ b/js/libs/fluidbook/fluidbook.search.js @@ -451,7 +451,7 @@ FluidbookSearch.prototype = { if (v.length > 2) { termType = v[2]; } - $this.menuSearchHints.append('' + v[0] + ''); + $this.menuSearchHints.append('' + v[0] + ''); }); var qoffset = $("#q").offset(); var top = qoffset.top + $("#q").outerHeight() + 5; @@ -510,13 +510,31 @@ FluidbookSearch.prototype = { window.location.hash = '/search/' + q; this.fluidbook.stats.track(1, this.fluidbook.currentPage, q); + + var continueProcessingAfterPlugins = true; + for (var p in this.plugins) { + if (!continueProcessingAfterPlugins) { + continue; + } + + var plugin = this.plugins[p]; + continueProcessingAfterPlugins = plugin.submitQuery(q); + } + + if (!continueProcessingAfterPlugins) { + return; + } + var $this = this; this.find(q, function (results) { $this.openResults(results); }); }, - openResults: function (results) { + openResults: function (results, gotoPageIfOneResult) { + if (gotoPageIfOneResult === undefined) { + gotoPageIfOneResult = false; + } var $this = this; // Handle empty result set @@ -548,6 +566,7 @@ FluidbookSearch.prototype = { // Use the index of all pages as a starting point to filter results thumbnails this.menuSearchResults.html(this.fluidbook.menu.index.getView()).hide(); + 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(','), @@ -579,6 +598,8 @@ FluidbookSearch.prototype = { return; } } else { + spreadEnabled++; + $(this).attr('data-enabled', '1'); // Add the link to the main result page. Link around the hits div is for better usability (previously wasn't clickable) $(this).append('
' + totalHits + ' ' + $this.fluidbook.l10n.__('hit(s)') + '
'); if ($this.fluidbook.pad.enabled) { @@ -591,15 +612,23 @@ FluidbookSearch.prototype = { $(this).find('a').attr('href', '#/page/' + $(this).attr('page')); } } - }); // Set Highlighting of results keywords this.setHighlightTerms(results.terms); - this.highlightSearchTerms(this.fluidbook.currentPage); + this.hideSearchHints(); + // Redirect to the only result page if the flag is enabled + if (gotoPageIfOneResult && spreadEnabled === 1) { + setTimeout(function () { + fluidbook.setCurrentPage($this.menuSearchResults.find('.doubleThumb[data-enabled="1"]').attr('page')); + fluidbook.nav.menuAPI.close(); + }, 100); + return; + } + + this.highlightSearchTerms(this.fluidbook.currentPage); - this.hideSearchHints(); this.menuSearchResults.fadeIn(300).scrollTop(0); // On some phones, the height of the search results is miscalculated due to the diff --git a/js/libs/fluidbook/special/wescosales.js b/js/libs/fluidbook/special/wescosales.js index 403f0b5b..e43d06ac 100644 --- a/js/libs/fluidbook/special/wescosales.js +++ b/js/libs/fluidbook/special/wescosales.js @@ -40,6 +40,10 @@ function initWesco() { $(this).closest('.wescosaleswindow').remove(); return false; }); + + setTimeout(function () { + getAllRefs(); + }, 5000); } function wescoResize() { @@ -125,6 +129,7 @@ function getAllRefs() { res.push(r); } } + break; } allrefs = res; } @@ -301,5 +306,35 @@ WescoSalesSearchPlugin.prototype = { }); return res; - } -}; + }, + + submitQuery: function (q) { + if (!q.match(/(\d\s*)/gm)) { + return true; + } + q = q.replace(/\s/gm, ''); + + if (q.length != 5) { + return true; + } + var all = getAllRefs(); + var res = false; + $.each(all, function (k, v) { + if (v.indexOf(q) === 0) { + var pages = fluidbook.datas.pagesOfCustomLinks[q]; + if (pages !== undefined && pages !== null && pages.length > 0) { + var results = {total: pages.length, results: []}; + $.each(pages, function (k, v) { + results.results[v] = 1; + }); + results.terms = []; + res = true; + fluidbook.search.openResults(results, true); + return true; + } + } + }); + + return !res; + }, +}; \ No newline at end of file -- 2.39.5