Closes #434.
Showing the changes to assets/javascripts (3 of 3 files). Show all
Unified · Split
| @@ -102,6 +102,9 @@ class app.Router · 101 unmodified lines | ||
| 102 | 102 | isRoot: -> |
| 103 | 103 | location.pathname is '/' |
| 104 | 104 | |
| 105 | + isDocIndex: -> | |
| 106 | + @context.doc and @context.entry is @context.doc.toEntry() | |
| 107 | + | |
| 105 | 108 | setInitialPath: -> |
| 106 | 109 | # Remove superfluous forward slashes at the beginning of the path |
| 107 | 110 | if (path = location.pathname.replace /^\/{2,}/g, '/') isnt location.pathname |
| @@ -20,7 +20,7 @@ class app.views.Search extends app.View · 19 unmodified lines | ||
| 20 | 20 | |
| 21 | 21 | @routes: |
| 22 | 22 | root: 'onRoot' |
| 23 | − after: 'autoFocus' | |
| 23 | + after: 'afterRoute' | |
| 24 | 24 | |
| 25 | 25 | init: -> |
| 26 | 26 | @addSubview @scope = new app.views.SearchScope @el |
| @@ -84,8 +84,10 @@ class app.views.Search extends app.View · 57 unmodified lines | ||
| 84 | 84 | return |
| 85 | 85 | |
| 86 | 86 | searchUrl: => |
| 87 | − return unless app.router.isRoot() | |
| 88 | − @scope.searchUrl() | |
| 87 | + if app.router.isRoot() | |
| 88 | + @scope.searchUrl() | |
| 89 | + else if not app.router.isDocIndex() | |
| 90 | + return | |
| 89 | 91 | |
| 90 | 92 | return unless value = @extractHashValue() |
| 91 | 93 | @input.value = @value = value |
| @@ -136,13 +138,18 @@ class app.views.Search extends app.View · 44 unmodified lines | ||
| 136 | 138 | |
| 137 | 139 | onRoot: (context) => |
| 138 | 140 | @reset() unless context.init |
| 139 | − @delay @searchUrl if context.hash | |
| 140 | 141 | return |
| 141 | 142 | |
| 143 | + afterRoute: (name, context) => | |
| 144 | + @delay @searchUrl if context.hash | |
| 145 | + @autoFocus() | |
| 146 | + | |
| 142 | 147 | extractHashValue: -> |
| 143 | 148 | if (value = @getHashValue())? |
| 144 | 149 | app.router.replaceHash() |
| 145 | 150 | value |
| 146 | 151 | |
| 152 | + HASH_RGX = new RegExp "^##{SEARCH_PARAM}=(.*)" | |
| 153 | + | |
| 147 | 154 | getHashValue: -> |
| 148 | − try (new RegExp "##{SEARCH_PARAM}=(.*)").exec($.urlDecode location.hash)?[1] catch | |
| 155 | + try HASH_RGX.exec($.urlDecode location.hash)?[1] catch | |
| @@ -32,19 +32,23 @@ class app.views.SearchScope extends app.View · 31 unmodified lines | ||
| 32 | 32 | name: -> |
| 33 | 33 | @doc?.name |
| 34 | 34 | |
| 35 | − search: (value) -> | |
| 36 | − unless @doc | |
| 37 | − @searcher.find app.docs.all(), 'text', value | |
| 35 | + search: (value, searchDisabled = false) -> | |
| 36 | + return if @doc | |
| 37 | + @searcher.find app.docs.all(), 'text', value | |
| 38 | + @searcher.find app.disabledDocs.all(), 'text', value if not @doc and searchDisabled | |
| 38 | 39 | return |
| 39 | 40 | |
| 40 | 41 | searchUrl: -> |
| 41 | 42 | if value = @extractHashValue() |
| 42 | − @search value | |
| 43 | + @search value, true | |
| 43 | 44 | return |
| 44 | 45 | |
| 45 | 46 | onResults: (results) => |
| 46 | − if results.length | |
| 47 | − @selectDoc results[0] | |
| 47 | + return unless doc = results[0] | |
| 48 | + if app.docs.contains(doc) | |
| 49 | + @selectDoc(doc) | |
| 50 | + else | |
| 51 | + @redirectToDoc(doc) | |
| 48 | 52 | return |
| 49 | 53 | |
| 50 | 54 | selectDoc: (doc) -> |
| @@ -63,6 +67,12 @@ class app.views.SearchScope extends app.View · 12 unmodified lines | ||
| 63 | 67 | @trigger 'change', @doc, previousDoc |
| 64 | 68 | return |
| 65 | 69 | |
| 70 | + redirectToDoc: (doc) -> | |
| 71 | + hash = location.hash | |
| 72 | + app.router.replaceHash('') | |
| 73 | + window.location = doc.fullPath() + hash | |
| 74 | + return | |
| 75 | + | |
| 66 | 76 | reset: => |
| 67 | 77 | return unless @doc |
| 68 | 78 | previousDoc = @doc |
| @@ -97,8 +107,10 @@ class app.views.SearchScope extends app.View · 28 unmodified lines | ||
| 97 | 107 | app.router.replaceHash(newHash) |
| 98 | 108 | value |
| 99 | 109 | |
| 110 | + HASH_RGX = new RegExp "^##{SEARCH_PARAM}=(.+?) ." | |
| 111 | + | |
| 100 | 112 | getHashValue: -> |
| 101 | − try (new RegExp "^##{SEARCH_PARAM}=(.+?) .").exec($.urlDecode location.hash)?[1] catch | |
| 113 | + try HASH_RGX.exec($.urlDecode location.hash)?[1] catch | |
| 102 | 114 | |
| 103 | 115 | afterRoute: (name, context) => |
| 104 | 116 | if !app.isSingleDoc() and context.init and context.doc |