1
0
Эх сурвалжийг харах

Optimize search autofocus code

Thibaut Courouble 8 жил өмнө
parent
commit
581e656fd2

+ 5 - 2
assets/javascripts/views/search/search.coffee

@@ -31,7 +31,7 @@ class app.views.Search extends app.View
 
     app.on 'ready', @onReady
     $.on window, 'hashchange', @searchUrl
-    $.on window, 'focus', @autoFocus
+    $.on window, 'focus', @onWindowFocus
     return
 
   focus: =>
@@ -43,6 +43,9 @@ class app.views.Search extends app.View
       @input.focus() unless document.activeElement?.tagName is 'INPUT'
     return
 
+  onWindowFocus: (event) =>
+    @autoFocus() if event.target is window
+
   getScopeDoc: ->
     @scope.getScope() if @scope.isActive()
 
@@ -135,7 +138,7 @@ class app.views.Search extends app.View
     return if app.shortcuts.eventInProgress?.name is 'escape'
     @reset(true) if not context.init and app.router.isIndex()
     @delay @searchUrl if context.hash
-    @delay @autoFocus
+    $.requestAnimationFrame @autoFocus
     return
 
   extractHashValue: ->