-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsearch.html
146 lines (136 loc) · 5.92 KB
/
search.html
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<!DOCTYPE html>
<html>
<head>
<!-- CSS only -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-giJF6kkoqNQ00vy+HMDP7azOuL0xtbfIcaT9wjKHr8RbDVddVHyTfAAsrekwKmP1" crossorigin="anonymous">
<!-- JavaScript Bundle with Popper -->
<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/js/bootstrap.bundle.min.js" integrity="sha384-ygbV9kiqUc6oa4msXn9868pTtWMgiQaeYH7/t7LECLbyPA2x65Kgf80OJFdroafW" crossorigin="anonymous"></script>
<script src="https://d3js.org/d3.v6.min.js"></script>
<script src="https://unpkg.com/d3-geo-voronoi@1.5"></script>
<script src="https://unpkg.com/topojson@3"></script><link href="https://fonts.googleapis.com/css2?family=Fira+Sans:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap" rel="stylesheet">
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-52207113-1"></script>
<script src="https://cdn.jsdelivr.net/npm/fuse.js@6.4.6"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-52207113-1');
</script>
<style>
html, body {margin: 0; height: 100%; overflow: hidden; font-family: 'Fira Sans', sans-serif;}
.tooltip {
position: absolute;
padding: 10px;
top: -100px;
left: -100px;
font-size: 0.9em;
pointer-events: none;
background: #fff;
border: 1px solid #ccc;
border-radius: 4px;
-moz-box-shadow: 3px 3px 10px 0px rgba(0, 0, 0, 0.25);
-webkit-box-shadow: 3px 3px 10px 0px rgba(0, 0, 0, 0.25);
box-shadow: 3px 3px 10px 0px rgba(0, 0, 0, 0.25);
}
.tooltip h5 {
margin: 0;
padding: 0;
}
.tooltip p {
margin: 0;
padding: 0;
}
.tooltip table {
margin: 0;
padding: 0;
border-collapse: collapse;
}
.card-body {
display: flex;
flex-direction: column;
height: 100%;
}
ul {
flex-shrink: 1;
}
</style>
<title>Bhāṣācitra | Search</title>
</head>
<body class="bg-dark text-white">
<div class="container p-5" style="display: flex; flex-direction: column; height: 100%;">
<h1>Search</h1>
<form class="form-inline">
<input class="form-control mr-sm-2" type="search" placeholder="Enter keywords (author, title, year, and/or language)" aria-label="Search">
</form>
<p class="text-muted"><span id="count">0</span> match(es)</p>
<ul id="board" class="mt-3" style="overflow-y: scroll;"></ul>
</div>
</body>
<script src="scripts/helpers.js"></script>
<script>
const options = {
isCaseSensitive: false,
// includeScore: false,
shouldSort: true,
// includeMatches: true,
findAllMatches: true,
// minMatchCharLength: 1,
// location: 0,
threshold: 0.4,
// distance: 100,
// useExtendedSearch: false,
ignoreLocation: true,
// ignoreFieldNorm: false,
keys: [
"title",
"author",
{
name: "langs",
weight: 3,
},
"topics",
"year"
]
}
var board = d3.select("#board")
board = board.append("table")
.attr("class", "table table-light table-striped card-text text-small")
board.append("thead")
.attr("class", "thead-light")
.append("tr")
.html("<th>Author</th><th>Year</th><th>Title</th><th>Collection</th><th>Loc.</th><th>Top.</th>")
board = board.append("tbody")
var count = d3.select("#count")
d3.json("data/refs.json").then(refs => {
for (i in refs) {
refs[i].langs = Object.keys(refs[i].languages)
}
const fuse = new Fuse(refs, options)
d3.select("input")
.on("keyup", function() {
board.selectAll("tr").remove()
var search = this.value
find = fuse.search(search)
count.text(find.length)
find.forEach(z => {
var x = z.item
var note = make_ref(x)
note += "<td>"
for (language in x.languages) {
note += ` <span class="badge bg-secondary">${language}</span>`
}
note += "</td><td>"
x.topics.forEach(topic => {
note += ` <span class="badge bg-primary">${topic}</span>`
})
note += "</td>"
board.append("tr")
.html(note)
})
})
})
</script>
</html>