From 9626b03e564c69ea53eddd5745c4744a480990d5 Mon Sep 17 00:00:00 2001 From: Manan Jethwani Date: Thu, 1 Apr 2021 18:49:00 +0530 Subject: [PATCH] added kind and path in response --- src/server/internalServer.cpp | 8 ++++++-- static/skin/taskbar.js | 25 +++++++------------------ static/templates/suggestion.json | 6 +++++- 3 files changed, 18 insertions(+), 21 deletions(-) diff --git a/src/server/internalServer.cpp b/src/server/internalServer.cpp index d58c02e5c..941903cac 100644 --- a/src/server/internalServer.cpp +++ b/src/server/internalServer.cpp @@ -415,7 +415,9 @@ std::unique_ptr 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); @@ -427,7 +429,9 @@ std::unique_ptr 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); } diff --git a/static/skin/taskbar.js b/static/skin/taskbar.js index 198f92206..810649f05 100644 --- a/static/skin/taskbar.js +++ b/static/skin/taskbar.js @@ -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 */ diff --git a/static/templates/suggestion.json b/static/templates/suggestion.json index cedb609a3..72159fa10 100644 --- a/static/templates/suggestion.json +++ b/static/templates/suggestion.json @@ -2,6 +2,10 @@ {{#suggestions}}{{^first}},{{/first}} { "value" : "{{value}}", - "label" : "{{label}}" + "label" : "{{label}}", + "kind" : "{{kind}}", + {{#path}} + "path" : "{{path}}" + {{/path}} }{{/suggestions}} ]