]> _ Git - fluidbook-html5.git/commitdiff
wip #2251 @3
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 1 Oct 2018 15:37:10 +0000 (17:37 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 1 Oct 2018 15:37:10 +0000 (17:37 +0200)
js/libs/fluidbook/fluidbook.search.js
js/libs/fluidbook/special/wescosales.js

index 8364cd5d1dfa6889f7edf3d31d9db645e6faa7e3..37ef9e1fd576b8caa927641dec8fdeffc8270505 100644 (file)
@@ -451,7 +451,7 @@ FluidbookSearch.prototype = {
             if (v.length > 2) {
                 termType = v[2];
             }
-            $this.menuSearchHints.append('<a class="hint" data-termtype="' + termType + '" term="' + v[0] + '" href="#/search/' + termType + '/' + v[0] + '">' + v[0] + '</a>');
+            $this.menuSearchHints.append('<a class="hint" term="' + v[0] + '" href="#/search/' + v[0] + '">' + v[0] + '</a>');
         });
         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('<a href="#/page/' + $(this).attr('page') + '"><div class="hits yes">' + totalHits + ' ' + $this.fluidbook.l10n.__('hit(s)') + '</div></a>');
                 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
index 403f0b5bb1c7c7ed8fcefe27c3151fc630eec907..e43d06ac197bba078a5b94a04d0805a5a8232ac9 100644 (file)
@@ -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