Browse Source

Don't autofocus search input on Android/iOS

Thibaut Courouble 8 years ago
parent
commit
63bb8cd1e1
2 changed files with 13 additions and 3 deletions
  1. 12 2
      assets/javascripts/lib/util.coffee
  2. 1 1
      assets/javascripts/views/search/search.coffee

+ 12 - 2
assets/javascripts/lib/util.coffee

@@ -336,11 +336,21 @@ $.popup = (value) ->
     window.open value.href or value, '_blank'
   return
 
+isMac = null
 $.isMac = ->
-  navigator.userAgent?.indexOf('Mac') >= 0
+  isMac ?= navigator.userAgent?.indexOf('Mac') >= 0
 
+isIE = null
 $.isIE = ->
-  navigator.userAgent?.indexOf('MSIE') >= 0 || navigator.userAgent?.indexOf('rv:11.0') >= 0
+  isIE ?= navigator.userAgent?.indexOf('MSIE') >= 0 || navigator.userAgent?.indexOf('rv:11.0') >= 0
+
+isAndroid = null
+$.isAndroid = ->
+  isAndroid ?= navigator.userAgent?.indexOf('Android') >= 0
+
+isIOS = null
+$.isIOS = ->
+  isIOS ?= navigator.userAgent?.indexOf('iPhone') >= 0 || navigator.userAgent?.indexOf('iPad') >= 0
 
 HIGHLIGHT_DEFAULTS =
   className: 'highlight'

+ 1 - 1
assets/javascripts/views/search/search.coffee

@@ -41,7 +41,7 @@ class app.views.Search extends app.View
     return
 
   autoFocus: =>
-    unless app.isMobile()
+    unless app.isMobile() or $.isAndroid() or $.isIOS()
       @input.focus() unless document.activeElement is @input
     return