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
31 31
32 app.on 'ready', @onReady32 app.on 'ready', @onReady
33 $.on window, 'hashchange', @searchUrl33 $.on window, 'hashchange', @searchUrl
34 $.on window, 'focus', @autoFocus34 $.on window, 'focus', @onWindowFocus
35 return35 return
36 36
37 focus: =>37 focus: =>
@@ -43,6 +43,9 @@ class app.views.Search extends app.View · 5 unmodified lines
43 @input.focus() unless document.activeElement?.tagName is 'INPUT'43 @input.focus() unless document.activeElement?.tagName is 'INPUT'
44 return44 return
45 45
46 onWindowFocus: (event) =>
47 @autoFocus() if event.target is window
48
46 getScopeDoc: ->49 getScopeDoc: ->
47 @scope.getScope() if @scope.isActive()50 @scope.getScope() if @scope.isActive()
48 51
@@ -135,7 +138,7 @@ class app.views.Search extends app.View · 86 unmodified lines
135 return if app.shortcuts.eventInProgress?.name is 'escape'138 return if app.shortcuts.eventInProgress?.name is 'escape'
136 @reset(true) if not context.init and app.router.isIndex()139 @reset(true) if not context.init and app.router.isIndex()
137 @delay @searchUrl if context.hash140 @delay @searchUrl if context.hash
138 @delay @autoFocus141 $.requestAnimationFrame @autoFocus
139 return142 return
140 143
141 extractHashValue: ->144 extractHashValue: ->