History

Reset search field when browsing to index page in single doc mode

Thibaut Courouble committed 9 years ago

Commit 98a6eb51 parent 82743162 files · +6 −13Browse files

Showing the changes to assets/javascripts (2 of 2 files). Show all

Unified · Split

2 files
  1. assets/javascripts/app/router.coffee +3 −6
  2. assets/javascripts/views/search/search.coffee +3 −7
assets/javascripts/app/router.coffee+3−6
@@ -112,18 +112,15 @@ class app.Router · 111 unmodified lines
112112 @triggerRoute 'notFound'
113113 return
114114
115− isRoot: ->
116− location.pathname is '/'
117−
118− isDocIndex: ->
119− @context and @context.doc and @context.entry is @context.doc.toEntry()
115+ isIndex: ->
116+ @context.path is '/' or (app.isSingleDoc() and @context?.entry?.isIndex())
120117
121118 setInitialPath: ->
122119 # Remove superfluous forward slashes at the beginning of the path
123120 if (path = location.pathname.replace /^\/{2,}/g, '/') isnt location.pathname
124121 page.replace path + location.search + location.hash, null, true
125122
126− if @isRoot()
123+ if location.pathname is '/'
127124 if path = @getInitialPathFromHash()
128125 page.replace path + location.search, null, true
129126 else if path = @getInitialPathFromCookie()
assets/javascripts/views/search/search.coffee+3−7
@@ -19,7 +19,6 @@ class app.views.Search extends app.View · 18 unmodified lines
1919 altS: 'stackoverflow'
2020
2121 @routes:
22− root: 'onRoot'
2322 after: 'afterRoute'
2423
2524 init: ->
@@ -77,9 +76,9 @@ class app.views.Search extends app.View · 51 unmodified lines
7776 return
7877
7978 searchUrl: =>
80− if app.router.isRoot()
79+ if location.pathname is '/'
8180 @scope.searchUrl()
82− else if not app.router.isDocIndex()
81+ else if not app.router.isIndex()
8382 return
8483
8584 return unless value = @extractHashValue()
@@ -129,11 +128,8 @@ class app.views.Search extends app.View · 43 unmodified lines
129128 $.stopEvent(event)
130129 return
131130
132− onRoot: (context) =>
133− @reset() unless context.init
134− return
135−
136131 afterRoute: (name, context) =>
132+ @reset() if not context.init and app.router.isIndex()
137133 @delay @searchUrl if context.hash
138134 @delay @autoFocus
139135 return