mirror of https://github.com/kiwix/libkiwix.git
adding kind and path attributes to suggest response object and using it in autocomplete
This commit is contained in:
parent
e4be97a032
commit
5cb276a933
|
@ -416,6 +416,8 @@ std::unique_ptr<Response> InternalServer::handle_suggest(const RequestContext& r
|
||||||
MustacheData result;
|
MustacheData result;
|
||||||
result.set("label", suggestion[0]);
|
result.set("label", suggestion[0]);
|
||||||
result.set("value", suggestion[0]);
|
result.set("value", suggestion[0]);
|
||||||
|
result.set("kind", "path");
|
||||||
|
result.set("path", suggestion[1]);
|
||||||
result.set("first", first);
|
result.set("first", first);
|
||||||
first = false;
|
first = false;
|
||||||
results.push_back(result);
|
results.push_back(result);
|
||||||
|
@ -428,6 +430,7 @@ std::unique_ptr<Response> InternalServer::handle_suggest(const RequestContext& r
|
||||||
MustacheData result;
|
MustacheData result;
|
||||||
result.set("label", "containing '" + term + "'...");
|
result.set("label", "containing '" + term + "'...");
|
||||||
result.set("value", term + " ");
|
result.set("value", term + " ");
|
||||||
|
result.set("kind", "pattern");
|
||||||
result.set("first", first);
|
result.set("first", first);
|
||||||
results.push_back(result);
|
results.push_back(result);
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,26 +5,30 @@ function htmlDecode(input) {
|
||||||
|
|
||||||
(function ($) {
|
(function ($) {
|
||||||
const root = $( `link[type='root']` ).attr("href");
|
const root = $( `link[type='root']` ).attr("href");
|
||||||
|
const bookName = window.location.pathname.split(`${root}/`)[1].split('/')[0];
|
||||||
|
|
||||||
$( "#kiwixsearchbox" ).autocomplete({
|
$( "#kiwixsearchbox" ).autocomplete({
|
||||||
|
|
||||||
source: `${root}/suggest?content=${window.location.pathname.split(`${root}/`)[1].split('/')[0]}`,
|
source: `${root}/suggest?content=${bookName}`,
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
cache: false,
|
cache: false,
|
||||||
|
|
||||||
response: function( event, ui ) {
|
response: function( event, ui ) {
|
||||||
|
|
||||||
for(const item of ui.content) {
|
for(const item of ui.content) {
|
||||||
item.label = htmlDecode(item.label);
|
item.label = htmlDecode(item.label);
|
||||||
item.value = htmlDecode(item.value);
|
item.value = htmlDecode(item.value);
|
||||||
|
if (item.path) item.path = htmlDecode(item.path);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
select: function(event, ui) {
|
select: function(event, ui) {
|
||||||
|
if (ui.item.kind === 'path') {
|
||||||
|
window.location.href = `${root}/${bookName}/${encodeURI(ui.item.path)}`;
|
||||||
|
} else {
|
||||||
$( "#kiwixsearchbox" ).val(ui.item.value);
|
$( "#kiwixsearchbox" ).val(ui.item.value);
|
||||||
$( "#kiwixsearchform" ).submit();
|
$( "#kiwixsearchform" ).submit();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
/* cybook hack */
|
/* cybook hack */
|
||||||
|
|
|
@ -2,6 +2,10 @@
|
||||||
{{#suggestions}}{{^first}},{{/first}}
|
{{#suggestions}}{{^first}},{{/first}}
|
||||||
{
|
{
|
||||||
"value" : "{{value}}",
|
"value" : "{{value}}",
|
||||||
"label" : "{{label}}"
|
"label" : "{{label}}",
|
||||||
|
"kind" : "{{kind}}"
|
||||||
|
{{#path}}
|
||||||
|
, "path" : "{{path}}"
|
||||||
|
{{/path}}
|
||||||
}{{/suggestions}}
|
}{{/suggestions}}
|
||||||
]
|
]
|
||||||
|
|
Loading…
Reference in New Issue