From: Vincent Vanwaelscappel Date: Fri, 28 Sep 2018 16:45:11 +0000 (+0200) Subject: wip #2251 @1 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=05d8fb9d65b7426dd239385eaf96c36969993a4d;p=fluidbook-html5.git wip #2251 @1 --- diff --git a/js/libs/fluidbook/fluidbook.search.js b/js/libs/fluidbook/fluidbook.search.js index 393bda6d..8364cd5d 100644 --- a/js/libs/fluidbook/fluidbook.search.js +++ b/js/libs/fluidbook/fluidbook.search.js @@ -5,6 +5,7 @@ function FluidbookSearch(fluidbook) { this.highlights = []; this.highlightEnabled = fluidbook.datas.highlightResults; this.resultPages = []; + this.plugins = []; this.init(); } @@ -87,6 +88,13 @@ FluidbookSearch.prototype = { res.push([k, v.t]); } + for (var p in this.plugins) { + var plugin = this.plugins[p]; + var h = plugin.getHints(q); + console.log(h); + res = res.concat(h); + } + res.sort(this.sortHints); callback(res.slice(0, 12)); }, @@ -439,7 +447,11 @@ FluidbookSearch.prototype = { } this.menuSearchHints.html(''); $.each(hints, function (k, v) { - $this.menuSearchHints.append('' + v[0] + ''); + var termType = 'word'; + if (v.length > 2) { + termType = v[2]; + } + $this.menuSearchHints.append('' + v[0] + ''); }); var qoffset = $("#q").offset(); var top = qoffset.top + $("#q").outerHeight() + 5; @@ -455,9 +467,11 @@ FluidbookSearch.prototype = { $("#searchHints").css({top: top, left: left}).show(); }, + killLastSearchHint: function () { this.kill(); }, + hideSearchHints: function () { this.menuSearchHints.html('').hide(); // Clear and hide all hints }, @@ -601,6 +615,9 @@ FluidbookSearch.prototype = { minScrollbarLength: 40, //maxScrollbarLength: 60 }); - } + }, + registerPlugin: function (p) { + this.plugins.push(p); + }, }; diff --git a/js/libs/fluidbook/special/wescosales.js b/js/libs/fluidbook/special/wescosales.js index d51fe8bd..403f0b5b 100644 --- a/js/libs/fluidbook/special/wescosales.js +++ b/js/libs/fluidbook/special/wescosales.js @@ -1,5 +1,6 @@ var wsref = {}; var normalizeRefCache = {}; +var allrefs = null; $(function () { if (fluidbook.datas.basket) { @@ -28,6 +29,8 @@ function initWescoNav() { } function initWesco() { + fluidbook.search.registerPlugin(new WescoSalesSearchPlugin()); + $(document).on('click', '[data-wescosales-ref]', function (e) { setWescoSalesPanel($(this).data('wescosales-ref'), e); return false; @@ -110,6 +113,24 @@ function setWescoSalesPanel(ref, e, updateOnly) { setInteractPanel(ref, updateOnly); } +function getAllRefs() { + if (allrefs === null) { + var res = []; + for (var country in DATAS.basketReferences) { + var sheet = DATAS.basketReferences[country]; + for (var linenum in sheet) { + var line = sheet[linenum]; + var r = normalizeRef(line[0].toString()); + if (res.indexOf(r) === -1) { + res.push(r); + } + } + } + allrefs = res; + } + return allrefs; +} + function setInteractPanel(ref, onlyRect) { if (onlyRect === undefined) { onlyRect = false; @@ -255,3 +276,30 @@ function getWescoRef(ref) { } return wsref[ref]; } + +function WescoSalesSearchPlugin() { + +} + +WescoSalesSearchPlugin.prototype = { + getHints: function (q) { + if (!q.match(/(\d\s*)/gm)) { + return []; + } + + q = q.replace(/\s/gm, ''); + + if (q.length > 5) { + return []; + } + var all = getAllRefs(); + var res = []; + $.each(all, function (k, v) { + if (v.indexOf(q) === 0) { + res.push([v, 100000, 'ref']); + } + }); + + return res; + } +};