Bläddra i källkod

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

Thibaut Courouble 8 år sedan
förälder
incheckning
98a6eb58cb
2 ändrade filer med 6 tillägg och 13 borttagningar
  1. 3 6
      assets/javascripts/app/router.coffee
  2. 3 7
      assets/javascripts/views/search/search.coffee

+ 3 - 6
assets/javascripts/app/router.coffee

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

+ 3 - 7
assets/javascripts/views/search/search.coffee

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