Add info text when no search results are found

pull/129/head
Thibaut 11 years ago
parent dec60043f0
commit 4928c845a5

@ -42,6 +42,7 @@ class app.Searcher
end: -> end: ->
@triggerResults [] unless @totalResults @triggerResults [] unless @totalResults
@trigger 'end'
@free() @free()
return return

@ -17,6 +17,12 @@ templates.sidebarEntry = (entry) ->
templates.sidebarResult = (entry) -> templates.sidebarResult = (entry) ->
"""<a href="#{entry.fullPath()}" class="_list-item _list-hover _list-result _icon-#{entry.doc.slug}"><span class="_list-reveal" data-reset-list title="Reveal in list"></span>#{$.escape entry.name}</a>""" """<a href="#{entry.fullPath()}" class="_list-item _list-hover _list-result _icon-#{entry.doc.slug}"><span class="_list-reveal" data-reset-list title="Reveal in list"></span>#{$.escape entry.name}</a>"""
templates.sidebarNoResults = ->
info = if app.isSingleDoc() or app.disabledDocs.isEmpty() then '' else """
<span class="_list-noresults-note">Note: documentations must be <a class="_list-noresults-link" data-pick-docs>enabled</a> before they appear in the search.</span>
"""
""" <div class="_list-noresults">No results. #{info}</div> """
templates.sidebarPageLink = (count) -> templates.sidebarPageLink = (count) ->
"""<span class="_list-item _list-pagelink">Show more\u2026 (#{count})</span>""" """<span class="_list-item _list-pagelink">Show more\u2026 (#{count})</span>"""

@ -25,7 +25,9 @@ class app.views.Search extends app.View
@addSubview @scope = new app.views.SearchScope @el @addSubview @scope = new app.views.SearchScope @el
@searcher = new app.Searcher @searcher = new app.Searcher
@searcher.on 'results', @onResults @searcher
.on 'results', @onResults
.on 'end', @onEnd
app.on 'ready', @onReady app.on 'ready', @onReady
$.on window, 'hashchange', @searchUrl $.on window, 'hashchange', @searchUrl
@ -66,6 +68,7 @@ class app.views.Search extends app.View
@addClass @constructor.activeClass @addClass @constructor.activeClass
@trigger 'searching' @trigger 'searching'
@hasResults = null
@flags = urlSearch: url, initialResults: true @flags = urlSearch: url, initialResults: true
@searcher.find @scope.getScope().entries.all(), 'text', @value @searcher.find @scope.getScope().entries.all(), 'text', @value
return return
@ -90,10 +93,15 @@ class app.views.Search extends app.View
return return
onResults: (results) => onResults: (results) =>
@hasResults = true if results.length
@trigger 'results', results, @flags @trigger 'results', results, @flags
@flags.initialResults = false @flags.initialResults = false
return return
onEnd: =>
@trigger 'noresults' unless @hasResults
return
onClick: (event) => onClick: (event) =>
if event.target is @resetLink if event.target is @resetLink
$.stopEvent(event) $.stopEvent(event)

@ -17,6 +17,7 @@ class app.views.Results extends app.View
@search @search
.on 'results', @onResults .on 'results', @onResults
.on 'noresults', @onNoResults
.on 'clear', @onClear .on 'clear', @onClear
return return
@ -28,6 +29,10 @@ class app.views.Results extends app.View
if flags.urlSearch then @openFirst() else @focusFirst() if flags.urlSearch then @openFirst() else @focusFirst()
return return
onNoResults: =>
@html @tmpl('sidebarNoResults')
return
onClear: => onClear: =>
@empty() @empty()
return return

@ -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 // List hover clone
// //

Loading…
Cancel
Save