[devdocsgjs/main: 528/1867] Limit new event listener to Chrome for Android




commit c6f0f1693fdcc952d47a9ed8035f4194e7f3cfee
Author: Jasper van Merle <jaspervmerle gmail com>
Date:   Tue Dec 4 00:10:28 2018 +0100

    Limit new event listener to Chrome for Android

 assets/javascripts/lib/util.coffee                  |  4 ++++
 assets/javascripts/views/search/search_scope.coffee | 16 ++++++++++------
 2 files changed, 14 insertions(+), 6 deletions(-)
---
diff --git a/assets/javascripts/lib/util.coffee b/assets/javascripts/lib/util.coffee
index 058106fd..001b13de 100644
--- a/assets/javascripts/lib/util.coffee
+++ b/assets/javascripts/lib/util.coffee
@@ -352,6 +352,10 @@ isIE = null
 $.isIE = ->
   isIE ?= navigator.userAgent?.indexOf('MSIE') >= 0 || navigator.userAgent?.indexOf('rv:11.0') >= 0
 
+isChromeForAndroid = null
+$.isChromeForAndroid = ->
+  isChromeForAndroid ?= navigator.userAgent?.indexOf('Android') >= 0 && /Chrome\/([.0-9])+ 
Mobile/.test(navigator.userAgent)
+
 isAndroid = null
 $.isAndroid = ->
   isAndroid ?= navigator.userAgent?.indexOf('Android') >= 0
diff --git a/assets/javascripts/views/search/search_scope.coffee 
b/assets/javascripts/views/search/search_scope.coffee
index 9be90dd2..8b104011 100644
--- a/assets/javascripts/views/search/search_scope.coffee
+++ b/assets/javascripts/views/search/search_scope.coffee
@@ -88,23 +88,27 @@ class app.views.SearchScope extends app.View
     @trigger 'change', null, previousDoc
     return
 
+  doScopeSearch: (event) =>
+    @search @input.value[0...@input.selectionStart]
+    $.stopEvent(event) if @doc
+    return
+
   onKeydown: (event) =>
     if event.which is 8 # backspace
       if @doc and not @input.value
         $.stopEvent(event)
         @reset()
-    else if not @doc and @input.value
+    else if not @doc and @input.value and not $.isChromeForAndroid()
       return if event.ctrlKey or event.metaKey or event.altKey or event.shiftKey
       if event.which is 9 or # tab
          (event.which is 32 and app.isMobile()) # space
-        @search @input.value[0...@input.selectionStart]
-        $.stopEvent(event) if @doc
+        @doScopeSearch(event)
     return
 
   onTextInput: (event) =>
-    if event.data == ' ' and app.isMobile()
-      @search @input.value[0...@input.selectionStart]
-      $.stopEvent(event) if @doc
+    return unless $.isChromeForAndroid()
+    if not @doc and @input.value and event.data == ' '
+      @doScopeSearch(event)
     return
 
   extractHashValue: ->


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]