-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
189 lines (163 loc) · 4.44 KB
/
Copy pathindex.html
File metadata and controls
189 lines (163 loc) · 4.44 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
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Vilani Dictionary</title>
<style>
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
.container {
display: flex;
flex-direction: column;
align-items: center;
width: 100vw;
height: 100vh;
padding-bottom: 2rem;
}
h1,
h2 {
text-align: center;
font-family: sans-serif;
}
.content-container {
margin-top: 1rem;
max-width: 30rem;
width: 100%;
height: 100%;
}
button {
background: #ffe082;
font-size: 1rem;
padding: .25rem .5rem;
border-top-right-radius: .5rem;
border-bottom-right-radius: .5rem;
position: absolute;
top: 0;
right: 0;
bottom: 0;
}
input {
font-size: 1rem;
padding: .25rem .5rem;
width: 100%;
border-radius: .5rem;
outline-color: none;
}
#display {
margin-top: 2rem;
padding: 1rem;
height: 100%;
overflow-y: auto;
}
table {
margin: 2rem auto;
width: 20rem;
border-collapse: collapse;
}
td,
th {
border: 1px solid black;
padding-left: .5rem;
padding-right: .5rem;
}
.form {
width: 100%;
position: relative;
}
form {
width: 100%;
}
.disclaimer {
justify-self: flex-end;
max-width: 40rem;
padding: 2rem;
margin-bottom: 1rem;
}
</style>
</head>
<body>
<h1>Vilani Dictionary</h1>
<div class="container">
<div class="content-container">
<div class="form">
<form>
<div class="search">
<input type="text" id="search-text">
<button id="search-btn">Search</button>
</div>
</form>
</div>
<div id="display">
</div>
</div>
<div class="disclaimer">
<div class="disclaimer-content">
The Traveller game in all forms is owned by Far Future Enterprises. Copyright 1977 - 2021 Far Future
Enterprises. Traveller is a registered trademark of Far Future Enterprises. Far Future permits web sites and
fanzines for this game, provided it contains this notice, that Far Future is notified, and subject to a
withdrawal of permission on 90 days notice. The contents of this site are for personal, non-commercial use only.
Any use of Far Future Enterprises's copyrighted material or trademarks anywhere on this web site and its files
should not be viewed as a challenge to those copyrights or trademarks. In addition, any program/articles/file on
this site cannot be republished or distributed without the consent of the author who contributed it.
</div>
</div>
</div>
<!-- Load the dictionary data function -->
<script src="./js/minisearch/umd/index.min.js"></script>
<script src="./data/data.js"></script>
<script>
let searchTxt = document.getElementById('search-text');
let searchBtn = document.getElementById('search-btn');
let resultsDisplay = document.getElementById('display');
let miniSearch;
document.addEventListener('DOMContentLoaded', () => {
miniSearch = new MiniSearch({
fields: ['word', 'meaning'], // fields to index for full-text search
storeFields: ['word', 'meaning'] // fields to return with search results
});
miniSearch.addAll(words);
})
searchBtn.addEventListener('click', (e) => {
e.preventDefault();
// search the index
let results = miniSearch.search(searchTxt.value, {
prefix: true
});
console.log(results)
if (results.length === 0) {
resultsDisplay.innerHTML = `<h2>Sorry, no matches were found for <em>${searchTxt.value}</em></h2>`;
} else {
let text = `
<h2>Results</h2>
<table>
<thead>
<tr>
<th>Word</th>
<th>Meaning</th>
</tr>
</thead>
<tbody>
`;
results.forEach(res => {
text += `
<tr>
<td>${res.word}</td>
<td>${res.meaning}</td>
</tr>
`
});
text += `
</tbody>
</table>`
resultsDisplay.innerHTML = text;
searchTxt.value = '';
}
})
</script>
</body>
</html>