Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/zzossig/hugo-theme-zzo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzzossig <zzossig@gmail.com>2020-06-11 08:02:09 +0300
committerzzossig <zzossig@gmail.com>2020-06-11 08:02:09 +0300
commit7dff0a3f08793ee1265cace4263f4ce4f102c257 (patch)
treead009389883942606367bf25e31341fe9db0eaa8 /layouts
parentf321503b94fafa405666acfec7c574ae50c60323 (diff)
[bug fix] Don't initialize search when disabled
fix #253
Diffstat (limited to 'layouts')
-rw-r--r--layouts/partials/head/scripts.html52
1 files changed, 28 insertions, 24 deletions
diff --git a/layouts/partials/head/scripts.html b/layouts/partials/head/scripts.html
index 42751e4..0006285 100644
--- a/layouts/partials/head/scripts.html
+++ b/layouts/partials/head/scripts.html
@@ -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');