From 4928c845a54aa6f80883110462529cc92ba79e4d Mon Sep 17 00:00:00 2001 From: Thibaut Date: Sat, 23 Aug 2014 17:51:40 -0400 Subject: [PATCH] Add info text when no search results are found --- assets/javascripts/app/searcher.coffee | 1 + assets/javascripts/templates/sidebar_tmpl.coffee | 6 ++++++ assets/javascripts/views/search/search.coffee | 10 +++++++++- assets/javascripts/views/sidebar/results.coffee | 5 +++++ assets/stylesheets/components/_sidebar.scss | 14 ++++++++++++++ 5 files changed, 35 insertions(+), 1 deletion(-) diff --git a/assets/javascripts/app/searcher.coffee b/assets/javascripts/app/searcher.coffee index bf5f8a5b..f2310344 100644 --- a/assets/javascripts/app/searcher.coffee +++ b/assets/javascripts/app/searcher.coffee @@ -42,6 +42,7 @@ class app.Searcher end: -> @triggerResults [] unless @totalResults + @trigger 'end' @free() return diff --git a/assets/javascripts/templates/sidebar_tmpl.coffee b/assets/javascripts/templates/sidebar_tmpl.coffee index 9ed4a4f2..1f171763 100644 --- a/assets/javascripts/templates/sidebar_tmpl.coffee +++ b/assets/javascripts/templates/sidebar_tmpl.coffee @@ -17,6 +17,12 @@ templates.sidebarEntry = (entry) -> templates.sidebarResult = (entry) -> """#{$.escape entry.name}""" +templates.sidebarNoResults = -> + info = if app.isSingleDoc() or app.disabledDocs.isEmpty() then '' else """ + Note: documentations must be enabled before they appear in the search. + """ + """
No results. #{info}
""" + templates.sidebarPageLink = (count) -> """Show more\u2026 (#{count})""" diff --git a/assets/javascripts/views/search/search.coffee b/assets/javascripts/views/search/search.coffee index 7c4191c0..e6ef6715 100644 --- a/assets/javascripts/views/search/search.coffee +++ b/assets/javascripts/views/search/search.coffee @@ -25,7 +25,9 @@ class app.views.Search extends app.View @addSubview @scope = new app.views.SearchScope @el @searcher = new app.Searcher - @searcher.on 'results', @onResults + @searcher + .on 'results', @onResults + .on 'end', @onEnd app.on 'ready', @onReady $.on window, 'hashchange', @searchUrl @@ -66,6 +68,7 @@ class app.views.Search extends app.View @addClass @constructor.activeClass @trigger 'searching' + @hasResults = null @flags = urlSearch: url, initialResults: true @searcher.find @scope.getScope().entries.all(), 'text', @value return @@ -90,10 +93,15 @@ class app.views.Search extends app.View return onResults: (results) => + @hasResults = true if results.length @trigger 'results', results, @flags @flags.initialResults = false return + onEnd: => + @trigger 'noresults' unless @hasResults + return + onClick: (event) => if event.target is @resetLink $.stopEvent(event) diff --git a/assets/javascripts/views/sidebar/results.coffee b/assets/javascripts/views/sidebar/results.coffee index e732be4d..6d204ce6 100644 --- a/assets/javascripts/views/sidebar/results.coffee +++ b/assets/javascripts/views/sidebar/results.coffee @@ -17,6 +17,7 @@ class app.views.Results extends app.View @search .on 'results', @onResults + .on 'noresults', @onNoResults .on 'clear', @onClear return @@ -28,6 +29,10 @@ class app.views.Results extends app.View if flags.urlSearch then @openFirst() else @focusFirst() return + onNoResults: => + @html @tmpl('sidebarNoResults') + return + onClear: => @empty() return diff --git a/assets/stylesheets/components/_sidebar.scss b/assets/stylesheets/components/_sidebar.scss index 4c136def..efcfca6b 100644 --- a/assets/stylesheets/components/_sidebar.scss +++ b/assets/stylesheets/components/_sidebar.scss @@ -229,6 +229,20 @@ } } +._list-noresults { + padding: .625rem .75rem; + line-height: 1.25rem; + font-size: .8125rem; + color: $textColorLight; +} + +._list-noresults-note { + display: block; + margin-top: .375rem; +} + +._list-noresults-link { cursor: pointer; } + // // List hover clone //