-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsearch.md
More file actions
57 lines (51 loc) · 1.4 KB
/
search.md
File metadata and controls
57 lines (51 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
---
layout: post
title: Search
---
<style type="text/css" media="screen">
#search-container {
margin: 2em 0;
}
#search-input {
margin: 0 20% 1em;
width: -webkit-fill-available;
width: -moz-available;
}
</style>
<div id="search-container">
<input type="text" id="search-input" placeholder="search...">
<ul id="results-container"></ul>
</div>
<script src="/assets/search.js" type="text/javascript"></script>
<script>
SimpleJekyllSearch({
searchInput: document.getElementById('search-input'),
resultsContainer: document.getElementById('results-container'),
json: '/search.json',
searchResultTemplate: `<li>
<a href="{url}">
{title}
</a>
</li>`,
onInit: function() {
// pre-populate search field if queried through url
let params = (new URL(document.location)).searchParams
let query = params.get('q')
if (query != undefined) {
let searchInput = document.getElementById('search-input')
searchInput.value = query
if (document.createEvent) {
let event = document.createEvent("HTMLEvents")
event.initEvent("input", true, true)
searchInput.dispatchEvent(event)
}
// for those insane people that still use IE8 or lower(??)
else {
let event = document.createEventObject()
event.eventType = 'input'
searchInput.fireEvent('on' + event.eventType, event)
}
}
}
})
</script>