Skip to content

Commit

Permalink
changed suggest response to label,url in place of label,value
Browse files Browse the repository at this point in the history
  • Loading branch information
MananJethwani committed Mar 18, 2021
1 parent baed447 commit 246c1be
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/server/internalServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ std::unique_ptr<Response> InternalServer::handle_suggest(const RequestContext& r
for(auto& suggestion:suggestions) {
MustacheData result;
result.set("label", suggestion[0]);
result.set("value", suggestion[0]);
result.set("url", bookName + "/" + suggestion[1]);
result.set("first", first);
first = false;
results.push_back(result);
Expand All @@ -427,7 +427,7 @@ std::unique_ptr<Response> InternalServer::handle_suggest(const RequestContext& r
if (reader->hasFulltextIndex()) {
MustacheData result;
result.set("label", "containing '" + term + "'...");
result.set("value", term + " ");
result.set("url", "search?content=" + bookName + "&pattern=" + kiwix::urlEncode(term, true) + "+");
result.set("first", first);
results.push_back(result);
}
Expand Down
10 changes: 8 additions & 2 deletions static/skin/taskbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,15 @@ function htmlDecode(input) {
}
},

focus: function(event, ui) {
$( "#kiwixsearchbox" ).val(ui.item.label);
return false;
},

select: function(event, ui) {
$( "#kiwixsearchbox" ).val(ui.item.value);
$( "#kiwixsearchform" ).submit();
window.location.href = `${root}/${ui.item.value}`;
$( "#kiwixsearchbox" ).val(ui.item.label);
return false;
},

});
Expand Down
4 changes: 3 additions & 1 deletion static/templates/suggestion.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
[
{{#suggestions}}{{^first}},{{/first}}
{
"value" : "{{value}}",
{{! HTML escaping is not disabled for the URL on purpose - otherwise invalid JSON may be produced for a URL containing a double quote.
HTML decoding is performed in the front-end by ../skin/taskbar.js }}
"value" : "{{url}}",
"label" : "{{label}}"
}{{/suggestions}}
]

0 comments on commit 246c1be

Please sign in to comment.