History

Optimize search autofocus code

Thibaut Courouble committed 9 years ago

Commit 581e6561 parent e2ad2e51 file · +5 −2Browse files

Unified · Split

assets/javascripts/views/search/search.coffee+5−2
@@ -31,7 +31,7 @@ class app.views.Search extends app.View · 30 unmodified lines
3131
3232 app.on 'ready', @onReady
3333 $.on window, 'hashchange', @searchUrl
34− $.on window, 'focus', @autoFocus
34+ $.on window, 'focus', @onWindowFocus
3535 return
3636
3737 focus: =>
@@ -43,6 +43,9 @@ class app.views.Search extends app.View · 5 unmodified lines
4343 @input.focus() unless document.activeElement?.tagName is 'INPUT'
4444 return
4545
46+ onWindowFocus: (event) =>
47+ @autoFocus() if event.target is window
48+
4649 getScopeDoc: ->
4750 @scope.getScope() if @scope.isActive()
4851
@@ -135,7 +138,7 @@ class app.views.Search extends app.View · 86 unmodified lines
135138 return if app.shortcuts.eventInProgress?.name is 'escape'
136139 @reset(true) if not context.init and app.router.isIndex()
137140 @delay @searchUrl if context.hash
138− @delay @autoFocus
141+ $.requestAnimationFrame @autoFocus
139142 return
140143
141144 extractHashValue: ->