HTML decoding of suggestions in the frontend

Since the `value` field of the search suggestion results is HTML
escaped/encoded in the backend (see static/templates/suggestion.json) it
must be decoded in the frontend.
This commit is contained in:
Veloman Yunkan 2021-03-03 00:41:38 +04:00 committed by Matthieu Gautier
parent 89d7e68a39
commit a7fea462b0
1 changed files with 10 additions and 0 deletions

View File

@ -4,6 +4,10 @@
<script type="text/javascript" src="{{root}}/skin/jquery-ui/external/jquery/jquery.js"></script>
<script type="text/javascript" src="{{root}}/skin/jquery-ui/jquery-ui.min.js"></script>
<script>
function htmlDecode(input) {
var doc = new DOMParser().parseFromString(input, "text/html");
return doc.documentElement.textContent;
}
var jk = jQuery.noConflict();
jk(function() {
jk( "#kiwixsearchbox" ).autocomplete({
@ -12,6 +16,12 @@
dataType: "json",
cache: false,
response: function( event, ui ) {
for(const item of ui.content) {
item.value = htmlDecode(item.value);
}
},
select: function(event, ui) {
jk( "#kiwixsearchbox" ).val(ui.item.value);
jk( "#kiwixsearchform" ).submit();