浏览代码

Don't autofocus search input on Android/iOS

Thibaut Courouble 8 年之前
父节点
当前提交
63bb8cd1e1
共有 2 个文件被更改,包括 13 次插入3 次删除
  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