Skip to content

Commit

Permalink
added kind and path in response
Browse files Browse the repository at this point in the history
  • Loading branch information
MananJethwani committed Apr 4, 2021
1 parent e5ddc38 commit 9626b03
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 21 deletions.
8 changes: 6 additions & 2 deletions src/server/internalServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,9 @@ 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[1]);
result.set("value", suggestion[0]);
result.set("kind", "path");
result.set("path", suggestion[1]);
result.set("first", first);
first = false;
results.push_back(result);
Expand All @@ -427,7 +429,9 @@ 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("value", term + " ");
result.set("kind", "pattern");
result.set("path", "");
result.set("first", first);
results.push_back(result);
}
Expand Down
25 changes: 7 additions & 18 deletions static/skin/taskbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,20 @@ function htmlDecode(input) {
cache: false,

response: function( event, ui ) {

for(const item of ui.content) {
item.label = htmlDecode(item.label);
item.value = encodeURI(htmlDecode(item.value));

if (item.label === `containing '${item.value}'...`) {
item.value = `${root}/search?content=${bookName}&pattern=${item.value}+`;
}
else {
item.value = `${root}/${bookName}/${item.value}`;
}
item.value = htmlDecode(item.value);
}
},

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

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

});

/* cybook hack */
Expand Down
6 changes: 5 additions & 1 deletion static/templates/suggestion.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
{{#suggestions}}{{^first}},{{/first}}
{
"value" : "{{value}}",
"label" : "{{label}}"
"label" : "{{label}}",
"kind" : "{{kind}}",
{{#path}}
"path" : "{{path}}"
{{/path}}
}{{/suggestions}}
]

0 comments on commit 9626b03

Please sign in to comment.