]> _ Git - fluidbook-html5.git/commitdiff
fix #2504
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 11 Jan 2019 15:30:54 +0000 (16:30 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 11 Jan 2019 15:30:54 +0000 (16:30 +0100)
js/libs/fluidbook/fluidbook.search.js

index d2d2a24f141f16fb735a51818c1abfbe1097397d..0297e2c20e8b846099e3809017316533d2f8a7d7 100644 (file)
@@ -64,7 +64,7 @@ FluidbookSearch.prototype = {
     },
 
     _loadTexts: function (callback) {
-        if (this.fluidbook.datas.searchWordSelectionAlgorithm == 'expression') {
+        if (this.fluidbook.datas.searchWordSelectionAlgorithm === 'expression') {
             loadJSLibrary('data/search.texts.js', function () {
                 callback();
             });
@@ -83,7 +83,7 @@ FluidbookSearch.prototype = {
         var v;
         for (var k in INDEX) {
             v = INDEX[k];
-            if (k.indexOf(q) != 0) {
+            if (k.indexOf(q) !== 0) {
                 continue;
             }
             res.push([k, v.t]);
@@ -101,7 +101,7 @@ FluidbookSearch.prototype = {
 
     getSearchWordSelectionAlgorithm: function (q) {
         var a = this.fluidbook.datas.searchWordSelectionAlgorithm;
-        if (q.indexOf(' ') === -1 && a == 'expression') {
+        if (q.indexOf(' ') === -1 && a === 'expression') {
             a = 'begins';
         }
         return a;
@@ -109,7 +109,7 @@ FluidbookSearch.prototype = {
 
     _find: function (q, callback) {
         var algo = this.getSearchWordSelectionAlgorithm(q);
-        if (algo == 'expression') {
+        if (algo === 'expression') {
             return this._findExpression(q, callback);
         }
         var words = this.normalizeQuery(q, true);
@@ -130,11 +130,11 @@ FluidbookSearch.prototype = {
                     continue;
                 }
 
-                if (algo == 'begins' && k.indexOf(q) != 0) {
+                if (algo === 'begins' && k.indexOf(q) !== 0) {
                     continue;
-                } else if (algo == 'contains' && k.indexOf(q) == -1) {
+                } else if (algo === 'contains' && k.indexOf(q) === -1) {
                     continue;
-                } else if (algo == 'exact' && k != q) {
+                } else if (algo === 'exact' && k !== q) {
                     continue;
                 }
                 v = INDEX[k];
@@ -166,7 +166,7 @@ FluidbookSearch.prototype = {
         total = 0;
         for (var dpNumber in doublesPages) {
             var doublePageOccurences = doublesPages[dpNumber];
-            if (Object.keys(doublePageOccurences).length == nbwords || this.fluidbook.datas.searchPageSelectionAlgorithm == 'OR') {
+            if (Object.keys(doublePageOccurences).length === nbwords || this.fluidbook.datas.searchPageSelectionAlgorithm === 'OR') {
                 var occ = 0;
                 for (var ww in doublePageOccurences) {
                     occ += doublePageOccurences[ww];
@@ -213,7 +213,7 @@ FluidbookSearch.prototype = {
             if (page > maxPage) {
                 continue;
             }
-            
+
             if (!this.singleMode && (page % 2) === 1) {
                 page--;
             }
@@ -286,30 +286,30 @@ FluidbookSearch.prototype = {
         }
         this.termsToHighlight = terms;
         this.highlights = [];
-        if (terms.length == 0) {
+        if (terms.length === 0) {
             return;
         }
         var algo = this.getSearchWordSelectionAlgorithm(terms.join(' '));
-        if (algo == 'expression') {
+        if (algo === 'expression') {
             return;
         }
         for (var t in terms) {
             var term = terms[t];
             for (var w in HIGHLIGHTS) {
-                if (algo != 'expression' && w.length < this.fluidbook.datas.ignoreWordLimit) {
+                if (algo !== 'expression' && w.length < this.fluidbook.datas.ignoreWordLimit) {
                     continue;
                 }
 
-                if (algo == 'begins' && w.indexOf(term) != 0) {
+                if (algo === 'begins' && w.indexOf(term) !== 0) {
                     continue;
-                } else if (algo == 'contains' && w.indexOf(term) == -1) {
+                } else if (algo === 'contains' && w.indexOf(term) === -1) {
                     continue;
-                } else if (algo == 'exact' && w != term) {
+                } else if (algo === 'exact' && w !== term) {
                     continue;
                 }
 
                 var color = t;
-                if (algo == 'expression') {
+                if (algo === 'expression') {
                     color = 0;
                 }
 
@@ -330,7 +330,7 @@ FluidbookSearch.prototype = {
             return;
         }
         this.clearHighlights();
-        if (this.termsToHighlight.length == 0) {
+        if (this.termsToHighlight.length === 0) {
             return;
         }
 
@@ -347,13 +347,13 @@ FluidbookSearch.prototype = {
                 evenPageNumber--;
             }
 
-            if (this.resultPages.indexOf(evenPageNumber) == -1) {
+            if (this.resultPages.indexOf(evenPageNumber) === -1) {
                 return;
             }
         }
 
         var pageNrs = [];
-        if (this.fluidbook.resize.orientation == 'portrait') {
+        if (this.fluidbook.resize.orientation === 'portrait') {
             pageNrs.push(pageNr);
         } else {
 
@@ -367,7 +367,7 @@ FluidbookSearch.prototype = {
             }
         }
 
-        if (this.fluidbook.l10n.dir == 'rtl') {
+        if (this.fluidbook.l10n.dir === 'rtl') {
             pageNrs.reverse();
         }
 
@@ -470,7 +470,7 @@ FluidbookSearch.prototype = {
         var qoffset = $("#q").offset();
         var top = qoffset.top + $("#q").outerHeight() + 5;
         var left = qoffset.left;
-        if (this.fluidbook.l10n.dir == 'rtl') {
+        if (this.fluidbook.l10n.dir === 'rtl') {
             left = -1 * ($(window).width() - left - $("#q").outerWidth());
         }
 
@@ -517,10 +517,12 @@ FluidbookSearch.prototype = {
     submitForm: function () {
         var q = $("#q").val();
 
-        if (q == '') {
+        if (q === '') {
             return false;
         }
 
+        this.closeKeyboardonTouchDevices();
+
         window.location.hash = '/search/' + q;
 
         this.fluidbook.stats.track(1, this.fluidbook.currentPage, q);
@@ -551,6 +553,8 @@ FluidbookSearch.prototype = {
         }
         var $this = this;
 
+        this.closeKeyboardonTouchDevices();
+
         // Handle empty result set
         if (results.total <= 0) {
             this.menuSearchResults.html('<div class="no-results">' + this.fluidbook.l10n.__('no result found') + '</div>');
@@ -661,5 +665,13 @@ FluidbookSearch.prototype = {
     registerPlugin: function (p) {
         this.plugins.push(p);
     },
+    closeKeyboardonTouchDevices: function () {
+        if (this.fluidbook.support.iOS || this.fluidbook.support.android) {
+            if (!$("#q").is(':focus')) {
+                return;
+            }
+            $("#q").blur();
+        }
+    }
 };