]> _ Git - fluidbook-html5.git/commitdiff
wip #2251 @1
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 2 Oct 2018 09:54:10 +0000 (11:54 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 2 Oct 2018 09:54:10 +0000 (11:54 +0200)
js/libs/fluidbook/fluidbook.search.js
js/libs/fluidbook/special/wescosales.js

index 1b274a43b9e61f00883d955cf40d07bed96cf954..111809012aa57380ba4c2b3a15ec0a237437147f 100644 (file)
@@ -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);
index 6d46be789b597c1054e3cff71b01551611ce31fb..27eeea8abc3e265272fa6ad81481f4633d18f12c 100644 (file)
@@ -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 () {