just-the-docs 0.2.9 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -57,6 +57,7 @@ $sidebar-color: $grey-lt-000 !default;
57
57
  $search-background-color: $white !default;
58
58
  $table-background-color: $white !default;
59
59
  $code-background-color: $grey-lt-000 !default;
60
+ $feedback-color: darken($sidebar-color, 3%) !default;
60
61
 
61
62
  $body-text-color: $grey-dk-100 !default;
62
63
  $body-heading-color: $grey-dk-300 !default;
@@ -94,8 +95,8 @@ $sp-5: map-get($spacers, sp-5) !default; // 1.5 rem == 24px
94
95
  $sp-6: map-get($spacers, sp-6) !default; // 2 rem == 32px
95
96
  $sp-7: map-get($spacers, sp-7) !default; // 2.5 rem == 40px
96
97
  $sp-8: map-get($spacers, sp-8) !default; // 3 rem == 48px
97
- $sp-9: map-get($spacers, sp-9) !default; // 4 rem == 48px
98
- $sp-10: map-get($spacers, sp-10) !default; // 4.5 rem == 48px
98
+ $sp-9: map-get($spacers, sp-9) !default; // 3.5 rem == 56px
99
+ $sp-10: map-get($spacers, sp-10) !default; // 4 rem == 64px
99
100
 
100
101
  //
101
102
  // Borders
@@ -113,9 +114,13 @@ $gutter-spacing: $sp-6 !default;
113
114
  $gutter-spacing-sm: $sp-4 !default;
114
115
  $nav-width: 264px !default;
115
116
  $nav-width-md: 248px !default;
117
+ $nav-list-item-height: $sp-6 !default;
118
+ $nav-list-item-height-sm: $sp-8 !default;
119
+ $nav-list-expander-right: true;
116
120
  $content-width: 800px !default;
117
121
  $header-height: 60px !default;
118
- $search-results-width: 500px !default;
122
+ $search-results-width: $content-width - $nav-width !default;
123
+ $transition-duration: 400ms;
119
124
 
120
125
  //
121
126
  // Media queries in pixels
@@ -24,24 +24,47 @@ jtd.onReady = function(ready) {
24
24
  // Show/hide mobile menu
25
25
 
26
26
  function initNav() {
27
- const mainNav = document.querySelector('.js-main-nav');
28
- const pageHeader = document.querySelector('.js-page-header');
29
- const navTrigger = document.querySelector('.js-main-nav-trigger');
27
+ jtd.addEvent(document, 'click', function(e){
28
+ var target = e.target;
29
+ while (target && !(target.classList && target.classList.contains('nav-list-expander'))) {
30
+ target = target.parentNode;
31
+ }
32
+ if (target) {
33
+ e.preventDefault();
34
+ target.parentNode.classList.toggle('active');
35
+ }
36
+ });
37
+
38
+ const siteNav = document.getElementById('site-nav');
39
+ const mainHeader = document.getElementById('main-header');
40
+ const menuButton = document.getElementById('menu-button');
30
41
 
31
- jtd.addEvent(navTrigger, 'click', function(e){
42
+ jtd.addEvent(menuButton, 'click', function(e){
32
43
  e.preventDefault();
33
- var text = navTrigger.innerText;
34
- var textToggle = navTrigger.getAttribute('data-text-toggle');
35
-
36
- mainNav.classList.toggle('nav-open');
37
- pageHeader.classList.toggle('nav-open');
38
- navTrigger.classList.toggle('nav-open');
39
- navTrigger.innerText = textToggle;
40
- navTrigger.setAttribute('data-text-toggle', text);
41
- textToggle = text;
42
- })
44
+
45
+ if (menuButton.classList.toggle('nav-open')) {
46
+ siteNav.classList.add('nav-open');
47
+ mainHeader.classList.add('nav-open');
48
+ } else {
49
+ siteNav.classList.remove('nav-open');
50
+ mainHeader.classList.remove('nav-open');
51
+ }
52
+ });
53
+
54
+ {%- if site.search_enabled != false and site.search.button %}
55
+ const searchInput = document.getElementById('search-input');
56
+ const searchButton = document.getElementById('search-button');
57
+
58
+ jtd.addEvent(searchButton, 'click', function(e){
59
+ e.preventDefault();
60
+
61
+ mainHeader.classList.add('nav-open');
62
+ searchInput.focus();
63
+ });
64
+ {%- endif %}
43
65
  }
44
66
 
67
+ {%- if site.search_enabled != false %}
45
68
  // Site search
46
69
 
47
70
  function initSearch() {
@@ -50,241 +73,377 @@ function initSearch() {
50
73
 
51
74
  request.onload = function(){
52
75
  if (request.status >= 200 && request.status < 400) {
53
- // Success!
54
- var data = JSON.parse(request.responseText);
76
+ var docs = JSON.parse(request.responseText);
55
77
 
56
- {% if site.search_tokenizer_separator != nil %}
57
- lunr.tokenizer.separator = {{ site.search_tokenizer_separator }}
58
- {% else %}
59
- lunr.tokenizer.separator = /[\s\-/]+/
60
- {% endif %}
61
-
62
- var index = lunr(function () {
78
+ lunr.tokenizer.separator = {{ site.search.tokenizer_separator | default: site.search_tokenizer_separator | default: "/[\s\-/]+/" }}
79
+
80
+ var index = lunr(function(){
63
81
  this.ref('id');
64
82
  this.field('title', { boost: 200 });
65
83
  this.field('content', { boost: 2 });
66
- this.field('url');
84
+ {%- if site.search.rel_url != false %}
85
+ this.field('relUrl');
86
+ {%- endif %}
67
87
  this.metadataWhitelist = ['position']
68
88
 
69
- for (var i in data) {
89
+ for (var i in docs) {
70
90
  this.add({
71
91
  id: i,
72
- title: data[i].title,
73
- content: data[i].content,
74
- url: data[i].url
92
+ title: docs[i].title,
93
+ content: docs[i].content,
94
+ {%- if site.search.rel_url != false %}
95
+ relUrl: docs[i].relUrl
96
+ {%- endif %}
75
97
  });
76
98
  }
77
99
  });
78
100
 
79
- searchResults(index, data);
101
+ searchLoaded(index, docs);
80
102
  } else {
81
- // We reached our target server, but it returned an error
82
103
  console.log('Error loading ajax request. Request status:' + request.status);
83
104
  }
84
105
  };
85
106
 
86
107
  request.onerror = function(){
87
- // There was a connection error of some sort
88
108
  console.log('There was a connection error');
89
109
  };
90
110
 
91
111
  request.send();
112
+ }
113
+
114
+ function searchLoaded(index, docs) {
115
+ var index = index;
116
+ var docs = docs;
117
+ var searchInput = document.getElementById('search-input');
118
+ var searchResults = document.getElementById('search-results');
119
+ var mainHeader = document.getElementById('main-header');
120
+ var currentInput;
121
+ var currentSearchIndex = 0;
122
+
123
+ function showSearch() {
124
+ document.documentElement.classList.add('search-active');
125
+ }
126
+
127
+ function hideSearch() {
128
+ document.documentElement.classList.remove('search-active');
129
+ }
92
130
 
93
- function searchResults(index, data) {
94
- var index = index;
95
- var docs = data;
96
- var searchInput = document.querySelector('.js-search-input');
97
- var searchResults = document.querySelector('.js-search-results');
131
+ function update() {
132
+ currentSearchIndex++;
98
133
 
99
- function hideResults() {
100
- searchResults.innerHTML = '';
101
- searchResults.classList.remove('active');
134
+ var input = searchInput.value;
135
+ if (input === '') {
136
+ hideSearch();
137
+ } else {
138
+ showSearch();
139
+ // scroll search input into view, workaround for iOS Safari
140
+ window.scroll(0, -1);
141
+ setTimeout(function(){ window.scroll(0, 0); }, 0);
142
+ }
143
+ if (input === currentInput) {
144
+ return;
145
+ }
146
+ currentInput = input;
147
+ searchResults.innerHTML = '';
148
+ if (input === '') {
149
+ return;
102
150
  }
103
151
 
104
- jtd.addEvent(searchInput, 'keydown', function(e){
105
- switch (e.keyCode) {
106
- case 38: // arrow up
107
- e.preventDefault();
108
- var active = document.querySelector('.search-result.active');
109
- if (active) {
110
- active.classList.remove('active');
111
- if (active.parentElement.previousSibling) {
112
- var previous = active.parentElement.previousSibling.querySelector('.search-result');
113
- previous.classList.add('active');
114
- }
115
- }
116
- return;
117
- case 40: // arrow down
118
- e.preventDefault();
119
- var active = document.querySelector('.search-result.active');
120
- if (active) {
121
- if (active.parentElement.nextSibling) {
122
- var next = active.parentElement.nextSibling.querySelector('.search-result');
123
- active.classList.remove('active');
124
- next.classList.add('active');
125
- }
126
- } else {
127
- var next = document.querySelector('.search-result');
128
- if (next) {
129
- next.classList.add('active');
130
- }
131
- }
132
- return;
133
- case 13: // enter
134
- e.preventDefault();
135
- var active = document.querySelector('.search-result.active');
136
- if (active) {
137
- active.click();
138
- } else {
139
- var first = document.querySelector('.search-result');
140
- if (first) {
141
- first.click();
142
- }
143
- }
144
- return;
145
- }
152
+ var results = index.query(function (query) {
153
+ var tokens = lunr.tokenizer(input)
154
+ query.term(tokens, {
155
+ boost: 10
156
+ });
157
+ query.term(tokens, {
158
+ wildcard: lunr.Query.wildcard.TRAILING
159
+ });
146
160
  });
147
161
 
148
- jtd.addEvent(searchInput, 'keyup', function(e){
149
- switch (e.keyCode) {
150
- case 27: // When esc key is pressed, hide the results and clear the field
151
- hideResults();
152
- searchInput.value = '';
153
- return;
154
- case 38: // arrow up
155
- case 40: // arrow down
156
- case 13: // enter
157
- e.preventDefault();
158
- return;
162
+ if ((results.length == 0) && (input.length > 2)) {
163
+ var tokens = lunr.tokenizer(input).filter(function(token, i) {
164
+ return token.str.length < 20;
165
+ })
166
+ if (tokens.length > 0) {
167
+ results = index.query(function (query) {
168
+ query.term(tokens, {
169
+ editDistance: Math.round(Math.sqrt(input.length / 2 - 1))
170
+ });
171
+ });
159
172
  }
173
+ }
174
+
175
+ if (results.length == 0) {
176
+ var noResultsDiv = document.createElement('div');
177
+ noResultsDiv.classList.add('search-no-result');
178
+ noResultsDiv.innerText = 'No results found';
179
+ searchResults.appendChild(noResultsDiv);
160
180
 
161
- hideResults();
181
+ } else {
182
+ var resultsList = document.createElement('ul');
183
+ resultsList.classList.add('search-results-list');
184
+ searchResults.appendChild(resultsList);
185
+
186
+ addResults(resultsList, results, 0, 10, 100, currentSearchIndex);
187
+ }
162
188
 
163
- var input = this.value;
164
- if (input === '') {
189
+ function addResults(resultsList, results, start, batchSize, batchMillis, searchIndex) {
190
+ if (searchIndex != currentSearchIndex) {
165
191
  return;
166
192
  }
193
+ for (var i = start; i < (start + batchSize); i++) {
194
+ if (i == results.length) {
195
+ return;
196
+ }
197
+ addResult(resultsList, results[i]);
198
+ }
199
+ setTimeout(function() {
200
+ addResults(resultsList, results, start + batchSize, batchSize, batchMillis, searchIndex);
201
+ }, batchMillis);
202
+ }
167
203
 
168
- var results = index.query(function (query) {
169
- var tokens = lunr.tokenizer(input)
170
- query.term(tokens, {
171
- boost: 10
172
- });
173
- query.term(tokens, {
174
- wildcard: lunr.Query.wildcard.TRAILING
175
- });
176
- });
204
+ function addResult(resultsList, result) {
205
+ var doc = docs[result.ref];
206
+
207
+ var resultsListItem = document.createElement('li');
208
+ resultsListItem.classList.add('search-results-list-item');
209
+ resultsList.appendChild(resultsListItem);
210
+
211
+ var resultLink = document.createElement('a');
212
+ resultLink.classList.add('search-result');
213
+ resultLink.setAttribute('href', doc.url);
214
+ resultsListItem.appendChild(resultLink);
215
+
216
+ var resultTitle = document.createElement('div');
217
+ resultTitle.classList.add('search-result-title');
218
+ resultLink.appendChild(resultTitle);
219
+
220
+ var resultDoc = document.createElement('div');
221
+ resultDoc.classList.add('search-result-doc');
222
+ resultDoc.innerHTML = '<svg viewBox="0 0 24 24" class="search-result-icon"><use xlink:href="#svg-doc"></use></svg>';
223
+ resultTitle.appendChild(resultDoc);
224
+
225
+ var resultDocTitle = document.createElement('div');
226
+ resultDocTitle.classList.add('search-result-doc-title');
227
+ resultDocTitle.innerHTML = doc.doc;
228
+ resultDoc.appendChild(resultDocTitle);
229
+ var resultDocOrSection = resultDocTitle;
230
+
231
+ if (doc.doc != doc.title) {
232
+ resultDoc.classList.add('search-result-doc-parent');
233
+ var resultSection = document.createElement('div');
234
+ resultSection.classList.add('search-result-section');
235
+ resultSection.innerHTML = doc.title;
236
+ resultTitle.appendChild(resultSection);
237
+ resultDocOrSection = resultSection;
238
+ }
177
239
 
178
- if (results.length > 0) {
179
- searchResults.classList.add('active');
180
- var resultsList = document.createElement('ul');
181
- resultsList.classList.add('search-results-list');
182
- searchResults.appendChild(resultsList);
183
-
184
- for (var i in results) {
185
- var result = results[i];
186
- var doc = docs[result.ref];
187
-
188
- var resultsListItem = document.createElement('li');
189
- resultsListItem.classList.add('search-results-list-item');
190
- resultsList.appendChild(resultsListItem);
191
-
192
- var resultLink = document.createElement('a');
193
- resultLink.classList.add('search-result');
194
- resultLink.setAttribute('href', doc.url);
195
- resultsListItem.appendChild(resultLink);
196
-
197
- var resultTitle = document.createElement('div');
198
- resultTitle.classList.add('search-result-title');
199
- resultTitle.innerText = doc.title;
200
- resultLink.appendChild(resultTitle);
201
-
202
- var resultRelUrl = document.createElement('span');
203
- resultRelUrl.classList.add('search-result-rel-url');
204
- resultRelUrl.innerText = doc.relUrl;
205
- resultTitle.appendChild(resultRelUrl);
206
-
207
- var metadata = result.matchData.metadata;
208
- var contentFound = false;
209
- for (var j in metadata) {
210
- if (metadata[j].title) {
211
- var position = metadata[j].title.position[0];
212
- var start = position[0];
213
- var end = position[0] + position[1];
214
- resultTitle.innerHTML = doc.title.substring(0, start) + '<span class="search-result-highlight">' + doc.title.substring(start, end) + '</span>' + doc.title.substring(end, doc.title.length)+'<span class="search-result-rel-url">'+doc.relUrl+'</span>';
215
-
216
- } else if (metadata[j].content && !contentFound) {
217
- contentFound = true;
218
-
219
- var position = metadata[j].content.position[0];
220
- var start = position[0];
221
- var end = position[0] + position[1];
222
- var previewStart = start;
223
- var previewEnd = end;
224
- var ellipsesBefore = true;
225
- var ellipsesAfter = true;
226
- for (var k = 0; k < 3; k++) {
227
- var nextSpace = doc.content.lastIndexOf(' ', previewStart - 2);
228
- var nextDot = doc.content.lastIndexOf('.', previewStart - 2);
229
- if ((nextDot > 0) && (nextDot > nextSpace)) {
230
- previewStart = nextDot + 1;
231
- ellipsesBefore = false;
232
- break;
233
- }
234
- if (nextSpace < 0) {
235
- previewStart = 0;
236
- ellipsesBefore = false;
237
- break;
238
- }
239
- previewStart = nextSpace + 1;
240
+ var metadata = result.matchData.metadata;
241
+ var titlePositions = [];
242
+ var contentPositions = [];
243
+ for (var j in metadata) {
244
+ var meta = metadata[j];
245
+ if (meta.title) {
246
+ var positions = meta.title.position;
247
+ for (var k in positions) {
248
+ titlePositions.push(positions[k]);
249
+ }
250
+ }
251
+ if (meta.content) {
252
+ var positions = meta.content.position;
253
+ for (var k in positions) {
254
+ var position = positions[k];
255
+ var previewStart = position[0];
256
+ var previewEnd = position[0] + position[1];
257
+ var ellipsesBefore = true;
258
+ var ellipsesAfter = true;
259
+ for (var k = 0; k < {{ site.search.preview_words_before | default: 5 }}; k++) {
260
+ var nextSpace = doc.content.lastIndexOf(' ', previewStart - 2);
261
+ var nextDot = doc.content.lastIndexOf('. ', previewStart - 2);
262
+ if ((nextDot >= 0) && (nextDot > nextSpace)) {
263
+ previewStart = nextDot + 1;
264
+ ellipsesBefore = false;
265
+ break;
240
266
  }
241
- for (var k = 0; k < 10; k++) {
242
- var nextSpace = doc.content.indexOf(' ', previewEnd + 1);
243
- var nextDot = doc.content.indexOf('.', previewEnd + 1);
244
- if ((nextDot > 0) && (nextDot < nextSpace)) {
245
- previewEnd = nextDot;
246
- ellipsesAfter = false;
247
- break;
248
- }
249
- if (nextSpace < 0) {
250
- previewEnd = doc.content.length;
251
- ellipsesAfter = false;
252
- break;
253
- }
254
- previewEnd = nextSpace;
267
+ if (nextSpace < 0) {
268
+ previewStart = 0;
269
+ ellipsesBefore = false;
270
+ break;
255
271
  }
256
- var preview = doc.content.substring(previewStart, start);
257
- if (ellipsesBefore) {
258
- preview = '... ' + preview;
272
+ previewStart = nextSpace + 1;
273
+ }
274
+ for (var k = 0; k < {{ site.search.preview_words_after | default: 10 }}; k++) {
275
+ var nextSpace = doc.content.indexOf(' ', previewEnd + 1);
276
+ var nextDot = doc.content.indexOf('. ', previewEnd + 1);
277
+ if ((nextDot >= 0) && (nextDot < nextSpace)) {
278
+ previewEnd = nextDot;
279
+ ellipsesAfter = false;
280
+ break;
259
281
  }
260
- preview += '<span class="search-result-highlight">' + doc.content.substring(start, end) + '</span>';
261
- preview += doc.content.substring(end, previewEnd);
262
- if (ellipsesAfter) {
263
- preview += ' ...';
282
+ if (nextSpace < 0) {
283
+ previewEnd = doc.content.length;
284
+ ellipsesAfter = false;
285
+ break;
264
286
  }
287
+ previewEnd = nextSpace;
288
+ }
289
+ contentPositions.push({
290
+ highlight: position,
291
+ previewStart: previewStart, previewEnd: previewEnd,
292
+ ellipsesBefore: ellipsesBefore, ellipsesAfter: ellipsesAfter
293
+ });
294
+ }
295
+ }
296
+ }
297
+
298
+ if (titlePositions.length > 0) {
299
+ titlePositions.sort(function(p1, p2){ return p1[0] - p2[0] });
300
+ resultDocOrSection.innerHTML = '';
301
+ addHighlightedText(resultDocOrSection, doc.title, 0, doc.title.length, titlePositions);
302
+ }
265
303
 
266
- var resultPreview = document.createElement('div');
267
- resultPreview.classList.add('search-result-preview');
268
- resultPreview.innerHTML = preview;
269
- resultLink.appendChild(resultPreview);
304
+ if (contentPositions.length > 0) {
305
+ contentPositions.sort(function(p1, p2){ return p1.highlight[0] - p2.highlight[0] });
306
+ var contentPosition = contentPositions[0];
307
+ var previewPosition = {
308
+ highlight: [contentPosition.highlight],
309
+ previewStart: contentPosition.previewStart, previewEnd: contentPosition.previewEnd,
310
+ ellipsesBefore: contentPosition.ellipsesBefore, ellipsesAfter: contentPosition.ellipsesAfter
311
+ };
312
+ var previewPositions = [previewPosition];
313
+ for (var j = 1; j < contentPositions.length; j++) {
314
+ contentPosition = contentPositions[j];
315
+ if (previewPosition.previewEnd < contentPosition.previewStart) {
316
+ previewPosition = {
317
+ highlight: [contentPosition.highlight],
318
+ previewStart: contentPosition.previewStart, previewEnd: contentPosition.previewEnd,
319
+ ellipsesBefore: contentPosition.ellipsesBefore, ellipsesAfter: contentPosition.ellipsesAfter
270
320
  }
321
+ previewPositions.push(previewPosition);
322
+ } else {
323
+ previewPosition.highlight.push(contentPosition.highlight);
324
+ previewPosition.previewEnd = contentPosition.previewEnd;
325
+ previewPosition.ellipsesAfter = contentPosition.ellipsesAfter;
326
+ }
327
+ }
328
+
329
+ var resultPreviews = document.createElement('div');
330
+ resultPreviews.classList.add('search-result-previews');
331
+ resultLink.appendChild(resultPreviews);
332
+
333
+ var content = doc.content;
334
+ for (var j = 0; j < Math.min(previewPositions.length, {{ site.search.previews | default: 3 }}); j++) {
335
+ var position = previewPositions[j];
336
+
337
+ var resultPreview = document.createElement('div');
338
+ resultPreview.classList.add('search-result-preview');
339
+ resultPreviews.appendChild(resultPreview);
340
+
341
+ if (position.ellipsesBefore) {
342
+ resultPreview.appendChild(document.createTextNode('... '));
343
+ }
344
+ addHighlightedText(resultPreview, content, position.previewStart, position.previewEnd, position.highlight);
345
+ if (position.ellipsesAfter) {
346
+ resultPreview.appendChild(document.createTextNode(' ...'));
271
347
  }
272
348
  }
273
349
  }
274
- });
275
350
 
276
- jtd.addEvent(searchInput, 'blur', function(){
277
- setTimeout(function(){ hideResults() }, 300);
278
- });
351
+ {%- if site.search.rel_url != false %}
352
+ var resultRelUrl = document.createElement('span');
353
+ resultRelUrl.classList.add('search-result-rel-url');
354
+ resultRelUrl.innerText = doc.relUrl;
355
+ resultTitle.appendChild(resultRelUrl);
356
+ {%- endif %}
357
+ }
358
+
359
+ function addHighlightedText(parent, text, start, end, positions) {
360
+ var index = start;
361
+ for (var i in positions) {
362
+ var position = positions[i];
363
+ var span = document.createElement('span');
364
+ span.innerHTML = text.substring(index, position[0]);
365
+ parent.appendChild(span);
366
+ index = position[0] + position[1];
367
+ var highlight = document.createElement('span');
368
+ highlight.classList.add('search-result-highlight');
369
+ highlight.innerHTML = text.substring(position[0], index);
370
+ parent.appendChild(highlight);
371
+ }
372
+ var span = document.createElement('span');
373
+ span.innerHTML = text.substring(index, end);
374
+ parent.appendChild(span);
375
+ }
279
376
  }
280
- }
281
377
 
282
- // Focus
378
+ jtd.addEvent(searchInput, 'focus', function(){
379
+ setTimeout(update, 0);
380
+ });
283
381
 
284
- function pageFocus() {
285
- var mainContent = document.querySelector('.js-main-content');
286
- mainContent.focus();
382
+ jtd.addEvent(searchInput, 'keyup', function(e){
383
+ switch (e.keyCode) {
384
+ case 27: // When esc key is pressed, hide the results and clear the field
385
+ searchInput.value = '';
386
+ break;
387
+ case 38: // arrow up
388
+ case 40: // arrow down
389
+ case 13: // enter
390
+ e.preventDefault();
391
+ return;
392
+ }
393
+ update();
394
+ });
395
+
396
+ jtd.addEvent(searchInput, 'keydown', function(e){
397
+ switch (e.keyCode) {
398
+ case 38: // arrow up
399
+ e.preventDefault();
400
+ var active = document.querySelector('.search-result.active');
401
+ if (active) {
402
+ active.classList.remove('active');
403
+ if (active.parentElement.previousSibling) {
404
+ var previous = active.parentElement.previousSibling.querySelector('.search-result');
405
+ previous.classList.add('active');
406
+ }
407
+ }
408
+ return;
409
+ case 40: // arrow down
410
+ e.preventDefault();
411
+ var active = document.querySelector('.search-result.active');
412
+ if (active) {
413
+ if (active.parentElement.nextSibling) {
414
+ var next = active.parentElement.nextSibling.querySelector('.search-result');
415
+ active.classList.remove('active');
416
+ next.classList.add('active');
417
+ }
418
+ } else {
419
+ var next = document.querySelector('.search-result');
420
+ if (next) {
421
+ next.classList.add('active');
422
+ }
423
+ }
424
+ return;
425
+ case 13: // enter
426
+ e.preventDefault();
427
+ var active = document.querySelector('.search-result.active');
428
+ if (active) {
429
+ active.click();
430
+ } else {
431
+ var first = document.querySelector('.search-result');
432
+ if (first) {
433
+ first.click();
434
+ }
435
+ }
436
+ return;
437
+ }
438
+ });
439
+
440
+ jtd.addEvent(document, 'click', function(e){
441
+ if (e.target != searchInput) {
442
+ hideSearch();
443
+ }
444
+ });
287
445
  }
446
+ {%- endif %}
288
447
 
289
448
  // Switch theme
290
449
 
@@ -302,10 +461,9 @@ jtd.setTheme = function(theme) {
302
461
 
303
462
  jtd.onReady(function(){
304
463
  initNav();
305
- pageFocus();
306
- if (typeof lunr !== 'undefined') {
307
- initSearch();
308
- }
464
+ {%- if site.search_enabled != false %}
465
+ initSearch();
466
+ {%- endif %}
309
467
  });
310
468
 
311
469
  })(window.jtd = window.jtd || {});