From: Vincent Vanwaelscappel Date: Tue, 2 Oct 2018 09:54:10 +0000 (+0200) Subject: wip #2251 @1 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=28bf58881ab3718b1b4522ad79d8838eb7ac3870;p=fluidbook-html5.git wip #2251 @1 --- diff --git a/js/libs/fluidbook/fluidbook.search.js b/js/libs/fluidbook/fluidbook.search.js index 1b274a43..11180901 100644 --- a/js/libs/fluidbook/fluidbook.search.js +++ b/js/libs/fluidbook/fluidbook.search.js @@ -88,6 +88,8 @@ FluidbookSearch.prototype = { res.push([k, v.t]); } + console.log(res); + for (var p in this.plugins) { var plugin = this.plugins[p]; var h = plugin.getHints(q); diff --git a/js/libs/fluidbook/special/wescosales.js b/js/libs/fluidbook/special/wescosales.js index 6d46be78..27eeea8a 100644 --- a/js/libs/fluidbook/special/wescosales.js +++ b/js/libs/fluidbook/special/wescosales.js @@ -1,6 +1,7 @@ var wsref = {}; var normalizeRefCache = {}; var allrefs = null; +var pagesofrefs = null; $(function () { if (fluidbook.datas.basket) { @@ -43,6 +44,7 @@ function initWesco() { setTimeout(function () { getAllRefs(); + getPagesOfRefs(); }, 5000); } @@ -136,6 +138,29 @@ function getAllRefs() { return allrefs; } +function getPagesOfRefs() { + if (pagesofrefs === null) { + pagesofrefs = {}; + $.each(fluidbook.datas.pagesOfCustomLinks, function (k, v) { + var possibleRefs = getPossibleReferences(k); + $.each(possibleRefs, function (kk, ref) { + pagesofrefs[ref] = v; + }); + }); + } + return pagesofrefs; +} + +function getPossibleReferences(ref) { + var trimmedRef = ref.replace(/^0+/, ""); + var res = [trimmedRef]; + for (var i = 0; i < 5 - trimmedRef.length; i++) { + trimmedRef = '0' + trimmedRef; + res.push(trimmedRef); + } + return res; +} + function setInteractPanel(ref, onlyRect) { if (onlyRect === undefined) { onlyRect = false; @@ -310,18 +335,22 @@ WescoSalesSearchPlugin.prototype = { submitQuery: function (q) { if (!q.match(/(\d\s*)/gm)) { + console.log('not ref (format)'); return true; } q = q.replace(/\s/gm, ''); if (q.length != 5) { + console.log('not ref (length)'); return true; } var all = getAllRefs(); var res = false; + var pagesofrefs = getPagesOfRefs(); + $.each(all, function (k, v) { if (v.indexOf(q) === 0) { - var pages = fluidbook.datas.pagesOfCustomLinks[q]; + var pages = pagesofrefs[q]; if (pages !== undefined && pages !== null && pages.length > 0) { var results = {total: pages.length, results: []}; $.each(pages, function (k, v) { @@ -339,11 +368,15 @@ WescoSalesSearchPlugin.prototype = { }, highlight: function (pageNr, terms) { - console.log(terms); this.clearHighlights(); $.each(terms, function (k, v) { - console.log(v, $('[data-wescosales-ref="' + v + '"]')); - $('[data-wescosales-ref="' + v + '"]').addClass('highlight'); + var possible = getPossibleReferences(v); + var selectors = []; + $.each(possible, function (kk, ref) { + selectors.push('[data-wescosales-ref="' + ref + '"]'); + }); + + $(selectors.join(',')).addClass('highlight'); }); }, clearHighlights: function () {