diff --git a/src/server/internalServer.cpp b/src/server/internalServer.cpp index c2ccfd742..c749ebd9f 100644 --- a/src/server/internalServer.cpp +++ b/src/server/internalServer.cpp @@ -416,6 +416,8 @@ std::unique_ptr InternalServer::handle_suggest(const RequestContext& r MustacheData result; result.set("label", suggestion[0]); result.set("value", suggestion[0]); + result.set("kind", "path"); + result.set("path", suggestion[1]); result.set("first", first); first = false; results.push_back(result); @@ -428,6 +430,7 @@ std::unique_ptr InternalServer::handle_suggest(const RequestContext& r MustacheData result; result.set("label", "containing '" + term + "'..."); result.set("value", term + " "); + result.set("kind", "pattern"); result.set("first", first); results.push_back(result); } diff --git a/static/skin/taskbar.js b/static/skin/taskbar.js index edc01b7f2..358e1c9e6 100644 --- a/static/skin/taskbar.js +++ b/static/skin/taskbar.js @@ -5,26 +5,30 @@ function htmlDecode(input) { (function ($) { const root = $( `link[type='root']` ).attr("href"); + const bookName = window.location.pathname.split(`${root}/`)[1].split('/')[0]; $( "#kiwixsearchbox" ).autocomplete({ - source: `${root}/suggest?content=${window.location.pathname.split(`${root}/`)[1].split('/')[0]}`, + source: `${root}/suggest?content=${bookName}`, dataType: "json", cache: false, response: function( event, ui ) { - for(const item of ui.content) { item.label = htmlDecode(item.label); item.value = htmlDecode(item.value); + if (item.path) item.path = htmlDecode(item.path); } }, select: function(event, ui) { - $( "#kiwixsearchbox" ).val(ui.item.value); - $( "#kiwixsearchform" ).submit(); + 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..d327741e7 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}} ]