-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsearch.html
74 lines (60 loc) · 2.12 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
<!DOCTYPE html>
<head>
<title>IA Search</title>
<meta charset="UTF-8">
<link href="https://esm.archive.org/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" type="text/css"/>
</head>
<style>
.tile { max-width: 300px; display: inline-block; vertical-align: top; }
.tile img { width: 100%; max-width: 100%; height: auto; }
.tile a { text-decoration: none; }
</style>
<body style="margin: 25px">
<h1><img src="https://archive.org/images/glogo.png"> Search</h1>
<div class="card card-body bg-light">
<center>
<a id="js-search" class="btn btn-sm btn-primary">Find archive.org items:</a>
<form>
<input id="q" class="form-control" type="text" name="q" placeholder="" style="max-width:25%"/>
</form>
</center>
</div>
</body>
<script type="module">
// can uncomment if want to use jQuery:
// import $ from 'https://esm.archive.org/jquery'
import Search from "../lib/search.js"
import Fields from "../lib/fields.js"
import * as Query from "../lib/query.js"
import log from '../util/log.js'
function search() {
const q = document.getElementById('q').value.trim()
const any = new Query.QueryString("any", "dragon")
const media = new Query.QueryMediaType("etree")
const query = ((q === '') ? new Query.QueryAnd(any, media) : new Query.QueryRaw(q))
const client = new Search(query, Fields, 1, 500, 10000)
const tile = (hit) => {
const e = document.createElement('div')
e.classList = 'tile card card-body bg-light'
e.innerHTML = `<a>
<img/>
<h3></h3>
<i>...</i><hr>
<p></p>
</a>`
e.querySelector('a').href = hit.detailsURL;
e.querySelector('img').src = hit.imageURL;
e.querySelector('h3').innerText = hit.title;
e.querySelector('i').innerText = "Date: "+hit.publicdate;
e.querySelector('p').innerText = hit.description;
document.body.appendChild(e)
}
client.renderCallback((result) => {
result.forEach((value) => {
log(value)
tile(value)
})
})
}
document.getElementById('js-search').addEventListener('click', search)
</script>