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: ->
@triggerResults [] unless @totalResults
@trigger 'end'
@free()
return

@ -17,6 +17,12 @@ templates.sidebarEntry = (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>"""
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) ->
"""<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
@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)

@ -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

@ -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
//

Loading…
Cancel
Save