[bug fix] Don't initialize search when disabled

fix #253
This commit is contained in:
zzossig 2020-06-11 14:02:09 +09:00
parent f321503b94
commit 7dff0a3f08
1 changed files with 28 additions and 24 deletions

View File

@ -558,6 +558,8 @@
var searchMenu = null;
var searchText = null;
{{ $enableSearch := ($.Param "enableSearch") }}
var enableSearch = JSON.parse({{ $enableSearch | jsonify }});
{{ $enableSearchHighlight := ($.Param "enableSearchHighlight") }}
var enableSearchHighlight = JSON.parse({{ $enableSearchHighlight | jsonify }});
{{ $searchResultPosition := ($.Param "searchResultPosition") }}
@ -567,30 +569,32 @@
var fuse = null;
(function initFuse() {
var xhr = new XMLHttpRequest();
xhr.open('GET', baseurl + "/index.json");
xhr.setRequestHeader('Content-Type', 'application/json; charset=utf-8');
xhr.onload = function () {
if (xhr.status === 200) {
fuse = new Fuse(JSON.parse(xhr.response.toString('utf-8')), {
keys: sectionType.includes('publication') ? ['title', 'abstract'] : ['title', 'description', 'content'],
includeMatches: enableSearchHighlight,
shouldSort: true,
threshold: 0.4,
location: 0,
distance: 100,
maxPatternLength: 32,
minMatchCharLength: 1,
});
window.fuse = fuse;
}
else {
console.error('[' + xhr.status + ']Error:', xhr.statusText);
}
};
xhr.send();
})();
if (enableSearch) {
(function initFuse() {
var xhr = new XMLHttpRequest();
xhr.open('GET', baseurl + "/index.json");
xhr.setRequestHeader('Content-Type', 'application/json; charset=utf-8');
xhr.onload = function () {
if (xhr.status === 200) {
fuse = new Fuse(JSON.parse(xhr.response.toString('utf-8')), {
keys: sectionType.includes('publication') ? ['title', 'abstract'] : ['title', 'description', 'content'],
includeMatches: enableSearchHighlight,
shouldSort: true,
threshold: 0.4,
location: 0,
distance: 100,
maxPatternLength: 32,
minMatchCharLength: 1,
});
window.fuse = fuse;
}
else {
console.error('[' + xhr.status + ']Error:', xhr.statusText);
}
};
xhr.send();
})();
}
function makeLi(ulElem, obj) {
var li = document.createElement('li');