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

pull/385/merge
Thibaut Courouble 8 years ago
parent 82743163c6
commit 98a6eb58cb

@ -112,18 +112,15 @@ class app.Router
@triggerRoute 'notFound' @triggerRoute 'notFound'
return return
isRoot: -> isIndex: ->
location.pathname is '/' @context.path is '/' or (app.isSingleDoc() and @context?.entry?.isIndex())
isDocIndex: ->
@context and @context.doc and @context.entry is @context.doc.toEntry()
setInitialPath: -> setInitialPath: ->
# Remove superfluous forward slashes at the beginning of the path # Remove superfluous forward slashes at the beginning of the path
if (path = location.pathname.replace /^\/{2,}/g, '/') isnt location.pathname if (path = location.pathname.replace /^\/{2,}/g, '/') isnt location.pathname
page.replace path + location.search + location.hash, null, true page.replace path + location.search + location.hash, null, true
if @isRoot() if location.pathname is '/'
if path = @getInitialPathFromHash() if path = @getInitialPathFromHash()
page.replace path + location.search, null, true page.replace path + location.search, null, true
else if path = @getInitialPathFromCookie() else if path = @getInitialPathFromCookie()

@ -19,7 +19,6 @@ class app.views.Search extends app.View
altS: 'stackoverflow' altS: 'stackoverflow'
@routes: @routes:
root: 'onRoot'
after: 'afterRoute' after: 'afterRoute'
init: -> init: ->
@ -77,9 +76,9 @@ class app.views.Search extends app.View
return return
searchUrl: => searchUrl: =>
if app.router.isRoot() if location.pathname is '/'
@scope.searchUrl() @scope.searchUrl()
else if not app.router.isDocIndex() else if not app.router.isIndex()
return return
return unless value = @extractHashValue() return unless value = @extractHashValue()
@ -129,11 +128,8 @@ class app.views.Search extends app.View
$.stopEvent(event) $.stopEvent(event)
return return
onRoot: (context) =>
@reset() unless context.init
return
afterRoute: (name, context) => afterRoute: (name, context) =>
@reset() if not context.init and app.router.isIndex()
@delay @searchUrl if context.hash @delay @searchUrl if context.hash
@delay @autoFocus @delay @autoFocus
return return

Loading…
Cancel
Save